diff --git a/janus_core/cli.py b/janus_core/cli.py index 3a33cb3c..483efdd2 100644 --- a/janus_core/cli.py +++ b/janus_core/cli.py @@ -155,6 +155,16 @@ def singlepoint( ), ), ] = None, + out_file: Annotated[ + Path, + typer.Option( + "--out", + help=( + "Path to save structure with calculated results. Default is inferred " + "from name of structure file." + ), + ), + ] = None, read_kwargs: ReadKwargs = None, calc_kwargs: CalcKwargs = None, write_kwargs: WriteKwargs = None, @@ -174,6 +184,9 @@ def singlepoint( Device to run model on. Default is "cpu". properties : Optional[str] Physical properties to calculate. Default is "energy". + out_file : Optional[Path] + Path to save structure with calculated results. Default is inferred from name + of the structure file. read_kwargs : Optional[dict[str, Any]] Keyword arguments to pass to ase.io.read. Default is {}. calc_kwargs : Optional[dict[str, Any]] @@ -187,6 +200,14 @@ def singlepoint( [read_kwargs, calc_kwargs, write_kwargs] ) + # Check filename for results not duplicated + if "filename" in write_kwargs: + raise ValueError("'filename' must be passed through the --out option") + + # Default filname for saving results determined in SinglePoint if not specified + if out_file: + write_kwargs["filename"] = out_file + s_point = SinglePoint( struct_path=struct_path, architecture=architecture, @@ -225,10 +246,10 @@ def geomopt( # pylint: disable=too-many-arguments,too-many-locals help="Fully optimize the cell vectors, angles, and atomic positions.", ), ] = False, - opt_file: Annotated[ + out_file: Annotated[ Path, typer.Option( - "--opt", + "--out", help=( "Path to save optimized structure. Default is inferred from name " "of structure file." @@ -282,7 +303,7 @@ def geomopt( # pylint: disable=too-many-arguments,too-many-locals fully_opt : bool Whether to fully optimize the cell vectors, angles, and atomic positions. Default is False. - opt_file : Optional[Path] + out_file : Optional[Path] Path to save optimized structure, or last structure if optimization did not converge. Default is inferred from name of structure file. traj_file : Optional[str] @@ -315,15 +336,15 @@ def geomopt( # pylint: disable=too-many-arguments,too-many-locals # Check optimized structure path not duplicated if "filename" in write_kwargs: - raise ValueError("'filename' must be passed through the --opt option") + raise ValueError("'filename' must be passed through the --out option") # Check trajectory path not duplicated if "trajectory" in opt_kwargs: raise ValueError("'trajectory' must be passed through the --traj option") # Set default filname for writing optimized structure if not specified - if opt_file: - write_kwargs["filename"] = opt_file + if out_file: + write_kwargs["filename"] = out_file else: write_kwargs["filename"] = f"{s_point.struct_name}-opt.xyz" diff --git a/tests/test_geomopt_cli.py b/tests/test_geomopt_cli.py index 074f96eb..4ccbe0ae 100644 --- a/tests/test_geomopt_cli.py +++ b/tests/test_geomopt_cli.py @@ -53,7 +53,7 @@ def test_geomopt_log(tmp_path, caplog): "geomopt", "--struct", DATA_PATH / "NaCl.cif", - "--opt", + "--out", results_path, "--log", f"{tmp_path}/test.log", @@ -75,7 +75,7 @@ def test_geomopt_traj(tmp_path): "geomopt", "--struct", DATA_PATH / "NaCl.cif", - "--opt", + "--out", results_path, "--traj", traj_path, @@ -97,7 +97,7 @@ def test_fully_opt(tmp_path, caplog): "geomopt", "--struct", DATA_PATH / "NaCl-deformed.cif", - "--opt", + "--out", results_path, "--fully-opt", ], @@ -123,7 +123,7 @@ def test_fully_opt_and_vectors(tmp_path, caplog): DATA_PATH / "NaCl-deformed.cif", "--fully-opt", "--vectors-only", - "--opt", + "--out", results_path, "--log", f"{tmp_path}/test.log", @@ -148,7 +148,7 @@ def test_vectors_not_fully_opt(tmp_path, caplog): "geomopt", "--struct", DATA_PATH / "NaCl.cif", - "--opt", + "--out", results_path, "--vectors-only", ], @@ -186,7 +186,7 @@ def test_restart(tmp_path): "geomopt", "--struct", data_path, - "--opt", + "--out", results_path, "--opt-kwargs", f"{{'restart': '{str(restart_path)}'}}", @@ -204,7 +204,7 @@ def test_restart(tmp_path): "geomopt", "--struct", DATA_PATH / "NaCl.cif", - "--opt", + "--out", results_path, "--opt-kwargs", f"{{'restart': '{str(restart_path)}'}}", diff --git a/tests/test_singlepoint_cli.py b/tests/test_singlepoint_cli.py index 555557a5..be25aa05 100644 --- a/tests/test_singlepoint_cli.py +++ b/tests/test_singlepoint_cli.py @@ -62,8 +62,8 @@ def test_singlepoint_properties(tmp_path): DATA_PATH / "H2O.cif", "--property", "energy", - "--write-kwargs", - f"{{'filename': '{str(results_path_1)}'}}", + "--out", + results_path_1, ], ) assert result.exit_code == 0 @@ -79,8 +79,8 @@ def test_singlepoint_properties(tmp_path): DATA_PATH / "H2O.cif", "--property", "stress", - "--write-kwargs", - f"{{'filename': '{str(results_path_2)}'}}", + "--out", + results_path_2, ], ) assert result.exit_code == 1 @@ -100,8 +100,8 @@ def test_singlepoint_read_kwargs(tmp_path): DATA_PATH / "benzene-traj.xyz", "--read-kwargs", "{'index': ':'}", - "--write-kwargs", - f"{{'filename': '{str(results_path)}'}}", + "--out", + results_path, "--property", "energy", ], @@ -124,8 +124,8 @@ def test_singlepoint_calc_kwargs(tmp_path): DATA_PATH / "NaCl.cif", "--calc-kwargs", "{'default_dtype': 'float32'}", - "--write-kwargs", - f"{{'filename': '{str(results_path)}'}}", + "--out", + results_path, "--property", "energy", ], @@ -146,8 +146,8 @@ def test_singlepoint_log(tmp_path, caplog): DATA_PATH / "NaCl.cif", "--property", "energy", - "--write-kwargs", - f"{{'filename': '{str(results_path)}'}}", + "--out", + results_path, "--log", f"{tmp_path}/test.log", ],