Skip to content

Commit 970d1fd

Browse files
committed
structures can take computed properties
1 parent 341f3fa commit 970d1fd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

atomrdf/datamodels/structure.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import atomrdf.datamodels.defects as defects
3434
import atomrdf.datamodels.structure_io as structure_io
3535
from atomrdf.utils import get_material, get_sample_id, get_sample_object, toPython
36+
from atomrdf.datamodels.workflow.property import *
3637
import atomrdf.properties as ap
3738

3839

@@ -661,6 +662,30 @@ class AtomicScaleSample(BaseModel, TemplateMixin):
661662
mixed_grain_boundary: Optional[defects.MixedGrainBoundary] = None
662663

663664
# properties
665+
calculated_property: Optional[List[CalculatedProperty]] = Field(
666+
default=[], description="Calculated properties from the simulation"
667+
)
668+
669+
def to_graph_calculated_properties(self, graph):
670+
if self.calculated_property:
671+
for param in self.calculated_property:
672+
param_uri = param.to_graph(graph)
673+
graph.add(
674+
(
675+
URIRef(self.id),
676+
ASMO.hasCalculatedProperty,
677+
param_uri,
678+
),
679+
validate=False,
680+
)
681+
682+
def from_graph_calculated_properties(cls, graph, sample_id):
683+
properties = []
684+
for prop_uri in graph.objects(URIRef(sample_id), ASMO.hasCalculatedProperty):
685+
prop = CalculatedProperty.from_graph(graph, prop_uri)
686+
properties.append(prop)
687+
cls.calculated_property = properties
688+
return cls
664689

665690
def to_graph(self, graph, force=False):
666691
# if force - creates a new ID and saves the structure again
@@ -680,6 +705,10 @@ def to_graph(self, graph, force=False):
680705
graph,
681706
sample,
682707
)
708+
709+
# now add calculated properties
710+
self.to_graph_calculated_properties(graph)
711+
683712
# now call defect methods
684713
# Defects
685714
defect_fields = [
@@ -758,6 +787,7 @@ def from_graph(cls, graph, sample_id):
758787

759788
cls = cls(**kwargs)
760789
cls.id = sample_id
790+
cls = cls.from_graph_calculated_properties(graph, sample_id)
761791
return cls
762792

763793
def update_attributes(self, atoms, repeat=None):

0 commit comments

Comments
 (0)