Skip to content

Commit

Permalink
Merge pull request #100 from pyscal/further_restructure_workflows
Browse files Browse the repository at this point in the history
Further restructure workflows
  • Loading branch information
srmnitc authored May 2, 2024
2 parents 4e34f59 + 60f2726 commit 7d97559
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 558 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#custom
rdf_structure_store/
*.json
*.ttl

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
16 changes: 16 additions & 0 deletions atomrdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import atomrdf.properties as prp
from atomrdf.stores import create_store
import atomrdf.json_io as json_io
from atomrdf.workflow.workflow import Workflow

from atomrdf.namespace import Namespace, CMSO, PLDO, PODO, ASMO

Expand Down Expand Up @@ -212,6 +213,7 @@ def __init__(
self.store = store
self._n_triples = 0
self._initialize_graph()
self.workflow = Workflow(self)

def add_structure(self, structure):
"""
Expand Down Expand Up @@ -697,6 +699,7 @@ def visualise(
rankdir="BT",
hide_types=False,
workflow_view=False,
sample_view=False,
size=None,
layout="neato",
):
Expand All @@ -713,6 +716,8 @@ def visualise(
Whether to hide the types in the visualization. Default is False.
workflow_view : bool, optional
Whether to enable the workflow view. Default is False.
sample_view : bool, optional
Whether to enable the sample view. Default is False.
size : tuple, optional
The size of the visualization. Default is None.
layout : str, optional
Expand Down Expand Up @@ -765,6 +770,7 @@ def visualise(
rankdir=rankdir,
hide_types=hide_types,
workflow_view=workflow_view,
sample_view=sample_view,
size=size,
layout=layout,
)
Expand Down Expand Up @@ -1178,3 +1184,13 @@ def to_file(self, sample, filename=None, format="poscar"):
else:
asesys = sys.write.ase()
write(filename, asesys, format=format)

def enable_workflow(self, workflow_object, workflow_environment=None, workflow_module=None):
self.workflow.inform_graph(workflow_object,
workflow_environment=workflow_environment,
workflow_module=workflow_module)

def add_workflow(self, job, workflow_environment=None, workflow_module=None, job_dict=None):
self.workflow.to_graph(job, workflow_environment=workflow_environment,
workflow_module=workflow_module,
job_dict=job_dict)
46 changes: 2 additions & 44 deletions atomrdf/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

import os

# special methods; for supporting workflow envs
from atomrdf.workflow import inform_graph


def create_store(kg, store, identifier, store_file=None, structure_store=None):
"""
Expand All @@ -32,30 +29,22 @@ def create_store(kg, store, identifier, store_file=None, structure_store=None):
"""
kg.store_file = store_file
if store == "Memory":
if store in ["Memory", "memory"]:
store_memory(
kg,
store,
identifier,
store_file=store_file,
structure_store=structure_store,
)
elif store == "SQLAlchemy":
elif store in ["SQLAlchemy", "db", "database", "sqlalchemy"]:
store_alchemy(
kg,
store,
identifier,
store_file=store_file,
structure_store=structure_store,
)
elif type(store).__name__ == "Project":
store_pyiron(
kg,
store,
identifier,
store_file=store_file,
structure_store=structure_store,
)
else:
raise ValueError("Unknown store found!")

Expand Down Expand Up @@ -121,37 +110,6 @@ def store_alchemy(kg, store, identifier, store_file=None, structure_store=None):
kg.graph.open(uri, create=True)
kg.structure_store = _setup_structure_store(structure_store=structure_store)


def store_pyiron(kg, store, identifier, store_file=None, structure_store=None):
"""
Store the pyiron knowledge graph in a database.
Parameters
----------
kg : pyiron.atomistics.structure.pyiron_atomistics.structure.AtomisticStructure
The pyiron knowledge graph to be stored.
store : pyiron.atomistics.structure.pyiron_atomistics.structure.AtomisticStructure
The store object where the knowledge graph will be stored.
identifier : str
The identifier for the knowledge graph.
store_file : str, optional
The path to the store file. If not provided, a default path will be used.
structure_store : str, optional
The path to the structure store. If not provided, a default path will be used.
Returns
-------
None
"""
structure_store = os.path.join(store.path, "rdf_structure_store")
kg.structure_store = _setup_structure_store(structure_store=structure_store)
store_file = os.path.join(store.path, f"{store.name}.db")
store_alchemy(kg, store, identifier, store_file, structure_store=structure_store)
# finally update project object
inform_graph(store, kg)


def _check_if_sqlalchemy_is_available():
try:
import sqlalchemy as sa
Expand Down
9 changes: 9 additions & 0 deletions atomrdf/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def visualize_graph(
rankdir="TB",
hide_types=False,
workflow_view=False,
sample_view=False,
size=None,
layout="dot",
):
Expand All @@ -120,6 +121,8 @@ def visualize_graph(
Whether to hide nodes with the "type" attribute. Default is False.
workflow_view : bool, optional
Whether to enable the workflow view. Default is False.
sample_view : bool, optional
Whether to enable the sample view. Default is False.
size : str, optional
The size of the graph. Default is None.
layout : str, optional
Expand Down Expand Up @@ -173,6 +176,12 @@ def visualize_graph(
fontname=styledict[istype1]["fontname"],
)
plot = False

elif sample_view:
green_list = ['wasDerivedFrom', 'wasGeneratedBy']
if string3 not in green_list:
plot = False


if hide_types and (string3 == "type"):
plot = False
Expand Down
2 changes: 1 addition & 1 deletion atomrdf/workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from atomrdf.workflow.pyiron import inform_graph
Loading

0 comments on commit 7d97559

Please sign in to comment.