Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further restructure workflows #100

Merged
merged 12 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading