-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set time and step via ase atoms object (#103)
* test setup * prepare for setting time / step from ase.atoms object * set step / time via ase attributes * test new features * update lock
- Loading branch information
Showing
6 changed files
with
180 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "znh5md" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
description = "ASE Interface for the H5MD format." | ||
authors = ["zincwarecode <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import ase.build | ||
import h5py | ||
import numpy as np | ||
import numpy.testing as npt | ||
import pytest | ||
from ase.calculators.singlepoint import SinglePointCalculator | ||
|
||
import znh5md | ||
|
||
|
||
def test_h5md_time(tmp_path): | ||
io = znh5md.IO(tmp_path / "test_time_step.h5", store="time") | ||
for step in range(1, 10): | ||
atoms = ase.build.molecule("H2O") | ||
atoms.calc = SinglePointCalculator(atoms, energy=step * 0.1) | ||
atoms.info["h5md_step"] = step | ||
atoms.info["h5md_time"] = step * 0.5 | ||
io.append(atoms) | ||
|
||
for idx, atoms in enumerate(io[:]): | ||
assert atoms.info["h5md_step"] == idx + 1 | ||
assert atoms.info["h5md_time"] == (idx + 1) * 0.5 | ||
assert atoms.get_potential_energy() == (idx + 1) * 0.1 | ||
|
||
with h5py.File(tmp_path / "test_time_step.h5") as f: | ||
npt.assert_array_equal( | ||
f["particles/atoms/position/time"][:], np.arange(1, 10) * 0.5 | ||
) | ||
npt.assert_array_equal(f["particles/atoms/position/step"][:], np.arange(1, 10)) | ||
npt.assert_array_equal( | ||
f["observables/atoms/energy/time"][:], np.arange(1, 10) * 0.5 | ||
) | ||
npt.assert_array_equal(f["observables/atoms/energy/step"][:], np.arange(1, 10)) | ||
npt.assert_array_equal( | ||
f["observables/atoms/energy/value"][:], np.arange(1, 10) * 0.1 | ||
) | ||
|
||
|
||
def test_inconsistent_time(tmp_path): | ||
images = [ase.build.molecule("H2O") for _ in range(10)] | ||
images[5].info["h5md_time"] = 0.5 | ||
|
||
io = znh5md.IO(tmp_path / "test_inconsistent_time.h5", store="time") | ||
with pytest.raises(ValueError): | ||
io.extend(images) | ||
|
||
|
||
def test_inconsistent_step(tmp_path): | ||
images = [ase.build.molecule("H2O") for _ in range(10)] | ||
images[5].info["h5md_step"] = 5 | ||
|
||
io = znh5md.IO(tmp_path / "test_inconsistent_step.h5", store="time") | ||
with pytest.raises(ValueError): | ||
io.extend(images) | ||
|
||
|
||
def test_wrong_store(tmp_path, capsys): | ||
io = znh5md.IO(tmp_path / "test_wrong_store.h5", store="linear") | ||
atoms = ase.build.molecule("H2O") | ||
atoms.info["h5md_step"] = 1 | ||
atoms.info["h5md_time"] = 0.1 | ||
|
||
with pytest.warns( | ||
UserWarning, match="time and step are ignored in 'linear' storage mode" | ||
): | ||
io.append(atoms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
def test_version(): | ||
assert znh5md.__version__ == "0.3.1" | ||
assert znh5md.__version__ == "0.3.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.