Commit c45a92f9 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added some basic metavalues, fixed issue with non-recursive parsing with pyyaml.

parent ef591291
Pipeline #8782 failed with stage
in 9 minutes and 6 seconds
...@@ -9,7 +9,7 @@ testing: ...@@ -9,7 +9,7 @@ testing:
- cd nomad-lab-base - cd nomad-lab-base
- git submodule foreach git checkout master - git submodule foreach git checkout master
- git submodule foreach git pull - git submodule foreach git pull
- sbt nwchem/test - sbt bigdft/test
- export PYTHONEXE=/labEnv/bin/python - export PYTHONEXE=/labEnv/bin/python
- sbt bigdft/test - sbt bigdft/test
only: only:
......
...@@ -59,37 +59,51 @@ class TestSinglePoint(unittest.TestCase): ...@@ -59,37 +59,51 @@ class TestSinglePoint(unittest.TestCase):
result = self.results["program_name"] result = self.results["program_name"]
self.assertEqual(result, "BigDFT") self.assertEqual(result, "BigDFT")
def test_simulation_cell(self):
result = self.results["simulation_cell"]
expected_result = convert_unit(np.array(
[
[7.1439, 0, 0],
[0, 7.1439, 0],
[0, 0, 8.3345],
]
), "angstrom")
self.assertTrue(np.array_equal(result, expected_result))
# def test_configuration_periodic_dimensions(self): # def test_configuration_periodic_dimensions(self):
# result = self.results["configuration_periodic_dimensions"] # result = self.results["configuration_periodic_dimensions"]
# self.assertTrue(np.array_equal(result, np.array([False, False, False]))) # self.assertTrue(np.array_equal(result, np.array([False, False, False])))
# def test_program_version(self): def test_program_version(self):
# result = self.results["program_version"] result = self.results["program_version"]
# self.assertEqual(result, "6.6") self.assertEqual(result, "1.8")
# def test_xc_functional(self): # def test_xc_functional(self):
# result = self.results["XC_functional"] # result = self.results["XC_functional"]
# self.assertEqual(result, "1.0*MGGA_C_TPSS+1.0*MGGA_X_TPSS") # self.assertEqual(result, "1.0*MGGA_C_TPSS+1.0*MGGA_X_TPSS")
# def test_atom_labels(self): def test_atom_labels(self):
# atom_labels = self.results["atom_labels"] atom_labels = self.results["atom_labels"]
# expected_labels = np.array(["O", "H", "H"]) expected_labels = np.array(["N", "N"])
# self.assertTrue(np.array_equal(atom_labels, expected_labels)) self.assertTrue(np.array_equal(atom_labels, expected_labels))
# def test_atom_positions(self): def test_atom_positions(self):
# atom_position = self.results["atom_positions"] atom_position = self.results["atom_positions"]
# expected_position = convert_unit(np.array( expected_position = convert_unit(np.array(
# [ [
# [0.00000000, 0.00000000, -0.11817375], [3.571946174, 3.571946174, 3.609775538],
# [0.76924532, 0.00000000, 0.47269501], [3.571946174, 3.571946174, 4.724765534],
# [-0.76924532, 0.00000000, 0.47269501], ]
# ] ), "angstrom")
# ), "angstrom") self.assertTrue(np.array_equal(atom_position, expected_position))
# self.assertTrue(np.array_equal(atom_position, expected_position))
def test_number_of_atoms(self):
# def test_number_of_atoms(self): n_atoms = self.results["number_of_atoms"]
# n_atoms = self.results["number_of_atoms"] self.assertEqual(n_atoms, 2)
# self.assertEqual(n_atoms, 3)
def test_electronic_structure_method(self):
result = self.results["electronic_structure_method"]
self.assertEqual(result, "DFT")
# def test_total_charge(self): # def test_total_charge(self):
# charge = self.results["total_charge"] # charge = self.results["total_charge"]
...@@ -137,9 +151,6 @@ class TestSinglePoint(unittest.TestCase): ...@@ -137,9 +151,6 @@ class TestSinglePoint(unittest.TestCase):
# result = self.results["scf_threshold_energy_change"] # result = self.results["scf_threshold_energy_change"]
# self.assertEqual(result, convert_unit(1.00E-06, "hartree")) # self.assertEqual(result, convert_unit(1.00E-06, "hartree"))
# def test_electronic_structure_method(self):
# result = self.results["electronic_structure_method"]
# self.assertEqual(result, "DFT")
# def test_scf_dft_number_of_iterations(self): # def test_scf_dft_number_of_iterations(self):
# result = self.results["number_of_scf_iterations"] # result = self.results["number_of_scf_iterations"]
......
# from yaml import CLoader as Loader
from yaml import Loader
with open("node_data.yml", "r") as fin:
loader = Loader(fin)
node = loader.compose_node()
print(node)
# while(True):
# token = loader.get_token()
# if token is None:
# break
# print(token)
Version Number : 1.8
scalar1: Moi
scalar2: Terve
scalar3: 5
import yaml
data = {}
listy = []
data["list"] = [1000000000000+x for x in range(2000000)]
with open('data.yml', 'w') as outfile:
yaml.dump(data, outfile, default_flow_style=True)
from yaml import CLoader as Loader
from pympler import tracker
tr = tracker.SummaryTracker()
tr.print_diff()
tr.print_diff()
with open("data.yml", "r") as fin:
loader = Loader(fin)
# data = loader.get_data()
# tr.print_diff()
index = 0
while(loader.check_data()):
token = loader.get_token()
index += 1
if index % 100 == 0:
tr.print_diff()
print(token)
...@@ -17,6 +17,14 @@ class BigDFTMainParser(AbstractBaseParser): ...@@ -17,6 +17,14 @@ class BigDFTMainParser(AbstractBaseParser):
""" """
super(BigDFTMainParser, self).__init__(file_path, parser_context) super(BigDFTMainParser, self).__init__(file_path, parser_context)
# Map keys in the output to funtions that handle the values
self.key_to_funct_map = {
"Version Number": lambda x: self.backend.addValue("program_version", x),
"Atomic structure": self.atomic_structure,
"Sizes of the simulation domain": self.simulation_domain,
# "Atomic Forces (Ha/Bohr)": self.atomic_structure
}
def parse(self): def parse(self):
"""The output file of a BigDFT run is a YAML document. Here we directly """The output file of a BigDFT run is a YAML document. Here we directly
parse this document with an existing YAML library, and push its parse this document with an existing YAML library, and push its
...@@ -32,6 +40,7 @@ class BigDFTMainParser(AbstractBaseParser): ...@@ -32,6 +40,7 @@ class BigDFTMainParser(AbstractBaseParser):
section_system_id = self.backend.openSection("section_system") section_system_id = self.backend.openSection("section_system")
section_method_id = self.backend.openSection("section_method") section_method_id = self.backend.openSection("section_method")
self.backend.addValue("program_name", "BigDFT") self.backend.addValue("program_name", "BigDFT")
self.backend.addValue("electronic_structure_method", "DFT")
loader = Loader(fin) loader = Loader(fin)
generator = self.generate_root_nodes(loader) generator = self.generate_root_nodes(loader)
...@@ -40,8 +49,9 @@ class BigDFTMainParser(AbstractBaseParser): ...@@ -40,8 +49,9 @@ class BigDFTMainParser(AbstractBaseParser):
# function on the value. # function on the value.
for key, value in generator: for key, value in generator:
if key == "Version Number": function = self.key_to_funct_map.get(key)
self.backend.addValue("program_version", value) if function is not None:
function(value)
# Close default sections # Close default sections
self.backend.closeSection("section_method", section_method_id) self.backend.closeSection("section_method", section_method_id)
...@@ -64,9 +74,9 @@ class BigDFTMainParser(AbstractBaseParser): ...@@ -64,9 +74,9 @@ class BigDFTMainParser(AbstractBaseParser):
key = loader.construct_scalar(loader.compose_node(node, None)) key = loader.construct_scalar(loader.compose_node(node, None))
value = loader.compose_node(node, key) value = loader.compose_node(node, key)
if isinstance(value, MappingNode): if isinstance(value, MappingNode):
value = loader.construct_mapping(value) value = loader.construct_mapping(value, deep=True)
elif isinstance(value, SequenceNode): elif isinstance(value, SequenceNode):
value = loader.construct_sequence(value) value = loader.construct_sequence(value, deep=True)
elif isinstance(value, ScalarNode): elif isinstance(value, ScalarNode):
value = loader.construct_scalar(value) value = loader.construct_scalar(value)
yield (key, value) yield (key, value)
...@@ -76,3 +86,20 @@ class BigDFTMainParser(AbstractBaseParser): ...@@ -76,3 +86,20 @@ class BigDFTMainParser(AbstractBaseParser):
""" """
print("Moi") print("Moi")
return return
def atomic_structure(self, structure):
np_positions = []
np_labels = []
positions = structure["Positions"]
for position in positions:
np_positions.append(*position.values())
np_labels.append(*position.keys())
np_positions = np.array(np_positions)
np_labels = np.array(np_labels)
self.backend.addArrayValues("atom_positions", np_positions, unit="angstrom")
self.backend.addArrayValues("atom_labels", np_labels)
self.backend.addValue("number_of_atoms", np_labels.size)
def simulation_domain(self, value):
simulation_cell = np.diag(value["Angstroem"])
self.backend.addArrayValues("simulation_cell", simulation_cell, unit="angstrom")
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