Skip to content

Commit

Permalink
Merge pull request #71 from nomad-coe/49-add-support-for-h5md-files
Browse files Browse the repository at this point in the history
49 add support for h5md files
  • Loading branch information
JFRudzinski authored Jan 17, 2024
2 parents 0e51245 + 71b5133 commit 39e5685
Show file tree
Hide file tree
Showing 11 changed files with 1,162 additions and 0 deletions.
5 changes: 5 additions & 0 deletions atomisticparsers/h5md/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This is a NOMAD parser for the [H5MD](http://www.??.org/) schema for hdf5 files. It will read
an hdf5 file and transform the content into NOMAD's unified Metainfo based Archive format according to the H5MD schema.



19 changes: 19 additions & 0 deletions atomisticparsers/h5md/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from .parser import H5MDParser
31 changes: 31 additions & 0 deletions atomisticparsers/h5md/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
import json
import logging

from nomad.utils import configure_logging
from nomad.datamodel import EntryArchive
from atomisticparsers.h5md import H5MDParser

if __name__ == "__main__":
configure_logging(console_log_level=logging.DEBUG)
archive = EntryArchive()
H5MDParser().parse(sys.argv[1], archive, logging)
json.dump(archive.m_to_dict(), sys.stdout, indent=2)
24 changes: 24 additions & 0 deletions atomisticparsers/h5md/metainfo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from nomad.metainfo import Environment

from . import h5md

m_env = Environment()
m_env.m_add_sub_section(Environment.packages, h5md.m_package)
190 changes: 190 additions & 0 deletions atomisticparsers/h5md/metainfo/h5md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import numpy as np # pylint: disable=unused-import
import typing # pylint: disable=unused-import
from nomad.metainfo import ( # pylint: disable=unused-import
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference
)
from nomad.datamodel.metainfo import simulation


m_package = Package()


class ParamEntry(MSection):
'''
Generic section defining a parameter name and value
'''

m_def = Section(validate=False)

kind = Quantity(
type=str,
shape=[],
description='''
Name of the parameter.
''')

value = Quantity(
type=str,
shape=[],
description='''
Value of the parameter as a string.
''')

unit = Quantity(
type=str,
shape=[],
description='''
Unit of the parameter as a string.
''')

# TODO add description quantity


class CalcEntry(MSection):
'''
Section describing a general type of calculation.
'''

m_def = Section(validate=False)

kind = Quantity(
type=str,
shape=[],
description='''
Kind of the quantity.
''')

value = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Value of this contribution.
''')

unit = Quantity(
type=str,
shape=[],
description='''
Unit of the parameter as a string.
''')

# TODO add description quantity

class ForceCalculations(simulation.method.ForceCalculations):

m_def = Section(validate=False, extends_base_section=True,)

x_h5md_parameters = SubSection(
sub_section=ParamEntry.m_def,
description='''
Contains non-normalized force calculation parameters.
''',
repeats=True)

class NeighborSearching(simulation.method.NeighborSearching):

m_def = Section(validate=False, extends_base_section=True,)

x_h5md_parameters = SubSection(
sub_section=ParamEntry.m_def,
description='''
Contains non-normalized neighbor searching parameters.
''',
repeats=True)

class AtomsGroup(simulation.system.AtomsGroup):
'''
Describes a group of atoms which may constitute a sub system as in the case of a
molecule.
'''

m_def = Section(validate=False, extends_base_section=True,)

x_h5md_parameters = SubSection( # TODO should this be called parameters or attributes or what?
sub_section=ParamEntry.m_def,
description='''
Contains additional information about the atom group .
''',
repeats=True)


class Calculation(simulation.calculation.Calculation):

m_def = Section(validate=False, extends_base_section=True,)

x_h5md_custom_calculations = SubSection(
sub_section=ParamEntry.m_def,
description='''
Contains other generic custom calculations that are not already defined.
''',
repeats=True)


class Energy(simulation.calculation.Energy):

m_def = Section(validate=False, extends_base_section=True,)

x_h5md_energy_contributions = SubSection(
sub_section=simulation.calculation.EnergyEntry.m_def,
description='''
Contains other custom energy contributions that are not already defined.
''',
repeats=True)


class Author(MSection):
'''
Contains the specifications of the program.
'''

m_def = Section(validate=False)

name = Quantity(
type=str,
shape=[],
description='''
Specifies the name of the author who generated the h5md file.
''',)

email = Quantity(
type=str,
shape=[],
description='''
Author's email.
''',)


class Run(simulation.run.Run):

m_def = Section(validate=False, extends_base_section=True,)

# TODO Not sure how we are dealing with versioning with H5MD-NOMAD
x_h5md_version = Quantity(
type=np.dtype(np.int32),
shape=[2],
description='''
Specifies the version of the h5md schema being followed.
''',)

x_h5md_author = SubSection(sub_section=Author.m_def)

x_h5md_creator = SubSection(sub_section=simulation.run.Program.m_def)
19 changes: 19 additions & 0 deletions atomisticparsers/h5md/nomad_plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
code_category: Atomistic code
# code_homepage: http://www.??.org/
# TODO is this the correct category
code_name: H5MD
metadata:
codeCategory: Atomistic code
codeLabel: H5MD
codeLabelStyle: All in capitals
codeName: h5md
# codeUrl: http://www.??.org/
parserDirName: dependencies/parsers/atomistic/atomisticparsers/h5md/
parserGitUrl: https://github.com/nomad-coe/atomistic-parsers.git
parserSpecific: ''
preamble: ''
status: production
tableOfFiles: ''
name: parsers/h5md
parser_class_name: atomisticparsers.h5md.parser.H5MDParser
python_package: atomisticparsers.h5md
Loading

0 comments on commit 39e5685

Please sign in to comment.