Skip to content

Commit dcde09e

Browse files
committed
Run ruff format on src/
1 parent ac4aa7d commit dcde09e

5 files changed

Lines changed: 128 additions & 151 deletions

File tree

src/matkit/cli.py

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def graspa_batch_setup(
115115
cutoff=cutoff,
116116
n_cycle=cycles,
117117
)
118-
click.echo(
119-
f"Set up {len(manifest)} simulations in {outdir}"
120-
)
118+
click.echo(f"Set up {len(manifest)} simulations in {outdir}")
121119
click.echo(f"Manifest written to {outdir}/simulations.jsonl")
122120
except Exception as e:
123121
click.echo(f"Error setting up batch simulations: {e}", err=True)
@@ -626,14 +624,10 @@ def mlip_cli():
626624
@click.option(
627625
"--run-type",
628626
default="geo_opt",
629-
type=click.Choice(
630-
["geo_opt", "cell_opt", "geo_opt_cell_opt"]
631-
),
627+
type=click.Choice(["geo_opt", "cell_opt", "geo_opt_cell_opt"]),
632628
help="Optimization type.",
633629
)
634-
@click.option(
635-
"--steps", default=1000, help="Max optimization steps."
636-
)
630+
@click.option("--steps", default=1000, help="Max optimization steps.")
637631
@click.option(
638632
"--fmax",
639633
default=1e-3,
@@ -722,14 +716,10 @@ def mace_opt_cmd(
722716
@click.option(
723717
"--run-type",
724718
default="geo_opt",
725-
type=click.Choice(
726-
["geo_opt", "cell_opt", "geo_opt_cell_opt"]
727-
),
719+
type=click.Choice(["geo_opt", "cell_opt", "geo_opt_cell_opt"]),
728720
help="Optimization type.",
729721
)
730-
@click.option(
731-
"--steps", default=1000, help="Max optimization steps."
732-
)
722+
@click.option("--steps", default=1000, help="Max optimization steps.")
733723
@click.option(
734724
"--fmax",
735725
default=1e-3,
@@ -743,9 +733,7 @@ def mace_opt_cmd(
743733
@click.option(
744734
"--task-name",
745735
default="omat",
746-
type=click.Choice(
747-
["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]
748-
),
736+
type=click.Choice(["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]),
749737
help="Task head for domain-specific prediction.",
750738
)
751739
@click.option(
@@ -817,9 +805,7 @@ def uma_opt_cmd(
817805
@click.option(
818806
"--task-name",
819807
default="omat",
820-
type=click.Choice(
821-
["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]
822-
),
808+
type=click.Choice(["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]),
823809
help="Task head for domain-specific prediction.",
824810
)
825811
@click.option(
@@ -865,9 +851,7 @@ def uma_sp_cmd(fname, model, task_name, device):
865851
@click.option(
866852
"--task-name",
867853
default="omat",
868-
type=click.Choice(
869-
["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]
870-
),
854+
type=click.Choice(["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]),
871855
help="Task head for domain-specific prediction.",
872856
)
873857
@click.option(
@@ -886,9 +870,7 @@ def uma_sp_cmd(fname, model, task_name, device):
886870
default=1.0,
887871
help="MD timestep in femtoseconds.",
888872
)
889-
@click.option(
890-
"--steps", default=1000, help="Number of MD steps."
891-
)
873+
@click.option("--steps", default=1000, help="Number of MD steps.")
892874
@click.option(
893875
"--ensemble",
894876
default="nvt",
@@ -985,22 +967,16 @@ def uma_md_cmd(
985967
"run_types",
986968
multiple=True,
987969
default=["geo_opt"],
988-
type=click.Choice(
989-
["geo_opt", "cell_opt", "geo_opt_cell_opt"]
990-
),
970+
type=click.Choice(["geo_opt", "cell_opt", "geo_opt_cell_opt"]),
991971
help="Optimization type(s). Can be specified multiple times.",
992972
)
993973
@click.option(
994974
"--task-name",
995975
default="omat",
996-
type=click.Choice(
997-
["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]
998-
),
976+
type=click.Choice(["omat", "oc20", "oc22", "oc25", "omol", "odac", "omc"]),
999977
help="Task head for domain-specific prediction.",
1000978
)
1001-
@click.option(
1002-
"--steps", default=1000, help="Max optimization steps."
1003-
)
979+
@click.option("--steps", default=1000, help="Max optimization steps.")
1004980
@click.option(
1005981
"--fmax",
1006982
default=1e-3,
@@ -1138,8 +1114,17 @@ def zeopp_cli():
11381114
type=click.Path(),
11391115
help="Output directory for result files.",
11401116
)
1141-
def zeopp_run(cif, analysis, probe_radius, chan_radius, num_samples,
1142-
ha, radii, network_path, outdir):
1117+
def zeopp_run(
1118+
cif,
1119+
analysis,
1120+
probe_radius,
1121+
chan_radius,
1122+
num_samples,
1123+
ha,
1124+
radii,
1125+
network_path,
1126+
outdir,
1127+
):
11431128
"""Run Zeo++ analysis on a CIF structure."""
11441129
from matkit.zeopp import run_zeopp
11451130

@@ -1244,9 +1229,16 @@ def zeopp_analyze(path, analysis):
12441229
help="Max parallel processes. Default: CPU count.",
12451230
)
12461231
def zeopp_run_batch(
1247-
cif_dir, outdir, analysis, probe_radius,
1248-
chan_radius, num_samples, ha, radii,
1249-
network_path, max_workers,
1232+
cif_dir,
1233+
outdir,
1234+
analysis,
1235+
probe_radius,
1236+
chan_radius,
1237+
num_samples,
1238+
ha,
1239+
radii,
1240+
network_path,
1241+
max_workers,
12501242
):
12511243
"""Run Zeo++ on all CIFs in a directory.
12521244

src/matkit/mlip/uma.py

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ase.io import read as ase_read
44
from ase.io import write as ase_write
55
from ase.optimize import BFGS
6+
67
try:
78
from ase.filters import ExpCellFilter
89
except ImportError:
@@ -33,9 +34,7 @@ def _create_calculator(
3334
"""
3435
from fairchem.core import pretrained_mlip, FAIRChemCalculator
3536

36-
predictor = pretrained_mlip.get_predict_unit(
37-
model, device=device
38-
)
37+
predictor = pretrained_mlip.get_predict_unit(model, device=device)
3938
return FAIRChemCalculator(predictor, task_name=task_name)
4039

4140

@@ -85,21 +84,13 @@ def _run_opt_uma_with_calc(
8584
converged = dyn.run(fmax=fmax_cell, steps=steps)
8685
total_steps = dyn.nsteps
8786
elif run_type == "geo_opt_cell_opt":
88-
traj1 = (
89-
f"{traj_prefix}_geo_opt.traj"
90-
if write_traj
91-
else None
92-
)
87+
traj1 = f"{traj_prefix}_geo_opt.traj" if write_traj else None
9388
dyn1 = BFGS(atoms, trajectory=traj1)
9489
dyn1.run(fmax=fmax, steps=steps)
9590
total_steps += dyn1.nsteps
9691

9792
ecf = ExpCellFilter(atoms)
98-
traj2 = (
99-
f"{traj_prefix}_cell_opt.traj"
100-
if write_traj
101-
else None
102-
)
93+
traj2 = f"{traj_prefix}_cell_opt.traj" if write_traj else None
10394
dyn2 = BFGS(ecf, trajectory=traj2)
10495
converged = dyn2.run(fmax=fmax_cell, steps=steps)
10596
total_steps += dyn2.nsteps
@@ -264,8 +255,7 @@ def run_md_uma(
264255
)
265256
else:
266257
raise ValueError(
267-
f"ensemble '{ensemble}' is not supported. "
268-
"Options: 'nve', 'nvt'."
258+
f"ensemble '{ensemble}' is not supported. Options: 'nve', 'nvt'."
269259
)
270260

271261
dyn.run(steps=steps)
@@ -312,18 +302,20 @@ def _gpu_worker(
312302
output_cif = outdir / f"{tag}.cif"
313303

314304
if output_cif.exists() and not overwrite:
315-
result_queue.put({
316-
"structure": stem,
317-
"model": model,
318-
"run_type": run_type,
319-
"task_name": task_name,
320-
"status": "skipped",
321-
"output_file": str(output_cif),
322-
"converged": None,
323-
"final_energy": None,
324-
"n_steps": None,
325-
"error_message": None,
326-
})
305+
result_queue.put(
306+
{
307+
"structure": stem,
308+
"model": model,
309+
"run_type": run_type,
310+
"task_name": task_name,
311+
"status": "skipped",
312+
"output_file": str(output_cif),
313+
"converged": None,
314+
"final_energy": None,
315+
"n_steps": None,
316+
"error_message": None,
317+
}
318+
)
327319
continue
328320

329321
try:
@@ -355,36 +347,40 @@ def _gpu_worker(
355347

356348
ase_write(str(output_cif), atoms)
357349

358-
result_queue.put({
359-
"structure": stem,
360-
"model": model,
361-
"run_type": run_type,
362-
"task_name": task_name,
363-
"status": "success",
364-
"output_file": str(output_cif),
365-
"converged": result["converged"],
366-
"final_energy": result["final_energy"],
367-
"n_steps": result["n_steps"],
368-
"error_message": None,
369-
})
350+
result_queue.put(
351+
{
352+
"structure": stem,
353+
"model": model,
354+
"run_type": run_type,
355+
"task_name": task_name,
356+
"status": "success",
357+
"output_file": str(output_cif),
358+
"converged": result["converged"],
359+
"final_energy": result["final_energy"],
360+
"n_steps": result["n_steps"],
361+
"error_message": None,
362+
}
363+
)
370364
print(
371365
f"[GPU {gpu_id}] Done: {tag} "
372366
f"(E={result['final_energy']:.4f}, "
373367
f"converged={result['converged']})"
374368
)
375369
except Exception as e:
376-
result_queue.put({
377-
"structure": stem,
378-
"model": model,
379-
"run_type": run_type,
380-
"task_name": task_name,
381-
"status": "failure",
382-
"output_file": None,
383-
"converged": None,
384-
"final_energy": None,
385-
"n_steps": None,
386-
"error_message": str(e),
387-
})
370+
result_queue.put(
371+
{
372+
"structure": stem,
373+
"model": model,
374+
"run_type": run_type,
375+
"task_name": task_name,
376+
"status": "failure",
377+
"output_file": None,
378+
"converged": None,
379+
"final_energy": None,
380+
"n_steps": None,
381+
"error_message": str(e),
382+
}
383+
)
388384
print(f"[GPU {gpu_id}] ERROR: {tag}: {e}")
389385

390386

@@ -441,19 +437,13 @@ def run_opt_uma_batch(
441437

442438
input_p = Path(input_path)
443439
if input_p.is_dir():
444-
input_files = sorted(
445-
str(f) for f in input_p.glob("*.cif")
446-
)
440+
input_files = sorted(str(f) for f in input_p.glob("*.cif"))
447441
if not input_files:
448-
raise FileNotFoundError(
449-
f"No CIF files found in: {input_path}"
450-
)
442+
raise FileNotFoundError(f"No CIF files found in: {input_path}")
451443
else:
452444
input_files = [str(input_p)]
453445

454-
jobs = list(
455-
itertools.product(input_files, models, run_types)
456-
)
446+
jobs = list(itertools.product(input_files, models, run_types))
457447
if not jobs:
458448
print("No jobs to run.")
459449
return ""
@@ -475,8 +465,7 @@ def run_opt_uma_batch(
475465
n_workers = min(num_gpus, len(jobs))
476466

477467
print(
478-
f"Running {len(jobs)} jobs across "
479-
f"{n_workers} workers (device={device})"
468+
f"Running {len(jobs)} jobs across {n_workers} workers (device={device})"
480469
)
481470

482471
ctx = get_context("spawn")
@@ -517,9 +506,7 @@ def run_opt_uma_batch(
517506
while not result_queue.empty():
518507
results.append(result_queue.get())
519508

520-
results.sort(
521-
key=lambda r: (r["structure"], r["model"], r["run_type"])
522-
)
509+
results.sort(key=lambda r: (r["structure"], r["model"], r["run_type"]))
523510

524511
outdir = Path(output_dir)
525512
outdir.mkdir(parents=True, exist_ok=True)

src/matkit/tobacco/create_linker_from_smiles.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ def smiles_to_cif(smiles, output_prefix="L1"):
269269
d = struct.get_distance(i, j, mic=True)
270270
jlabel = f"{struct[j].symbol}{j + 1}"
271271
dist = round(d, 4)
272-
bond_block += (
273-
f"{label:<6}{jlabel:<6}"
274-
f"{dist:<8}. S\n"
275-
)
272+
bond_block += f"{label:<6}{jlabel:<6}{dist:<8}. S\n"
276273

277274
with open(final_cif, "w", encoding="utf-8") as f:
278275
f.write(

0 commit comments

Comments
 (0)