Commit 205d57de authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Merge branch 'v1.0.5-misc-fixes' into 'v1.0.5'

Misc hot fixes

See merge request !596
parents 9ae79c6b cfba0ba7
Pipeline #126661 passed with stage
in 19 seconds
......@@ -226,6 +226,22 @@ class EnergyEntry(Atomic):
Value of the potential energy.
''')
kinetic = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
Value of the kinetic energy.
''')
correction = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
Value of the correction to the energy.
''')
class Energy(MSection):
'''
......@@ -241,6 +257,7 @@ class Energy(MSection):
Contains the value and information regarding the total energy of the system.
''')
# TODO this should be removed and replaced by correction in EnergyEntry
current = SubSection(
sub_section=EnergyEntry.m_def,
description='''
......@@ -257,7 +274,7 @@ class Energy(MSection):
Contains the value and information regarding the converged zero-point
vibrations energy calculated using the method described in zero_point_method.
''')
# this should be removed and replaced by electronic.kinetic
kinetic_electronic = SubSection(
sub_section=EnergyEntry.m_def,
description='''
......@@ -265,6 +282,13 @@ class Energy(MSection):
kinetic energy.
''')
electronic = SubSection(
sub_section=EnergyEntry.m_def,
description='''
Contains the value and information regarding the self-consistent electronic
energy.
''')
correlation = SubSection(
sub_section=EnergyEntry.m_def,
description='''
......@@ -384,7 +408,7 @@ class Energy(MSection):
''',
repeats=True)
# TODO determine if correction can be generalized in EnergyEntry
# TODO remove this should be be entropy.correction
correction_entropy = SubSection(
sub_section=EnergyEntry.m_def,
description='''
......@@ -393,6 +417,7 @@ class Energy(MSection):
in account. Defined consistently with XC_method.
''')
# TODO remove this should be in electrostatic.correction
correction_hartree = SubSection(
sub_section=EnergyEntry.m_def,
description='''
......@@ -401,6 +426,7 @@ class Energy(MSection):
density electrostatic energy. Defined consistently with XC_method.
''')
# TODO remove this should be in xc.correction
correction_xc = SubSection(
sub_section=EnergyEntry.m_def,
description='''
......@@ -677,6 +703,22 @@ class BandGap(MSection):
The lowest unoccupied energy.
""")
value_fundamental = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
GW fundamental band gap
''')
value_optical = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
GW optical band gap
''')
class BandEnergies(MSection):
'''
......@@ -762,6 +804,71 @@ class BandEnergies(MSection):
Values of the band energies.
''')
qp_linearization_prefactor = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
description='''
Values of the GW quasi particle linearization pre-factor.
''')
value_xc_potential = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW exchange-correlation potential.
''')
value_correlation = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW correlation energy.
''')
value_exchange = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW exchange energy.
''')
value_xc = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW exchange-correlation energy.
''')
value_qp = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW quasi-particle energy.
''')
value_ks = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the Kohn-Sham energy.
''')
value_ks_xc = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the Kohn-Sham exchange-correlation energy.
''')
band_gap = SubSection(sub_section=BandGap.m_def, repeats=True)
class BandStructure(MSection):
'''
......@@ -966,6 +1073,14 @@ class MultipolesEntry(Atomic):
m_def = Section(validate=False)
origin = Quantity(
type=np.dtype(np.float64),
shape=[3],
unit='meter',
description='''
Origin in cartesian space.
''')
n_multipoles = Quantity(
type=int,
shape=[],
......@@ -1014,118 +1129,6 @@ class Multipoles(MSection):
higher_order = SubSection(sub_section=MultipolesEntry.m_def, repeats=True)
class GWBandEnergies(BandEnergies):
'''
Contains information regarding the GW eigenvalues.
'''
m_def = Section(validate=False)
n_spin_channels = Quantity(
type=int,
shape=[],
description='''
Number of spin channels.
''')
qp_linearization_prefactor = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
description='''
Values of the GW quasi particle linearization pre-factor.
''')
value_xc_potential = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW exchange-correlation potential.
''')
value_correlation = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW correlation energy.
''')
value_exchange = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW exchange energy.
''')
value_xc = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW exchange-correlation energy.
''')
value_qp = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the GW quasi-particle energy.
''')
value_ks = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the Kohn-Sham energy.
''')
value_ks_xc = Quantity(
type=np.dtype(np.float64),
shape=['n_spin_channels', 'n_kpoints', 'n_bands'],
unit='joule',
description='''
Diagonal matrix elements of the Kohn-Sham exchange-correlation energy.
''')
class GW(MSection):
'''
Section containing the results of a GW calculation.
'''
m_def = Section(validate=False)
fermi_energy = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
GW Fermi energy
''')
fundamental_gap = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
GW fundamental band gap
''')
optical_gap = Quantity(
type=np.dtype(np.float64),
shape=[],
unit='joule',
description='''
GW optical band gap
''')
eigenvalues = SubSection(sub_section=GWBandEnergies.m_def, repeats=True)
class Thermodynamics(MSection):
'''
Section containing results related to a thermodynamics calculation.
......@@ -1577,8 +1580,6 @@ class BaseCalculation(MSection):
band_structure_phonon = SubSection(sub_section=BandStructure.m_def, repeats=True)
gw = SubSection(sub_section=GW.m_def, repeats=True)
thermodynamics = SubSection(sub_section=Thermodynamics.m_def, repeats=True)
excited_states = SubSection(sub_section=ExcitedStates.m_def, repeats=True)
......
......@@ -72,5 +72,5 @@ based on nomad@fairdi's metainfo:
:members:
'''
from nomad.parsing.parser import Parser, BrokenParser, MissingParser, MatchingParser, FairdiParser
from nomad.parsing.parser import Parser, BrokenParser, MissingParser, MatchingParser, MatchingParserInterface
from nomad.parsing.artificial import TemplateParser, GenerateRandomParser, ChaosParser, EmptyParser
......@@ -13,7 +13,7 @@
# limitations under the License.
from typing import Dict, Any, List
from typing import List
import os
import logging
import numpy as np
......@@ -21,7 +21,6 @@ import re
from ase.data import chemical_symbols
from nomad.datamodel import EntryArchive
from nomad.parsing import FairdiParser
from nomad.parsing.file_parser import TextParser, Quantity
from nomad.datamodel.metainfo.simulation.run import Run, Program
from nomad.datamodel.metainfo.simulation.method import Method
......@@ -30,21 +29,20 @@ from nomad.datamodel.metainfo.simulation.calculation import (
Calculation, Energy, EnergyEntry, Forces, ForcesEntry, Thermodynamics)
class BasicParser(FairdiParser):
class BasicParser:
'''
Defines a fairdi parser that parse basic quantities for sections method, system and
single_configuration_calculation.
Arguments:
specifications: dictionary that will be passed on to FairdiParser
code_name: name of the code
units_mapping: dictionary of nomad units for basic quantities such as length
auxiliary_files: re pattern to match auxilliary files from mainfile. If no files
are found will match files in working directory.
kwargs: metainfo_key: re pattern pairs used to parse quantity
'''
def __init__(self, specifications: Dict[str, Any], **kwargs):
super().__init__(**specifications)
self.specifications = specifications
def __init__(self, code_name: str, **kwargs):
self.code_name = code_name
self.units_mapping = kwargs.get('units_mapping', {})
self.auxilliary_files = kwargs.get('auxilliary_files', '')
self.mainfile_parser = TextParser()
......@@ -129,7 +127,7 @@ class BasicParser(FairdiParser):
sections[n].m_parent.m_remove_sub_section(definition, n)
sec_run = self.archive.m_create(Run)
sec_run.program = Program(name=self.specifications.get('code_name', ''))
sec_run.program = Program(name=self.code_name)
energy_unit = self.units_mapping.get('energy', 1.0)
length_unit = self.units_mapping.get('length', 1.0)
......
......@@ -22,8 +22,9 @@ import re
import os
import os.path
from functools import lru_cache
import importlib
from nomad import config
from nomad import config, utils
from nomad.datamodel import EntryArchive, EntryMetadata
......@@ -220,8 +221,33 @@ class MatchingParser(Parser):
return self.name
# For backward compatibility
FairdiParser = MatchingParser
class MatchingParserInterface(MatchingParser):
'''
An interface to the NOMAD parsers.
Arguments:
parser_class_name: concatenation of module path and parser class name
'''
def __init__(self, parser_class_name: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self._parser_class_name = parser_class_name
self._mainfile_parser = None
@property
def mainfile_parser(self):
if self._mainfile_parser is None:
try:
module_path, parser_class = self._parser_class_name.rsplit('.', 1)
module = importlib.import_module(module_path)
self._mainfile_parser = getattr(module, parser_class)()
except Exception as e:
logger = utils.get_logger(__name__)
logger.error('Error importing parser.', exc_info=e)
raise e
return self._mainfile_parser
def parse(self, mainfile: str, archive: EntryArchive, logger=None):
self.mainfile_parser.parse(mainfile, archive, logger)
class ArchiveParser(MatchingParser):
......
This diff is collapsed.
......@@ -1028,7 +1028,7 @@ class Entry(Proc):
with utils.timer(logger, 'parser executed', input_size=self.mainfile_file.size):
if not config.process.reuse_parser:
if isinstance(parser, parsing.FairdiParser):
if isinstance(parser, parsing.MatchingParserInterface):
try:
parser = parser.__class__()
except Exception as e:
......
......@@ -61,6 +61,6 @@ def test_common_metainfo():
def test_vasp_metainfo():
from nomad.datamodel.metainfo.simulation.run import Run
from vaspparser.metainfo import m_env # pylint: disable=unused-import
from electronicparsers.vasp.metainfo import m_env # pylint: disable=unused-import
run = Run()
assert 'vasp_src_date' in run.m_def.all_quantities
......@@ -315,9 +315,7 @@ class TestBasicParser:
def onetep_parser(self):
re_f = r'\-*\d+\.\d+E*\-*\+*\d+'
return BasicParser(
specifications=dict(
name='parsers/onetep', code_name='ONETEP', code_homepage='https://www.onetep.org/',
domain='dft', mainfile_contents_re=r'####### # # ####### ####### ####### ######'),
'ONETEP',
units_mapping=dict(energy=ureg.hartree, length=ureg.bohr),
auxilliary_files=r'([\w\-]+\.dat)',
program_version=r'Version\s*([\d\.]+)',
......
......@@ -354,3 +354,16 @@ class TestClient:
assert 'Atoms / Molecules' in result.output
assert 'DOS' in result.output
assert 'Band structures' in result.output
@pytest.mark.usefixtures('reset_config')
class TestDev:
def test_parser_metadata(self):
result = invoke_cli(
cli, ['dev', 'parser-metadata'], catch_exceptions=True)
assert result.exit_code == 0, result.output
assert 'yambo' in result.output
assert 'lammps' in result.output
assert 'elastic' in result.output
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment