From 7530ee80b69f18fe72d6088ca42766695099a9f3 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 10:36:35 +0200 Subject: [PATCH 1/9] add rotate method --- atomrdf/structure.py | 73 ++++++++++++++++++++++++++++++++++++++++++-- setup.py | 3 +- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index a01da69..8da1748 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -33,6 +33,10 @@ from rdflib import Graph, Literal, Namespace, XSD, RDF, RDFS, BNode, URIRef from atomrdf.namespace import CMSO, PLDO, PODO +from atomman.defect.Dislocation import Dislocation +import atomman as am +import atomman.unitconvert as uc + # read element data file file_location = os.path.dirname(__file__).split("/") file_location = "/".join(file_location[:-1]) @@ -242,9 +246,6 @@ def _make_dislocation( will be generated. If set to "periodicarray", a periodic array of dislocations will be generated. """ - from atomman.defect.Dislocation import Dislocation - import atomman as am - import atomman.unitconvert as uc if structure is not None: # create a structure with the info @@ -1897,3 +1898,69 @@ def add_gb(self, gb_dict): Literal(gb_dict["MisorientationAngle"], datatype=XSD.float), ) ) + + + def rotate(self, rotation_vectors, graph=None, label=None): + + box = am.Box( + avect=self.box[0], + bvect=self.box[1], + cvect=self.box[2], + ) + + atoms = am.Atoms( + atype=self.atoms.types, pos=self.atoms.positions + ) + + element = [val for key, val in self.atoms._type_dict.items()] + + system = am.System( + atoms=atoms, + box=box, + pbc=[True, True, True], + symbols=element, + scale=False, + ) + + #now rotate with atomman + system = system.rotate(rotation_vectors) + + #now convert back and return the system + box = [system.box.avect, + system.box.bvect, + system.box.cvect] + + atom_df = system.atoms_df() + types = [int(x) for x in atom_df.atype.values] + + species = [] + for t in types: + species.append(element[int(t) - 1]) + + positions = np.column_stack( + (atom_df["pos[0]"].values, + atom_df["pos[1]"].values, + atom_df["pos[2]"].values) + ) + + atom_dict = {"positions": positions, "types": types, "species": species} + atom_obj = Atoms() + atom_obj.from_dict(atom_dict) + + output_structure = System() + output_structure.box = box + output_structure.atoms = atom_obj + #output_structure = output_structure.modify.remap_to_box() + if graph is not None: + output_structure.graph = graph + else: + output_structure.graph = self.graph + output_structure.atoms._lattice = self.atoms._lattice + output_structure.atoms._lattice_constant = self.atoms._lattice_constant + output_structure._structure_dict = self._structure_dict + if label is not None: + output_structure.label = label + else: + output_structure.label = self.label + output_structure.to_graph() + return output_structure diff --git a/setup.py b/setup.py index ea692f5..33c6ab7 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,8 @@ url = 'https://pyscal.org', install_requires=['numpy', 'ase', 'rdflib', 'pyyaml', 'graphviz', 'networkx', - 'pyscal3', 'spglib', 'pandas', 'owlready2'], + 'pyscal3', 'spglib', 'pandas', 'owlready2', + 'atomman'], classifiers=[ 'Programming Language :: Python :: 3' ], From 49ca9b5a3136212dbffe4025517ce9e93203d863 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 12:25:33 +0200 Subject: [PATCH 2/9] add triples for rotation --- atomrdf/network/ontology.py | 12 ++++++++++++ atomrdf/structure.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/atomrdf/network/ontology.py b/atomrdf/network/ontology.py index 1fc42aa..46e35d4 100644 --- a/atomrdf/network/ontology.py +++ b/atomrdf/network/ontology.py @@ -1,3 +1,15 @@ +""" +Documentation for the ontology module. + +Updates needed +-------------- +ASMO module + +- Add math operations, see sample.py for the complete list of items - at the moment, 4 cardinal operations, +but maybe more will be needed. + +- StructureOperation: StructureRotation and associated vectors, see structure.py +""" import os from atomrdf.network.network import OntologyNetwork diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 8da1748..8e8f6f8 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -31,7 +31,7 @@ import atomrdf.properties as prp from rdflib import Graph, Literal, Namespace, XSD, RDF, RDFS, BNode, URIRef -from atomrdf.namespace import CMSO, PLDO, PODO +from atomrdf.namespace import CMSO, PLDO, PODO, UNSAFEASMO, PROV from atomman.defect.Dislocation import Dislocation import atomman as am @@ -1963,4 +1963,31 @@ def rotate(self, rotation_vectors, graph=None, label=None): else: output_structure.label = self.label output_structure.to_graph() + if output_structure.graph is not None: + self.add_rotation_triples(rotation_vectors, output_structure.sample) return output_structure + + def add_rotation_triples(self, rotation_vectors, child_sample_id): + activity_id = f"activity:{uuid.uuid4()}" + activity = self.graph.create_node(activity_id, UNSAFEASMO.StructureRotation) + self.graph.add((activity, RDF.type, PROV.Activity)) + self.graph.add((child_sample_id, PROV.wasGeneratedBy, activity)) + self.graph.add((child_sample_id, PROV.wasDerivedFrom, self.sample)) + + rot_vector_01 = self.graph.create_node(f"{activity_id}_RotationVector_1", CMSO.Vector) + self.graph.add((activity, CMSO.hasVector, rot_vector_01)) + self.graph.add((rot_vector_01, CMSO.hasComponent_x, Literal(rotation_vectors[0][0], datatype=XSD.float),)) + self.graph.add((rot_vector_01, CMSO.hasComponent_y, Literal(rotation_vectors[0][1], datatype=XSD.float),)) + self.graph.add((rot_vector_01, CMSO.hasComponent_z, Literal(rotation_vectors[0][2], datatype=XSD.float),)) + + rot_vector_02 = self.graph.create_node(f"{activity_id}_RotationVector_2", CMSO.Vector) + self.graph.add((activity, CMSO.hasVector, rot_vector_02)) + self.graph.add((rot_vector_02, CMSO.hasComponent_x, Literal(rotation_vectors[1][0], datatype=XSD.float),)) + self.graph.add((rot_vector_02, CMSO.hasComponent_y, Literal(rotation_vectors[1][1], datatype=XSD.float),)) + self.graph.add((rot_vector_02, CMSO.hasComponent_z, Literal(rotation_vectors[1][2], datatype=XSD.float),)) + + rot_vector_03 = self.graph.create_node(f"{activity_id}_RotationVector_3", CMSO.Vector) + self.graph.add((activity, CMSO.hasVector, rot_vector_03)) + self.graph.add((rot_vector_03, CMSO.hasComponent_x, Literal(rotation_vectors[2][0], datatype=XSD.float),)) + self.graph.add((rot_vector_03, CMSO.hasComponent_y, Literal(rotation_vectors[2][1], datatype=XSD.float),)) + self.graph.add((rot_vector_03, CMSO.hasComponent_z, Literal(rotation_vectors[2][2], datatype=XSD.float),)) From 3ee4362c4da9720b073af565282c5ccbe14d7eb6 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 12:37:50 +0200 Subject: [PATCH 3/9] fix namespace --- atomrdf/namespace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atomrdf/namespace.py b/atomrdf/namespace.py index 9cefee3..42ee0d3 100644 --- a/atomrdf/namespace.py +++ b/atomrdf/namespace.py @@ -74,5 +74,5 @@ def __init__(self, infile, delimiter="/"): MDO = RDFLibNamespace("https://w3id.org/mdo/calculation/") MATH = RDFLibNamespace("http://purls.helmholtz-metadaten.de/asmo/") -UNSAFECMSO = RDFLibNamespace(os.path.join(file_location, "data/cmso.owl")) -UNSAFEASMO = RDFLibNamespace(os.path.join(file_location, "data/asmo.owl")) +UNSAFECMSO = RDFLibNamespace("http://purls.helmholtz-metadaten.de/cmso/") +UNSAFEASMO = RDFLibNamespace("http://purls.helmholtz-metadaten.de/asmo/") From 15f6b4dce4e9f11a0f6f1aeb87e5d362ca3e86d4 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 15:34:03 +0200 Subject: [PATCH 4/9] add rotate example --- examples/09_structure_modification.ipynb | 2471 ++++++++++++++++++++++ 1 file changed, 2471 insertions(+) create mode 100644 examples/09_structure_modification.ipynb diff --git a/examples/09_structure_modification.ipynb b/examples/09_structure_modification.ipynb new file mode 100644 index 0000000..3d2ddbf --- /dev/null +++ b/examples/09_structure_modification.ipynb @@ -0,0 +1,2471 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Rotation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b9f09d8bbc5a4f9eb2a89f1420f7711c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from atomrdf import System, KnowledgeGraph" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "kg = KnowledgeGraph()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "s = System.create.element.Al(repetitions=(1,1,1), graph=kg)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 4.05, + 4.05, + 0, + 0 + ], + "y": [ + 0, + 0, + 4.05, + 4.05, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 4.05, + 4.05, + 0, + 0 + ], + "y": [ + 0, + 0, + 4.05, + 4.05, + 0 + ], + "z": [ + 4.05, + 4.05, + 4.05, + 4.05, + 4.05 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 4.05, + 4.05, + 0, + 0 + ], + "y": [ + 0, + 0, + 0, + 0, + 0 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 4.05, + 4.05, + 0, + 0 + ], + "y": [ + 4.05, + 4.05, + 4.05, + 4.05, + 4.05 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 0, + 0, + 0, + 0 + ], + "y": [ + 0, + 4.05, + 4.05, + 0, + 0 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 4.05, + 4.05, + 4.05, + 4.05, + 4.05 + ], + "y": [ + 0, + 4.05, + 4.05, + 0, + 0 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "marker": { + "color": "#33a02c", + "line": { + "color": "#455A64", + "width": 0.5 + }, + "opacity": 1, + "size": 10, + "sizemode": "diameter", + "sizeref": 750 + }, + "mode": "markers", + "opacity": 1, + "type": "scatter3d", + "x": [ + 0, + 2.025, + 0, + 2.025 + ], + "y": [ + 0, + 0, + 2.025, + 2.025 + ], + "z": [ + 0, + 2.025, + 2.025, + 0 + ] + } + ], + "layout": { + "margin": { + "b": 10, + "l": 10, + "r": 10, + "t": 10 + }, + "scene": { + "aspectmode": "data", + "xaxis": { + "showbackground": false, + "showticklabels": false, + "title": { + "text": "" + }, + "zerolinecolor": "#455A64" + }, + "yaxis": { + "showbackground": false, + "showticklabels": false, + "title": { + "text": "" + }, + "zerolinecolor": "#455A64" + }, + "zaxis": { + "showbackground": false, + "showticklabels": false, + "title": { + "text": "" + }, + "zerolinecolor": "#455A64" + } + }, + "showlegend": false, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "width": 700 + } + }, + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "s.show.all()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "rotation_vectors = [[ 1, 1, 0],\n", + " [-1, 1, 0],\n", + " [ 0, 0, 1]]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "srot = s.rotate(rotation_vectors)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 5.727564927611035, + 5.727564927611035, + 0, + 0 + ], + "y": [ + 0, + 0, + 5.727564927611035, + 5.727564927611035, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 5.727564927611035, + 5.727564927611035, + 0, + 0 + ], + "y": [ + 0, + 0, + 5.727564927611035, + 5.727564927611035, + 0 + ], + "z": [ + 4.05, + 4.05, + 4.05, + 4.05, + 4.05 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 5.727564927611035, + 5.727564927611035, + 0, + 0 + ], + "y": [ + 0, + 0, + 0, + 0, + 0 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 5.727564927611035, + 5.727564927611035, + 0, + 0 + ], + "y": [ + 5.727564927611035, + 5.727564927611035, + 5.727564927611035, + 5.727564927611035, + 5.727564927611035 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 0, + 0, + 0, + 0, + 0 + ], + "y": [ + 0, + 5.727564927611035, + 5.727564927611035, + 0, + 0 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "line": { + "color": "#263238", + "width": 2 + }, + "mode": "lines", + "name": "lines", + "showlegend": false, + "type": "scatter3d", + "x": [ + 5.727564927611035, + 5.727564927611035, + 5.727564927611035, + 5.727564927611035, + 5.727564927611035 + ], + "y": [ + 0, + 5.727564927611035, + 5.727564927611035, + 0, + 0 + ], + "z": [ + 0, + 0, + 4.05, + 4.05, + 0 + ] + }, + { + "marker": { + "color": "#33a02c", + "line": { + "color": "#455A64", + "width": 0.5 + }, + "opacity": 1, + "size": 10, + "sizemode": "diameter", + "sizeref": 750 + }, + "mode": "markers", + "opacity": 1, + "type": "scatter3d", + "x": [ + 5.727564927611034, + 0, + 1.4318912319027586, + 2.8637824638055176, + 1.4318912319027586, + 2.8637824638055176, + 4.295673695708277, + 4.295673695708277 + ], + "y": [ + 2.8637824638055176, + 0, + 1.4318912319027586, + 5.727564927611034, + 4.295673695708277, + 2.8637824638055176, + 1.4318912319027586, + 4.295673695708277 + ], + "z": [ + 4.049999999999999, + 4.049999999999999, + 2.0249999999999995, + 4.049999999999999, + 2.0249999999999995, + 4.049999999999999, + 2.0249999999999995, + 2.0249999999999995 + ] + } + ], + "layout": { + "margin": { + "b": 10, + "l": 10, + "r": 10, + "t": 10 + }, + "scene": { + "aspectmode": "data", + "xaxis": { + "showbackground": false, + "showticklabels": false, + "title": { + "text": "" + }, + "zerolinecolor": "#455A64" + }, + "yaxis": { + "showbackground": false, + "showticklabels": false, + "title": { + "text": "" + }, + "zerolinecolor": "#455A64" + }, + "zaxis": { + "showbackground": false, + "showticklabels": false, + "title": { + "text": "" + }, + "zerolinecolor": "#455A64" + } + }, + "showlegend": false, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "width": 700 + } + }, + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "srot.show.all()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "activity_f4817a59-7dc7-4d15-8b89-3fc13abf447e\n", + "\n", + "activity_f4817a59-7dc7-4d15-8b89-3fc13abf447e\n", + "\n", + "\n", + "\n", + "asmo.StructureRotation\n", + "\n", + "asmo.StructureRotation\n", + "\n", + "\n", + "\n", + "activity_f4817a59-7dc7-4d15-8b89-3fc13abf447e->asmo.StructureRotation\n", + "\n", + "\n", + "type\n", + "\n", + "\n", + "\n", + "Activity\n", + "\n", + "Activity\n", + "\n", + "\n", + "\n", + "activity_f4817a59-7dc7-4d15-8b89-3fc13abf447e->Activity\n", + "\n", + "\n", + "type\n", + "\n", + "\n", + "\n", + "sample_bd69db38-80b6-4f4c-ba3e-bef9c5d583bd\n", + "\n", + "sample_bd69db38-80b6-4f4c-ba3e-bef9c5d583bd\n", + "\n", + "\n", + "\n", + "sample_bd69db38-80b6-4f4c-ba3e-bef9c5d583bd->activity_f4817a59-7dc7-4d15-8b89-3fc13abf447e\n", + "\n", + "\n", + "wasGeneratedBy\n", + "\n", + "\n", + "\n", + "sample_a1831aab-8b65-405d-848d-7f5d19dacb18\n", + "\n", + "sample_a1831aab-8b65-405d-848d-7f5d19dacb18\n", + "\n", + "\n", + "\n", + "sample_bd69db38-80b6-4f4c-ba3e-bef9c5d583bd->sample_a1831aab-8b65-405d-848d-7f5d19dacb18\n", + "\n", + "\n", + "wasDerivedFrom\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kg.visualise( workflow_view=True, layout='dot')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "workflow-rdf", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From bfe012ef01a7b7292890886daf37f7fd52c0f98f Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 15:39:43 +0200 Subject: [PATCH 5/9] add rotation test --- tests/test_rotate.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/test_rotate.py diff --git a/tests/test_rotate.py b/tests/test_rotate.py new file mode 100644 index 0000000..f319e24 --- /dev/null +++ b/tests/test_rotate.py @@ -0,0 +1,17 @@ +import pytest +import os +from atomrdf import KnowledgeGraph, System + +def test_rotate(): + kg = KnowledgeGraph() + s = System.create.element.Al(repetitions=(1,1,1), graph=kg) + rotation_vectors = [[ 1, 1, 0], + [-1, 1, 0], + [ 0, 0, 1]] + srot = s.rotate(rotation_vectors) + assert np.abs(srot.box[0][0] - 5.728) < 1E-3 + assert np.abs(srot.box[1][1] - 5.728) < 1E-3 + assert np.abs(srot.box[2][2] - 4.050) < 1E-3 + assert srot.natoms == 8 + + \ No newline at end of file From 6ae90e1f2891da50b57924eddb00d77899f46357 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 15:40:47 +0200 Subject: [PATCH 6/9] update tests --- tests/test_rotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_rotate.py b/tests/test_rotate.py index f319e24..5a6a320 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -1,6 +1,7 @@ import pytest import os from atomrdf import KnowledgeGraph, System +import numpy as np def test_rotate(): kg = KnowledgeGraph() @@ -14,4 +15,3 @@ def test_rotate(): assert np.abs(srot.box[2][2] - 4.050) < 1E-3 assert srot.natoms == 8 - \ No newline at end of file From cbcb29e2b39c73ed3e6111c1b2ccb2d76a5c161f Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 16:29:53 +0200 Subject: [PATCH 7/9] add first draft of shear --- atomrdf/structure.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 8e8f6f8..3749b45 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -1991,3 +1991,10 @@ def add_rotation_triples(self, rotation_vectors, child_sample_id): self.graph.add((rot_vector_03, CMSO.hasComponent_x, Literal(rotation_vectors[2][0], datatype=XSD.float),)) self.graph.add((rot_vector_03, CMSO.hasComponent_y, Literal(rotation_vectors[2][1], datatype=XSD.float),)) self.graph.add((rot_vector_03, CMSO.hasComponent_z, Literal(rotation_vectors[2][2], datatype=XSD.float),)) + + def shear_system(self, shear): + if not len(shear) == 3: + raise ValueError("shear vector must be of length 3") + for x in range(len(self.atoms['positions'])): + if self.atoms['condition'][x]: + self.atoms['positions'][x] += np.array(shear) \ No newline at end of file From f8d8c11ee029924455cf2bdc2dc662b5071ff425 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 21:21:55 +0200 Subject: [PATCH 8/9] add more shear methods --- atomrdf/structure.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 3749b45..5268af7 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -1901,7 +1901,6 @@ def add_gb(self, gb_dict): def rotate(self, rotation_vectors, graph=None, label=None): - box = am.Box( avect=self.box[0], bvect=self.box[1], @@ -1992,9 +1991,39 @@ def add_rotation_triples(self, rotation_vectors, child_sample_id): self.graph.add((rot_vector_03, CMSO.hasComponent_y, Literal(rotation_vectors[2][1], datatype=XSD.float),)) self.graph.add((rot_vector_03, CMSO.hasComponent_z, Literal(rotation_vectors[2][2], datatype=XSD.float),)) - def shear_system(self, shear): + def _select_by_plane(self, plane, distance, reverse_orientation=False): + plane_norm = np.linalg.norm(plane) + selection = [] + for pos in self.atoms.positions: + dist = np.dot(plane, pos)/plane_norm + + if dist < distance: + selection.append(True) + else: + selection.append(False) + if reverse_orientation: + selection = np.invert(selection) + return selection + + def select_by_plane(self, plane, distance, reverse_orientation=False): + selection = self._select_by_plane(plane, distance, + reverse_orientation=reverse_orientation) + self.apply_selection(condition=selection) + + def shear_system(self, shear, plane=None, distance=None, reverse_orientation=False): + if plane is not None: + if distance is None: + raise ValueError('distance needs to be provided') + + if plane is not None: + self.select_by_plane(plane, distance, reverse_orientation=reverse_orientation) + if not len(shear) == 3: raise ValueError("shear vector must be of length 3") + for x in range(len(self.atoms['positions'])): if self.atoms['condition'][x]: - self.atoms['positions'][x] += np.array(shear) \ No newline at end of file + self.atoms['positions'][x] += np.array(shear) + + if plane is not None: + self.remove_selection() \ No newline at end of file From 6643ff20f24f6a9dbda447b5bb7013b89bf40e08 Mon Sep 17 00:00:00 2001 From: Sarath Date: Thu, 23 May 2024 22:54:23 +0200 Subject: [PATCH 9/9] add shear method --- atomrdf/structure.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/atomrdf/structure.py b/atomrdf/structure.py index 5268af7..0ca136d 100644 --- a/atomrdf/structure.py +++ b/atomrdf/structure.py @@ -2026,4 +2026,7 @@ def shear_system(self, shear, plane=None, distance=None, reverse_orientation=Fal self.atoms['positions'][x] += np.array(shear) if plane is not None: - self.remove_selection() \ No newline at end of file + self.remove_selection() + + def add_shear_triples(self): + pass \ No newline at end of file