Skip to content
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
64 changes: 62 additions & 2 deletions atomrdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,65 @@ def _initialize_graph(self):
(CMSO.Vector, CMSO.hasUnit, URIRef("http://qudt.org/vocab/unit/ANGSTROM"))
)

def add_calculated_quantity(self, sample, propertyname, value, unit=None):
def add_output_of_simulation(self, simulation_term,
value,
property_label,
base_quantity=None,
unit=None,
has_simulation_algorithm=None,
has_computational_method=None):
"""
Create a new output of simulation in the graph. The types of different terms are defined in the ontology.
Those should be access by kg.terms.ontolog.ontology_term.
Parameters
----------
simulation_term : OntoTerm
The term representing the simulation.
value : float
The value of the output.
property_label : str
The label of the property.
base_quantity : OntoTerm, optional
The base quantity of the output. Default is None.
unit : OntoTerm, optional
The unit of the output. Default is None.
has_simulation_algorithm : OntoTerm, optional
The simulation algorithm used. Default is None.
has_computational_method : OntoTerm, optional
The computational method used. Default is None.
Returns
-------
URIRef
The newly created output of simulation.
"""
main_id = str(uuid.uuid4())
simulation_node = self.create_node(f"simulation:{main_id}", simulation_term)
if has_simulation_algorithm is not None:
self.add((simulation_node, ASMO.usesSimulationAlgorithm, has_simulation_algorithm))
if has_computational_method is not None:
self.add((simulation_node, ASMO.hasComputationalMethod, has_computational_method))
if base_quantity is None:
base_quantity = ASMO.CalculatedProperty
prop = self.create_node(f"simulation:{main_id}_{property_label}", base_quantity)
self.add((prop, ASMO.wasCalculatedBy, simulation_node))
self.add((prop, RDFS.label, Literal(property_label)))
self.add((prop, ASMO.hasValue, Literal(value)))
if unit is not None:
self.add((prop, ASMO.hasUnit, unit))
return prop


def add_calculated_quantity(self, sample, propertyname, value, base_quantity=None, unit=None):
"""
Add a calculated quantity to a sample.
Expand Down Expand Up @@ -669,8 +727,10 @@ def add_calculated_quantity(self, sample, propertyname, value, unit=None):
>>> sample = graph.create_node("Sample1", CMSO.Sample)
>>> graph.add_calculated_quantity(sample, "energy", "10.5", "eV")
"""
if base_quantity is None:
base_quantity = ASMO.CalculatedProperty

prop = self.create_node(f"{sample}_{propertyname}", CMSO.CalculatedProperty)
prop = self.create_node(f"{sample}_{propertyname}", base_quantity)
self.add((sample, CMSO.hasCalculatedProperty, prop))
self.add((prop, RDFS.label, Literal(propertyname)))
self.add((prop, ASMO.hasValue, Literal(value)))
Expand Down
22 changes: 22 additions & 0 deletions atomrdf/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,32 @@ def __init__(self, value, unit=None, graph=None, parent=None, sample_parent=None
self._label = None
self._sample_parent = sample_parent

def __getitem__(self, index):
if isinstance(self._value, (list, np.ndarray)):
if isinstance(index, slice):
value = self._value[index.start:index.stop:index.step]
else:
value = self._value[index]
return Property(value, unit=self._unit, graph=self._graph, parent=self._parent, sample_parent=self._sample_parent)

else:
raise TypeError('This property is not a list or array, therefore not subscriptable.')


def _clean_value(self, value):
if isinstance(value, str):
if (value[0] == '[') and (value[-1] == ']'):
value = np.array(json.loads(value))
if isinstance(value, (list, np.ndarray)):
value = np.array(value)
return value

def __repr__(self):
if self._unit is not None:
return f"{self._value} {self._unit}"
return f"{self._value}"

#
@property
def value(self):
return self._value
Expand Down Expand Up @@ -275,6 +290,13 @@ def _create_node(self, res):
self._graph.add((parent, ASMO.hasUnit, URIRef(f"http://qudt.org/vocab/unit/{self._unit}")))
return parent

def update_physical_quantity(self, ontoterm):
if self._graph is not None:
if self._parent is not None:
self._graph.remove((self._parent, RDF.type, None))
#remove the old type
self._graph.add((self._parent, RDF.type, ontoterm.URIRef))

#overloaded operations
def __add__(self, value):
res = self._value + self._declass(value)
Expand Down
8 changes: 4 additions & 4 deletions atomrdf/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,13 +1821,13 @@ def _add_simulation_cell(self):
)
self.graph.add((self.sample, CMSO.hasSimulationCell, simulation_cell))
volume = self.graph.create_node(
f"{self._name}_Volume", UNSAFEASMO.Volume, label="SimulationCellVolume"
f"{self._name}_Volume", ASMO.Volume, label="SimulationCellVolume"
)
self.graph.add((simulation_cell, UNSAFECMSO.hasVolume, volume))
self.graph.add((simulation_cell, CMSO.hasVolume, volume))
self.graph.add(
(
volume,
UNSAFEASMO.hasValue,
ASMO.hasValue,
Literal(
np.round(self.schema.simulation_cell.volume(), decimals=2),
datatype=XSD.float,
Expand All @@ -1837,7 +1837,7 @@ def _add_simulation_cell(self):
self.graph.add(
(
volume,
UNSAFEASMO.hasUnit,
ASMO.hasUnit,
URIRef(f"http://qudt.org/vocab/unit/ANGSTROM3"),
)
)
Expand Down
2 changes: 1 addition & 1 deletion atomrdf/workflow/jobdict.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ structure:
initial: System obj
final: System obj
intermediate: False
method: MolecularStatics/MolecularDynamics/DensityFunctionalTheory/EquationOfState/QuasiHarmonicModel
method: MolecularStatics/MolecularDynamics/DensityFunctionalTheory/EquationOfState/QuasiHarmonicModel/ThermodynamicIntegration
path: job path folder
dof:
- AtomicPositionRelaxation
Expand Down
18 changes: 18 additions & 0 deletions atomrdf/workflow/pyiron/murnaghan.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ def process_job(job):
"base": "Volume",
}
)
outputs.append(
{
"label": "TotalEnergy",
"value": np.round(job['output/energy'], decimals=4),
"unit": "EV",
"associate_to_sample": True,
"base": "TotalEnergy",
}
)
outputs.append(
{
"label": "Volume",
"value": np.round(job['output/volume'], decimals=4),
"unit": "ANGSTROM3",
"associate_to_sample": True,
"base": "Volume",
}
)
outputs.append(
{
"label": "BulkModulus",
Expand Down
2 changes: 1 addition & 1 deletion atomrdf/workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _add_outputs(self, job_dict, activity):
#here we add the classes by property
#call func here
prop = self._select_base_property(out, main_id, CMSO.CalculatedProperty)
self.kg.add((prop, ASMO.wasCalculatedBy, activity))
self.kg.add((prop, UNSAFEASMO.wasCalculatedBy, activity))

if out["associate_to_sample"]:
self.kg.add((job_dict['sample']['final'], CMSO.hasCalculatedProperty, prop))
Expand Down
Loading