Skip to content

Commit

Permalink
Read all structures in trajectory by default (#165)
Browse files Browse the repository at this point in the history
* Read full trajectory by default

---------

Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com>
  • Loading branch information
ElliottKasoar and oerc0122 committed May 30, 2024
1 parent 823494b commit 5168039
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ janus singlepoint --struct tests/data/NaCl.cif --arch mace --calc-kwargs "{'mode

This calculates both forces and energies, defines the MLIP architecture and path to your locally saved model, and changes where the log and results files are saved.

Note: the MACE calculator currently returns energy, forces and stress together, so in this case the choice of property will not change the output.
> [!NOTE]
> The MACE calculator currently returns energy, forces and stress together, so in this case the choice of property will not change the output.
By default, all structures in a trajectory file will be read, but specific structures can be selected using --read-kwargs:

```shell
janus singlepoint --struct tests/data/benzene-traj.xyz --read-kwargs "{'index': 0}"
```

For all options, run `janus singlepoint --help`.

Expand Down
12 changes: 10 additions & 2 deletions janus_core/calculations/single_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class SinglePoint:
device : Devices
Device to run model on. Default is "cpu".
read_kwargs : ASEReadArgs
Keyword arguments to pass to ase.io.read. Default is {}.
Keyword arguments to pass to ase.io.read. By default,
read_kwargs["index"] is ":".
calc_kwargs : Optional[dict[str, Any]]
Keyword arguments to pass to the selected calculator. Default is {}.
log_kwargs : Optional[dict[str, Any]]
Expand Down Expand Up @@ -105,7 +106,8 @@ def __init__(
device : Devices
Device to run MLIP model on. Default is "cpu".
read_kwargs : Optional[ASEReadArgs]
Keyword arguments to pass to ase.io.read. Default is {}.
Keyword arguments to pass to ase.io.read. By default,
read_kwargs["index"] is ":".
calc_kwargs : Optional[dict[str, Any]]
Keyword arguments to pass to the selected calculator. Default is {}.
log_kwargs : Optional[dict[str, Any]]
Expand Down Expand Up @@ -138,6 +140,9 @@ def __init__(
self.struct_path = struct_path
self.struct_name = struct_name

# Read full trajectory by default
read_kwargs.setdefault("index", ":")

# Read structure if given as path
if self.struct_path:
self.read_structure(**read_kwargs)
Expand Down Expand Up @@ -196,6 +201,9 @@ def set_calculator(
if isinstance(self.struct, list):
for struct in self.struct:
struct.calc = calculator
# Return single Atoms object if only one image in list
if len(self.struct) == 1:
self.struct = self.struct[0]
else:
self.struct.calc = calculator

Expand Down
2 changes: 1 addition & 1 deletion tests/data/singlepoint_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ out: "NaCl-results.xyz"
calc-kwargs:
model: "small"
read-kwargs:
index: ":"
index: 0
1 change: 0 additions & 1 deletion tests/test_single_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def test_single_point_traj():
single_point = SinglePoint(
struct_path=DATA_PATH / "benzene-traj.xyz",
architecture="mace",
read_kwargs={"index": ":"},
calc_kwargs={"model": MODEL_PATH},
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_singlepoint_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ def test_config(tmp_path):
)
assert result.exit_code == 0
atoms = read(results_path, index=":")
assert len(atoms) == 2
assert len(atoms) == 1

# Read singlepoint summary file
with open(summary_path, encoding="utf8") as file:
sp_summary = yaml.safe_load(file)

assert "index" in sp_summary["inputs"]["calc"]["read_kwargs"]
assert sp_summary["inputs"]["calc"]["read_kwargs"]["index"] == ":"
assert sp_summary["inputs"]["calc"]["read_kwargs"]["index"] == 0


def test_invalid_config():
Expand Down

0 comments on commit 5168039

Please sign in to comment.