From d9a7a0ca3faecfac28ca01a249747e90c64fbe3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20B=C3=BCschelberger?= Date: Thu, 27 Jul 2023 10:22:26 +0000 Subject: [PATCH] debug retrieval of results from zacrosjob --- examples/XYZ/lattice_input.dat | 37 +++++++++++++++++++ .../Ziff-Gulari-Barshad-model-variants.json | 2 +- examples/Ziff-Gulari-Barshad-model.json | 2 +- examples/zacros_model_example.py | 13 ++----- osp/tools/mapping_functions.py | 6 +-- osp/wrappers/simzacros/simzacros_session.py | 7 +--- 6 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 examples/XYZ/lattice_input.dat diff --git a/examples/XYZ/lattice_input.dat b/examples/XYZ/lattice_input.dat new file mode 100644 index 0000000..4111b5b --- /dev/null +++ b/examples/XYZ/lattice_input.dat @@ -0,0 +1,37 @@ +lattice periodic_cell + +cell_vectors # in row format (Angstroms) + 2.774687009376012 0.000000000000000 + 0.000000000000000 2.774687009376012 + +repeat_cell 6 6 + +n_site_types 2 +site_type_names brg hol + +n_cell_sites 3 +site_types brg brg hol + +site_coordinates # fractional coordinates (x,y) in row format + + 0.500000000000000 0.000000000000000 + 0.000000000000000 0.500000000000000 + 0.500000000000000 0.500000000000000 + +neighboring_structure # site-neighsite cell + + 1-2 self + 1-3 self + 2-3 self + + 2-1 north + 3-1 north + + 1-2 east + 3-2 east + + 1-2 southeast + +end_neighboring_structure + +end_lattice diff --git a/examples/Ziff-Gulari-Barshad-model-variants.json b/examples/Ziff-Gulari-Barshad-model-variants.json index 8f22fde..0abac43 100644 --- a/examples/Ziff-Gulari-Barshad-model-variants.json +++ b/examples/Ziff-Gulari-Barshad-model-variants.json @@ -19,7 +19,7 @@ "wall_time": 100 }, - "lattice_input": {"xyz_file": "../tests/test_files/lattice_input.dat"}, + "lattice_input": {"xyz_file": "XYZ/lattice_input.dat"}, "energetics_input": [ { "name": "CO_Point_brg", diff --git a/examples/Ziff-Gulari-Barshad-model.json b/examples/Ziff-Gulari-Barshad-model.json index e10a967..5da022a 100644 --- a/examples/Ziff-Gulari-Barshad-model.json +++ b/examples/Ziff-Gulari-Barshad-model.json @@ -19,7 +19,7 @@ "wall_time": 3600 }, - "lattice_input": {"xyz_file": "./Zacros_inputs/lattice_input.dat"}, + "lattice_input": {"xyz_file": "./XYZ/lattice_input.dat"}, "energetics_input": [ { "name": "CO_Point", diff --git a/examples/zacros_model_example.py b/examples/zacros_model_example.py index 8401204..caacaa3 100644 --- a/examples/zacros_model_example.py +++ b/examples/zacros_model_example.py @@ -1,21 +1,16 @@ """Example of py/Zacros model""" import os -import json from osp.models.zacros.co_pyzacros import COpyZacrosModel from osp.wrappers.simzacros.simzacros_session import SimzacrosSession -from osp.core.namespaces import emmo, cuba +from osp.core.namespaces import cuba from osp.core.utils import import_cuds -from osp.core.utils import pretty_print -#path = os.path.join(os.path.dirname(__file__), "Ziff-Gulari-Barshad-model.json") -path = os.path.join(os.path.dirname(__file__), "Ziff-Gulari-Barshad-model-variants.json") - -with open(path, mode="r+") as file: - content = json.loads(file.read()) # alternatively with the standard file. Needs connection to minio! -#content = COpyZacrosModel.Config.schema_extra["example"] +content = COpyZacrosModel.Config.schema_extra["example"] +directory = os.path.dirname(__file__) +content["lattice_input"]["xyz_file"] = os.path.join(directory, "XYZ", "lattice_input.dat") model = COpyZacrosModel(**content) diff --git a/osp/tools/mapping_functions.py b/osp/tools/mapping_functions.py index f2e78e8..05cec8f 100644 --- a/osp/tools/mapping_functions.py +++ b/osp/tools/mapping_functions.py @@ -1664,7 +1664,7 @@ def map_results(engine, root_cuds_object: Cuds) -> str: tarball = map_tarball(engine, last_calculation[0]) - elif isinstance(engine, pz.ZacrosResults): + elif isinstance(engine, pz.ZacrosJob): search_calculation = search.find_cuds_objects_by_oclass( emmo.MesoscopicCalculation, root_cuds_object, rel=cuba.relationship) @@ -1810,10 +1810,8 @@ def map_tarball(engine, root_cuds_object, path=None) -> str: :return str: file system path to tarball """ - path = "plams_workdir/" - tar = tempfile.NamedTemporaryFile().name - shutil.make_archive(tar, "tar", path) + shutil.make_archive(tar, "tar", engine.path) tar_file = f"{tar}.tar" print(f"Job output dumped to {tar_file}") diff --git a/osp/wrappers/simzacros/simzacros_session.py b/osp/wrappers/simzacros/simzacros_session.py index 200aa8c..1eb117b 100644 --- a/osp/wrappers/simzacros/simzacros_session.py +++ b/osp/wrappers/simzacros/simzacros_session.py @@ -5,12 +5,9 @@ from osp.tools.io_functions import raise_error from osp.tools.mapping_functions import map_function, map_results from osp.core.utils import simple_search as search -from arcp import is_arcp_uri, parse_arcp from osp.models.utils.general import get_download import scm.pyzacros as pz import os -from urllib.parse import parse_qs -from pathlib import Path # from osp.core.utils import pretty_print @@ -41,7 +38,7 @@ def _run(self, root_cuds_object: Cuds): pz_job = pz.ZacrosJob(settings=pz_settings, lattice=pz_lattice, mechanism=pz_mechanism, cluster_expansion=pz_cluster_expansion) results = pz_job.run() - self._tarball = map_results(results, root_cuds_object) + self._tarball = map_results(pz_job, root_cuds_object) # Attributes to easily access (syntactic) info from results. self.get_reaction_network = results.get_reaction_network() @@ -118,7 +115,7 @@ def _apply_added(self, root_obj, buffer): lattice = search_lattice.pop() if "file://" in str(lattice.iri): split = str(lattice.iri).split("file://") - self.lattice = Path(split[-1]).resolve() + self.lattice = split[-1] else: self.lattice = get_download(str(lattice.uid), as_file=True) else: