Skip to content

Commit

Permalink
Merge pull request #105 from pyscal/pack_calculations
Browse files Browse the repository at this point in the history
Pack calculations
  • Loading branch information
srmnitc authored May 5, 2024
2 parents a4a408b + 4ed0bf3 commit 31d7b1b
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.6.9
current_version = 0.6.10
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ url: 'https://atomrdf.pyscal.org'
license: "MIT"
repository-code: https://github.com/pyscal/atomRDF
type: software
version: 0.6.9
version: 0.6.10
28 changes: 25 additions & 3 deletions atomrdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from atomrdf.workflow.workflow import Workflow
from atomrdf.sample import Sample

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

# read element data file
file_location = os.path.dirname(__file__).split("/")
Expand Down Expand Up @@ -804,7 +804,7 @@ def write(self, filename, format="json-ld"):
with open(filename, "w") as fout:
fout.write(self.graph.serialize(format=format))

def archive(self, package_name, format="turtle", compress=True):
def archive(self, package_name, format="turtle", compress=True, add_simulations=False):
"""
Publish a dataset from graph including per atom quantities.
Expand Down Expand Up @@ -852,7 +852,7 @@ def archive(self, package_name, format="turtle", compress=True):
os.mkdir(structure_store)

# now go through each sample, and copy the file, at the same time fix the paths
for sample in self.samples:
for sample in self.sample_ids:
filepath = self.value(URIRef(f"{sample}_Position"), CMSO.hasPath).toPython()
shutil.copy(filepath, structure_store)

Expand All @@ -869,6 +869,20 @@ def archive(self, package_name, format="turtle", compress=True):
Literal(new_relpath, datatype=XSD.string),
)
)
#copy simulation files if needed
if add_simulations:
sim_store = f"{package_name}/simulation_store"
os.mkdir(sim_store)
activities = self.activity_ids
for activity in activities:
path = self.value(activity, CMSO.hasPath)
if path is not None:
newpath = "/".join([sim_store, activity.toPython()])
shutil.copytree(path, newpath)

#remove old path
self.remove((activity, CMSO.hasPath, None))
self.add((activity, CMSO.hasPath, Literal(newpath, datatype=XSD.string)))

triple_file = os.path.join(package_name, "triples")
self.write(triple_file, format=format)
Expand Down Expand Up @@ -1086,6 +1100,14 @@ def samples(self):
sample_objects.append(Sample(name, ids, self))
return sample_objects

@property
def activity_ids(self):
"""
Returns a list of all Samples in the graph
"""

return [x[0] for x in self.triples((None, RDF.type, PROV.Activity))]

def iterate_graph(self, item, create_new_graph=False):
"""
Iterate through the graph starting from the given item.
Expand Down
5 changes: 5 additions & 0 deletions atomrdf/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def get_string_from_URI(x):
if len(rawsplit) > 1:
return "_".join(rawsplit), "BNode"

if "activity:" in raw:
rawsplit = raw.split(":")
if len(rawsplit) > 1:
return "_".join(rawsplit), "BNode"

# just a normal url split now
rawsplit = raw.split("/")
if len(rawsplit) > 1:
Expand Down
7 changes: 6 additions & 1 deletion atomrdf/workflow/pyiron.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def process_murnaghan_job(job):
murnaghan_dict['structure'] = get_structures(job)['structure']
murnaghan_dict['sample'] = get_structures(job)['sample']
murnaghan_dict['intermediate'] = False
murnaghan_dict['path'] = get_simulation_folder(job)

#add the murnaghan method
murnaghan_dict['method'] = "EquationOfState"
Expand Down Expand Up @@ -207,8 +208,12 @@ def process_lammps_job(job):
method_dict['sample'] = structure_dict['sample']
method_dict['outputs'] = output_dict
method_dict['intermediate'] = False
method_dict['path'] = get_simulation_folder(job)
return method_dict

def get_simulation_folder(job):
return os.path.join(job.project.path, f'{job.name}_hdf5')

def get_structures(job):
initial_pyiron_structure = job.structure
final_pyiron_structure = job.get_structure(frame=-1)
Expand Down Expand Up @@ -288,7 +293,7 @@ def lammps_identify_method(job):
mdict["pressure"] = press
mdict["dof"] = dof
mdict["ensemble"] = ensemble
mdict["id"] = job.id
#mdict["id"] = job.id

# now process potential
inpdict = job.input.to_dict()
Expand Down
16 changes: 10 additions & 6 deletions atomrdf/workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ast
import uuid
import importlib
import uuid

from atomrdf.structure import System

Expand Down Expand Up @@ -267,13 +268,15 @@ def _add_method(

# add activity
# ----------------------------------------------------------
main_id = job_dict['id']
activity = URIRef(f"activity_{main_id}")
main_id = uuid.uuid4()
main_id = f'activity:{main_id}'
job_dict['id'] = main_id
activity = URIRef(main_id)
self.kg.add((activity, RDF.type, PROV.Activity))

# add method
# ----------------------------------------------------------
method = URIRef(f"method_{main_id}")
method = URIRef(f"{main_id}_method")
if job_dict["method"] == "MolecularStatics":
#TODO: Replace with ASMO.MolecularStatics
self.kg.add((method, RDF.type, ASMO.MolecularDynamics))
Expand All @@ -300,6 +303,7 @@ def _add_method(
# add that structure was generated
#TODO: Move hasComputationalMethod here after EquationOfState is added
self.kg.add((job_dict['sample']['final'], PROV.wasGeneratedBy, activity))
self.kg.add((activity, CMSO.hasPath, Literal(job_dict['path'], datatype=XSD.string)))
self._add_inputs(job_dict, activity)
self._add_outputs(job_dict, activity)
self._add_software(job_dict, method)
Expand Down Expand Up @@ -393,7 +397,7 @@ def _add_md(self, job_dict, method, activity):
# add temperature if needed
if job_dict["temperature"] is not None:
temperature = self.kg.create_node(
f"temperature_{main_id}", ASMO.InputParameter
f"{main_id}_temperature", ASMO.InputParameter
)
self.kg.add(
(temperature, RDFS.label, Literal("temperature", datatype=XSD.string))
Expand All @@ -412,7 +416,7 @@ def _add_md(self, job_dict, method, activity):

if job_dict["pressure"] is not None:
pressure = self.kg.create_node(
f"pressure_{main_id}", ASMO.InputParameter
f"{main_id}_pressure", ASMO.InputParameter
)
self.kg.add(
(pressure, RDFS.label, Literal("pressure", datatype=XSD.string))
Expand All @@ -430,7 +434,7 @@ def _add_md(self, job_dict, method, activity):
)

# potentials need to be mapped
potential = URIRef(f"potential_{main_id}")
potential = URIRef(f"{main_id}_potential")
if "meam" in job_dict["potential"]["type"]:
self.kg.add((potential, RDF.type, ASMO.ModifiedEmbeddedAtomModel))
elif "eam" in job_dict["potential"]["type"]:
Expand Down
73 changes: 61 additions & 12 deletions examples/workflow_examples/01_lammps_pyiron.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ff41537d7d5a411dad2041ebe785887e",
"model_id": "21fb303d02c64375a340d2958fb85147",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -60,7 +60,7 @@
"metadata": {},
"outputs": [],
"source": [
"project = 'wf1a'\n",
"project = 'wf1c'\n",
"pr = Project(project)"
]
},
Expand Down Expand Up @@ -111,21 +111,21 @@
"<!-- Generated by graphviz version 9.0.0 (20231125.0833)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"232pt\" height=\"44pt\"\n",
" viewBox=\"0.00 0.00 231.75 44.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<svg width=\"230pt\" height=\"44pt\"\n",
" viewBox=\"0.00 0.00 230.25 44.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 40)\">\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-40 227.75,-40 227.75,4 -4,4\"/>\n",
"<!-- sample_4ff68114&#45;deac&#45;439a&#45;8540&#45;554d4a919e63 -->\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-40 226.25,-40 226.25,4 -4,4\"/>\n",
"<!-- sample_e91f804d&#45;5c09&#45;46dc&#45;8eef&#45;8a7a33b1c135 -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>sample_4ff68114&#45;deac&#45;439a&#45;8540&#45;554d4a919e63</title>\n",
"<polygon fill=\"#d9d9d9\" stroke=\"#d9d9d9\" points=\"223.75,-36 0,-36 0,0 223.75,0 223.75,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"111.88\" y=\"-15.28\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\">sample_4ff68114&#45;deac&#45;439a&#45;8540&#45;554d4a919e63</text>\n",
"<title>sample_e91f804d&#45;5c09&#45;46dc&#45;8eef&#45;8a7a33b1c135</title>\n",
"<polygon fill=\"#d9d9d9\" stroke=\"#d9d9d9\" points=\"222.25,-36 0,-36 0,0 222.25,0 222.25,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"111.12\" y=\"-15.28\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\">sample_e91f804d&#45;5c09&#45;46dc&#45;8eef&#45;8a7a33b1c135</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x7fb2d0b99310>"
"<graphviz.graphs.Digraph at 0x7f8373a835d0>"
]
},
"execution_count": 7,
Expand Down Expand Up @@ -187,7 +187,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The job j1 was saved and received the ID: 134\n"
"The job j1 was saved and received the ID: 154\n"
]
}
],
Expand All @@ -197,14 +197,63 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"id": "af64675d-2630-4e83-9b54-d83aa92f0df0",
"metadata": {},
"outputs": [],
"source": [
"kg.add_workflow(job, workflow_environment='pyiron')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "b20c7a38-e530-44e4-a062-2c660052ba37",
"metadata": {},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "c4010a08",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/mnt/c/Users/menon/Documents/repos/projects-iuc17/atomRDF/examples/workflow_examples/wf1c/j1_hdf5/j1'"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"os.path.join(job.project.path, f'{job.name}_hdf5', job.name)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "6df3f9f7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ls: cannot access '/mnt/c/Users/menon/Documents/repos/projects-iuc17/atomRDF/examples/workflow_examples/wf1c/j1': No such file or directory\n"
]
}
],
"source": [
"! ls /mnt/c/Users/menon/Documents/repos/projects-iuc17/atomRDF/examples/workflow_examples/wf1c/j1"
]
},
{
"cell_type": "code",
"execution_count": 14,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='atomrdf',
version='0.6.9',
version='0.6.10',
author='Abril Azocar Guzman, Sarath Menon',
author_email='[email protected]',
description='Ontology based structural manipulation and quering',
Expand Down

0 comments on commit 31d7b1b

Please sign in to comment.