-
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.
* bump version * add test case * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test info/calc/arrays * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * partial test * partial bugfix * bugfix finalize * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * undo * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * partially fixed * final bugfix * remove debug prints * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove comment * fix version test * test frames as well * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * another test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8fc920a
commit fa64d56
Showing
5 changed files
with
98 additions
and
25 deletions.
There are no files selected for viewing
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
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 numpy.testing as npt | ||
from ase.build import molecule | ||
from ase.calculators.singlepoint import SinglePointCalculator | ||
|
||
import znh5md | ||
import znh5md.serialization | ||
|
||
|
||
def test_single_entry_info(tmp_path): | ||
# Test a special case where only the first config has the key | ||
# which caused an error in the past | ||
io = znh5md.IO(tmp_path / "test.h5") | ||
water = molecule("H2O") | ||
water.info["density"] = 0.997 | ||
io.append(water) | ||
del water.info["density"] | ||
io.extend([water for _ in range(5)]) | ||
assert len(io) == 6 | ||
assert len(list(io)) == 6 | ||
assert len(io[:]) == 6 | ||
assert io[0].info["density"] == 0.997 | ||
assert "density" not in io[1].info | ||
|
||
frames = znh5md.serialization.Frames.from_ase(list(io)) | ||
assert len(frames) == 6 | ||
assert len(list(frames)) == 6 | ||
|
||
|
||
def test_single_entry_arrays(tmp_path): | ||
# Test a special case where only the first config has the key | ||
# which caused an error in the past | ||
io = znh5md.IO(tmp_path / "test.h5") | ||
water = molecule("H2O") | ||
water.arrays["density"] = [0.997, 0.998, 0.999] | ||
io.append(water) | ||
del water.arrays["density"] | ||
io.extend([water for _ in range(5)]) | ||
assert len(io) == 6 | ||
assert len(list(io)) == 6 | ||
assert len(io[:]) == 6 | ||
npt.assert_array_equal(io[0].arrays["density"], [0.997, 0.998, 0.999]) | ||
assert "density" not in io[1].arrays | ||
|
||
frames = znh5md.serialization.Frames.from_ase(list(io)) | ||
assert len(frames) == 6 | ||
assert len(list(frames)) == 6 | ||
|
||
|
||
def test_single_entry_calc(tmp_path): | ||
# Test a special case where only the first config has the key | ||
# which caused an error in the past | ||
io = znh5md.IO(tmp_path / "test.h5") | ||
water = molecule("H2O") | ||
water.calc = SinglePointCalculator(water, energy=0.0, forces=[0.0, 0.0, 0.0]) | ||
io.append(water) | ||
water.calc = None | ||
io.extend([water for _ in range(5)]) | ||
assert len(io) == 6 | ||
assert len(list(io)) == 6 | ||
assert len(io[:]) == 6 | ||
assert io[0].calc.results["energy"] == 0.0 | ||
assert io[1].calc is None | ||
|
||
frames = znh5md.serialization.Frames.from_ase(list(io)) | ||
assert len(frames) == 6 | ||
assert len(list(frames)) == 6 |
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
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
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