Skip to content

Commit

Permalink
Entry point (#14)
Browse files Browse the repository at this point in the history
* Add entry point

* Update nomad-lab

* Fix commit

* Move specs to entry point

* Add other parser specs

* Fix init

* Revert

* Remove import

* Add aliases
  • Loading branch information
ladinesa authored Sep 2, 2024
1 parent fd38bde commit defb8c2
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pip install --upgrade pip
pip install '.[tests]' --index-url https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple
# we need the latest nomad version for testing
pip install nomad-lab[infrastructure]@git+https://github.com/nomad-coe/nomad.git@develop
#pip install nomad-lab[infrastructure]@git+https://github.com/nomad-coe/nomad.git@develop
pip install coverage coveralls
- name: mypy
run: |
Expand Down
52 changes: 51 additions & 1 deletion databaseparsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,55 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from pydantic import Field
from typing import Optional

# from .openkim.parser import OpenKIMParser
from nomad.config.models.plugins import ParserEntryPoint


class EntryPoint(ParserEntryPoint):
parser_class_name: str = Field(
description="""
The fully qualified name of the Python class that implements the parser.
This class must have a function `def parse(self, mainfile, archive, logger)`.
"""
)
code_name: Optional[str]
code_homepage: Optional[str]
code_category: Optional[str]
metadata: Optional[dict] = Field(
description="""
Metadata passed to the UI. Deprecated. """
)

def load(self):
from nomad.parsing import MatchingParserInterface

return MatchingParserInterface(**self.dict())


openkim_parser_entry_point = EntryPoint(
name='parsers/openkim',
aliases=['parsers/openkim'],
description='NOMAD parser for OPENKIM.',
python_package='databaseparsers.openkim',
mainfile_contents_re=r'openkim|OPENKIM|OpenKIM',
mainfile_mime_re='(application/json)|(text/.*)',
parser_class_name='databaseparsers.openkim.OpenKIMParser',
code_name='OpenKIM',
code_homepage='https://openkim.org/',
code_category='Database manager',
metadata={
'codeCategory': 'Database manager',
'codeLabel': 'OpenKIM',
'codeLabelStyle': 'Capitals: O,K,I,M',
'codeName': 'openkim',
'codeUrl': 'https://openkim.org/',
'parserDirName': 'dependencies/parsers/database/databaseparsers/openkim/',
'parserGitUrl': 'https://github.com/nomad-coe/database-parsers.git',
'parserSpecific': '',
'preamble': '',
'status': 'production',
'tableOfFiles': '',
},
)
59 changes: 39 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ readme = "README.md"
authors = [{ name = "The NOMAD Authors" }]
license = { file = "LICENSE" }
dependencies = [
"nomad-lab>=1.3.6.dev1",
"nomad-schema-plugin-simulation-workflow@git+https://github.com/nomad-coe/nomad-schema-plugin-simulation-workflow.git@develop",
"nomad-schema-plugin-run@git+https://github.com/nomad-coe/nomad-schema-plugin-run.git@develop"
"nomad-schema-plugin-run@git+https://github.com/nomad-coe/nomad-schema-plugin-run.git@develop",
"pydantic>=1.10.8,<2.0.0",
]

[project.urls]
Expand All @@ -28,40 +30,57 @@ tests = [
"pytest-cov==2.7.1",
"astroid==2.11.7",
"typing-extensions==4.4.0",
"ruff==0.1.4",
"ruff==0.1.8",
]

[tool.ruff]
include = ["electronicparsers/*.py", "tests/*.py"]
select = [
lint.select = [
"E", # pycodestyle
"W", # pycodestyle
"PL", # pylint
]
ignore = [
"E501", # Line too long ({width} > {limit} characters)
"E701", # Multiple statements on one line (colon)
"E731", # Do not assign a lambda expression, use a def
"E402", # Module level import not at top of file
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements
"PLR2004", # Magic value used instead of constant
"PLW0603", # Using the global statement
"PLW2901", # redefined-loop-name
"PLR1714", # consider-using-in
"PLR5501", # else-if-used
lint.ignore = [
"E501", # Line too long ({width} > {limit} characters)
"E701", # Multiple statements on one line (colon)
"E731", # Do not assign a lambda expression, use a def
"E402", # Module level import not at top of file
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements
"PLR2004", # Magic value used instead of constant
"PLW0603", # Using the global statement
"PLW2901", # redefined-loop-name
"PLR1714", # consider-using-in
"PLR5501", # else-if-used
]
fixable = ["ALL"]
lint.fixable = ["ALL"]

# Same as Black.
line-length = 88
indent-width = 4

[tool.ruff.format]
# use single quotes for strings.
quote-style = "single"

# indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[tool.setuptools.packages.find]
include = [
"databaseparsers*",
]

[tool.setuptools.package-data]
databaseparsers = ["*/metadata.yaml", "*/README.md"]
[project.entry-points.'nomad.plugin']
openkimparser = "databaseparsers:openkim_parser_entry_point"

[tool.mypy]
strict = false
Expand Down
32 changes: 25 additions & 7 deletions tests/test_openkimparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ def test_entry(parser):
assert sec_system.atoms.positions[1][1].magnitude == approx(1.65893189e-10)
assert sec_system.atoms.lattice_vectors[2][2].magnitude == approx(3.31786378e-10)

assert sec_run[0].method[0].force_field.model[0].name == 'LJ_ElliottAkerson_2015_Universal__MO_959249795837_003'
assert (
sec_run[0].method[0].force_field.model[0].name
== 'LJ_ElliottAkerson_2015_Universal__MO_959249795837_003'
)

sec_scc = sec_run[8].calculation[0]
assert sec_scc.energy.total.value.magnitude == approx(4.513135831891813e-19)

assert sec_run[0].x_openkim_meta['meta.runner.driver.name'] == 'LatticeConstantCubicEnergy'
assert (
sec_run[0].x_openkim_meta['meta.runner.driver.name']
== 'LatticeConstantCubicEnergy'
)


def test_elastic(parser):
Expand All @@ -67,13 +73,19 @@ def test_elastic(parser):

def test_phonon(parser):
archive = EntryArchive()
parser.parse('tests/data/openkim/openkim_archive_phonon-dispersion-relation-cubic-crystal-npt.json', archive, None)
parser.parse(
'tests/data/openkim/openkim_archive_phonon-dispersion-relation-cubic-crystal-npt.json',
archive,
None,
)

sec_run = archive.run
assert len(sec_run) == 337
assert sec_run[0].calculation[0].stress.total.value[0][1].magnitude == approx(0)
sec_band_structure = sec_run[15].calculation[0].band_structure_phonon[0]
assert sec_band_structure.segment[0].energies[0][3][1].magnitude == approx(9.639834657408083e-22)
assert sec_band_structure.segment[0].energies[0][3][1].magnitude == approx(
9.639834657408083e-22
)
assert np.shape(sec_band_structure.segment[0].kpoints) == (100, 3)

# workflow = archive.workflow
Expand All @@ -83,13 +95,19 @@ def test_phonon(parser):

def test_stacking_fault(parser):
archive = EntryArchive()
parser.parse('tests/data/openkim/StackingFaultFccCrystal_0bar_Ac__TE_567672586460_002.json', archive, None)
parser.parse(
'tests/data/openkim/StackingFaultFccCrystal_0bar_Ac__TE_567672586460_002.json',
archive,
None,
)

sec_run = archive.run
assert len(sec_run) == 6
assert sec_run[1].system[0].atoms.labels == ['Ac']
assert sec_run[0].system[0].atoms.positions[0][2].magnitude == approx(0.)
assert sec_run[2].system[0].atoms.lattice_vectors[2][2].magnitude == approx(5.913618618249901e-10)
assert sec_run[0].system[0].atoms.positions[0][2].magnitude == approx(0.0)
assert sec_run[2].system[0].atoms.lattice_vectors[2][2].magnitude == approx(
5.913618618249901e-10
)

# workflow = archive.workflow
# assert workflow.m_def.name == 'Interface'
Expand Down

0 comments on commit defb8c2

Please sign in to comment.