From 470a7e08b6b7268122081327096573269f06623c Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Thu, 11 Apr 2024 15:39:07 +0200 Subject: [PATCH] minor update to workflows --- environment.yml | 3 +++ pyscal_rdf/workflow/pyiron.py | 2 +- pyscal_rdf/workflow/workflow.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/environment.yml b/environment.yml index 32ab4ae..e6ca18c 100644 --- a/environment.yml +++ b/environment.yml @@ -16,3 +16,6 @@ dependencies: - owlready2 - plotly - ipywidgets + - sqlalchemy + - pip: + - "git+https://github.com/RDFLib/rdflib-sqlalchemy.git@develop" diff --git a/pyscal_rdf/workflow/pyiron.py b/pyscal_rdf/workflow/pyiron.py index 13ad67a..d1cf6f8 100644 --- a/pyscal_rdf/workflow/pyiron.py +++ b/pyscal_rdf/workflow/pyiron.py @@ -17,7 +17,7 @@ def _check_if_job_is_valid(job): raise TypeError('These type of pyiron Job is not currently supported') -def _add_structures(kg, job): +def _add_structures(job): initial_pyiron_structure = job.structure final_pyiron_structure = job.get_structure(frame=-1) initial_pyscal_structure = System.read.ase(initial_pyiron_structure) diff --git a/pyscal_rdf/workflow/workflow.py b/pyscal_rdf/workflow/workflow.py index 936af82..1e29788 100644 --- a/pyscal_rdf/workflow/workflow.py +++ b/pyscal_rdf/workflow/workflow.py @@ -1,13 +1,22 @@ """ Workflows aspects for non-automated annotation of structures. +This consists of a workflow class which implements the necessary methods to serialise triples as needed. +Custom workflow solutions can be implemented. An example available here is pyiron. +The custom workflow env should implement the following functions: + +_check_if_job_is_valid +_add_structure +_identify_method +extract_calculated_properties +inform_graph + +See pyscal_rdf.workflow.pyiron for more details """ from pyscal_rdf.structure import System from rdflib import Graph, Literal, Namespace, XSD, RDF, RDFS, BNode, URIRef, FOAF, SKOS, DCTERMS -import pyscal_rdf.workflow.pyiron as pi - import warnings import numpy as np import os @@ -15,14 +24,29 @@ import ast import uuid +#Move imports to another file PROV = Namespace("http://www.w3.org/ns/prov#") CMSO = Namespace("http://purls.helmholtz-metadaten.de/cmso/") PODO = Namespace("http://purls.helmholtz-metadaten.de/podo/") ASO = Namespace("http://purls.helmholtz-metadaten.de/aso/") +#custom imports as needed +import pyscal_rdf.workflow.pyiron as pi + + class Workflow: def __init__(self, kg, environment='pyiron'): + """ + Initialize the workflow environment + + Parameters + ---------- + kg: pyscal-rdf KnowledgeGraph + environment: string + the workflow environment. This is used to import the necessary functions. + + """ self.kg = kg if environment == 'pyiron': self.wenv = pi @@ -31,7 +55,7 @@ def __init__(self, kg, def _prepare_job(self, workflow_object): self.wenv._check_if_job_is_valid(workflow_object) - parent_structure, parent_sample, structure, sample = self.wenv._add_structures(self.kg, workflow_object) + parent_structure, parent_sample, structure, sample = self.wenv._add_structures(workflow_object) method_dict = self.wenv._identify_method(workflow_object) if (structure is None) and (sample is None):