Skip to content

Commit

Permalink
Merge pull request #86 from pyscal/reorder_triples
Browse files Browse the repository at this point in the history
Reorder triples
  • Loading branch information
srmnitc authored Apr 17, 2024
2 parents b2a7062 + dd95a92 commit 28602b1
Show file tree
Hide file tree
Showing 8 changed files with 3,223 additions and 2,432 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.5.1
current_version = 0.5.2
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.5.1
version: 0.5.2
16 changes: 14 additions & 2 deletions atomrdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ def add_structure(self, structure):
structure.graph = self
structure.to_graph()

def _is_valid(self, input_list):
valid = False
for x in input_list:
if x is not None:
valid = True
break
return valid

def _is_ontoterm(self, term):
return type(term).__name__ == 'OntoTerm'

Expand Down Expand Up @@ -317,6 +325,11 @@ def remove(self, triple):
return self.graph.remove(modified_triple)


def create_node(self, namestring, classtype):
item = URIRef(namestring)
self.add((item, RDF.type, classtype))
return item

def _initialize_graph(self):
"""
Create the RDF Graph from the data stored
Expand Down Expand Up @@ -349,9 +362,8 @@ def _initialize_graph(self):


def add_calculated_quantity(self, sample, propertyname, value, unit=None):
prop = URIRef(f'{self._name}_{propertyname}')
prop = self.create_node(propertyname, CMSO.CalculatedProperty)
self.add((sample, CMSO.hasCalculatedProperty, prop))
self.add((prop, RDF.type, CMSO.CalculatedProperty))
self.add((prop, RDFS.label, Literal(propertyname)))
self.add((prop, CMSO.hasValue, Literal(value)))
if unit is not None:
Expand Down
234 changes: 123 additions & 111 deletions atomrdf/structure.py

Large diffs are not rendered by default.

73 changes: 35 additions & 38 deletions atomrdf/workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,44 @@ def _prepare_job(self, workflow_object):
parent_structure.to_graph()
parent_sample = parent_structure.sample

self.structure = structure
self.sample = sample
self.mdict = method_dict
self.parent_sample = parent_sample

def _get_lattice_properties(self, ):
if self.parent_sample is None:
return

material = list([k[2] for k in self.kg.triples((self.parent_sample, CMSO.hasMaterial, None))])[0]
crystal_structure = self.kg.value(material, CMSO.hasStructure)

altname = self.kg.value(crystal_structure, CMSO.hasAltName)

space_group = self.kg.value(crystal_structure, CMSO.hasSpaceGroup)
space_group_symbol = self.kg.value(space_group, CMSO.hasSpaceGroupSymbol)
space_group_number = self.kg.value(space_group, CMSO.hasSpaceGroupNumber)

unit_cell = self.kg.value(crystal_structure, CMSO.hasUnitCell)
blattice = self.kg.value(unit_cell, Namespace("http://purls.helmholtz-metadaten.de/cmso/").hasBravaisLattice)

lattice_parameter = self.kg.value(unit_cell, CMSO.hasLatticeParameter)
lattice_parameter_x = self.kg.value(lattice_parameter, CMSO.hasLength_x)
lattice_parameter_y = self.kg.value(lattice_parameter, CMSO.hasLength_y)
lattice_parameter_z = self.kg.value(lattice_parameter, CMSO.hasLength_z)

lattice_angle = self.kg.value(unit_cell, CMSO.hasAngle)
lattice_angle_x = self.kg.value(lattice_angle, CMSO.hasAngle_alpha)
lattice_angle_y = self.kg.value(lattice_angle, CMSO.hasAngle_beta)
lattice_angle_z = self.kg.value(lattice_angle, CMSO.hasAngle_gamma)

targets = [altname, space_group_symbol, space_group_number, blattice,
[lattice_parameter_x, lattice_parameter_y, lattice_parameter_z],
[lattice_angle_x, lattice_angle_y, lattice_angle_z]]

self.structure._add_crystal_structure(targets=targets)


def _add_inherited_properties(self, ):
#Here we need to add inherited info: CalculatedProperties will be lost
#Defects will be inherited
Expand Down Expand Up @@ -102,52 +136,15 @@ def _add_inherited_properties(self, ):
for triple in self.kg.triples((parent_simcell, PODO.hasNumberOfVacancies, None)):
self.kg.graph.add((simcell, triple[1], triple[2]))

def _get_lattice_properties(self, ):
if self.parent_sample is None:
return

parent_material = list([k[2] for k in self.kg.triples((self.parent_sample, CMSO.hasMaterial, None))])[0]
parent_crystal_structure = self.kg.value(parent_material, CMSO.hasStructure)
parent_altname = self.kg.value(parent_crystal_structure, CMSO.hasAltName)

#add this to new structure
material = list([k[2] for k in self.kg.triples((self.sample, CMSO.hasMaterial, None))])[0]
crystal_structure = self.kg.value(material, CMSO.hasStructure)
self.kg.add((crystal_structure, CMSO.hasAltName, parent_altname))

#space group
parent_space_group = self.kg.value(parent_crystal_structure, CMSO.hasSpaceGroup)
space_group = self.kg.value(crystal_structure, CMSO.hasSpaceGroup)
for triple in self.kg.triples((parent_space_group, None, None)):
self.kg.graph.add((space_group, triple[1], triple[2]))

#unit cell
parent_unit_cell = self.kg.value(parent_crystal_structure, CMSO.hasUnitCell)
parent_bv = self.kg.value(parent_unit_cell, Namespace("http://purls.helmholtz-metadaten.de/cmso/").hasBravaisLattice)

unit_cell = self.kg.value(crystal_structure, CMSO.hasUnitCell)
self.kg.graph.add((unit_cell, Namespace("http://purls.helmholtz-metadaten.de/cmso/").hasBravaisLattice, parent_bv))

#lattice parameter
parent_lattice_parameter = self.kg.value(parent_unit_cell, CMSO.hasLatticeParameter)
lattice_parameter = self.kg.value(unit_cell, CMSO.hasLatticeParameter)
for triple in self.kg.triples((parent_lattice_parameter, None, None)):
self.kg.graph.add((lattice_parameter, triple[1], triple[2]))

#lattice angle
parent_lattice_angle = self.kg.value(parent_unit_cell, CMSO.hasAngle)
lattice_angle = self.kg.value(unit_cell, CMSO.hasAngle)
for triple in self.kg.triples((parent_lattice_angle, None, None)):
self.kg.graph.add((lattice_angle, triple[1], triple[2]))


def add_structural_relation(self, ):
self.kg.add((self.sample, RDF.type, PROV.Entity))
if self.parent_sample is not None:
self.kg.add((self.parent_sample, RDF.type, PROV.Entity))
self.kg.add((self.sample, PROV.wasDerivedFrom, self.parent_sample))
self._add_inherited_properties()
self._get_lattice_properties()
self._add_inherited_properties()


def add_method(self, ):
Expand Down
Loading

0 comments on commit 28602b1

Please sign in to comment.