Skip to content

Commit defb8c2

Browse files
authored
Entry point (#14)
* Add entry point * Update nomad-lab * Fix commit * Move specs to entry point * Add other parser specs * Fix init * Revert * Remove import * Add aliases
1 parent fd38bde commit defb8c2

File tree

4 files changed

+116
-29
lines changed

4 files changed

+116
-29
lines changed

.github/workflows/python-actions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
pip install --upgrade pip
1515
pip install '.[tests]' --index-url https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple
1616
# we need the latest nomad version for testing
17-
pip install nomad-lab[infrastructure]@git+https://github.com/nomad-coe/nomad.git@develop
17+
#pip install nomad-lab[infrastructure]@git+https://github.com/nomad-coe/nomad.git@develop
1818
pip install coverage coveralls
1919
- name: mypy
2020
run: |

databaseparsers/__init__.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,55 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
#
19+
from pydantic import Field
20+
from typing import Optional
1921

20-
# from .openkim.parser import OpenKIMParser
22+
from nomad.config.models.plugins import ParserEntryPoint
23+
24+
25+
class EntryPoint(ParserEntryPoint):
26+
parser_class_name: str = Field(
27+
description="""
28+
The fully qualified name of the Python class that implements the parser.
29+
This class must have a function `def parse(self, mainfile, archive, logger)`.
30+
"""
31+
)
32+
code_name: Optional[str]
33+
code_homepage: Optional[str]
34+
code_category: Optional[str]
35+
metadata: Optional[dict] = Field(
36+
description="""
37+
Metadata passed to the UI. Deprecated. """
38+
)
39+
40+
def load(self):
41+
from nomad.parsing import MatchingParserInterface
42+
43+
return MatchingParserInterface(**self.dict())
44+
45+
46+
openkim_parser_entry_point = EntryPoint(
47+
name='parsers/openkim',
48+
aliases=['parsers/openkim'],
49+
description='NOMAD parser for OPENKIM.',
50+
python_package='databaseparsers.openkim',
51+
mainfile_contents_re=r'openkim|OPENKIM|OpenKIM',
52+
mainfile_mime_re='(application/json)|(text/.*)',
53+
parser_class_name='databaseparsers.openkim.OpenKIMParser',
54+
code_name='OpenKIM',
55+
code_homepage='https://openkim.org/',
56+
code_category='Database manager',
57+
metadata={
58+
'codeCategory': 'Database manager',
59+
'codeLabel': 'OpenKIM',
60+
'codeLabelStyle': 'Capitals: O,K,I,M',
61+
'codeName': 'openkim',
62+
'codeUrl': 'https://openkim.org/',
63+
'parserDirName': 'dependencies/parsers/database/databaseparsers/openkim/',
64+
'parserGitUrl': 'https://github.com/nomad-coe/database-parsers.git',
65+
'parserSpecific': '',
66+
'preamble': '',
67+
'status': 'production',
68+
'tableOfFiles': '',
69+
},
70+
)

pyproject.toml

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ readme = "README.md"
1010
authors = [{ name = "The NOMAD Authors" }]
1111
license = { file = "LICENSE" }
1212
dependencies = [
13+
"nomad-lab>=1.3.6.dev1",
1314
"nomad-schema-plugin-simulation-workflow@git+https://github.com/nomad-coe/nomad-schema-plugin-simulation-workflow.git@develop",
14-
"nomad-schema-plugin-run@git+https://github.com/nomad-coe/nomad-schema-plugin-run.git@develop"
15+
"nomad-schema-plugin-run@git+https://github.com/nomad-coe/nomad-schema-plugin-run.git@develop",
16+
"pydantic>=1.10.8,<2.0.0",
1517
]
1618

1719
[project.urls]
@@ -28,40 +30,57 @@ tests = [
2830
"pytest-cov==2.7.1",
2931
"astroid==2.11.7",
3032
"typing-extensions==4.4.0",
31-
"ruff==0.1.4",
33+
"ruff==0.1.8",
3234
]
3335

3436
[tool.ruff]
3537
include = ["electronicparsers/*.py", "tests/*.py"]
36-
select = [
38+
lint.select = [
3739
"E", # pycodestyle
3840
"W", # pycodestyle
3941
"PL", # pylint
4042
]
41-
ignore = [
42-
"E501", # Line too long ({width} > {limit} characters)
43-
"E701", # Multiple statements on one line (colon)
44-
"E731", # Do not assign a lambda expression, use a def
45-
"E402", # Module level import not at top of file
46-
"PLR0911", # Too many return statements
47-
"PLR0912", # Too many branches
48-
"PLR0913", # Too many arguments in function definition
49-
"PLR0915", # Too many statements
50-
"PLR2004", # Magic value used instead of constant
51-
"PLW0603", # Using the global statement
52-
"PLW2901", # redefined-loop-name
53-
"PLR1714", # consider-using-in
54-
"PLR5501", # else-if-used
43+
lint.ignore = [
44+
"E501", # Line too long ({width} > {limit} characters)
45+
"E701", # Multiple statements on one line (colon)
46+
"E731", # Do not assign a lambda expression, use a def
47+
"E402", # Module level import not at top of file
48+
"PLR0911", # Too many return statements
49+
"PLR0912", # Too many branches
50+
"PLR0913", # Too many arguments in function definition
51+
"PLR0915", # Too many statements
52+
"PLR2004", # Magic value used instead of constant
53+
"PLW0603", # Using the global statement
54+
"PLW2901", # redefined-loop-name
55+
"PLR1714", # consider-using-in
56+
"PLR5501", # else-if-used
5557
]
56-
fixable = ["ALL"]
58+
lint.fixable = ["ALL"]
59+
60+
# Same as Black.
61+
line-length = 88
62+
indent-width = 4
63+
64+
[tool.ruff.format]
65+
# use single quotes for strings.
66+
quote-style = "single"
67+
68+
# indent with spaces, rather than tabs.
69+
indent-style = "space"
70+
71+
# Like Black, respect magic trailing commas.
72+
skip-magic-trailing-comma = false
73+
74+
# Like Black, automatically detect the appropriate line ending.
75+
line-ending = "auto"
5776

5877
[tool.setuptools.packages.find]
5978
include = [
6079
"databaseparsers*",
6180
]
6281

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

6685
[tool.mypy]
6786
strict = false

tests/test_openkimparser.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ def test_entry(parser):
4545
assert sec_system.atoms.positions[1][1].magnitude == approx(1.65893189e-10)
4646
assert sec_system.atoms.lattice_vectors[2][2].magnitude == approx(3.31786378e-10)
4747

48-
assert sec_run[0].method[0].force_field.model[0].name == 'LJ_ElliottAkerson_2015_Universal__MO_959249795837_003'
48+
assert (
49+
sec_run[0].method[0].force_field.model[0].name
50+
== 'LJ_ElliottAkerson_2015_Universal__MO_959249795837_003'
51+
)
4952

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

53-
assert sec_run[0].x_openkim_meta['meta.runner.driver.name'] == 'LatticeConstantCubicEnergy'
56+
assert (
57+
sec_run[0].x_openkim_meta['meta.runner.driver.name']
58+
== 'LatticeConstantCubicEnergy'
59+
)
5460

5561

5662
def test_elastic(parser):
@@ -67,13 +73,19 @@ def test_elastic(parser):
6773

6874
def test_phonon(parser):
6975
archive = EntryArchive()
70-
parser.parse('tests/data/openkim/openkim_archive_phonon-dispersion-relation-cubic-crystal-npt.json', archive, None)
76+
parser.parse(
77+
'tests/data/openkim/openkim_archive_phonon-dispersion-relation-cubic-crystal-npt.json',
78+
archive,
79+
None,
80+
)
7181

7282
sec_run = archive.run
7383
assert len(sec_run) == 337
7484
assert sec_run[0].calculation[0].stress.total.value[0][1].magnitude == approx(0)
7585
sec_band_structure = sec_run[15].calculation[0].band_structure_phonon[0]
76-
assert sec_band_structure.segment[0].energies[0][3][1].magnitude == approx(9.639834657408083e-22)
86+
assert sec_band_structure.segment[0].energies[0][3][1].magnitude == approx(
87+
9.639834657408083e-22
88+
)
7789
assert np.shape(sec_band_structure.segment[0].kpoints) == (100, 3)
7890

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

8496
def test_stacking_fault(parser):
8597
archive = EntryArchive()
86-
parser.parse('tests/data/openkim/StackingFaultFccCrystal_0bar_Ac__TE_567672586460_002.json', archive, None)
98+
parser.parse(
99+
'tests/data/openkim/StackingFaultFccCrystal_0bar_Ac__TE_567672586460_002.json',
100+
archive,
101+
None,
102+
)
87103

88104
sec_run = archive.run
89105
assert len(sec_run) == 6
90106
assert sec_run[1].system[0].atoms.labels == ['Ac']
91-
assert sec_run[0].system[0].atoms.positions[0][2].magnitude == approx(0.)
92-
assert sec_run[2].system[0].atoms.lattice_vectors[2][2].magnitude == approx(5.913618618249901e-10)
107+
assert sec_run[0].system[0].atoms.positions[0][2].magnitude == approx(0.0)
108+
assert sec_run[2].system[0].atoms.lattice_vectors[2][2].magnitude == approx(
109+
5.913618618249901e-10
110+
)
93111

94112
# workflow = archive.workflow
95113
# assert workflow.m_def.name == 'Interface'

0 commit comments

Comments
 (0)