Commit 3d3e3d06 authored by Lauri Himanen's avatar Lauri Himanen

Fixed issue in not giving the geometry optimization completion flag properly,...

Fixed issue in not giving the geometry optimization completion flag properly, fixed issue in reading geometry optimization frames if maximum number of steps reached.
parent 13e0bfa7
......@@ -44,6 +44,8 @@ class CP2KGeoOptParser(MainHierarchicalParser):
self.cache_service.add("frame_sequence_potential_energy", [])
self.cache_service.add("frame_sequence_local_frames_ref", [])
self.cache_service.add("geometry_optimization_method")
self.cache_service.add("geometry_optimization_converged")
self.cache_service.add("geometry_opt_max_reached")
#=======================================================================
# Cache levels
......@@ -62,15 +64,12 @@ class CP2KGeoOptParser(MainHierarchicalParser):
subMatchers=[
SM( " *** CONJUGATE GRADIENTS ***".replace("*", "\*"),
adHoc=self.adHoc_conjugate_gradient(),
otherMetaInfo=["geometry_optimization_method"],
),
SM( " *** BFGS ***".replace("*", "\*"),
adHoc=self.adHoc_bfgs(),
otherMetaInfo=["geometry_optimization_method"],
),
SM( " *** L-BFGS ***".replace("*", "\*"),
adHoc=self.adHoc_bfgs(),
otherMetaInfo=["geometry_optimization_method"],
),
# SM( "",
# forwardMatch=True,
......@@ -79,11 +78,8 @@ class CP2KGeoOptParser(MainHierarchicalParser):
# self.cm.quickstep_calculation(),
# SM( " -------- Informations at step"),
# SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.regexs.word)),
# SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.regexs.float),
# otherMetaInfo=["frame_sequence_potential_energy"]
# ),
# SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.regexs.float)),
# ],
# otherMetaInfo=["atom_positions"],
# adHoc=self.adHoc_step(),
# ),
SM( " OPTIMIZATION STEP:",
......@@ -94,9 +90,6 @@ class CP2KGeoOptParser(MainHierarchicalParser):
SM( "",
forwardMatch=True,
sections=["x_cp2k_section_geometry_optimization_step"],
otherMetaInfo=[
"atom_positions",
],
subMatchers=[
# SM( "",
# forwardMatch=True,
......@@ -126,23 +119,17 @@ class CP2KGeoOptParser(MainHierarchicalParser):
# ),
SM( " -------- Informations at step"),
SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.regexs.word)),
SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.regexs.float),
otherMetaInfo=["frame_sequence_potential_energy"]
),
SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.regexs.float)),
SM( " Real energy change =\s+(?P<x_cp2k_optimization_energy_change__hartree>{})".format(self.regexs.float)),
SM( " Decrease in energy =\s+(?P<x_cp2k_optimization_energy_decrease>{})".format(self.regexs.word)),
SM( " Used time =\s+(?P<x_cp2k_optimization_used_time>{})".format(self.regexs.float)),
SM( " Max. step size =\s+(?P<x_cp2k_optimization_max_step_size__bohr>{})".format(self.regexs.float)),
SM( " Conv. limit for step size =\s+(?P<x_cp2k_optimization_step_size_convergence_limit__bohr>{})".format(self.regexs.float),
otherMetaInfo=["geometry_optimization_geometry_change"]
),
SM( " Conv. limit for step size =\s+(?P<x_cp2k_optimization_step_size_convergence_limit__bohr>{})".format(self.regexs.float)),
SM( " Convergence in step size =\s+(?P<x_cp2k_optimization_step_size_convergence>{})".format(self.regexs.word)),
SM( " RMS step size =\s+(?P<x_cp2k_optimization_rms_step_size__bohr>{})".format(self.regexs.float)),
SM( " Convergence in RMS step =\s+(?P<x_cp2k_optimization_rms_step_size_convergence>{})".format(self.regexs.word)),
SM( " Max. gradient =\s+(?P<x_cp2k_optimization_max_gradient__bohr_1hartree>{})".format(self.regexs.float)),
SM( " Conv. limit for gradients =\s+(?P<x_cp2k_optimization_gradient_convergence_limit__bohr_1hartree>{})".format(self.regexs.float),
otherMetaInfo=["geometry_optimization_threshold_force"]
),
SM( " Conv. limit for gradients =\s+(?P<x_cp2k_optimization_gradient_convergence_limit__bohr_1hartree>{})".format(self.regexs.float)),
SM( " Conv. for gradients =\s+(?P<x_cp2k_optimization_max_gradient_convergence>{})".format(self.regexs.word)),
SM( " RMS gradient =\s+(?P<x_cp2k_optimization_rms_gradient__bohr_1hartree>{})".format(self.regexs.float)),
SM( " Conv. in RMS gradients =\s+(?P<x_cp2k_optimization_rms_gradient_convergence>{})".format(self.regexs.word)),
......@@ -153,7 +140,9 @@ class CP2KGeoOptParser(MainHierarchicalParser):
),
SM( " *** GEOMETRY OPTIMIZATION COMPLETED ***".replace("*", "\*"),
adHoc=self.adHoc_geo_opt_converged(),
otherMetaInfo=["geometry_optimization_converged"]
),
SM( " *** MAXIMUM NUMBER OF OPTIMIZATION STEPS REACHED ***".replace("*", "\*"),
adHoc=self.adHoc_geo_opt_max_steps_reached(),
),
SM( " Reevaluating energy at the minimum",
# sections=["x_cp2k_section_geometry_optimization_energy_reevaluation"],
......@@ -192,6 +181,12 @@ class CP2KGeoOptParser(MainHierarchicalParser):
]
)
#===========================================================================
# onOpen triggers
def onOpen_section_frame_sequence(self, backend, gIndex, section):
self.cache_service["geometry_optimization_converged"] = False
self.cache_service["geometry_opt_max_reached"] = False
#===========================================================================
# onClose triggers
def onClose_x_cp2k_section_geometry_optimization(self, backend, gIndex, section):
......@@ -229,8 +224,13 @@ class CP2KGeoOptParser(MainHierarchicalParser):
if add_last_setting == "NUMERIC" or add_last_setting == "SYMBOLIC":
add_last = True
# Push the trajectory
# Determine number of steps. If the optimization was quit due to
# maximum number of steps reached, the energy for the last step is not
# calculated, and thus the final geometry is not reported. This is
# detected and then the number of frames is adjusted.
n_steps = len(steps) + 1
if self.cache_service["geometry_opt_max_reached"]:
n_steps -= 1
last_step = n_steps - 1
# First push the original system geometry
......@@ -259,6 +259,9 @@ class CP2KGeoOptParser(MainHierarchicalParser):
self.cache_service.addArrayValues("frame_sequence_local_frames_ref")
backend.addValue("number_of_frames_in_sequence", n_steps)
def onClose_section_frame_sequence(self, backend, gIndex, section):
self.cache_service.addValue("geometry_optimization_converged")
def onClose_section_sampling_method(self, backend, gIndex, section):
self.backend.addValue("sampling_method", "geometry_optimization")
......@@ -297,14 +300,14 @@ class CP2KGeoOptParser(MainHierarchicalParser):
"""Called when the geometry optimization converged.
"""
def wrapper(parser):
parser.backend.addValue("geometry_optimization_converged", True)
self.cache_service["geometry_optimization_converged"] = True
return wrapper
def adHoc_geo_opt_not_converged(self):
"""Called when the geometry optimization did not converge.
def adHoc_geo_opt_max_steps_reached(self):
"""Called when the geometry optimization converged.
"""
def wrapper(parser):
parser.backend.addValue("geometry_optimization_converged", False)
self.cache_service["geometry_opt_max_reached"] = True
return wrapper
def adHoc_conjugate_gradient(self):
......
This diff is collapsed.
&MOTION
&GEO_OPT
TYPE MINIMIZATION
OPTIMIZER BFGS
MAX_ITER 3
RMS_FORCE 3.0E-4
MAX_FORCE 4.5E-4
&END GEO_OPT
&END MOTION
&GLOBAL
PREFERRED_FFT_LIBRARY FFTSG
RUN_TYPE GEO_OPT
PROJECT_NAME gopt
EXTENDED_FFT_LENGTHS
PRINT_LEVEL MEDIUM
&END GLOBAL
&FORCE_EVAL
METHOD QuickStep
&PRINT
&FORCES
FILENAME forces
&EACH
MD 1
&END EACH
&END FORCES
&END PRINT
&SUBSYS
&PRINT
&CELL ON
&END CELL
&END PRINT
&TOPOLOGY
COORD_FILE_NAME adsorbate_structure.xyz
COORD_FILE_FORMAT XYZ
&CENTER_COORDINATES T
&END CENTER_COORDINATES
&END TOPOLOGY
&CELL
ABC [angstrom] 20 20 20
PERIODIC NONE
&END CELL
&KIND S
POTENTIAL GTH-PBE-q6
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Au
POTENTIAL GTH-PBE-q11
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND H
POTENTIAL GTH-PBE-q1
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Pt
POTENTIAL GTH-PBE-q18
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Y
POTENTIAL GTH-PBE-q11
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Zr
POTENTIAL GTH-PBE-q12
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Nb
POTENTIAL GTH-PBE-q13
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Mo
POTENTIAL GTH-PBE-q14
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Tc
POTENTIAL GTH-PBE-q15
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Fe
POTENTIAL GTH-PBE-q16
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Co
POTENTIAL GTH-PBE-q17
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Ni
POTENTIAL GTH-PBE-q18
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Cu
POTENTIAL GTH-PBE-q11
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&KIND Zn
POTENTIAL GTH-PBE-q12
BASIS_SET DZVP-MOLOPT-SR-GTH
&END KIND
&END SUBSYS
&DFT
POTENTIAL_FILE_NAME POTENTIAL
UKS
BASIS_SET_FILE_NAME BASIS_MOLOPT
&POISSON
PERIODIC NONE
POISSON_SOLVER WAVELET
&END POISSON
&QS
MAP_CONSISTENT
EXTRAPOLATION ASPC
EXTRAPOLATION_ORDER 4
METHOD GPW
EPS_DEFAULT 1.0E-12
&END QS
&MGRID
NGRIDS 4
REL_CUTOFF 30
CUTOFF 300
&END MGRID
&PRINT
&LOWDIN ON
FILENAME lowdin
&EACH
MD 1
&END EACH
&END LOWDIN
&PDOS
LOG_PRINT_KEY TRUE
APPEND
FILENAME dosfile
NLUMO -1
COMPONENTS .FALSE.
&END PDOS
&END PRINT
&XC
&VDW_POTENTIAL
POTENTIAL_TYPE PAIR_POTENTIAL
&PAIR_POTENTIAL
LONG_RANGE_CORRECTION .TRUE.
TYPE DFTD3(BJ)
CALCULATE_C9_TERM .TRUE.
REFERENCE_FUNCTIONAL PBE
REFERENCE_C9_TERM .TRUE.
PARAMETER_FILE_NAME dftd3.dat
&END PAIR_POTENTIAL
&END VDW_POTENTIAL
&XC_GRID
XC_SMOOTH_RHO NONE
XC_DERIV SPLINE2
&END XC_GRID
&XC_FUNCTIONAL PBE
&END XC_FUNCTIONAL
&END XC
&SCF
EPS_LUMO 0.000001
CHOLESKY INVERSE_DBCSR
MAX_SCF 1
EPS_SCF 1.0E-6
SCF_GUESS RESTART
ADDED_MOS 200
MAX_ITER_LUMO 10000
&SMEAR ON
ELECTRONIC_TEMPERATURE [K] 300
METHOD FERMI_DIRAC
&END SMEAR
&PRINT
&RESTART_HISTORY OFF
&END RESTART_HISTORY
&RESTART LOW
BACKUP_COPIES 0
&END RESTART
&END PRINT
&DIAGONALIZATION
ALGORITHM STANDARD
&END DIAGONALIZATION
&OUTER_SCF
EPS_SCF 1.0E-6
MAX_SCF 1
&END OUTER_SCF
&MIXING
NBUFFER 8
METHOD BROYDEN_MIXING
BETA 1.5
ALPHA 0.1
&END MIXING
&END SCF
&END DFT
&END FORCE_EVAL
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -781,6 +781,44 @@ class TestGeoOpt(unittest.TestCase):
self.assertTrue(np.array_equal(result_end, expected_end))
class TestGeoOptMaxSteps(unittest.TestCase):
"""Tests that if a maximum number of steps is reached in geometry
optimization, the correct amount of frames is reported.
"""
@classmethod
def setUpClass(cls):
cls.results = get_result("geo_opt/max_steps")
def test_geometry_optimization_converged(self):
result = self.results["geometry_optimization_converged"]
self.assertFalse(result)
def test_number_of_frames_in_sequence(self):
result = self.results["number_of_frames_in_sequence"]
self.assertEqual(result, 3)
def test_frame_sequence_to_sampling_ref(self):
result = self.results["frame_sequence_to_sampling_ref"]
self.assertEqual(result, 0)
def test_frame_sequence_local_frames_ref(self):
result = self.results["frame_sequence_local_frames_ref"]
expected_result = np.array([0, 1, 2])
self.assertTrue(np.array_equal(result, expected_result))
def test_sampling_method(self):
result = self.results["sampling_method"]
self.assertEqual(result, "geometry_optimization")
def test_frame_sequence_potential_energy(self):
result = self.results["frame_sequence_potential_energy"]
self.assertEqual(len(result), 3)
def test_atom_positions(self):
result = self.results["atom_positions"]
self.assertEqual(len(result), 3)
class TestGeoOptTrajFormats(unittest.TestCase):
"""Different trajectory formats in geometry optimization.
"""
......@@ -1370,6 +1408,7 @@ if __name__ == '__main__':
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForceFiles))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestPreprocessor))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOpt))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptMaxSteps))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajFormats))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptOptimizers))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajectory))
......
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