Commit bc9a0527 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added support for parsing the D2 and D3 vdW settings.

parent 4961e40b
......@@ -42,6 +42,7 @@ class CP2KCommonParser(CommonParser):
#=======================================================================
# Globally cached values
self.cache_service.add("simulation_cell", single=False, update=False)
self.cache_service.add("lattice_vectors", single=False, update=False)
self.cache_service.add("number_of_scf_iterations", 0)
self.cache_service.add("atom_positions", single=False, update=True)
self.cache_service.add("atom_labels", single=False, update=False)
......@@ -232,6 +233,34 @@ class CP2KCommonParser(CommonParser):
SM( " DFT\| Self-interaction correction \(SIC\)\s+(?P<self_interaction_correction_method>[^\n]+)"),
],
),
SM( " vdW POTENTIAL\|\s+",
forwardMatch=True,
sections=["x_cp2k_section_vdw_settings"],
subMatchers=[
SM( " vdW POTENTIAL\|\s+(?P<x_cp2k_vdw_type>{})".format(self.regexs.eol)),
SM( " vdW POTENTIAL\|\s+Potential Form:\s+(?P<x_cp2k_vdw_name>{})".format(self.regexs.eol)),
SM( " vdW POTENTIAL\|\s+BJ Damping:\s+(?P<x_cp2k_vdw_bj_damping_name>{})".format(self.regexs.eol)),
SM( " vdW POTENTIAL\|\s+Cutoff Radius \[Bohr\]:\s+(?P<x_cp2k_vdw_cutoff_radius>{})".format(self.regexs.float)),
SM( " vdW POTENTIAL\|\+sScaling Factor:s+(?P<x_cp2k_vdw_scaling_factor>{})".format(self.regexs.float),
sections=["x_cp2k_section_vdw_d2_settings"],
subMatchers=[
SM( " vdW POTENTIAL\|\s+Exp Prefactor for Damping:\s+(?P<x_cp2k_vdw_damping_factor>{})".format(self.regexs.float)),
SM( " vdW PARAMETER\|\s+Atom=(?P<x_cp2k_vdw_parameter_element_name>{})\s+C6\[J*nm^6*mol^-1\]=\s+(?P<x_cp2k_vdw_parameter_c6>{})\s+r\(vdW\)\[A\]=\s+(?P<x_cp2k_vdw_parameter_radius>{})".format(self.regexs.word, self.regexs.float, self.regexs.float),
sections=["x_cp2k_section_vdw_element_settings"],
repeats=True,
),
],
),
SM( " vdW POTENTIAL\|\s+s6 Scaling Factor:\s+(?P<x_cp2k_vdw_s6_scaling_factor>{})".format(self.regexs.float),
sections=["x_cp2k_section_vdw_d3_settings"],
subMatchers=[
SM( " vdW POTENTIAL\|\s+sr6 Scaling Factor:\s+(?P<x_cp2k_vdw_sr6_scaling_factor>{})".format(self.regexs.float)),
SM( " vdW POTENTIAL\|\s+s8 Scaling Factor:\s+(?P<x_cp2k_vdw_s8_scaling_factor>{})".format(self.regexs.float)),
SM( " vdW POTENTIAL\|\s+Cutoff for CN calculation:\s+(?P<x_cp2k_vdw_cn_cutoff>{})".format(self.regexs.float)),
],
)
]
),
SM( " DFT\+U\|",
adHoc=self.adHoc_dft_plus_u,
),
......@@ -427,6 +456,19 @@ class CP2KCommonParser(CommonParser):
backend.addValue("number_of_basis_sets_atom_centered", len(self.basis_set_info))
backend.closeSection("section_method_basis_set", method_basis_id)
def onClose_x_cp2k_section_vdw_settings(self, backend, gIndex, section):
"""Figures out the common metainfo for vdw from the CP2K specific
settings.
"""
vdw_name = section["x_cp2k_vdw_name"][0]
name_map = {
"S. Grimme, JCC 27: 1787 (2006)": "G06",
"S. Grimme et al, JCP 132: 154104 (2010)": "G10",
}
nomad_vdw_name = name_map.get(vdw_name)
if nomad_vdw_name is not None:
backend.addValue("van_der_Waals_method", nomad_vdw_name)
def onClose_x_cp2k_section_atomic_kind(self, backend, gIndex, section):
# basisID = backend.openSection("section_basis_set_atom_centered")
......@@ -541,6 +583,7 @@ class CP2KCommonParser(CommonParser):
# Push the results to cache
self.cache_service["simulation_cell"] = cell
self.cache_service["lattice_vectors"] = cell
def adHoc_atom_forces(self, parser):
"""Used to extract the final atomic forces printed at the end of a
......
......@@ -249,6 +249,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
def onClose_section_system(self, backend, gIndex, section):
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
self.cache_service.addArrayValues("lattice_vectors", unit="angstrom")
def onClose_section_method(self, backend, gIndex, section):
traj_file = self.file_service.get_file_by_id("trajectory")
......
......@@ -298,10 +298,12 @@ class CP2KMDParser(MainHierarchicalParser):
# simulation cel only on the first step to section_system
if i_step == 0 and self.ensemble == "NPT" and self.cell_iterator is None:
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
self.cache_service.addArrayValues("lattice_vectors", unit="angstrom")
# Unchanging cell
if self.ensemble != "NPT":
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
self.cache_service.addArrayValues("lattice_vectors", unit="angstrom")
# Trajectory
if freqs["trajectory"][1] and self.traj_iterator is not None:
......@@ -352,6 +354,7 @@ class CP2KMDParser(MainHierarchicalParser):
line = next(self.cell_iterator)
cell = np.reshape(line, (3, 3))
self.backend.addArrayValues("simulation_cell", cell, unit="angstrom")
self.backend.addArrayValues("lattice_vectors", cell, unit="angstrom")
# Output file
if md_steps:
......
......@@ -92,6 +92,7 @@ class CP2KSinglePointParser(MainHierarchicalParser):
"""
self.cache_service.addArrayValues("atom_positions", unit="angstrom")
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
self.cache_service.addArrayValues("lattice_vectors", unit="angstrom")
#===========================================================================
# adHoc functions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
&GLOBAL
PROJECT dftd2_t1
PRINT_LEVEL MEDIUM
RUN_TYPE ENERGY
&END GLOBAL
&FORCE_EVAL
METHOD QS
&DFT
BASIS_SET_FILE_NAME ../../GTH_BASIS_SETS
POTENTIAL_FILE_NAME ../../POTENTIAL
&MGRID
NGRIDS 1
CUTOFF 100
&END MGRID
&QS
METHOD GPW
&END QS
&SCF
SCF_GUESS ATOMIC
MAX_SCF 1
EPS_SCF 1.0e-0
&END SCF
&XC
&XC_FUNCTIONAL PBE
&END XC_FUNCTIONAL
&vdW_POTENTIAL
DISPERSION_FUNCTIONAL PAIR_POTENTIAL
&PAIR_POTENTIAL
TYPE DFTD2
REFERENCE_FUNCTIONAL PBE
&END PAIR_POTENTIAL
&END vdW_POTENTIAL
&END XC
&END DFT
&SUBSYS
&CELL
ABC 6.0 6.0 6.0
PERIODIC NONE
&END
&COORD
C 7.499969 9.250001 7.500000
C 7.499969 5.750001 7.500000
H 8.205969 8.887002 6.753000
H 6.499969 8.887002 7.262000
H 7.793968 8.887002 8.485001
H 7.499969 10.340001 7.500000
H 7.199968 6.113001 6.517000
H 8.501968 6.113001 7.731000
H 6.798969 6.113001 8.252001
H 7.499969 4.660001 7.500000
&END COORD
&KIND H
BASIS_SET DZV-GTH
POTENTIAL GTH-PBE-q1
&END
&KIND C
BASIS_SET DZVP-GTH
POTENTIAL GTH-PBE-q4
&END
&END SUBSYS
&END
This diff is collapsed.
Pair potential vdW calculation
Dispersion potential type: DFT-D3
Scaling parameter (s6) 1.0000000000000000
Scaling parameter (s8) 0.72199999999999998
Zero Damping parameter (sr6) 1.2170000000000001
Zero Damping parameter (sr8) 1.0000000000000000
Cutoff coordination numbers 9.9999999999999995E-007
Total vdW energy [au] : -1.4768519876345225E-003
Total vdW energy [kcal] : -0.92673860612936865
&GLOBAL
PROJECT dftd3_t1
PRINT_LEVEL MEDIUM
RUN_TYPE ENERGY
&END GLOBAL
&FORCE_EVAL
METHOD QS
&DFT
BASIS_SET_FILE_NAME ../../GTH_BASIS_SETS
POTENTIAL_FILE_NAME ../../POTENTIAL
&MGRID
NGRIDS 1
CUTOFF 100
&END MGRID
&QS
METHOD GPW
&END QS
&SCF
SCF_GUESS ATOMIC
MAX_SCF 1
EPS_SCF 1.0e-0
&END SCF
&XC
&XC_FUNCTIONAL PBE
&END XC_FUNCTIONAL
&vdW_POTENTIAL
DISPERSION_FUNCTIONAL PAIR_POTENTIAL
&PAIR_POTENTIAL
TYPE DFTD3
PARAMETER_FILE_NAME ../../dftd3.dat
REFERENCE_FUNCTIONAL PBE
&PRINT_DFTD
&END
&END PAIR_POTENTIAL
&END vdW_POTENTIAL
&END XC
&END DFT
&SUBSYS
&CELL
ABC 6.0 6.0 6.0
PERIODIC NONE
&END
&COORD
C 7.499969 9.250001 7.500000
C 7.499969 5.750001 7.500000
H 8.205969 8.887002 6.753000
H 6.499969 8.887002 7.262000
H 7.793968 8.887002 8.485001
H 7.499969 10.340001 7.500000
H 7.199968 6.113001 6.517000
H 8.501968 6.113001 7.731000
H 6.798969 6.113001 8.252001
H 7.499969 4.660001 7.500000
&END COORD
&KIND H
BASIS_SET DZV-GTH
POTENTIAL GTH-PBE-q1
&END
&KIND C
BASIS_SET DZVP-GTH
POTENTIAL GTH-PBE-q4
&END
&END SUBSYS
&END
This diff is collapsed.
Pair potential vdW calculation
Dispersion potential type: DFT-D3(BJ)
Scaling parameter (s6) 1.0000000000000000
Scaling parameter (s8) 0.78749999999999998
BJ Damping parameter (a1) 0.42890000000000000
BJ Damping parameter (a2) 4.4406999999999996
Cutoff coordination numbers 9.9999999999999995E-007
Total vdW energy [au] : -3.5512378384574906E-003
Total vdW energy [kcal] : -2.2284353692865868
&GLOBAL
PROJECT dftd3_t1
PRINT_LEVEL MEDIUM
RUN_TYPE ENERGY
&END GLOBAL
&FORCE_EVAL
METHOD QS
&DFT
BASIS_SET_FILE_NAME ../../GTH_BASIS_SETS
POTENTIAL_FILE_NAME ../../POTENTIAL
&MGRID
NGRIDS 1
CUTOFF 100
&END MGRID
&QS
METHOD GPW
&END QS
&SCF
SCF_GUESS ATOMIC
MAX_SCF 1
EPS_SCF 1.0e-0
&END SCF
&XC
&XC_FUNCTIONAL PBE
&END XC_FUNCTIONAL
&vdW_POTENTIAL
DISPERSION_FUNCTIONAL PAIR_POTENTIAL
&PAIR_POTENTIAL
TYPE DFTD3(BJ)
PARAMETER_FILE_NAME ../../dftd3.dat
REFERENCE_FUNCTIONAL PBE
&PRINT_DFTD
&END
&END PAIR_POTENTIAL
&END vdW_POTENTIAL
&END XC
&END DFT
&SUBSYS
&CELL
ABC 6.0 6.0 6.0
PERIODIC NONE
&END
&COORD
C 7.499969 9.250001 7.500000
C 7.499969 5.750001 7.500000
H 8.205969 8.887002 6.753000
H 6.499969 8.887002 7.262000
H 7.793968 8.887002 8.485001
H 7.499969 10.340001 7.500000
H 7.199968 6.113001 6.517000
H 8.501968 6.113001 7.731000
H 6.798969 6.113001 8.252001
H 7.499969 4.660001 7.500000
&END COORD
&KIND H
BASIS_SET DZV-GTH
POTENTIAL GTH-PBE-q1
&END
&KIND C
BASIS_SET DZVP-GTH
POTENTIAL GTH-PBE-q4
&END
&END SUBSYS
&END
This diff is collapsed.
......@@ -348,12 +348,16 @@ class TestEnergyForce(unittest.TestCase):
def test_simulation_cell(self):
cell = self.results["simulation_cell"]
vectors = self.results["lattice_vectors"]
n_vectors = cell.shape[0]
n_dim = cell.shape[1]
self.assertEqual(n_vectors, 3)
self.assertEqual(n_dim, 3)
expected_cell = convert_unit(np.array([[5.431, 0, 0], [0, 5.431, 0], [0, 0, 5.431]]), "angstrom")
self.assertTrue(np.array_equal(cell, expected_cell))
self.assertTrue(np.array_equal(vectors, expected_cell))
def test_number_of_atoms(self):
n_atoms = self.results["number_of_atoms"]
......@@ -1100,6 +1104,25 @@ class TestMDEnsembles(unittest.TestCase):
self.assertTrue(np.array_equal(expected_cell_end, simulation_cell[-1, :, :]))
class TestVDWMethod(unittest.TestCase):
"""Tests that different van der Waals methods are recognized correctly.
"""
def test_d2(self):
results = get_result("vdw/d2")
result = results["van_der_Waals_method"]
self.assertEqual(result, "G06")
def test_d3(self):
results = get_result("vdw/d3")
result = results["van_der_Waals_method"]
self.assertEqual(result, "G10")
def test_d3_bj(self):
results = get_result("vdw/d3_bj")
result = results["van_der_Waals_method"]
self.assertEqual(result, "G10")
class TestElectronicStructureMethod(unittest.TestCase):
"""Tests that different methods are recognized correctly.
"""
......@@ -1146,6 +1169,8 @@ if __name__ == '__main__':
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMD))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMDPrintSettings))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMDEnsembles))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMDEnsembles))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestVDWMethod))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestElectronicStructureMethod))
alltests = unittest.TestSuite(suites)
unittest.TextTestRunner(verbosity=0).run(alltests)
Markdown is supported
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