-
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.
* save units in attrs of H5 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * hardcode PBC and 3D data * only create groups when required * fix time * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test positions * remove `initialize_database_groups` * bump version to 0.2.0 * test multiple python versions * bump version test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b2f39b6
commit aa6f9f4
Showing
16 changed files
with
371 additions
and
44 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
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
Large diffs are not rendered by default.
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
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
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,41 @@ | ||
"""Use the MDAnalysis library to read H5 files and check compliance with the H5MD standard.""" | ||
import pathlib | ||
|
||
import ase.build | ||
import MDAnalysis as mda | ||
import numpy as np | ||
import pytest | ||
from MDAnalysis.coordinates.H5MD import H5MDReader | ||
|
||
import znh5md | ||
|
||
|
||
@pytest.fixture | ||
def trajectory() -> list[ase.Atoms]: | ||
"""Generate ase.Atoms objects that moves linearly in space.""" | ||
water = ase.build.molecule("H2O") | ||
atoms_list = [water] | ||
while len(atoms_list) < 100: | ||
atoms = atoms_list[-1].copy() | ||
atoms.positions += [0.1, 0.1, 0.1] | ||
atoms_list.append(atoms) | ||
return atoms_list | ||
|
||
|
||
@pytest.fixture | ||
def h5_trajectory(tmp_path, trajectory) -> pathlib.Path: | ||
"""Write the trajectory to an H5 file.""" | ||
filename = tmp_path / "trajectory.h5" | ||
db = znh5md.io.DataWriter(filename=filename) | ||
reader = znh5md.io.AtomsReader(trajectory) | ||
db.add(reader) | ||
return filename | ||
|
||
|
||
def test_read_h5md(h5_trajectory, trajectory): | ||
u = mda.Universe.empty(n_atoms=3, trajectory=True) | ||
reader = H5MDReader(h5_trajectory) | ||
u.trajectory = reader | ||
assert len(u.trajectory) == 100 | ||
for ref, ts in zip(trajectory, u.trajectory): | ||
assert np.allclose(ref.positions, ts.positions) |
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
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
Oops, something went wrong.