-
Notifications
You must be signed in to change notification settings - Fork 81
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
Trim coordinate_transform.py, new features for spin method #1054
Merged
daico007
merged 6 commits into
mosdef-hub:main
from
daico007:improve_compound_coord_transform
Nov 2, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
359697d
Trim coordinate_transform.py, new features for spin method
daico007 ad20777
adjust tests
daico007 4c6aff8
Merge branch 'main' into improve_compound_coord_transform
daico007 e028950
add unit test
daico007 5658ef1
Merge branch 'main' into improve_compound_coord_transform
daico007 9bf4c3b
Merge branch 'main' into improve_compound_coord_transform
daico007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2416,7 +2416,7 @@ def rotate(self, theta, around): | |
new_positions = _rotate(self.xyz_with_ports, theta, around) | ||
self.xyz_with_ports = new_positions | ||
|
||
def spin(self, theta, around): | ||
def spin(self, theta, around, anchor=None): | ||
"""Rotate Compound in place around an arbitrary vector. | ||
|
||
Parameters | ||
|
@@ -2425,12 +2425,23 @@ def spin(self, theta, around): | |
The angle by which to rotate the Compound, in radians. | ||
around : np.ndarray, shape=(3,), dtype=float | ||
The axis about which to spin the Compound. | ||
anchor : mb.Compound, optional, default=None (self) | ||
Anchor compound/particle to perform spinning. | ||
If the anchor is not a particle, the spin will be | ||
around the center of the anchor Compound. | ||
""" | ||
around = np.asarray(around).reshape(3) | ||
center_pos = self.center | ||
self.translate(-center_pos) | ||
|
||
if anchor: | ||
msg = f"{anchor} is not part of {self}." | ||
assert anchor in self.successors(), msg | ||
else: | ||
anchor = self | ||
anchor_pos = anchor.center | ||
|
||
self.translate(-anchor_pos) | ||
self.rotate(theta, around) | ||
self.translate(center_pos) | ||
self.translate(anchor_pos) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is smart. |
||
|
||
def rotate_dihedral(self, bond, phi): | ||
"""Rotate a dihedral about a central bond. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you pass it a compound, it should spin around the center of mass of that compound. This way you don't have to specify particle/compound, since it'll still use the center of mass of a single bead compound (the synonym for a particle in mbuild). Also, what does the "(self)" mean? I'm inferring that this means the value of None really will use self. Not sure if this is standard to put in the function definition, but maybe could add a bit of uncertainty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if None is provided for the anchor, the Compound will rotate around its own self.pos, which will be its center of mass, this option is for when you want rotate a compound but around one particular particle instead the center of mass (e.g., rotate a chain attached to a surface, but you want the particle attached to the surface to be fixed, or else that bond will be wonky)