Commit 0b4b92ed authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Fixed issue with pushing arrays with addValue.

parent 4499b75e
...@@ -164,21 +164,6 @@ class InputObject(object): ...@@ -164,21 +164,6 @@ class InputObject(object):
self.data_dimension = None self.data_dimension = None
self.default_value = 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): def get_formatted_value(self):
""" Used to set the value of the keyword. The data will be transformed """ Used to set the value of the keyword. The data will be transformed
into the correct data type and dimension from a simple string. into the correct data type and dimension from a simple string.
...@@ -214,6 +199,21 @@ class Keyword(InputObject): ...@@ -214,6 +199,21 @@ class Keyword(InputObject):
return returned 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): def get_value(self):
"""If the units of this value can be changed, return a value and the """If the units of this value can be changed, return a value and the
unit separately. unit separately.
...@@ -252,7 +252,7 @@ class Keyword(InputObject): ...@@ -252,7 +252,7 @@ class Keyword(InputObject):
#=============================================================================== #===============================================================================
class Section(InputObject): class Section(object):
"""An input section in a CP2K calculation. """An input section in a CP2K calculation.
""" """
__slots__ = ['accessed', 'name', 'keywords', 'default_keyword_names', 'default_keyword', 'section_parameter', 'sections', 'description'] __slots__ = ['accessed', 'name', 'keywords', 'default_keyword_names', 'default_keyword', 'section_parameter', 'sections', 'description']
...@@ -305,8 +305,9 @@ class SectionParameters(InputObject): ...@@ -305,8 +305,9 @@ class SectionParameters(InputObject):
class DefaultKeyword(InputObject): class DefaultKeyword(InputObject):
"""Default keyword in the CP2K input. """Default keyword in the CP2K input.
""" """
__slots__ = ['lone_value']
def __init__(self): def __init__(self):
super(DefaultKeyword, self).__init__("DEFAULT_KEYWORD") super(DefaultKeyword, self).__init__("DEFAULT_KEYWORD")
self.default_value = None
self.lone_value = None self.lone_value = None
self.value = "" self.value = ""
...@@ -227,8 +227,8 @@ def generate_input_object_metainfo_json(child, parent, name_stack): ...@@ -227,8 +227,8 @@ def generate_input_object_metainfo_json(child, parent, name_stack):
# Description # Description
description = child.description description = child.description
if description is None: if description is None or description.isspace():
description = "" description = "Settings for {}".format(child.name)
json_obj["description"] = description json_obj["description"] = description
# Shape # Shape
...@@ -264,8 +264,8 @@ def generate_section_metainfo_json(child, parent, name_stack): ...@@ -264,8 +264,8 @@ def generate_section_metainfo_json(child, parent, name_stack):
json_obj["superNames"] = ["x_cp2k_{}".format(path)] json_obj["superNames"] = ["x_cp2k_{}".format(path)]
description = child.description description = child.description
if description is None: if description is None or description.isspace():
description = "" description = "Settings for {}".format(child.name)
json_obj["description"] = description json_obj["description"] = description
return json_obj return json_obj
......
...@@ -278,17 +278,24 @@ class CP2KInputParser(BasicParser): ...@@ -278,17 +278,24 @@ class CP2KInputParser(BasicParser):
keywords = section.keywords.get(default_name) keywords = section.keywords.get(default_name)
for keyword in keywords: for keyword in keywords:
if keyword.value is not None: if keyword.value is not None:
name = "{}.{}".format(path, keyword.default_name)
formatted_value = keyword.get_formatted_value() formatted_value = keyword.get_formatted_value()
if formatted_value is not None: self.add_formatted_value_to_backend(name, formatted_value)
self.backend.addValue("{}.{}".format(path, keyword.default_name), formatted_value)
# Section parameter # Section parameter
if section.section_parameter is not None: section_parameter = section.section_parameter
self.backend.addValue("{}.SECTION_PARAMETERS".format(path), section.section_parameter.value) 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 # Default keyword
if section.default_keyword is not None: default_keyword = section.default_keyword
self.backend.addValue("{}.DEFAULT_KEYWORD".format(path), section.default_keyword.value) 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 # Subsections
for name, subsections in section.sections.iteritems(): for name, subsections in section.sections.iteritems():
...@@ -299,6 +306,13 @@ class CP2KInputParser(BasicParser): ...@@ -299,6 +306,13 @@ class CP2KInputParser(BasicParser):
name_stack.pop() 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): def setup_version(self, version_number):
""" The pickle file which contains preparsed data from the """ The pickle file which contains preparsed data from the
cp2k_input.xml is version specific. By calling this function before cp2k_input.xml is version specific. By calling this function before
......
...@@ -270,7 +270,7 @@ class TestEnergyForce(unittest.TestCase): ...@@ -270,7 +270,7 @@ class TestEnergyForce(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.results = get_results("energy_force", "section_run") cls.results = get_results("energy_force", "section_run")
# cls.results.print_summary() cls.results.print_summary()
def test_energy_total_scf_iteration(self): def test_energy_total_scf_iteration(self):
energy_total = self.results["energy_total_scf_iteration"] energy_total = self.results["energy_total_scf_iteration"]
...@@ -450,14 +450,14 @@ if __name__ == '__main__': ...@@ -450,14 +450,14 @@ if __name__ == '__main__':
logger.setLevel(logging.ERROR) logger.setLevel(logging.ERROR)
suites = [] suites = []
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestErrors)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestErrors))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestEnergyForce)) suites.append(unittest.TestLoader().loadTestsFromTestCase(TestEnergyForce))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestStressTensorMethods)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestStressTensorMethods))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSelfInteractionCorrectionMethod)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSelfInteractionCorrectionMethod))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestConfigurationPeriodicDimensions)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestConfigurationPeriodicDimensions))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSCFConvergence)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSCFConvergence))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForceFiles)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForceFiles))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestPreprocessor)) # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestPreprocessor))
alltests = unittest.TestSuite(suites) alltests = unittest.TestSuite(suites)
unittest.TextTestRunner(verbosity=0).run(alltests) 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