Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
parser-cp2k
Commits
fe625fdc
Commit
fe625fdc
authored
Jun 06, 2016
by
Lauri Himanen
Browse files
Started doing the MD parser.
parent
106eb43e
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py
0 → 100644
View file @
fe625fdc
from
nomadcore.simple_parser
import
SimpleMatcher
as
SM
from
nomadcore.baseclasses
import
MainHierarchicalParser
from
commonmatcher
import
CommonMatcher
import
cp2kparser.generic.configurationreading
import
cp2kparser.generic.csvparsing
from
nomadcore.caching_backend
import
CachingLevel
import
logging
logger
=
logging
.
getLogger
(
"nomad"
)
#===============================================================================
class
CP2KMDParser
(
MainHierarchicalParser
):
"""Used to parse the CP2K calculation with run types:
-MD
-MOLECULAR_DYNAMICS
"""
def
__init__
(
self
,
file_path
,
parser_context
):
"""
"""
super
(
CP2KMDParser
,
self
).
__init__
(
file_path
,
parser_context
)
self
.
setup_common_matcher
(
CommonMatcher
(
parser_context
))
self
.
traj_iterator
=
None
#=======================================================================
# Globally cached values
self
.
cache_service
.
add_cache_object
(
"number_of_frames_in_sequence"
,
0
)
self
.
cache_service
.
add_cache_object
(
"frame_sequence_potential_energy"
,
[])
self
.
cache_service
.
add_cache_object
(
"frame_sequence_local_frames_ref"
,
[])
#=======================================================================
# Cache levels
self
.
caching_level_for_metaname
.
update
({
# 'x_cp2k_optimization_energy': CachingLevel.ForwardAndCache,
# 'x_cp2k_section_geometry_optimization_step': CachingLevel.ForwardAndCache,
# 'x_cp2k_section_quickstep_calculation': CachingLevel.ForwardAndCache,
# 'x_cp2k_section_geometry_optimization': CachingLevel.ForwardAndCache,
# 'x_cp2k_section_geometry_optimization_energy_reevaluation': CachingLevel.ForwardAndCache,
})
#=======================================================================
# SimpleMatchers
self
.
md
=
SM
(
" MD\| Molecular Dynamics Protocol"
,
sections
=
[
"x_cp2k_section_md"
],
subMatchers
=
[
SM
(
" MD\| Ensemble Type\s+(?P<x_cp2k_md_ensemble_type>{})"
.
format
(
self
.
cm
.
regex_word
)),
SM
(
" MD\| Number of Time Steps\s+(?P<x_cp2k_md_number_of_time_steps>{})"
.
format
(
self
.
cm
.
regex_word
)),
SM
(
" MD\| Time Step \[fs\]\s+(?P<x_cp2k_md_time_step__fs>{})"
.
format
(
self
.
cm
.
regex_f
)),
SM
(
" MD\| Temperature \[K\]\s+(?P<x_cp2k_md_temperature>{})"
.
format
(
self
.
cm
.
regex_f
)),
SM
(
" MD\| Temperature tolerance \[K\]\s+(?P<x_cp2k_md_temperature_tolerance>{})"
.
format
(
self
.
cm
.
regex_f
)),
SM
(
" MD\| Print MD information every\s+(?P<x_cp2k_md_print_frequency>{}) step(s)"
.
format
(
self
.
cm
.
regex_i
)),
SM
(
" MD\| File type Print frequency\[steps\] File names"
),
SM
(
" MD\| Coordinates\s+(?P<x_cp2k_md_coordinates_print_frequency>{})\s+(?P<x_cp2k_md_coordinates_filename>{})"
.
format
(
self
.
cm
.
regex_i
,
self
.
cm
.
regex_word
)),
SM
(
" MD\| Velocities\s+(?P<x_cp2k_md_velocities_print_frequency>{})\s+(?P<x_cp2k_md_velocities_filename>{})"
.
format
(
self
.
cm
.
regex_i
,
self
.
cm
.
regex_word
)),
SM
(
" MD\| Energies\s+(?P<x_cp2k_md_energies_print_frequency>{})\s+(?P<x_cp2k_md_energies_filename>{})"
.
format
(
self
.
cm
.
regex_i
,
self
.
cm
.
regex_word
)),
SM
(
" MD\| Dump\s+(?P<x_cp2k_md_dump_print_frequency>{})\s+(?P<x_cp2k_md_dump_filename>{})"
.
format
(
self
.
cm
.
regex_i
,
self
.
cm
.
regex_word
)),
]
)
# Compose root matcher according to the run type. This way the
# unnecessary regex parsers will not be compiled and searched. Saves
# computational time.
self
.
root_matcher
=
SM
(
""
,
forwardMatch
=
True
,
sections
=
[
"section_run"
,
"section_sampling_method"
],
subMatchers
=
[
SM
(
""
,
forwardMatch
=
True
,
sections
=
[
"section_method"
],
subMatchers
=
[
self
.
cm
.
header
(),
self
.
cm
.
quickstep_header
(),
],
),
self
.
md
,
]
)
#===========================================================================
# onClose triggers
def
onClose_x_cp2k_section_geometry_optimization
(
self
,
backend
,
gIndex
,
section
):
# Get the re-evaluated energy and add it to frame_sequence_potential_energy
energy
=
section
.
get_latest_value
([
"x_cp2k_section_geometry_optimization_energy_reevaluation"
,
"x_cp2k_section_quickstep_calculation"
,
"x_cp2k_energy_total"
]
)
if
energy
is
not
None
:
self
.
cache_service
[
"frame_sequence_potential_energy"
].
append
(
energy
)
# Push values from cache
self
.
cache_service
.
push_array_values
(
"frame_sequence_potential_energy"
)
self
.
cache_service
.
push_value
(
"geometry_optimization_method"
)
self
.
backend
.
addValue
(
"frame_sequence_to_sampling_ref"
,
0
)
# Get the optimization convergence criteria from the last optimization
# step
section
.
add_latest_value
([
"x_cp2k_section_geometry_optimization_step"
,
"x_cp2k_optimization_step_size_convergence_limit"
],
"geometry_optimization_geometry_change"
,
)
section
.
add_latest_value
([
"x_cp2k_section_geometry_optimization_step"
,
"x_cp2k_optimization_gradient_convergence_limit"
],
"geometry_optimization_threshold_force"
,
)
# Push the information into single configuration and system
steps
=
section
[
"x_cp2k_section_geometry_optimization_step"
]
each
=
self
.
cache_service
[
"each_geo_opt"
]
add_last
=
False
add_last_setting
=
self
.
cache_service
[
"traj_add_last"
]
if
add_last_setting
==
"NUMERIC"
or
add_last_setting
==
"SYMBOLIC"
:
add_last
=
True
# Push the trajectory
n_steps
=
len
(
steps
)
+
1
last_step
=
n_steps
-
1
for
i_step
in
range
(
n_steps
):
singleId
=
backend
.
openSection
(
"section_single_configuration_calculation"
)
systemId
=
backend
.
openSection
(
"section_system"
)
if
self
.
traj_iterator
is
not
None
:
if
(
i_step
+
1
)
%
each
==
0
or
(
i_step
==
last_step
and
add_last
):
try
:
pos
=
next
(
self
.
traj_iterator
)
except
StopIteration
:
logger
.
error
(
"Could not get the next geometries from an external file. It seems that the number of optimization steps in the CP2K outpufile doesn't match the number of steps found in the external trajectory file."
)
else
:
backend
.
addArrayValues
(
"atom_positions"
,
pos
,
unit
=
"angstrom"
)
backend
.
closeSection
(
"section_system"
,
systemId
)
backend
.
closeSection
(
"section_single_configuration_calculation"
,
singleId
)
self
.
cache_service
.
push_array_values
(
"frame_sequence_local_frames_ref"
)
backend
.
addValue
(
"number_of_frames_in_sequence"
,
n_steps
)
def
onClose_section_sampling_method
(
self
,
backend
,
gIndex
,
section
):
self
.
backend
.
addValue
(
"sampling_method"
,
"geometry_optimization"
)
def
onClose_x_cp2k_section_geometry_optimization_step
(
self
,
backend
,
gIndex
,
section
):
energy
=
section
[
"x_cp2k_optimization_energy"
]
if
energy
is
not
None
:
self
.
cache_service
[
"frame_sequence_potential_energy"
].
append
(
energy
[
0
])
def
onClose_section_method
(
self
,
backend
,
gIndex
,
section
):
traj_file
=
self
.
file_service
.
get_file_by_id
(
"trajectory"
)
traj_format
=
self
.
cache_service
[
"trajectory_format"
]
if
traj_format
is
not
None
and
traj_file
is
not
None
:
# Use special parsing for CP2K pdb files because they don't follow the proper syntax
if
traj_format
==
"PDB"
:
self
.
traj_iterator
=
cp2kparser
.
generic
.
csvparsing
.
iread
(
traj_file
,
columns
=
[
3
,
4
,
5
],
start
=
"CRYST"
,
end
=
"END"
)
else
:
try
:
self
.
traj_iterator
=
cp2kparser
.
generic
.
configurationreading
.
iread
(
traj_file
)
except
ValueError
:
pass
def
onClose_section_single_configuration_calculation
(
self
,
backend
,
gIndex
,
section
):
self
.
cache_service
[
"frame_sequence_local_frames_ref"
].
append
(
gIndex
)
#===========================================================================
# adHoc functions
def
adHoc_geo_opt_converged
(
self
):
"""Called when the geometry optimization converged.
"""
def
wrapper
(
parser
):
parser
.
backend
.
addValue
(
"geometry_optimization_converged"
,
True
)
return
wrapper
def
adHoc_geo_opt_not_converged
(
self
):
"""Called when the geometry optimization did not converge.
"""
def
wrapper
(
parser
):
parser
.
backend
.
addValue
(
"geometry_optimization_converged"
,
False
)
return
wrapper
def
adHoc_conjugate_gradient
(
self
):
"""Called when conjugate gradient method is used.
"""
def
wrapper
(
parser
):
self
.
cache_service
[
"geometry_optimization_method"
]
=
"conjugate_gradient"
return
wrapper
def
adHoc_bfgs
(
self
):
"""Called when conjugate gradient method is used.
"""
def
wrapper
(
parser
):
self
.
cache_service
[
"geometry_optimization_method"
]
=
"bfgs"
return
wrapper
# def adHoc_step(self):
# """Called when all the step information has been retrieved from the
# output file. Here further information is gathered from external files.
# """
# def wrapper(parser):
# self.cache_service["number_of_frames_in_sequence"] += 1
# return wrapper
parser/parser-cp2k/cp2kparser/versions/versionsetup.py
View file @
fe625fdc
...
...
@@ -29,6 +29,8 @@ def get_main_parser(version_id, run_type):
"WFN_OPT"
:
"SinglePointParser"
,
"GEO_OPT"
:
"GeoOptParser"
,
"GEOMETRY_OPTIMIZATION"
:
"GeoOptParser"
,
"MD"
:
"MDParser"
,
"MOLECULAR_DYNAMICS"
:
"MDParser"
,
}
try
:
parser
=
parser_map
[
run_type
]
...
...
test/unittests/cp2k_2.6.2/md/nve/H2O-32-1.ener
0 → 100644
View file @
fe625fdc
# Step Nr. Time[fs] Kin.[a.u.] Temp[K] Pot.[a.u.] Cons Qty[a.u.] UsedTime[s]
0 0.000000 0.007125335 300.000000000 -34.330396471 -34.323271136 0.000000000
1 0.500000 0.006533348 275.075405378 -34.329778993 -34.323245645 5.596860174
2 1.000000 0.005583688 235.091633019 -34.328790653 -34.323206964 2.152504481
3 1.500000 0.004815598 202.752506973 -34.327998978 -34.323183380 2.176433628
4 2.000000 0.004566544 192.266488819 -34.327754290 -34.323187747 2.145689724
5 2.500000 0.004788928 201.629598676 -34.327997890 -34.323208962 2.183614561
6 3.000000 0.005184860 218.299664775 -34.328412394 -34.323227533 2.156728805
7 3.500000 0.005470470 230.324748558 -34.328704052 -34.323233583 1.372403022
8 4.000000 0.005526692 232.691881533 -34.328757407 -34.323230715 2.158405874
9 4.500000 0.005371243 226.146979313 -34.328598255 -34.323227013 2.157126734
10 5.000000 0.005062914 213.165337396 -34.328287038 -34.323224123 2.141358878
test/unittests/cp2k_2.6.2/md/nve/H2O-32-pos-1.xyz
0 → 100644
View file @
fe625fdc
6
i = 0, time = 0.000, E = -34.3303964710
O 2.2803980000 9.1465390000 5.0886960000
O 1.2517030000 2.4062610000 7.7699080000
H 1.7620190000 9.8204290000 5.5284540000
H 3.0959870000 9.1070880000 5.5881860000
H 0.5541290000 2.9826340000 8.0820240000
H 1.7712570000 2.9547790000 7.1821810000
6
i = 1, time = 0.500, E = -34.3297789925
O 2.2807055575 9.1465838595 5.0883919888
O 1.2498929917 2.4074289284 7.7692382491
H 1.7550641677 9.8178358845 5.5212255966
H 3.1112981302 9.0969170746 5.5956143531
H 0.5663993495 2.9792400173 8.0854791515
H 1.7745194198 2.9517247311 7.1939396477
6
i = 2, time = 1.000, E = -34.3287906528
O 2.2810938851 9.1465143736 5.0880057320
O 1.2481430886 2.4083371258 7.7685912598
H 1.7468317341 9.8169710643 5.5154127828
H 3.1265398790 9.0869161313 5.6032028662
H 0.5758344344 2.9781042647 8.0902773264
H 1.7797622574 2.9504835298 7.2036786282
6
i = 3, time = 1.500, E = -34.3279989781
O 2.2816569948 9.1463220223 5.0875919643
O 1.2464808250 2.4089259514 7.7679581102
H 1.7376017910 9.8176768475 5.5110703534
H 3.1398366791 9.0773366634 5.6100676793
H 0.5816795339 2.9798971014 8.0968435085
H 1.7872918494 2.9513202206 7.2111353246
6
i = 4, time = 2.000, E = -34.3277542904
O 2.2824536844 9.1460139717 5.0872014341
O 1.2449189507 2.4091830380 7.7673245034
H 1.7278297775 9.8195589149 5.5080907122
H 3.1497224743 9.0684159063 5.6155281103
H 0.5837476503 2.9848496112 8.1053394370
H 1.7970573968 2.9542015292 7.2164224211
6
i = 5, time = 2.500, E = -34.3279978897
O 2.2835075421 9.1456102023 5.0868767781
O 1.2434524580 2.4091462088 7.7666758161
H 1.7181028654 9.8220570351 5.5062468114
H 3.1552105753 9.0603654046 5.6191356782
H 0.5824842170 2.9926888277 8.1156135109
H 1.8086404408 2.9588109314 7.2199843450
6
i = 6, time = 3.000, E = -34.3284123938
O 2.2848116168 9.1451387997 5.0866494510
O 1.2420611951 2.4088940254 7.7660011551
H 1.7090732160 9.8245375564 5.5052476019
H 3.1557721856 9.0533599447 5.6206772705
H 0.5788535575 3.0026992793 8.1272265032
H 1.8213326965 2.9646247282 7.2224917951
6
i = 7, time = 3.500, E = -34.3287040522
O 2.2863340532 9.1446310518 5.0865370925
O 1.2407164792 2.4085282817 7.7652951031
H 1.7013784598 9.8263832260 5.5047906840
H 3.1513029381 9.0475240318 5.6201716574
H 0.5741065883 3.0138823014 8.1395347678
H 1.8342810097 2.9710164962 7.2247109095
6
i = 8, time = 4.000, E = -34.3287574070
O 2.2880225370 9.1441174852 5.0865411149
O 1.2393883154 2.4081553744 7.7645574288
H 1.6955650581 9.8270646411 5.5046034983
H 3.1421140712 9.0429166182 5.6178695663
H 0.5695320041 3.0251531775 8.1517995491
H 1.8466448643 2.9773546982 7.2273850117
6
i = 9, time = 4.500, E = -34.3285982555
O 2.2898069785 9.1436252146 5.0866444773
O 1.2380505706 2.4078718032 7.7637918013
H 1.6920290647 9.8261894866 5.5044715741
H 3.1289538455 9.0395163855 5.6142598682
H 0.5662695747 3.0355160242 8.1632992842
H 1.8577079508 2.9830741256 7.2311516146
6
i = 10, time = 5.000, E = -34.3282870379
O 2.2916014875 9.1431763260 5.0868100688
O 1.2366834078 2.4077552776 7.7630044423
H 1.6909790671 9.8235337924 5.5042564094
H 3.1130341664 9.0372111810 5.6100739746
H 0.5652070478 3.0441761067 8.1734257299
H 1.8669280879 2.9877213524 7.2364955946
test/unittests/cp2k_2.6.2/md/nve/H2O-32.inp
0 → 100644
View file @
fe625fdc
&FORCE_EVAL
METHOD QS
&DFT
BASIS_SET_FILE_NAME ../../BASIS_SET
POTENTIAL_FILE_NAME ../../GTH_POTENTIALS
&MGRID
CUTOFF 200
REL_CUTOFF 30
&END MGRID
&QS
EPS_DEFAULT 1.0E-12
WF_INTERPOLATION PS
EXTRAPOLATION_ORDER 3
&END QS
&SCF
SCF_GUESS ATOMIC
&PRINT
&RESTART OFF
&END
&END
&END SCF
&XC
&XC_FUNCTIONAL Pade
&END XC_FUNCTIONAL
&END XC
&END DFT
&SUBSYS
&CELL
ABC 9.8528 9.8528 9.8528
&END CELL
&COORD
O 2.280398 9.146539 5.088696
O 1.251703 2.406261 7.769908
H 1.762019 9.820429 5.528454
H 3.095987 9.107088 5.588186
H 0.554129 2.982634 8.082024
H 1.771257 2.954779 7.182181
&END COORD
&KIND H
BASIS_SET DZVP-GTH-PADE
POTENTIAL GTH-PADE-q1
&END KIND
&KIND O
BASIS_SET DZVP-GTH-PADE
POTENTIAL GTH-PADE-q6
&END KIND
&END SUBSYS
&END FORCE_EVAL
&GLOBAL
PROJECT H2O-32
RUN_TYPE MD
PRINT_LEVEL MEDIUM
&END GLOBAL
&MOTION
&MD
ENSEMBLE NVE
STEPS 10
TIMESTEP 0.5
TEMPERATURE 300.0
&END MD
&END MOTION
test/unittests/cp2k_2.6.2/md/nve/unittest.out
0 → 100644
View file @
fe625fdc
This diff is collapsed.
Click to expand it.
test/unittests/cp2k_2.6.2/run_tests.py
View file @
fe625fdc
...
...
@@ -678,24 +678,42 @@ class TestGeoOptTrajectory(unittest.TestCase):
i_conf
+=
1
#===============================================================================
class
TestMD
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
results
=
get_results
(
"md/nve"
,
"section_run"
)
def
test_ensemble_type
(
self
):
result
=
self
.
results
[
"x_cp2k_md_ensemble_type"
]
self
.
assertEqual
(
result
,
"NVE"
)
# md = self.results["x_cp2k_section_md"][0]
# for key, value in md.simpleValues.iteritems():
# print "{}: {}".format(key, value)
#===============================================================================
if
__name__
==
'__main__'
:
logger
=
logging
.
getLogger
(
"cp2kparser"
)
logger
.
setLevel
(
logging
.
ERROR
)
suites
=
[]
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestErrors
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestXCFunctional
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestEnergyForce
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestStressTensorMethods
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestSelfInteractionCorrectionMethod
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestConfigurationPeriodicDimensions
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestSCFConvergence
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestForceFiles
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestPreprocessor
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestGeoOpt
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestGeoOptTrajFormats
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestGeoOptOptimizers
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestGeoOptTrajectory
))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestErrors))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestEnergyForce))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestStressTensorMethods))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSelfInteractionCorrectionMethod))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestConfigurationPeriodicDimensions))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSCFConvergence))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForceFiles))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestPreprocessor))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOpt))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajFormats))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptOptimizers))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajectory))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestMD
))
alltests
=
unittest
.
TestSuite
(
suites
)
unittest
.
TextTestRunner
(
verbosity
=
0
).
run
(
alltests
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment