Skip to content

Commit

Permalink
Merge pull request #38 from pyscal/add_status
Browse files Browse the repository at this point in the history
add inspect function
  • Loading branch information
srmnitc authored Jun 26, 2023
2 parents db9a5e2 + 8a7d69c commit bbe9461
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pyscal_rdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,28 @@ def add_calculated_quantity(self, propertyname, value, unit=None, sample=None):
self.add((prop, CMSO.hasUnit, URIRef(f'https://qudt.org/2.1/vocab/unit#{unit}')))


def inspect_sample(self, sample=None):
if sample is None:
sample = self.sample
natoms = self.graph.value(sample, CMSO.hasNumberOfAtoms).toPython()
material = list([k[2] for k in self.graph.triples((sample, CMSO.hasMaterial, None))])[0]
defects = list([k[2] for k in self.graph.triples((material, CMSO.hasDefect, None))])
defect_types = list([self.graph.value(d, RDF.type).toPython() for d in defects])
props = list([k[2].toPython() for k in self.graph.triples((sample, CMSO.hasCalculatedProperty, None))])
propvals = list([self.graph.value(d, CMSO.hasValue).toPython() for d in props])
units = list([self.graph.value(d, CMSO.hasUnit).toPython() for d in props])
st = []
st.append(f'Sample with {natoms} atoms.\n')
if len(defect_types) > 0:
st.append('With defects:\n')
for d in defect_types:
st.append(f'{d}\n')
if len(props) > 0:
st.append('With calculated properties:\n')
for x in range(len(props)):
st.append(f'{props[x]} with value: {propvals[x]} and unit: {units[x]}\n')

return " ".join(st)

def visualize(self, *args, **kwargs):
"""
Expand Down

0 comments on commit bbe9461

Please sign in to comment.