Skip to content

Commit

Permalink
Merge pull request #53 from nomad-coe/merging_TB_and_TightBinding
Browse files Browse the repository at this point in the history
Merging TB and TightBinding: DFTB+ and xTB parsers
  • Loading branch information
JosePizarro3 authored Nov 20, 2023
2 parents 65f9e51 + e6b7f22 commit ffd93bc
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 43 deletions.
11 changes: 11 additions & 0 deletions atomisticparsers/bopfox/metainfo/bopfox.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ class Model(simulation.method.Model):
''')


class xTB(simulation.method.xTB):

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

x_bopfox_parameters = Quantity(
type=JSON,
shape=[],
description='''
''')


class AtomParameters(simulation.method.AtomParameters):

m_def = Section(validate=False, extends_base_section=True)
Expand Down
10 changes: 4 additions & 6 deletions atomisticparsers/bopfox/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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 (
Method, TB, TBModel, ForceField, Model, Interaction
Method, TB, xTB, ForceField, Model, Interaction
)
from nomad.datamodel.metainfo.simulation.system import System, Atoms
from nomad.datamodel.metainfo.simulation.calculation import (
Expand Down Expand Up @@ -345,7 +345,7 @@ def parse(self, filepath, archive, logger):
self.init_parser()

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

sec_method = sec_run.m_create(Method)
parameters = self.mainfile_parser.get_simulation_parameters()
Expand All @@ -358,11 +358,9 @@ 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_method_type = sec_method.m_create(TB)
sec_model = sec_method_type.m_create(TBModel)
sec_model = sec_method.m_create(TB).m_create(xTB)
else:
sec_method_type = sec_method.m_create(ForceField)
sec_model = sec_method_type.m_create(Model)
sec_model = sec_method.m_create(ForceField).m_create(Model)

sec_model.name = model.name
sec_model.x_bopfox_parameters = model.parameters
Expand Down
10 changes: 2 additions & 8 deletions atomisticparsers/dftbplus/metainfo/dftbplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import numpy as np # pylint: disable=unused-import

from nomad.metainfo import ( # pylint: disable=unused-import
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference, JSON
Package, Quantity, Section, SubSection, JSON
)
from nomad.datamodel.metainfo import simulation

Expand Down Expand Up @@ -153,7 +152,7 @@ class Energy(simulation.calculation.Energy):
x_dftbp_force_related = SubSection(simulation.calculation.EnergyEntry.m_def)


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

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

Expand All @@ -164,11 +163,6 @@ class Method(simulation.method.Method):
-
''')


class TB(simulation.method.TB):

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

x_dftbp_n_sk_files = Quantity(
type=np.dtype(np.int32),
shape=[],
Expand Down
3 changes: 2 additions & 1 deletion atomisticparsers/dftbplus/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ def parse_system(source):
setattr(sec_run, f'x_dftbp_{key}', self.out_parser.get(key))

sec_method = sec_run.m_create(Method)
sec_method.x_dftbp_input_parameters = input_parameters
sec_tb = sec_method.m_create(TB)
sec_tb.name = 'DFTB'
sec_tb.x_dftbp_input_parameters = input_parameters
sec_tb.x_dftbp_sk_files = self.out_parser.sk_files

for step in self.out_parser.get('step', []):
Expand Down
5 changes: 2 additions & 3 deletions atomisticparsers/xtb/metainfo/xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import numpy as np # pylint: disable=unused-import

from nomad.metainfo import ( # pylint: disable=unused-import
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference, JSON
Package, Quantity, Section, SubSection, JSON
)
from nomad.datamodel.metainfo import simulation

Expand All @@ -39,7 +38,7 @@ class Run(simulation.method.Method):
''')


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

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

Expand Down
23 changes: 11 additions & 12 deletions atomisticparsers/xtb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from nomad.units import ureg
from nomad.parsing.file_parser import Quantity, TextParser
from nomad.datamodel.metainfo.simulation.run import Run, Program, TimeRun
from nomad.datamodel.metainfo.simulation.method import Method, TB, TBModel, Interaction
from nomad.datamodel.metainfo.simulation.method import Method, TB, xTB, Interaction
from nomad.datamodel.metainfo.simulation.system import System, Atoms
from nomad.datamodel.metainfo.simulation.calculation import (
Calculation, ScfIteration, Energy, EnergyEntry, BandEnergies, Multipoles, MultipolesEntry
Expand Down Expand Up @@ -584,27 +584,26 @@ def parse_method(self, section):
return

sec_method = self.archive.run[-1].m_create(Method)
# calculation paraeters
parameters = {p[0]: p[1] for p in self.out_parser.get(section, {}).get('setup', {}).get('parameter', [])}
sec_method.x_xtb_setup = parameters
# tight-binding model
sec_method.tb = TB()
sec_tb_model = sec_method.tb.m_create(TBModel)
sec_tb_model.name = section
sec_tb = sec_method.m_create(TB)
sec_tb.name = 'xTB'
sec_tb.x_xtb_setup = parameters
sec_xtb = sec_tb.m_create(xTB)
sec_xtb.name = section

if model.get('reference') is not None:
sec_tb_model.reference = model.reference
sec_xtb.reference = model.reference

for contribution in model.get('contribution', []):
name = contribution.name.lower()
if name == 'hamiltonian':
sec_interaction = sec_tb_model.m_create(Interaction, TBModel.hamiltonian)
sec_interaction = sec_xtb.m_create(Interaction, xTB.hamiltonian)
elif name == 'coulomb':
sec_interaction = sec_tb_model.m_create(Interaction, TBModel.coulomb)
sec_interaction = sec_xtb.m_create(Interaction, xTB.coulomb)
elif name == 'repulsion':
sec_interaction = sec_tb_model.m_create(Interaction, TBModel.repulsion)
sec_interaction = sec_xtb.m_create(Interaction, xTB.repulsion)
else:
sec_interaction = sec_tb_model.m_create(Interaction, TBModel.contributions)
sec_interaction = sec_xtb.m_create(Interaction, xTB.contributions)
sec_interaction.type = name
sec_interaction.parameters = {
p[0]: p[1].tolist() if isinstance(p[1], np.ndarray) else p[1] for p in contribution.parameters}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_bopfoxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#

import pytest
import numpy as np

from nomad.datamodel import EntryArchive
from atomisticparsers.bopfox import BOPfoxParser
Expand All @@ -41,7 +42,7 @@ def test_energy(parser):
sec_method = sec_run.method[0]
assert sec_method.x_bopfox_simulation_parameters['bopkernel'] == 'jackson'
assert sec_method.x_bopfox_simulation_parameters['scftol'] == approx(0.001)
sec_model = sec_method.tb.model[0]
sec_model = sec_method.tb.xtb
assert sec_model.name == 'test'
assert sec_model.hamiltonian[0].name == 'ddsigma'
assert (sec_model.hamiltonian[1].atom_labels == ['W', 'W']).all()
Expand Down
5 changes: 3 additions & 2 deletions tests/test_dftbplusparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def test_static(parser):
assert sec_run[0].x_dftbp_parser_version == '8'

sec_method = archive.run[0].method
assert sec_method[0].x_dftbp_input_parameters['Hamiltonian']['Mixer']['InverseJacobiWeight'] == 0.01
assert sec_method[0].x_dftbp_input_parameters['Analysis']['ElectronDynamics']['Perturbation']['SpinType'] == 'Singlet'
assert sec_method[0].tb.name == 'DFTB'
assert sec_method[0].tb.x_dftbp_input_parameters['Hamiltonian']['Mixer']['InverseJacobiWeight'] == 0.01
assert sec_method[0].tb.x_dftbp_input_parameters['Analysis']['ElectronDynamics']['Perturbation']['SpinType'] == 'Singlet'

sec_system = archive.run[0].system
assert len(sec_system[0].atoms.labels) == 1415
Expand Down
21 changes: 11 additions & 10 deletions tests/test_xtbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ def test_scf(parser):
assert sec_run.time_run.date_end > 0

sec_method = sec_run.method
assert sec_method[0].x_xtb_setup['# basis functions'] == 6
assert sec_method[0].x_xtb_setup['Broyden damping'] == approx(0.4)

sec_model = sec_method[0].tb.model
assert sec_model[0].hamiltonian[0].parameters['H0-scaling (s, p, d)'][1] == approx(2.23)
assert sec_model[0].contributions[0].type == 'dispersion'
assert sec_model[0].contributions[0].parameters['a1'][0] == approx(0.52)
assert sec_model[0].repulsion[0].parameters['rExp'][0] == approx(1.0)
assert sec_model[0].coulomb[0].parameters['third order'][0] == 'shell-resolved'
assert sec_model[0].coulomb[0].parameters['cn-shift'][0] == approx(1.2)
assert sec_method[0].tb.name == 'xTB'
assert sec_method[0].tb.x_xtb_setup['# basis functions'] == 6
assert sec_method[0].tb.x_xtb_setup['Broyden damping'] == approx(0.4)

sec_model = sec_method[0].tb.xtb
assert sec_model.hamiltonian[0].parameters['H0-scaling (s, p, d)'][1] == approx(2.23)
assert sec_model.contributions[0].type == 'dispersion'
assert sec_model.contributions[0].parameters['a1'][0] == approx(0.52)
assert sec_model.repulsion[0].parameters['rExp'][0] == approx(1.0)
assert sec_model.coulomb[0].parameters['third order'][0] == 'shell-resolved'
assert sec_model.coulomb[0].parameters['cn-shift'][0] == approx(1.2)

sec_system = sec_run.system
assert len(sec_system) == 1
Expand Down

0 comments on commit ffd93bc

Please sign in to comment.