Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IndexError #88

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "znh5md"
version = "0.1.8"
version = "0.1.9"
description = "High Performance Interface for H5MD Trajectories"
authors = ["zincwarecode <zincwarecode@gmail.com>"]
license = "Apache-2.0"
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ def atoms_list(request) -> list[ase.Atoms]:
)
for _ in range(21)
]

if getattr(request, "param", "").endswith("vary_pbc"):
atoms[0].pbc = np.array([True, True, False])
atoms[1].pbc = np.array([True, False, True])
16 changes: 16 additions & 0 deletions tests/test_ASEH5MD.py
Original file line number Diff line number Diff line change
@@ -70,3 +70,19 @@ def test_request_missing_properties(tmp_path, atoms_list, remove_calc):
group_names=["stress"]
):
db.add_chunk_data(**chunk)


@pytest.mark.parametrize("atoms_list", ["vary_size"], indirect=True)
def test_skip_property(tmp_path, atoms_list):
os.chdir(tmp_path)

db = znh5md.io.DataWriter(filename="db.h5")
db.initialize_database_groups()

atoms_list[-1].arrays.pop("momenta")
atoms_list[-1].get_momenta()

db.add(znh5md.io.AtomsReader(atoms_list))

traj = znh5md.ASEH5MD("db.h5")
assert traj.get_atoms_list() == atoms_list
2 changes: 1 addition & 1 deletion tests/test_znh5md.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@


def test_version():
assert znh5md.__version__ == "0.1.8"
assert znh5md.__version__ == "0.1.9"


def test_shape(example_h5):
14 changes: 9 additions & 5 deletions znh5md/znh5md/h5ase.py
Original file line number Diff line number Diff line change
@@ -17,11 +17,15 @@ def _gather_value(particles_data, key, idx):

Returns None if the key is not present in the data.
"""
if key in particles_data:
if key in [GRP.species, GRP.position, GRP.velocity, GRP.forces, GRP.momentum]:
# use PARTICLES_GRP
return rm_nan(particles_data[key][idx])
return particles_data[key][idx]
try:
if key in particles_data:
if key in [GRP.species, GRP.position, GRP.velocity, GRP.forces, GRP.momentum]:
# use PARTICLES_GRP
return rm_nan(particles_data[key][idx])
return particles_data[key][idx]
except IndexError:
# a property might not be available at all frames.
pass
return None