Skip to content

Commit

Permalink
Use run schema plug in
Browse files Browse the repository at this point in the history
  • Loading branch information
ladinesa committed Dec 7, 2023
1 parent 0e51245 commit af1e078
Show file tree
Hide file tree
Showing 21 changed files with 337 additions and 240 deletions.
13 changes: 8 additions & 5 deletions atomisticparsers/asap/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

from nomad.units import ureg
from nomad.parsing.file_parser import FileParser
from nomad.datamodel.metainfo.simulation.run import Run, Program
from nomad.datamodel.metainfo.simulation.method import (
Method, ForceField, Model)
from runschema.run import Run, Program
from runschema.method import (
Method, ForceField, Model
)
from simulationworkflowschema import (
GeometryOptimization, GeometryOptimizationMethod
)
Expand Down Expand Up @@ -73,7 +74,8 @@ def init_parser(self):

def parse_method(self):
traj = self.traj_parser.traj
sec_method = self.archive.run[0].m_create(Method)
sec_method = Method()
self.archive.run[0].method.append(sec_method)

if traj[0].calc is not None:
sec_method.force_field = ForceField(model=[Model(name=traj[0].calc.name)])
Expand Down Expand Up @@ -117,7 +119,8 @@ def parse(self, filepath, archive, logger):
if self.traj_parser.traj is None:
return

sec_run = self.archive.m_create(Run)
sec_run = Run()
self.archive.run.append(sec_run)
sec_run. program = Program(name='ASAP', version=self.traj_parser.get_version())

# TODO do we build the topology and method for each frame
Expand Down
41 changes: 21 additions & 20 deletions atomisticparsers/bopfox/metainfo/bopfox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference, JSON
)
from nomad.datamodel.metainfo import simulation
import runschema


m_package = Package()


class Method(simulation.calculation.Method):
class Method(runschema.calculation.Method):

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

Expand All @@ -38,71 +39,71 @@ class Method(simulation.calculation.Method):
''')


class Energy(simulation.calculation.Energy):
class Energy(runschema.calculation.Energy):

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

x_bopfox_bond = SubSection(
sub_section=simulation.calculation.EnergyEntry.m_def,
sub_section=runschema.calculation.EnergyEntry.m_def,
description='''
Contains the value and information regarding the bond energy.
''')

x_bopfox_prom = SubSection(
sub_section=simulation.calculation.EnergyEntry.m_def,
sub_section=runschema.calculation.EnergyEntry.m_def,
description='''
Contains the value and information regarding the promotion energy.
''')

x_bopfox_rep1 = SubSection(
sub_section=simulation.calculation.EnergyEntry.m_def,
sub_section=runschema.calculation.EnergyEntry.m_def,
description='''
Contains the value and information regarding the first repulsion energy.
''')

x_bopfox_rep2 = SubSection(
sub_section=simulation.calculation.EnergyEntry.m_def,
sub_section=runschema.calculation.EnergyEntry.m_def,
description='''
Contains the value and information regarding the second repulsion energy.
''')

x_bopfox_rep3 = SubSection(
sub_section=simulation.calculation.EnergyEntry.m_def,
sub_section=runschema.calculation.EnergyEntry.m_def,
description='''
Contains the value and information regarding the third repulsion energy.
''')


class Forces(simulation.calculation.Forces):
class Forces(runschema.calculation.Forces):

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

x_bopfox_analytic = SubSection(
sub_section=simulation.calculation.ForcesEntry.m_def,
sub_section=runschema.calculation.ForcesEntry.m_def,
description='''
Contains the value and information regarding the analytic forces.
''')

x_bopfox_rep1 = SubSection(
sub_section=simulation.calculation.ForcesEntry.m_def,
sub_section=runschema.calculation.ForcesEntry.m_def,
description='''
Contains the value and information regarding the first analytic forces.
''')

x_bopfox_rep2 = SubSection(
sub_section=simulation.calculation.ForcesEntry.m_def,
sub_section=runschema.calculation.ForcesEntry.m_def,
description='''
Contains the value and information regarding the second analytic forces.
''')

x_bopfox_rep3 = SubSection(
sub_section=simulation.calculation.ForcesEntry.m_def,
sub_section=runschema.calculation.ForcesEntry.m_def,
description='''
Contains the value and information regarding the third analytic forces.
''')


class x_bopfox_onsite_levels_value(simulation.calculation.AtomicValues):
class x_bopfox_onsite_levels_value(runschema.calculation.AtomicValues):

m_def = Section(validate=False)

Expand All @@ -114,21 +115,21 @@ class x_bopfox_onsite_levels_value(simulation.calculation.AtomicValues):
''')


class x_bopfox_onsite_levels(simulation.calculation.Atomic):
class x_bopfox_onsite_levels(runschema.calculation.Atomic):

m_def = Section(validate=False)

orbital_projected = SubSection(sub_section=x_bopfox_onsite_levels_value.m_def, repeats=True)


class Calculation(simulation.calculation.Calculation):
class Calculation(runschema.calculation.Calculation):

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

x_bopfox_onsite_levels = SubSection(sub_section=x_bopfox_onsite_levels.m_def, repeats=True)


class Interaction(simulation.method.Interaction):
class Interaction(runschema.method.Interaction):

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

Expand Down Expand Up @@ -161,7 +162,7 @@ class Interaction(simulation.method.Interaction):
''')


class Model(simulation.method.Model):
class Model(runschema.method.Model):

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

Expand All @@ -172,7 +173,7 @@ class Model(simulation.method.Model):
''')


class xTB(simulation.method.xTB):
class xTB(runschema.method.xTB):

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

Expand All @@ -183,7 +184,7 @@ class xTB(simulation.method.xTB):
''')


class AtomParameters(simulation.method.AtomParameters):
class AtomParameters(runschema.method.AtomParameters):

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

Expand Down
41 changes: 26 additions & 15 deletions atomisticparsers/bopfox/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

from nomad.units import ureg
from nomad.parsing.file_parser import TextParser, Quantity, DataTextParser
from nomad.datamodel.metainfo.simulation.run import Run, Program
from nomad.datamodel.metainfo.simulation.method import (
from runschema.run import Run, Program
from runschema.method import (
Method, TB, xTB, ForceField, Model, Interaction
)
from nomad.datamodel.metainfo.simulation.system import System, Atoms
from nomad.datamodel.metainfo.simulation.calculation import (
from runschema.system import System, Atoms
from runschema.calculation import (
Calculation, Energy, EnergyEntry, Forces, ForcesEntry, Stress, StressEntry, Charges,
ChargesValue
)
Expand Down Expand Up @@ -344,10 +344,12 @@ def parse(self, filepath, archive, logger):

self.init_parser()

sec_run = archive.m_create(Run)
sec_run = Run()
archive.run.append(sec_run)
sec_run.program = Program(name='BOPfox', version=self.mainfile_parser.get('program_version'))

sec_method = sec_run.m_create(Method)
sec_method = Method()
sec_run.method.append(sec_method)
parameters = self.mainfile_parser.get_simulation_parameters()
sec_method.x_bopfox_simulation_parameters = parameters
# force field parameters
Expand All @@ -358,9 +360,11 @@ def parse(self, filepath, archive, logger):
# bop uses a tight-binding model
tb = model.parameters.get('version', 'bop').lower() in ['bop', 'tight-binding']
if tb:
sec_model = sec_method.m_create(TB).m_create(xTB)
sec_model = xTB()
sec_method.tb = TB(xtb=sec_model)
else:
sec_model = sec_method.m_create(ForceField).m_create(Model)
sec_model = Model()
sec_method.force_field = ForceField(model=[sec_model])

sec_model.name = model.name
sec_model.x_bopfox_parameters = model.parameters
Expand Down Expand Up @@ -419,20 +423,23 @@ def parse_system(source, target=None):
if positions is None:
return

sec_system = sec_run.m_create(System) if target is None else target
sec_system = System()
sec_run.system.append(sec_system) if target is None else target
sec_system.atoms = Atoms(labels=labels, positions=positions * ureg.angstrom)
if lattice_vectors is not None:
sec_system.atoms.lattice_vectors = lattice_vectors * ureg.angstrom

return sec_system

def parse_calculation(source, target=None):
sec_calc = sec_run.m_create(Calculation) if target is None else target
sec_calc = Calculation()
sec_run.calculation.append(sec_calc) if target is None else target

# energy
n_atoms = self.mainfile_parser.get('n_atoms', [1, 1])[0]
if source.get('energy') is not None:
sec_energy = sec_calc.m_create(Energy)
sec_energy = Energy()
sec_calc.energy = sec_energy
for contribution in source.energy.get('contribution', []):
name = self._metainfo_map.get(contribution.type)
energy_entry = EnergyEntry(
Expand All @@ -449,7 +456,8 @@ def parse_calculation(source, target=None):

# forces
if source.get('forces') is not None:
sec_forces = sec_calc.m_create(Forces)
sec_forces = Forces()
sec_calc.forces = sec_forces
for contribution in source.forces.get('contribution', []):
name = self._metainfo_map.get(contribution.type)
forces_entry = ForcesEntry(value=contribution.atomic * ureg.eV / ureg.angstrom)
Expand All @@ -471,7 +479,8 @@ def symmetrize(stress):

# stress
if source.get('stress') is not None:
sec_stress = sec_calc.m_create(Stress)
sec_stress = Stress()
sec_calc.stress = sec_stress
for contribution in source.stress.get('contribution', []):
name = self._metainfo_map.get(contribution.type)
stress_entry = StressEntry(values_per_atom=[symmetrize(
Expand All @@ -486,7 +495,8 @@ def symmetrize(stress):

# charges
if source.get('charges') is not None:
sec_charges = sec_calc.m_create(Charges)
sec_charges = Charges()
sec_calc.charges.append(sec_charges)
sec_charges.n_electrons = source.charges.n_electrons
sec_charges.value = source.charges.charge * ureg.elementary_charge
# magnetic moments
Expand All @@ -498,7 +508,8 @@ def symmetrize(stress):

# onsite levels
if source.get('onsite_levels') is not None:
sec_onsite = sec_calc.m_create(x_bopfox_onsite_levels)
sec_onsite = x_bopfox_onsite_levels()
sec_calc.x_bopfox_onsite_levels.append(sec_onsite)
for onsite in source.onsite_levels.get('energy', []):
sec_onsite.orbital_projected.append(x_bopfox_onsite_levels_value(
orbital=onsite[0], atom_index=onsite[1] - 1, value=onsite[2]
Expand Down
32 changes: 16 additions & 16 deletions atomisticparsers/dftbplus/metainfo/dftbplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from nomad.metainfo import ( # pylint: disable=unused-import
Package, Quantity, Section, SubSection, JSON
)
from nomad.datamodel.metainfo import simulation
import runschema


m_package = Package()


class AtomParameters(simulation.method.AtomParameters):
class AtomParameters(runschema.method.AtomParameters):

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

Expand All @@ -46,7 +46,7 @@ class AtomParameters(simulation.method.AtomParameters):
''')


class System(simulation.system.System):
class System(runschema.system.System):

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

Expand All @@ -72,7 +72,7 @@ class System(simulation.system.System):
''')


class BandEnergies(simulation.calculation.BandEnergies):
class BandEnergies(runschema.calculation.BandEnergies):

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

Expand All @@ -91,7 +91,7 @@ class BandEnergies(simulation.calculation.BandEnergies):
''')


class Calculation(simulation.calculation.Calculation):
class Calculation(runschema.calculation.Calculation):

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

Expand Down Expand Up @@ -131,28 +131,28 @@ class Calculation(simulation.calculation.Calculation):
''')


class Energy(simulation.calculation.Energy):
class Energy(runschema.calculation.Energy):

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

x_dftbp_total_mermin = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_total_mermin = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_band = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_band = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_ts = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_ts = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_band_free = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_band_free = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_band_t0 = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_band_t0 = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_scc = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_scc = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_dispersion = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_dispersion = SubSection(runschema.calculation.EnergyEntry.m_def)

x_dftbp_force_related = SubSection(simulation.calculation.EnergyEntry.m_def)
x_dftbp_force_related = SubSection(runschema.calculation.EnergyEntry.m_def)


class TB(simulation.method.TB):
class TB(runschema.method.TB):

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

Expand All @@ -176,7 +176,7 @@ class TB(simulation.method.TB):
''')


class Run(simulation.run.Run):
class Run(runschema.run.Run):

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

Expand Down
Loading

0 comments on commit af1e078

Please sign in to comment.