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
0b4b92ed
Commit
0b4b92ed
authored
May 24, 2016
by
Lauri Himanen
Browse files
Fixed issue with pushing arrays with addValue.
parent
4499b75e
Changes
5
Hide whitespace changes
Inline
Side-by-side
parser/parser-cp2k/cp2kparser/generic/inputparsing.py
View file @
0b4b92ed
...
...
@@ -164,21 +164,6 @@ class InputObject(object):
self
.
data_dimension
=
None
self
.
default_value
=
None
#===============================================================================
class
Keyword
(
InputObject
):
"""Information about a keyword in a CP2K calculation.
"""
__slots__
=
[
'unit'
,
'value_no_unit'
,
'default_unit'
,
'default_name'
]
def
__init__
(
self
,
name
,
default_value
,
default_unit
,
default_name
):
super
(
Keyword
,
self
).
__init__
(
name
)
self
.
unit
=
None
self
.
value_no_unit
=
None
self
.
default_unit
=
default_unit
self
.
default_value
=
default_value
self
.
default_name
=
default_name
def
get_formatted_value
(
self
):
""" Used to set the value of the keyword. The data will be transformed
into the correct data type and dimension from a simple string.
...
...
@@ -214,6 +199,21 @@ class Keyword(InputObject):
return
returned
#===============================================================================
class
Keyword
(
InputObject
):
"""Information about a keyword in a CP2K calculation.
"""
__slots__
=
[
'unit'
,
'value_no_unit'
,
'default_unit'
,
'default_name'
]
def
__init__
(
self
,
name
,
default_value
,
default_unit
,
default_name
):
super
(
Keyword
,
self
).
__init__
(
name
)
self
.
unit
=
None
self
.
value_no_unit
=
None
self
.
default_unit
=
default_unit
self
.
default_value
=
default_value
self
.
default_name
=
default_name
def
get_value
(
self
):
"""If the units of this value can be changed, return a value and the
unit separately.
...
...
@@ -252,7 +252,7 @@ class Keyword(InputObject):
#===============================================================================
class
Section
(
InputO
bject
):
class
Section
(
o
bject
):
"""An input section in a CP2K calculation.
"""
__slots__
=
[
'accessed'
,
'name'
,
'keywords'
,
'default_keyword_names'
,
'default_keyword'
,
'section_parameter'
,
'sections'
,
'description'
]
...
...
@@ -305,8 +305,9 @@ class SectionParameters(InputObject):
class
DefaultKeyword
(
InputObject
):
"""Default keyword in the CP2K input.
"""
__slots__
=
[
'lone_value'
]
def
__init__
(
self
):
super
(
DefaultKeyword
,
self
).
__init__
(
"DEFAULT_KEYWORD"
)
self
.
default_value
=
None
self
.
lone_value
=
None
self
.
value
=
""
parser/parser-cp2k/cp2kparser/tools/xmlpreparser.py
View file @
0b4b92ed
...
...
@@ -227,8 +227,8 @@ def generate_input_object_metainfo_json(child, parent, name_stack):
# Description
description
=
child
.
description
if
description
is
None
:
description
=
"
"
if
description
is
None
or
description
.
isspace
()
:
description
=
"
Settings for {}"
.
format
(
child
.
name
)
json_obj
[
"description"
]
=
description
# Shape
...
...
@@ -264,8 +264,8 @@ def generate_section_metainfo_json(child, parent, name_stack):
json_obj
[
"superNames"
]
=
[
"x_cp2k_{}"
.
format
(
path
)]
description
=
child
.
description
if
description
is
None
:
description
=
"
"
if
description
is
None
or
description
.
isspace
()
:
description
=
"
Settings for {}"
.
format
(
child
.
name
)
json_obj
[
"description"
]
=
description
return
json_obj
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/input_data/cp2k_input_tree.pickle
View file @
0b4b92ed
No preview for this file type
parser/parser-cp2k/cp2kparser/versions/cp2k262/inputparser.py
View file @
0b4b92ed
...
...
@@ -278,17 +278,24 @@ class CP2KInputParser(BasicParser):
keywords
=
section
.
keywords
.
get
(
default_name
)
for
keyword
in
keywords
:
if
keyword
.
value
is
not
None
:
name
=
"{}.{}"
.
format
(
path
,
keyword
.
default_name
)
formatted_value
=
keyword
.
get_formatted_value
()
if
formatted_value
is
not
None
:
self
.
backend
.
addValue
(
"{}.{}"
.
format
(
path
,
keyword
.
default_name
),
formatted_value
)
self
.
add_formatted_value_to_backend
(
name
,
formatted_value
)
# Section parameter
if
section
.
section_parameter
is
not
None
:
self
.
backend
.
addValue
(
"{}.SECTION_PARAMETERS"
.
format
(
path
),
section
.
section_parameter
.
value
)
section_parameter
=
section
.
section_parameter
if
section_parameter
is
not
None
:
name
=
"{}.SECTION_PARAMETERS"
.
format
(
path
)
formatted_value
=
section_parameter
.
get_formatted_value
()
self
.
add_formatted_value_to_backend
(
name
,
formatted_value
)
# Default keyword
if
section
.
default_keyword
is
not
None
:
self
.
backend
.
addValue
(
"{}.DEFAULT_KEYWORD"
.
format
(
path
),
section
.
default_keyword
.
value
)
default_keyword
=
section
.
default_keyword
if
default_keyword
is
not
None
:
name
=
"{}.DEFAULT_KEYWORD"
.
format
(
path
)
formatted_value
=
default_keyword
.
get_formatted_value
()
self
.
add_formatted_value_to_backend
(
name
,
formatted_value
)
# Subsections
for
name
,
subsections
in
section
.
sections
.
iteritems
():
...
...
@@ -299,6 +306,13 @@ class CP2KInputParser(BasicParser):
name_stack
.
pop
()
def
add_formatted_value_to_backend
(
self
,
name
,
formatted_value
):
if
formatted_value
is
not
None
:
if
isinstance
(
formatted_value
,
np
.
ndarray
):
self
.
backend
.
addArrayValues
(
name
,
formatted_value
)
else
:
self
.
backend
.
addValue
(
name
,
formatted_value
)
def
setup_version
(
self
,
version_number
):
""" The pickle file which contains preparsed data from the
cp2k_input.xml is version specific. By calling this function before
...
...
test/unittests/cp2k_2.6.2/run_tests.py
View file @
0b4b92ed
...
...
@@ -270,7 +270,7 @@ class TestEnergyForce(unittest.TestCase):
@
classmethod
def
setUpClass
(
cls
):
cls
.
results
=
get_results
(
"energy_force"
,
"section_run"
)
#
cls.results.print_summary()
cls
.
results
.
print_summary
()
def
test_energy_total_scf_iteration
(
self
):
energy_total
=
self
.
results
[
"energy_total_scf_iteration"
]
...
...
@@ -450,14 +450,14 @@ 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(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(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))
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