Skip to content

Commit ea6d3c8

Browse files
authored
Merge pull request #177 from pyscal/Sf_fixes_3
Sf fixes 3
2 parents a48556a + 8229ceb commit ea6d3c8

File tree

6 files changed

+108
-8
lines changed

6 files changed

+108
-8
lines changed

atomrdf/graph.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,65 @@ def _initialize_graph(self):
639639
(CMSO.Vector, CMSO.hasUnit, URIRef("http://qudt.org/vocab/unit/ANGSTROM"))
640640
)
641641

642-
def add_calculated_quantity(self, sample, propertyname, value, unit=None):
642+
def add_output_of_simulation(self, simulation_term,
643+
value,
644+
property_label,
645+
base_quantity=None,
646+
unit=None,
647+
has_simulation_algorithm=None,
648+
has_computational_method=None):
649+
"""
650+
Create a new output of simulation in the graph. The types of different terms are defined in the ontology.
651+
Those should be access by kg.terms.ontolog.ontology_term.
652+
653+
Parameters
654+
----------
655+
simulation_term : OntoTerm
656+
The term representing the simulation.
657+
658+
value : float
659+
The value of the output.
660+
661+
property_label : str
662+
The label of the property.
663+
664+
base_quantity : OntoTerm, optional
665+
The base quantity of the output. Default is None.
666+
667+
unit : OntoTerm, optional
668+
The unit of the output. Default is None.
669+
670+
671+
has_simulation_algorithm : OntoTerm, optional
672+
The simulation algorithm used. Default is None.
673+
674+
has_computational_method : OntoTerm, optional
675+
The computational method used. Default is None.
676+
677+
Returns
678+
-------
679+
URIRef
680+
The newly created output of simulation.
681+
682+
"""
683+
main_id = str(uuid.uuid4())
684+
simulation_node = self.create_node(f"simulation:{main_id}", simulation_term)
685+
if has_simulation_algorithm is not None:
686+
self.add((simulation_node, ASMO.usesSimulationAlgorithm, has_simulation_algorithm))
687+
if has_computational_method is not None:
688+
self.add((simulation_node, ASMO.hasComputationalMethod, has_computational_method))
689+
if base_quantity is None:
690+
base_quantity = ASMO.CalculatedProperty
691+
prop = self.create_node(f"simulation:{main_id}_{property_label}", base_quantity)
692+
self.add((prop, ASMO.wasCalculatedBy, simulation_node))
693+
self.add((prop, RDFS.label, Literal(property_label)))
694+
self.add((prop, ASMO.hasValue, Literal(value)))
695+
if unit is not None:
696+
self.add((prop, ASMO.hasUnit, unit))
697+
return prop
698+
699+
700+
def add_calculated_quantity(self, sample, propertyname, value, base_quantity=None, unit=None):
643701
"""
644702
Add a calculated quantity to a sample.
645703
@@ -669,8 +727,10 @@ def add_calculated_quantity(self, sample, propertyname, value, unit=None):
669727
>>> sample = graph.create_node("Sample1", CMSO.Sample)
670728
>>> graph.add_calculated_quantity(sample, "energy", "10.5", "eV")
671729
"""
730+
if base_quantity is None:
731+
base_quantity = ASMO.CalculatedProperty
672732

673-
prop = self.create_node(f"{sample}_{propertyname}", CMSO.CalculatedProperty)
733+
prop = self.create_node(f"{sample}_{propertyname}", base_quantity)
674734
self.add((sample, CMSO.hasCalculatedProperty, prop))
675735
self.add((prop, RDFS.label, Literal(propertyname)))
676736
self.add((prop, ASMO.hasValue, Literal(value)))

atomrdf/sample.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,32 @@ def __init__(self, value, unit=None, graph=None, parent=None, sample_parent=None
213213
self._label = None
214214
self._sample_parent = sample_parent
215215

216+
def __getitem__(self, index):
217+
if isinstance(self._value, (list, np.ndarray)):
218+
if isinstance(index, slice):
219+
value = self._value[index.start:index.stop:index.step]
220+
else:
221+
value = self._value[index]
222+
return Property(value, unit=self._unit, graph=self._graph, parent=self._parent, sample_parent=self._sample_parent)
223+
224+
else:
225+
raise TypeError('This property is not a list or array, therefore not subscriptable.')
226+
227+
216228
def _clean_value(self, value):
217229
if isinstance(value, str):
218230
if (value[0] == '[') and (value[-1] == ']'):
219231
value = np.array(json.loads(value))
232+
if isinstance(value, (list, np.ndarray)):
233+
value = np.array(value)
220234
return value
221235

222236
def __repr__(self):
223237
if self._unit is not None:
224238
return f"{self._value} {self._unit}"
225239
return f"{self._value}"
226240

241+
#
227242
@property
228243
def value(self):
229244
return self._value
@@ -275,6 +290,13 @@ def _create_node(self, res):
275290
self._graph.add((parent, ASMO.hasUnit, URIRef(f"http://qudt.org/vocab/unit/{self._unit}")))
276291
return parent
277292

293+
def update_physical_quantity(self, ontoterm):
294+
if self._graph is not None:
295+
if self._parent is not None:
296+
self._graph.remove((self._parent, RDF.type, None))
297+
#remove the old type
298+
self._graph.add((self._parent, RDF.type, ontoterm.URIRef))
299+
278300
#overloaded operations
279301
def __add__(self, value):
280302
res = self._value + self._declass(value)

atomrdf/structure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,13 +1976,13 @@ def _add_simulation_cell(self):
19761976
)
19771977
self.graph.add((self.sample, CMSO.hasSimulationCell, simulation_cell))
19781978
volume = self.graph.create_node(
1979-
f"{self._name}_Volume", UNSAFEASMO.Volume, label="SimulationCellVolume"
1979+
f"{self._name}_Volume", ASMO.Volume, label="SimulationCellVolume"
19801980
)
1981-
self.graph.add((simulation_cell, UNSAFECMSO.hasVolume, volume))
1981+
self.graph.add((simulation_cell, CMSO.hasVolume, volume))
19821982
self.graph.add(
19831983
(
19841984
volume,
1985-
UNSAFEASMO.hasValue,
1985+
ASMO.hasValue,
19861986
Literal(
19871987
np.round(self.schema.simulation_cell.volume(), decimals=2),
19881988
datatype=XSD.float,
@@ -1992,7 +1992,7 @@ def _add_simulation_cell(self):
19921992
self.graph.add(
19931993
(
19941994
volume,
1995-
UNSAFEASMO.hasUnit,
1995+
ASMO.hasUnit,
19961996
URIRef(f"http://qudt.org/vocab/unit/ANGSTROM3"),
19971997
)
19981998
)

atomrdf/workflow/jobdict.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ structure:
55
initial: System obj
66
final: System obj
77
intermediate: False
8-
method: MolecularStatics/MolecularDynamics/DensityFunctionalTheory/EquationOfState/QuasiHarmonicModel
8+
method: MolecularStatics/MolecularDynamics/DensityFunctionalTheory/EquationOfState/QuasiHarmonicModel/ThermodynamicIntegration
99
path: job path folder
1010
dof:
1111
- AtomicPositionRelaxation

atomrdf/workflow/pyiron/murnaghan.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ def process_job(job):
4242
"base": "Volume",
4343
}
4444
)
45+
outputs.append(
46+
{
47+
"label": "TotalEnergy",
48+
"value": np.round(job['output/energy'], decimals=4),
49+
"unit": "EV",
50+
"associate_to_sample": True,
51+
"base": "TotalEnergy",
52+
}
53+
)
54+
outputs.append(
55+
{
56+
"label": "Volume",
57+
"value": np.round(job['output/volume'], decimals=4),
58+
"unit": "ANGSTROM3",
59+
"associate_to_sample": True,
60+
"base": "Volume",
61+
}
62+
)
4563
outputs.append(
4664
{
4765
"label": "BulkModulus",

atomrdf/workflow/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def _add_outputs(self, job_dict, activity):
415415
#here we add the classes by property
416416
#call func here
417417
prop = self._select_base_property(out, main_id, CMSO.CalculatedProperty)
418-
self.kg.add((prop, ASMO.wasCalculatedBy, activity))
418+
self.kg.add((prop, UNSAFEASMO.wasCalculatedBy, activity))
419419

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

0 commit comments

Comments
 (0)