Skip to content

Commit

Permalink
Merge pull request #126 from pyscal/modify_shear
Browse files Browse the repository at this point in the history
Modify shear
  • Loading branch information
srmnitc authored Jun 6, 2024
2 parents 7b30405 + 14872f4 commit 35244b8
Show file tree
Hide file tree
Showing 5 changed files with 3,226 additions and 314 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.8.12
current_version = 0.8.13
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.8.12
version: 0.8.13
45 changes: 42 additions & 3 deletions atomrdf/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,8 @@ def select_by_plane(self, plane, distance, reverse_orientation=False):
def translate(self, translation_vector,
plane=None, distance=None,
reverse_orientation=False,
copy_structure=True):
copy_structure=True,
add_triples=True):

if copy_structure:
sys = self.duplicate()
Expand Down Expand Up @@ -2153,7 +2154,7 @@ def translate(self, translation_vector,
if plane is not None:
sys.remove_selection()

if sys.graph is not None:
if (sys.graph is not None) and add_triples:
sys.add_translation_triples(translation_vector, plane, distance)
if self.sample.toPython() != sys.sample.toPython():
sys.graph.add((sys.sample, PROV.wasDerivedFrom, self.sample))
Expand All @@ -2172,6 +2173,45 @@ def add_translation_triples(self, translation_vector, plane, distance, ):
self.graph.add((t_vector, CMSO.hasComponent_y, Literal(translation_vector[1], datatype=XSD.float),))
self.graph.add((t_vector, CMSO.hasComponent_z, Literal(translation_vector[2], datatype=XSD.float),))

def shear(self, shear_vector,
plane,
distance,
reverse_orientation=False,
copy_structure=True):

if copy_structure:
sys = self.duplicate()
#and add this new structure to the graph
sys.to_graph()
else:
sys = self

if not np.dot(shear_vector, plane) == 0:
raise ValueError("shear vector must be perpendicular to the plane")

sys = sys.translate(shear_vector, plane=plane, distance=distance,
reverse_orientation=reverse_orientation, copy_structure=False,
add_triples=False)

if sys.graph is not None:
sys.add_shear_triples(shear_vector, plane, distance)
if self.sample.toPython() != sys.sample.toPython():
sys.graph.add((sys.sample, PROV.wasDerivedFrom, self.sample))
return sys

def add_shear_triples(self, translation_vector, plane, distance, ):
activity_id = f"operation:{uuid.uuid4()}"
activity = self.graph.create_node(activity_id, UNSAFEASMO.ShearOperation)
self.graph.add((self.sample, PROV.wasGeneratedBy, activity))

#now add specifics
#shear is a vector
t_vector = self.graph.create_node(f"{activity_id}_ShearVector", CMSO.Vector)
self.graph.add((activity, CMSO.hasVector, t_vector))
self.graph.add((t_vector, CMSO.hasComponent_x, Literal(translation_vector[0], datatype=XSD.float),))
self.graph.add((t_vector, CMSO.hasComponent_y, Literal(translation_vector[1], datatype=XSD.float),))
self.graph.add((t_vector, CMSO.hasComponent_z, Literal(translation_vector[2], datatype=XSD.float),))

#if plane is provided, add that as well
if plane is not None:
plane_vector = self.graph.create_node(f"{activity_id}_PlaneVector", CMSO.Vector)
Expand All @@ -2180,4 +2220,3 @@ def add_translation_triples(self, translation_vector, plane, distance, ):
self.graph.add((plane_vector, CMSO.hasComponent_y, Literal(plane[1], datatype=XSD.float),))
self.graph.add((plane_vector, CMSO.hasComponent_z, Literal(plane[2], datatype=XSD.float),))
self.graph.add((activity, UNSAFECMSO.hasDistance, Literal(distance, datatype=XSD.float)))

3,489 changes: 3,181 additions & 308 deletions examples/09_structure_modification.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='atomrdf',
version='0.8.12',
version='0.8.13',
author='Abril Azocar Guzman, Sarath Menon',
author_email='sarath.menon@pyscal.org',
description='Ontology based structural manipulation and quering',
Expand Down

0 comments on commit 35244b8

Please sign in to comment.