Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new creation routines #19

Merged
merged 1 commit into from
Jun 13, 2023
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
2 changes: 1 addition & 1 deletion pyscal_rdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def add_gb(self, gb_dict, name=None):

def add_vacancy(self, concentration, number=None, name=None):
vacancy_01 = BNode(name)
self.add((self.sample, CMSO.hasDefect, vacancy_01))
self.add((self.material, CMSO.hasDefect, vacancy_01))
self.add((vacancy_01, RDF.type, PODO.Vacancy))
self.add((vacancy_01, PODO.hasVacancyConcentration, Literal(concentration, datatype=XSD.float)))
if number is not None:
Expand Down
37 changes: 32 additions & 5 deletions pyscal_rdf/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Network:
def __init__(self):
self.g = nx.DiGraph()

def add(self, sub, pred, obj, dtype=None):
def add(self, sub, pred, obj, dtype=None, pred_prefix="cmso"):
pred = f'{pred_prefix}:{pred}'
self.g.add_node(sub, node_type="object")
self.g.add_node(pred, node_type="property")
if dtype is not None:
Expand Down Expand Up @@ -78,7 +79,30 @@ def __init__(self):
self.add("LatticeAngle", "hasAngle_alpha", "LatticeAngle_alpha", dtype="float")
self.add("LatticeAngle", "hasAngle_beta", "LatticeAngle_beta", dtype="float")
self.add("LatticeAngle", "hasAngle_gamma", "LatticeAngle_gamma", dtype="float")


#add GB properties
self.add("Material", "hasDefect", "Defect", pred_prefix="pldo")
self.add("Defect", "type", "GrainBoundary", pred_prefix="rdf")
self.add("Defect", "type", "TwistBoundary", pred_prefix="rdf")
self.add("Defect", "type", "TiltBoundary", pred_prefix="rdf")
self.add("Defect", "type", "SymmetricTiltBoundary", pred_prefix="rdf")
self.add("Defect", "type", "MixedBoundary", pred_prefix="rdf")
self.add("Defect", "hasSigmaValue", "Sigma", dtype="integer", pred_prefix="pldo")
self.add("Defect", "hasGBPlane", "GBPlane", pred_prefix="pldo")
self.add("GBPlane", "hasMillerIndices", "MillerIndices", dtype="string", pred_prefix="pldo")
self.add("Defect", "hasRotationAxis", "RotationAxis", pred_prefix="pldo")
self.add("RotationAxis", "hasComponentX", "RotationAxis_x", dtype="float", pred_prefix="pldo")
self.add("RotationAxis", "hasComponentY", "RotationAxis_y", dtype="float", pred_prefix="pldo")
self.add("RotationAxis", "hasComponentZ", "RotationAxis_z", dtype="float", pred_prefix="pldo")
self.add("Defect", "hasMisorientationAngle", "MisorientationAngle", pred_prefix="pldo")
self.add("MisorientationAngle", "hasAngle", "Angle", pred_prefix="pldo")

#add vacancy
self.add("Defect", "type", "Vacancy", pred_prefix="rdf")
self.add("Vacancy", "hasVacancyConcentration", "VacancyConcentration", pred_prefix="podo", dtype="float")
self.add("Vacancy", "hasNumberOfVacancy", "NumberOfVacancy", pred_prefix="podo", dtype="integer")


def get_path_from_sample(self, target):
path = self.get_shortest_path(source="Sample", target=target)
triplets = []
Expand All @@ -100,16 +124,19 @@ def formulate_query(self, target, value):
def _formulate_query_path(self, triplets):
query = []
query.append("PREFIX cmso: <https://purls.helmholtz-metadaten.de/cmso/>")
query.append("PREFIX pldo: <https://purls.helmholtz-metadaten.de/pldo/>")
query.append("PREFIX podo: <https://purls.helmholtz-metadaten.de/podo/>")
query.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>")
query.append("SELECT DISTINCT ?sample")
query.append("WHERE {")
for triple in triplets:
query.append(" ?%s cmso:%s ?%s ."%(triple[0].lower(),
query.append(" ?%s %s ?%s ."%(triple[0].lower(),
triple[1],
triple[2].lower()))
return query

def _formulate_filter_expression(self, triplets, value):
value, datatype = self._check_value(value)
def _formulate_filter_expression(self, triplets, value):
value, datatype = self._check_value(value)
last_val = self.g.nodes[triplets[-1][-1]]
last_val_name = triplets[-1][-1].lower()

Expand Down
74 changes: 52 additions & 22 deletions wrap_creation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,95 @@
},
"outputs": [],
"source": [
"from pyscal_rdf import StructureGraph"
"from pyscal_rdf.network import OntologyNetwork"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "9a21e979-8497-4d0e-88f3-4452bab8b85d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"sg = StructureGraph()"
"n = OntologyNetwork()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4f8d7425-24ed-4d62-a562-22cb7be78130",
"metadata": {},
"execution_count": 10,
"id": "1ce29502-3322-41fd-960b-e7d3d792cd74",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Fe\n"
"I3m\n",
"[['Sample', 'cmso:hasMaterial', 'Material'], ['Material', 'cmso:hasStructure', 'CrystalStructure'], ['CrystalStructure', 'cmso:hasSpaceGroup', 'SpaceGroup'], ['SpaceGroup', 'cmso:hasSpaceGroupSymbol', 'SpaceGroupSymbol']]\n",
"['I3m'] single_string\n"
]
},
{
"data": {
"text/plain": [
"'PREFIX cmso: <https://purls.helmholtz-metadaten.de/cmso/> PREFIX pldo: <https://purls.helmholtz-metadaten.de/pldo/> PREFIX podo: <https://purls.helmholtz-metadaten.de/podo/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT ?sample WHERE { ?sample cmso:hasMaterial ?material . ?material cmso:hasStructure ?crystalstructure . ?crystalstructure cmso:hasSpaceGroup ?spacegroup . ?spacegroup cmso:hasSpaceGroupSymbol ?spacegroupsymbol . FILTER (?spacegroupsymbol=\"I3m\"^^xsd:string) }'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sys = sg.create_element(\"Fe\")"
"triplets = n.formulate_query(\"SpaceGroupSymbol\", \"I3m\")\n",
"triplets"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a8915d92-1e95-4612-ac71-fab71e662c86",
"metadata": {
"tags": []
},
"execution_count": 9,
"id": "4f8d7425-24ed-4d62-a562-22cb7be78130",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b82e539b32664ccfbf6a2963d562b1b9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"CytoscapeWidget(cytoscape_layout={'name': 'cola', 'avoidOverlap': True, 'animate': True}, cytoscape_style=[{'s…"
"['PREFIX cmso: <https://purls.helmholtz-metadaten.de/cmso/>',\n",
" 'PREFIX pldo: <https://purls.helmholtz-metadaten.de/pldo/>',\n",
" 'PREFIX podo: <https://purls.helmholtz-metadaten.de/podo/>',\n",
" 'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>',\n",
" 'SELECT DISTINCT ?sample',\n",
" 'WHERE {',\n",
" ' ?sample cmso:hasMaterial ?material .',\n",
" ' ?material cmso:hasStructure ?crystalstructure .',\n",
" ' ?crystalstructure cmso:hasSpaceGroup ?spacegroup .',\n",
" ' ?spacegroup cmso:hasSpaceGroupSymbol ?spacegroupsymbol .']"
]
},
"execution_count": 5,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sg.visualise()"
"query = n._formulate_query_path(triplets)\n",
"query"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8915d92-1e95-4612-ac71-fab71e662c86",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"xx"
]
},
{
Expand Down Expand Up @@ -95,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down