From e7e23cd305591207a1d069580638426474d8aea6 Mon Sep 17 00:00:00 2001 From: Jose Pizarro Date: Mon, 17 Jul 2023 12:20:50 +0200 Subject: [PATCH 1/6] Fixed method.tb section for DFTB+ and xTB --- .../dftbplus/metainfo/dftbplus.py | 10 ++------- atomisticparsers/dftbplus/parser.py | 2 +- atomisticparsers/xtb/metainfo/xtb.py | 5 ++--- atomisticparsers/xtb/parser.py | 22 +++++++++---------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/atomisticparsers/dftbplus/metainfo/dftbplus.py b/atomisticparsers/dftbplus/metainfo/dftbplus.py index e2ff655c..f8ccb7c8 100644 --- a/atomisticparsers/dftbplus/metainfo/dftbplus.py +++ b/atomisticparsers/dftbplus/metainfo/dftbplus.py @@ -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 @@ -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) @@ -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=[], diff --git a/atomisticparsers/dftbplus/parser.py b/atomisticparsers/dftbplus/parser.py index c70e3171..efe20ae6 100644 --- a/atomisticparsers/dftbplus/parser.py +++ b/atomisticparsers/dftbplus/parser.py @@ -353,8 +353,8 @@ 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.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', []): diff --git a/atomisticparsers/xtb/metainfo/xtb.py b/atomisticparsers/xtb/metainfo/xtb.py index b2f5a3cf..caa280e2 100644 --- a/atomisticparsers/xtb/metainfo/xtb.py +++ b/atomisticparsers/xtb/metainfo/xtb.py @@ -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 @@ -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) diff --git a/atomisticparsers/xtb/parser.py b/atomisticparsers/xtb/parser.py index 046b392e..bfae031d 100644 --- a/atomisticparsers/xtb/parser.py +++ b/atomisticparsers/xtb/parser.py @@ -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 @@ -584,27 +584,25 @@ 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.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} From 377e728ba81170532628242ca34ffa0ca9e3c279 Mon Sep 17 00:00:00 2001 From: Jose Pizarro Date: Mon, 17 Jul 2023 12:49:55 +0200 Subject: [PATCH 2/6] Fixed tests --- tests/test_dftbplusparser.py | 4 ++-- tests/test_xtbparser.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_dftbplusparser.py b/tests/test_dftbplusparser.py index 5f4f2784..152f51df 100644 --- a/tests/test_dftbplusparser.py +++ b/tests/test_dftbplusparser.py @@ -41,8 +41,8 @@ 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.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 diff --git a/tests/test_xtbparser.py b/tests/test_xtbparser.py index bd1f65ad..727d73fd 100644 --- a/tests/test_xtbparser.py +++ b/tests/test_xtbparser.py @@ -43,16 +43,16 @@ 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.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 From 77386867f7384a518213c32e7ed5c24df9fac9df Mon Sep 17 00:00:00 2001 From: Jose Pizarro Date: Mon, 17 Jul 2023 14:20:05 +0200 Subject: [PATCH 3/6] Added tb.name Fixed BOPfox parser for TB --- atomisticparsers/bopfox/metainfo/bopfox.py | 11 +++++++++++ atomisticparsers/bopfox/parser.py | 10 ++++------ atomisticparsers/dftbplus/parser.py | 1 + atomisticparsers/xtb/parser.py | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/atomisticparsers/bopfox/metainfo/bopfox.py b/atomisticparsers/bopfox/metainfo/bopfox.py index 2c4fecaf..1186083f 100644 --- a/atomisticparsers/bopfox/metainfo/bopfox.py +++ b/atomisticparsers/bopfox/metainfo/bopfox.py @@ -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) diff --git a/atomisticparsers/bopfox/parser.py b/atomisticparsers/bopfox/parser.py index 2f0a12a0..d6a97459 100644 --- a/atomisticparsers/bopfox/parser.py +++ b/atomisticparsers/bopfox/parser.py @@ -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 ( @@ -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() @@ -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 diff --git a/atomisticparsers/dftbplus/parser.py b/atomisticparsers/dftbplus/parser.py index efe20ae6..e5a37283 100644 --- a/atomisticparsers/dftbplus/parser.py +++ b/atomisticparsers/dftbplus/parser.py @@ -354,6 +354,7 @@ def parse_system(source): sec_method = sec_run.m_create(Method) 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 diff --git a/atomisticparsers/xtb/parser.py b/atomisticparsers/xtb/parser.py index bfae031d..c1d9968c 100644 --- a/atomisticparsers/xtb/parser.py +++ b/atomisticparsers/xtb/parser.py @@ -586,6 +586,7 @@ def parse_method(self, section): sec_method = self.archive.run[-1].m_create(Method) parameters = {p[0]: p[1] for p in self.out_parser.get(section, {}).get('setup', {}).get('parameter', [])} 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 From 2e82dfe913bef5c257fefda37eac747352b4a5e2 Mon Sep 17 00:00:00 2001 From: Jose Pizarro Date: Mon, 17 Jul 2023 14:22:59 +0200 Subject: [PATCH 4/6] Fixed testing and adding tb.name --- tests/test_bopfoxparser.py | 2 +- tests/test_dftbplusparser.py | 1 + tests/test_xtbparser.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_bopfoxparser.py b/tests/test_bopfoxparser.py index 9ee02e91..08fd7917 100644 --- a/tests/test_bopfoxparser.py +++ b/tests/test_bopfoxparser.py @@ -41,7 +41,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() diff --git a/tests/test_dftbplusparser.py b/tests/test_dftbplusparser.py index 152f51df..d148b4f5 100644 --- a/tests/test_dftbplusparser.py +++ b/tests/test_dftbplusparser.py @@ -41,6 +41,7 @@ def test_static(parser): assert sec_run[0].x_dftbp_parser_version == '8' sec_method = archive.run[0].method + 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' diff --git a/tests/test_xtbparser.py b/tests/test_xtbparser.py index 727d73fd..a7e07493 100644 --- a/tests/test_xtbparser.py +++ b/tests/test_xtbparser.py @@ -43,6 +43,7 @@ def test_scf(parser): assert sec_run.time_run.date_end > 0 sec_method = sec_run.method + 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) From 6b713eee0897b4ba834b79f903e70d5b2e8ec572 Mon Sep 17 00:00:00 2001 From: Jose Pizarro Date: Mon, 13 Nov 2023 10:52:17 +0100 Subject: [PATCH 5/6] Fix BOPfox testing --- tests/test_bopfoxparser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_bopfoxparser.py b/tests/test_bopfoxparser.py index 08fd7917..7471f622 100644 --- a/tests/test_bopfoxparser.py +++ b/tests/test_bopfoxparser.py @@ -44,14 +44,14 @@ def test_energy(parser): 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() + assert sec_model.hamiltonian[1].atom_labels == ['W', 'W'] assert sec_model.hamiltonian[2].functional_form == 'screenedpowerlaw' assert sec_model.hamiltonian[3].x_bopfox_cutoff == approx(4.4) assert sec_model.hamiltonian[4].x_bopfox_dcutoff == approx(1.3) assert sec_model.hamiltonian[5].x_bopfox_valence == ['d', 'd'] - assert (sec_model.hamiltonian[6].atom_labels == ['W', 'Mo']).all() + assert sec_model.hamiltonian[6].atom_labels == ['W', 'Mo'] assert sec_model.hamiltonian[7].parameters[0] == approx(0.8359765) - assert (sec_model.repulsion[2].atom_labels == ['Mo', 'Mo']).all() + assert sec_model.repulsion[2].atom_labels == ['Mo', 'Mo'] assert sec_model.repulsion[0].x_bopfox_cutoff == approx(5.0) assert sec_model.repulsion[1].parameters[2] == approx(-2.909290858) assert sec_model.repulsion[2].functional_form == 'env_Yukawa' From e6b7f22ca2e4b4fb523e70a5c5998a62f8c72e21 Mon Sep 17 00:00:00 2001 From: Jose Pizarro Date: Mon, 20 Nov 2023 11:34:56 +0100 Subject: [PATCH 6/6] Fix BOPfox testing --- tests/test_bopfoxparser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_bopfoxparser.py b/tests/test_bopfoxparser.py index 7471f622..8548da17 100644 --- a/tests/test_bopfoxparser.py +++ b/tests/test_bopfoxparser.py @@ -17,6 +17,7 @@ # import pytest +import numpy as np from nomad.datamodel import EntryArchive from atomisticparsers.bopfox import BOPfoxParser @@ -44,14 +45,14 @@ def test_energy(parser): 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'] + assert (sec_model.hamiltonian[1].atom_labels == ['W', 'W']).all() assert sec_model.hamiltonian[2].functional_form == 'screenedpowerlaw' assert sec_model.hamiltonian[3].x_bopfox_cutoff == approx(4.4) assert sec_model.hamiltonian[4].x_bopfox_dcutoff == approx(1.3) assert sec_model.hamiltonian[5].x_bopfox_valence == ['d', 'd'] - assert sec_model.hamiltonian[6].atom_labels == ['W', 'Mo'] + assert (sec_model.hamiltonian[6].atom_labels == ['W', 'Mo']).all() assert sec_model.hamiltonian[7].parameters[0] == approx(0.8359765) - assert sec_model.repulsion[2].atom_labels == ['Mo', 'Mo'] + assert (sec_model.repulsion[2].atom_labels == ['Mo', 'Mo']).all() assert sec_model.repulsion[0].x_bopfox_cutoff == approx(5.0) assert sec_model.repulsion[1].parameters[2] == approx(-2.909290858) assert sec_model.repulsion[2].functional_form == 'env_Yukawa'