Skip to content

Commit 8124a16

Browse files
Update H5MD parser and schema (#143)
* Update H5MD parser and schema * Fix linting errors * Fix linting and formatting (imports) * ruff * rebase correction --------- Co-authored-by: jrudz <rudzinski@mpip-mainz.mpg.de>
1 parent 6a568d0 commit 8124a16

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/nomad_simulation_parsers/parsers/h5md/parser.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
from nomad.parsing.parser import MatchingParser
99
from nomad.units import ureg
1010
from nomad.utils import get_logger
11-
12-
# from nomad_simulations.schema_packages.workflow import molecular_dynamics
1311
from structlog.stdlib import BoundLogger
1412

1513
from nomad_simulation_parsers.parsers.utils.mdparserutils import MDParser
1614
from nomad_simulation_parsers.schema_packages import h5md
17-
from nomad_simulation_parsers.schema_packages.h5md import MolecularDynamics, Simulation
1815

1916
LOGGER = get_logger(__name__)
2017

@@ -504,10 +501,10 @@ def write_to_archive(self) -> None:
504501
# TODO consider using a single parser for the whole archive
505502
# create metainfo parsers
506503
self.simulation_parser.annotation_key = h5md.HDF5_KEY
507-
simulation_data = Simulation()
504+
simulation_data = h5md.Simulation()
508505
self.simulation_parser.data_object = simulation_data
509506
self.workflow_parser.annotation_key = h5md.HDF5_KEY
510-
workflow_data = MolecularDynamics()
507+
workflow_data = h5md.MolecularDynamics()
511508
self.workflow_parser.data_object = workflow_data
512509

513510
# map from h5 source to metainfo target

src/nomad_simulation_parsers/parsers/lammps/file_parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def __init__(self) -> None:
435435

436436
def init_quantities(self) -> None:
437437
def str_op(val: str) -> str | list[str]:
438-
val = val.split('#', 1)[0]
438+
val = val.split('#', 1)[0]
439439
val = re.sub(f'&{RE_N}+', ' ', val)
440440
val = val.split()
441441
val = val if len(val) > 1 else val[0]

src/nomad_simulation_parsers/parsers/lammps/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def _create_custom_parser(
553553
else:
554554
# TODO: Assumes the extension is always a valid lammps dump format, improve
555555
# Fallback to file extension
556-
file_type = traj_file.split('.', 1)[-1]
556+
file_type = traj_file.rsplit('.', 1)[-1]
557557

558558
# TODO: add support for other LAMMPS dump file formats (https://docs.lammps.org/dump.html)
559559
if file_type == 'dcd' or file_type == 'xyz' and data_file:

src/nomad_simulation_parsers/schema_packages/h5md.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ class CustomProperty(physical_property.PhysicalProperty):
266266
)
267267
add_mapping_annotation(name, HDF5_KEY, '.name')
268268

269+
contribution_type = Quantity(
270+
type=str,
271+
description="""
272+
Type of contribution to the physical property.
273+
""",
274+
)
275+
269276
value = Quantity(
270277
type=np.dtype(np.float64),
271278
shape=[],

tests/parsers/test_h5md_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def assert_systems(archive: EntryArchive) -> None:
6161

6262
assert sec_systems[2].positions[80][1].to('angstrom').magnitude == approx(28.748762)
6363
assert sec_systems[2].velocities[50][2].to('angstrom/ps').magnitude == approx(400.0)
64-
assert sec_systems[3].lattice_vectors[2][2].to(
65-
'angstrom'
66-
).magnitude == approx(68.22318)
64+
assert sec_systems[3].lattice_vectors[2][2].to('angstrom').magnitude == approx(
65+
68.22318
66+
)
6767
assert sec_systems[3].periodic_boundary_conditions == [True, True, True]
6868
assert sec_systems[0].bond_list[200][0] == 198
6969
assert sec_systems[0].dimensionality == 3

0 commit comments

Comments
 (0)