Skip to content

Commit

Permalink
Add other parser specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ladinesa committed Aug 26, 2024
1 parent 450b1be commit bd8114a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 28 deletions.
30 changes: 26 additions & 4 deletions databaseparsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.
#
from pydantic import Field
from typing import Optional

from nomad.config.models.plugins import ParserEntryPoint

Expand All @@ -28,14 +29,19 @@ class EntryPoint(ParserEntryPoint):
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
from . import (
openkim
)
from . import openkim

return MatchingParserInterface(self.parser_class_name)
return MatchingParserInterface(**self.dict())


openkim_parser_entry_point = EntryPoint(
Expand All @@ -45,4 +51,20 @@ def load(self):
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': '',
},
)
51 changes: 34 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,49 @@ 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 = [
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 bd8114a

Please sign in to comment.