Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
parser-cp2k
Commits
c8fbaf28
Commit
c8fbaf28
authored
Jun 01, 2016
by
Lauri Himanen
Browse files
Created new cp2k specific metainfo for the quickstep calculation which required some modifications.
parent
f4e2a529
Changes
6
Show whitespace changes
Inline
Side-by-side
parser/parser-cp2k/cp2kparser/generic/utils.py
0 → 100644
View file @
c8fbaf28
#===============================================================================
def
try_to_add_value
(
backend
,
section
,
source_name
,
destination_name
):
original
=
section
[
source_name
]
if
original
is
not
None
:
backend
.
addValue
(
destination_name
,
original
[
0
])
#===============================================================================
def
try_to_add_array_values
(
backend
,
section
,
source_name
,
destination_name
,
unit
=
None
):
original
=
section
[
source_name
]
if
original
is
not
None
:
backend
.
addArrayValues
(
destination_name
,
original
[
0
])
parser/parser-cp2k/cp2kparser/versions/cp2k262/commonmatcher.py
View file @
c8fbaf28
...
...
@@ -19,6 +19,7 @@ class CommonMatcher(object):
# Repeating regex definitions
self
.
parser_context
=
parser_context
self
.
backend
=
parser_context
.
caching_backend
self
.
file_service
=
parser_context
.
file_service
self
.
cache_service
=
parser_context
.
cache_service
self
.
regex_f
=
"-?\d+\.\d+(?:E(?:\+|-)\d+)?"
# Regex for a floating point value
...
...
@@ -26,7 +27,6 @@ class CommonMatcher(object):
self
.
regex_word
=
"[^\s]+"
# Regex for a single word. Can contain anything else but whitespace
self
.
section_method_index
=
None
self
.
section_system_index
=
None
self
.
forces
=
None
#=======================================================================
# Cache levels
...
...
@@ -34,15 +34,6 @@ class CommonMatcher(object):
'x_cp2k_atoms'
:
CachingLevel
.
ForwardAndCache
,
'section_XC_functionals'
:
CachingLevel
.
ForwardAndCache
,
'self_interaction_correction_method'
:
CachingLevel
.
Cache
,
'x_cp2k_section_md_coordinates'
:
CachingLevel
.
Cache
,
'x_cp2k_section_md_coordinate_atom'
:
CachingLevel
.
Cache
,
'x_cp2k_md_coordinate_atom_string'
:
CachingLevel
.
Cache
,
'x_cp2k_md_coordinate_atom_float'
:
CachingLevel
.
Cache
,
'x_cp2k_section_md_forces'
:
CachingLevel
.
Cache
,
'x_cp2k_section_md_force_atom'
:
CachingLevel
.
Cache
,
'x_cp2k_md_force_atom_string'
:
CachingLevel
.
Cache
,
'x_cp2k_md_force_atom_float'
:
CachingLevel
.
Cache
,
}
#=======================================================================
...
...
@@ -135,15 +126,16 @@ class CommonMatcher(object):
)
# SimpleMatcher for an SCF wavefunction optimization
def
scf
(
self
):
def
quickstep_calculation
(
self
):
return
SM
(
" SCF WAVEFUNCTION OPTIMIZATION"
,
sections
=
[
"x_cp2k_section_quickstep_calculation"
],
subMatchers
=
[
SM
(
r
" Trace\(PS\):"
,
sections
=
[
"section_scf_iteration"
],
sections
=
[
"
x_cp2k_
section_scf_iteration"
],
repeats
=
True
,
subMatchers
=
[
SM
(
r
" Exchange-correlation energy:\s+(?P<energy_XC_scf_iteration__hartree>{})"
.
format
(
self
.
regex_f
)),
SM
(
r
"\s+\d+\s+\S+\s+{0}\s+{0}\s+{0}\s+(?P<energy_total_scf_iteration__hartree>{0})\s+(?P<energy_change_scf_iteration__hartree>{0})"
.
format
(
self
.
regex_f
)),
SM
(
r
" Exchange-correlation energy:\s+(?P<
x_cp2k_
energy_XC_scf_iteration__hartree>{})"
.
format
(
self
.
regex_f
)),
SM
(
r
"\s+\d+\s+\S+\s+{0}\s+{0}\s+{0}\s+(?P<
x_cp2k_
energy_total_scf_iteration__hartree>{0})\s+(?P<
x_cp2k_
energy_change_scf_iteration__hartree>{0})"
.
format
(
self
.
regex_f
)),
]
),
SM
(
r
" \*\*\* SCF run converged in\s+(\d+) steps \*\*\*"
,
...
...
@@ -154,22 +146,25 @@ class CommonMatcher(object):
otherMetaInfo
=
[
"single_configuration_calculation_converged"
],
adHoc
=
self
.
adHoc_single_point_not_converged
()
),
SM
(
r
" Electronic kinetic energy:\s+(?P<electronic_kinetic_energy__hartree>{})"
.
format
(
self
.
regex_f
)),
SM
(
r
" Electronic kinetic energy:\s+(?P<
x_cp2k_
electronic_kinetic_energy__hartree>{})"
.
format
(
self
.
regex_f
)),
SM
(
r
" **************************** NUMERICAL STRESS ********************************"
.
replace
(
"*"
,
"\*"
),
# endReStr=" **************************** NUMERICAL STRESS END *****************************".replace("*", "\*"),
adHoc
=
self
.
adHoc_stress_calculation
(),
),
SM
(
r
" ENERGY\| Total FORCE_EVAL \( \w+ \) energy \(a\.u\.\):\s+(?P<energy_total__hartree>{0})"
.
format
(
self
.
regex_f
)),
SM
(
r
" ENERGY\| Total FORCE_EVAL \( \w+ \) energy \(a\.u\.\):\s+(?P<x_cp2k_energy_total__hartree>{0})"
.
format
(
self
.
regex_f
),
otherMetaInfo
=
[
"energy_total"
],
),
SM
(
r
" ATOMIC FORCES in \[a\.u\.\]"
),
SM
(
r
" # Atom Kind Element X Y Z"
,
adHoc
=
self
.
adHoc_atom_forces
(),
otherMetaInfo
=
[
"atom_forces"
],
otherMetaInfo
=
[
"atom_forces"
,
"x_cp2k_atom_forces"
],
),
SM
(
r
" (?:NUMERICAL )?STRESS TENSOR \[GPa\]"
,
sections
=
[
"section_stress_tensor"
],
otherMetaInfo
=
[
"stress_tensor"
],
sections
=
[
"x_cp2k_section_stress_tensor"
],
subMatchers
=
[
SM
(
r
"\s+X\s+Y\s+Z"
,
adHoc
=
self
.
adHoc_stress_tensor
()
adHoc
=
self
.
adHoc_stress_tensor
(),
otherMetaInfo
=
[
"stress_tensor"
,
"section_stress_tensor"
],
),
SM
(
" 1/3 Trace\(stress tensor\):\s+(?P<x_cp2k_stress_tensor_one_third_of_trace__GPa>{})"
.
format
(
self
.
regex_f
)),
SM
(
" Det\(stress tensor\)\s+:\s+(?P<x_cp2k_stress_tensor_determinant__GPa3>{})"
.
format
(
self
.
regex_f
)),
...
...
@@ -181,7 +176,7 @@ class CommonMatcher(object):
)
# SimpleMatcher for an SCF wavefunction optimization
def
quickstep
(
self
):
def
quickstep
_header
(
self
):
return
SM
(
" MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom"
,
forwardMatch
=
True
,
...
...
@@ -195,10 +190,6 @@ class CommonMatcher(object):
#===========================================================================
# onClose triggers
def
onClose_section_scf_iteration
(
self
,
backend
,
gIndex
,
section
):
"""Keep track of how many SCF iteration are made."""
self
.
cache_service
[
"number_of_scf_iterations"
]
+=
1
def
onClose_x_cp2k_section_total_numbers
(
self
,
backend
,
gIndex
,
section
):
"""Keep track of how many SCF iteration are made."""
number_of_atoms
=
section
[
"x_cp2k_atoms"
][
0
]
...
...
@@ -254,13 +245,14 @@ class CommonMatcher(object):
let's get it dynamically just in case there's something wrong.
"""
self
.
section_system_index
=
gIndex
if
self
.
forces
is
not
None
:
backend
.
addArrayValues
(
"atom_forces"
,
self
.
forces
,
unit
=
"forceAu"
)
self
.
forces
=
None
#
if self.forces is not None:
#
backend.addArrayValues("atom_forces", self.forces, unit="forceAu")
#
self.forces = None
self
.
cache_service
.
push_value
(
"number_of_atoms"
)
self
.
cache_service
.
push_array_values
(
"simulation_cell"
,
unit
=
"angstrom"
)
self
.
cache_service
.
push_array_values
(
"configuration_periodic_dimensions"
)
self
.
cache_service
.
push_array_values
(
"atom_positions"
,
unit
=
"angstrom"
)
# self.cache_service.push_array_values("atom_forces", unit="forceAu")
self
.
cache_service
.
push_array_values
(
"atom_labels"
)
def
onClose_section_single_configuration_calculation
(
self
,
backend
,
gIndex
,
section
):
...
...
@@ -321,7 +313,8 @@ class CommonMatcher(object):
# If anything found, push the results to the correct section
if
len
(
force_array
)
!=
0
:
self
.
forces
=
force_array
# self.cache_service["atom_forces"] = force_array
self
.
backend
.
addArrayValues
(
"x_cp2k_atom_forces"
,
force_array
,
unit
=
"forceAu"
)
return
wrapper
...
...
@@ -334,7 +327,7 @@ class CommonMatcher(object):
row2
=
[
float
(
x
)
for
x
in
parser
.
fIn
.
readline
().
split
()[
-
3
:]]
row3
=
[
float
(
x
)
for
x
in
parser
.
fIn
.
readline
().
split
()[
-
3
:]]
stress_array
=
np
.
array
([
row1
,
row2
,
row3
])
parser
.
backend
.
addArrayValues
(
"stress_tensor"
,
stress_array
,
unit
=
"GPa"
)
parser
.
backend
.
addArrayValues
(
"
x_cp2k_
stress_tensor"
,
stress_array
,
unit
=
"GPa"
)
return
wrapper
...
...
@@ -369,14 +362,14 @@ class CommonMatcher(object):
"""Called when the SCF cycle of a single point calculation has converged.
"""
def
wrapper
(
parser
):
parser
.
backend
.
addValue
(
"
single_configuration_calculation
_converged"
,
True
)
parser
.
backend
.
addValue
(
"
x_cp2k_quickstep
_converged"
,
True
)
return
wrapper
def
adHoc_single_point_not_converged
(
self
):
"""Called when the SCF cycle of a single point calculation did not converge.
"""
def
wrapper
(
parser
):
parser
.
backend
.
addValue
(
"
single_configuration_calculation
_converged"
,
False
)
parser
.
backend
.
addValue
(
"
x_cp2k_quickstep
_converged"
,
False
)
return
wrapper
def
adHoc_x_cp2k_section_quickstep_atom_information
(
self
):
...
...
@@ -420,6 +413,11 @@ class CommonMatcher(object):
return
wrapper
def
debug
(
self
):
def
wrapper
(
parser
):
print
"FOUND"
return
wrapper
#===========================================================================
def
getOnCloseTriggers
(
self
):
"""
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py
View file @
c8fbaf28
...
...
@@ -6,6 +6,8 @@ import cp2kparser.generic.csvparsing
from
nomadcore.caching_backend
import
CachingLevel
import
logging
import
ase.io
import
numpy
as
np
import
math
logger
=
logging
.
getLogger
(
"nomad"
)
...
...
@@ -30,80 +32,83 @@ class CP2KGeoOptParser(MainHierarchicalParser):
# Cache levels
self
.
caching_level_for_metaname
.
update
({
'x_cp2k_optimization_energy'
:
CachingLevel
.
ForwardAndCache
,
'x_cp2k_optimization_step_size_convergence_limit'
:
CachingLevel
.
ForwardAndCache
,
'x_cp2k_section_geometry_optimization_information'
:
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
.
geo_opt
=
SM
(
" *** STARTING GEOMETRY OPTIMIZATION ***"
.
replace
(
"*"
,
"\*"
),
sections
=
[
"section_frame_sequence"
],
sections
=
[
"section_frame_sequence"
,
"x_cp2k_section_geometry_optimization"
],
subMatchers
=
[
SM
(
" *** CONJUGATE GRADIENTS ***"
.
replace
(
"*"
,
"\*"
),
adHoc
=
self
.
adHoc_conjugate_gradient
(),
otherMetaInfo
=
[
"geometry_optimization_method"
]
otherMetaInfo
=
[
"geometry_optimization_method"
]
,
),
SM
(
" *** BFGS ***"
.
replace
(
"*"
,
"\*"
),
adHoc
=
self
.
adHoc_bfgs
(),
otherMetaInfo
=
[
"geometry_optimization_method"
]
otherMetaInfo
=
[
"geometry_optimization_method"
]
,
),
SM
(
" *** L-BFGS ***"
.
replace
(
"*"
,
"\*"
),
adHoc
=
self
.
adHoc_bfgs
(),
otherMetaInfo
=
[
"geometry_optimization_method"
]
),
SM
(
""
,
forwardMatch
=
True
,
sections
=
[
"section_single_configuration_calculation"
,
"section_system"
,
"x_cp2k_section_geometry_optimization_information"
],
subMatchers
=
[
self
.
cm
.
scf
(),
SM
(
" -------- Informations at step"
),
SM
(
" Optimization Method =\s+(?P<x_cp2k_optimization_method>{})"
.
format
(
self
.
cm
.
regex_word
)),
SM
(
" Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})"
.
format
(
self
.
cm
.
regex_f
),
otherMetaInfo
=
[
"frame_sequence_potential_energy"
]
),
],
adHoc
=
self
.
adHoc_step
()
otherMetaInfo
=
[
"geometry_optimization_method"
],
),
# SM( "",
# forwardMatch=True,
# sections=["section_single_configuration_calculation", "section_system", "x_cp2k_section_geometry_optimization_step"],
# subMatchers=[
# self.cm.quickstep_calculation(),
# SM( " -------- Informations at step"),
# SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.cm.regex_word)),
# SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.cm.regex_f),
# otherMetaInfo=["frame_sequence_potential_energy"]
# ),
# ],
# otherMetaInfo=["atom_positions"],
# adHoc=self.adHoc_step(),
# ),
SM
(
" OPTIMIZATION STEP:"
,
endReStr
=
" Conv. in RMS gradients ="
,
name
=
"geooptstep"
,
repeats
=
True
,
sections
=
[
"section_single_configuration_calculation"
,
"section_system"
],
sections
=
[
"section_system"
],
subMatchers
=
[
SM
(
""
,
forwardMatch
=
True
,
sections
=
[
"x_cp2k_section_geometry_optimization_
information
"
],
sections
=
[
"x_cp2k_section_geometry_optimization_
step
"
],
otherMetaInfo
=
[
"atom_positions"
,
],
subMatchers
=
[
SM
(
""
,
forwardMatch
=
True
,
endReStr
=
" *** MNBRACK - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***"
.
replace
(
"*"
,
"\*"
).
format
(
self
.
cm
.
regex_i
),
subMatchers
=
[
SM
(
" SCF WAVEFUNCTION OPTIMIZATION"
,
forwardMatch
=
True
,
adHoc
=
self
.
debug
(),
repeats
=
True
,
subMatchers
=
[
self
.
cm
.
scf
(),
]
)
]
),
SM
(
""
,
forwardMatch
=
True
,
endReStr
=
" *** BRENT - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***"
.
replace
(
"*"
,
"\*"
).
format
(
self
.
cm
.
regex_i
),
subMatchers
=
[
SM
(
" SCF WAVEFUNCTION OPTIMIZATION"
,
forwardMatch
=
True
,
repeats
=
True
,
subMatchers
=
[
self
.
cm
.
scf
(),
]
)
]
),
# SM( "",
# forwardMatch=True,
# endReStr=" *** MNBRACK - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***".replace("*", "\*").format(self.cm.regex_i),
# subMatchers=[
# SM(" SCF WAVEFUNCTION OPTIMIZATION",
# forwardMatch=True,
# repeats=True,
# subMatchers=[
# self.cm.quickstep_calculation(),
# ]
# )
# ]
# ),
# SM( "",
# forwardMatch=True,
# endReStr=" *** BRENT - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***".replace("*", "\*").format(self.cm.regex_i),
# subMatchers=[
# SM(" SCF WAVEFUNCTION OPTIMIZATION",
# forwardMatch=True,
# repeats=True,
# subMatchers=[
# self.cm.quickstep_calculation(),
# ]
# )
# ]
# ),
SM
(
" -------- Informations at step"
),
SM
(
" Optimization Method =\s+(?P<x_cp2k_optimization_method>{})"
.
format
(
self
.
cm
.
regex_word
)),
SM
(
" Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})"
.
format
(
self
.
cm
.
regex_f
),
...
...
@@ -135,6 +140,13 @@ class CP2KGeoOptParser(MainHierarchicalParser):
adHoc
=
self
.
adHoc_geo_opt_converged
(),
otherMetaInfo
=
[
"geometry_optimization_converged"
]
),
SM
(
" Reevaluating energy at the minimum"
,
sections
=
[
"x_cp2k_section_geometry_optimization_energy_reevaluation"
,
"section_system"
],
subMatchers
=
[
self
.
cm
.
quickstep_calculation
(),
],
adHoc
=
self
.
adHoc_step
()
),
],
)
...
...
@@ -150,7 +162,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
sections
=
[
"section_method"
],
subMatchers
=
[
self
.
cm
.
header
(),
self
.
cm
.
quickstep
(),
self
.
cm
.
quickstep
_header
(),
],
),
self
.
geo_opt
...
...
@@ -159,11 +171,18 @@ class CP2KGeoOptParser(MainHierarchicalParser):
#===========================================================================
# onClose triggers
def
onClose_section_frame_sequence
(
self
,
backend
,
gIndex
,
section
):
def
onClose_x_cp2k_section_geometry_optimization
(
self
,
backend
,
gIndex
,
section
):
# Get the re-evaluated energy and add it to frame_sequence_potential_energy
reeval
=
section
[
"x_cp2k_section_geometry_optimization_energy_reevaluation"
][
0
]
quickstep
=
reeval
[
"x_cp2k_section_quickstep_calculation"
][
0
]
energy
=
quickstep
[
"x_cp2k_energy_total"
]
self
.
cache_service
[
"frame_sequence_potential_energy"
].
append
(
energy
[
0
])
self
.
cache_service
.
push_value
(
"number_of_frames_in_sequence"
)
self
.
cache_service
.
push_array_values
(
"frame_sequence_potential_energy"
)
opt_section
=
section
[
"x_cp2k_section_geometry_optimization_
information
"
]
opt_section
=
section
[
"x_cp2k_section_geometry_optimization_
step
"
]
if
opt_section
is
not
None
:
opt_section
=
opt_section
[
-
1
]
geo_limit
=
opt_section
[
"x_cp2k_optimization_step_size_convergence_limit"
]
...
...
@@ -176,10 +195,10 @@ class CP2KGeoOptParser(MainHierarchicalParser):
def
onClose_section_sampling_method
(
self
,
backend
,
gIndex
,
section
):
self
.
backend
.
addValue
(
"sampling_method"
,
"geometry_optimization"
)
def
onClose_x_cp2k_section_geometry_optimization_
information
(
self
,
backend
,
gIndex
,
section
):
energy
=
section
[
"x_cp2k_optimization_energy"
]
[
0
]
# backend.addValue("energy_total", energy)
self
.
cache_service
[
"frame_sequence_potential_energy"
].
append
(
energy
)
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"
)
...
...
@@ -230,7 +249,6 @@ class CP2KGeoOptParser(MainHierarchicalParser):
output file. Here further information is gathered from external files.
"""
def
wrapper
(
parser
):
# print "STEP"
self
.
cache_service
[
"number_of_frames_in_sequence"
]
+=
1
# Get the next position from the trajectory file
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py
View file @
c8fbaf28
from
nomadcore.simple_parser
import
SimpleMatcher
as
SM
from
nomadcore.baseclasses
import
MainHierarchicalParser
from
singlepointforceparser
import
CP2KSinglePointForceParser
from
nomadcore.caching_backend
import
CachingLevel
from
commonmatcher
import
CommonMatcher
from
cp2kparser.generic.utils
import
try_to_add_value
,
try_to_add_array_values
import
logging
logger
=
logging
.
getLogger
(
"nomad"
)
...
...
@@ -18,6 +20,16 @@ class CP2KSinglePointParser(MainHierarchicalParser):
super
(
CP2KSinglePointParser
,
self
).
__init__
(
file_path
,
parser_context
)
self
.
setup_common_matcher
(
CommonMatcher
(
parser_context
))
#=======================================================================
# Cache levels
self
.
caching_level_for_metaname
.
update
({
'x_cp2k_energy_total_scf_iteration'
:
CachingLevel
.
ForwardAndCache
,
'x_cp2k_energy_XC_scf_iteration'
:
CachingLevel
.
ForwardAndCache
,
'x_cp2k_energy_change_scf_iteration'
:
CachingLevel
.
ForwardAndCache
,
'x_cp2k_stress_tensor'
:
CachingLevel
.
ForwardAndCache
,
'x_cp2k_section_stress_tensor'
:
CachingLevel
.
ForwardAndCache
,
})
#=======================================================================
# SimpleMatchers
self
.
root_matcher
=
SM
(
""
,
...
...
@@ -26,8 +38,8 @@ class CP2KSinglePointParser(MainHierarchicalParser):
otherMetaInfo
=
[
"atom_forces"
],
subMatchers
=
[
self
.
cm
.
header
(),
self
.
cm
.
quickstep
(),
self
.
cm
.
scf
()
self
.
cm
.
quickstep
_header
(),
self
.
cm
.
quickstep_calculation
()
,
]
)
...
...
@@ -51,7 +63,28 @@ class CP2KSinglePointParser(MainHierarchicalParser):
# iterations is given. E.g. in geometry optimization there are multiple
# scf calculations so this loses it's meaning sort of.
self
.
cache_service
.
push_value
(
"number_of_scf_iterations"
)
self
.
cache_service
[
"number_of_scf_iterations"
]
=
0
def
onClose_x_cp2k_section_scf_iteration
(
self
,
backend
,
gIndex
,
section
):
"""Keep track of how many SCF iteration are made."""
self
.
cache_service
[
"number_of_scf_iterations"
]
+=
1
gId
=
backend
.
openSection
(
"section_scf_iteration"
)
try_to_add_value
(
backend
,
section
,
"x_cp2k_energy_total_scf_iteration"
,
"energy_total_scf_iteration"
)
try_to_add_value
(
backend
,
section
,
"x_cp2k_energy_XC_scf_iteration"
,
"energy_XC_scf_iteration"
)
try_to_add_value
(
backend
,
section
,
"x_cp2k_energy_change_scf_iteration"
,
"energy_change_scf_iteration"
)
backend
.
closeSection
(
"section_scf_iteration"
,
gId
)
def
onClose_x_cp2k_section_quickstep_calculation
(
self
,
backend
,
gIndex
,
section
):
""""""
try_to_add_value
(
backend
,
section
,
"x_cp2k_energy_total"
,
"energy_total"
)
try_to_add_value
(
backend
,
section
,
"x_cp2k_electronic_kinetic_energy"
,
"electronic_kinetic_energy"
)
try_to_add_value
(
backend
,
section
,
"x_cp2k_quickstep_converged"
,
"single_configuration_calculation_converged"
)
try_to_add_array_values
(
backend
,
section
,
"x_cp2k_atom_forces"
,
"atom_forces"
)
def
onClose_x_cp2k_section_stress_tensor
(
self
,
backend
,
gIndex
,
section
):
""""""
gId
=
backend
.
openSection
(
"section_stress_tensor"
)
try_to_add_array_values
(
backend
,
section
,
"x_cp2k_stress_tensor"
,
"stress_tensor"
)
backend
.
closeSection
(
"section_stress_tensor"
,
gId
)
#===========================================================================
# adHoc functions
src/main/scala/eu/nomad_lab/parsers/Cp2kParser.scala
View file @
c8fbaf28
...
...
@@ -42,6 +42,7 @@ object Cp2kParser extends SimpleExternalParserGenerator(
"parser-cp2k/cp2kparser/generic/inputparsing.py"
,
"parser-cp2k/cp2kparser/generic/configurationreading.py"
,
"parser-cp2k/cp2kparser/generic/csvparsing.py"
,
"parser-cp2k/cp2kparser/generic/utils.py"
,
"parser-cp2k/cp2kparser/versions/__init__.py"
,
"parser-cp2k/cp2kparser/versions/versionsetup.py"
,
"parser-cp2k/cp2kparser/versions/cp2k262/__init__.py"
,
...
...
test/unittests/cp2k_2.6.2/run_tests.py
View file @
c8fbaf28
...
...
@@ -18,15 +18,19 @@ from cp2kparser import CP2KParser
from
nomadcore.unit_conversion.unit_conversion
import
convert_unit
# Setup the logger so that it doesn't spam messages during tests
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
(
'%(filename)s: '
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
(
'%(filename)s: '
'%(levelname)s: '
'%(funcName)s(): '
'%(lineno)d:
\t
'
'%(message)s'
)
'%(message)s'
)
)
logger
=
logging
.
getLogger
(
"nomad"
)
logger
.
setLevel
(
logging
.
CRITICAL
)
logging
.
getLogger
(
"nomadcore.caching_backend"
).
setLevel
(
logging
.
CRITICAL
)
#===============================================================================
...
...
@@ -42,7 +46,7 @@ def get_results(folder, metainfo_to_keep=None):
"""
dirname
=
os
.
path
.
dirname
(
__file__
)
filename
=
os
.
path
.
join
(
dirname
,
folder
,
"unittest.out"
)
parser
=
CP2KParser
(
filename
,
metainfo_to_keep
)
parser
=
CP2KParser
(
filename
,
None
)
results
=
parser
.
parse
()
return
results
...
...
@@ -50,7 +54,7 @@ def get_results(folder, metainfo_to_keep=None):
#===============================================================================
def
get_result
(
folder
,
metaname
,
optimize
=
True
):
if
optimize
:
results
=
get_results
(
folder
,
metanam
e
)
results
=
get_results
(
folder
,
Non
e
)
else
:
results
=
get_results
(
folder
)
result
=
results
[
metaname
]
...
...
@@ -298,7 +302,7 @@ class TestEnergyForce(unittest.TestCase):
self
.
assertTrue
(
np
.
array_equal
(
result
,
expected_result
))
def
test_atom_forces
(
self
):
atomic_forces
=
self
.
results
[
"atom_forces"
]
result
=
self
.
results
[
"atom_forces"
]
expected_result
=
convert_unit
(
np
.
array
([
[
0.00000000
,
0.00000000
,
0.00000000
],
...
...
@@ -312,7 +316,7 @@ class TestEnergyForce(unittest.TestCase):
]),
"forceAu"
)
self
.
assertTrue
(
np
.
array_equal
(
atomic_forces
,
expected_result
))
self
.
assertTrue
(
np
.
array_equal
(
result
,
expected_result
))
def
test_atom_label
(
self
):
atom_labels
=
self
.
results
[
"atom_labels"
]
...
...
@@ -486,13 +490,13 @@ class TestGeoOpt(unittest.TestCase):
result
=
self
.
results
[
"frame_sequence_potential_energy"
]
expected_result
=
convert_unit
(
np
.
array
([
-
17.1488237635
,
-
17.1534159246
,
-
17.1941015290
,
-
17.2092321965
,
-
17.2097667733
,
-
17.2097743028
,
-
17.2097743229
,
-
17.20977820662248
,
]),
"hartree"
)
...
...
@@ -527,9 +531,8 @@ class TestGeoOpt(unittest.TestCase):
class
TestGeoOptTrajFormats
(
unittest
.
TestCase
):
def
test_xyz
(
self
):
result
=
get_result
(
"geo_opt/geometry_formats/xyz"
,
"atom_positions"
,
optimize
=
True
)
# print "XYZ"
# print result
expected_start
=
convert_unit
(
np
.
array
([
[
12.2353220000
,
1.3766420000
,
10.8698800000
],
...
...
@@ -597,17 +600,17 @@ if __name__ == '__main__':
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
(
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
))
alltests
=
unittest
.
TestSuite
(
suites
)
unittest
.
TextTestRunner
(
verbosity
=
0
).
run
(
alltests
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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