-
Notifications
You must be signed in to change notification settings - Fork 5
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
Trajectory operators #16
base: main
Are you sure you want to change the base?
Conversation
src/beignet/center_of_mass.py
Outdated
import torch | ||
|
||
|
||
def compute_center_of_mass(traj): |
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.
center_of_mass
src/beignet/center_of_mass.py
Outdated
import torch | ||
|
||
|
||
def compute_center_of_mass(traj): |
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.
Add type annotations, e.g.,
center_of_mass(input: Tensor) -> Tensor
.
src/beignet/center_of_mass.py
Outdated
import torch | ||
|
||
|
||
def compute_center_of_mass(traj): |
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.
Rename traj
to input
to match PyTorch style.
src/beignet/center_of_mass.py
Outdated
|
||
Returns | ||
------- | ||
com : torch.Tensor, shape=(n_frames, 3) |
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.
Rename com
to output
to match PyTorch style.
src/beignet/center_of_mass.py
Outdated
|
||
Parameters | ||
---------- | ||
traj : Trajectory |
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.
Trajectory
is not a type.
src/beignet/center_of_mass.py
Outdated
|
||
|
||
def compute_center_of_mass(traj): | ||
"""Compute the center of mass for each frame. |
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.
Add the raw string prefix (r
).
src/beignet/center_of_mass.py
Outdated
com = torch.empty((traj.n_frames, 3)) | ||
|
||
masses = torch.tensor([a.element.mass for a in traj.top.atoms]) | ||
masses /= masses.sum() |
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.
Do not use assignment ops.
src/beignet/center_of_mass.py
Outdated
com = torch.empty((traj.n_frames, 3)) | ||
|
||
masses = torch.tensor([a.element.mass for a in traj.top.atoms]) | ||
masses /= masses.sum() |
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.
Do not use methods.
src/beignet/center_of_mass.py
Outdated
Coordinates of the center of mass for each frame | ||
""" | ||
|
||
com = torch.empty((traj.n_frames, 3)) |
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.
This should be zeros
. empty
is random.
src/beignet/center_of_mass.py
Outdated
|
||
com = torch.empty((traj.n_frames, 3)) | ||
|
||
masses = torch.tensor([a.element.mass for a in traj.top.atoms]) |
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.
What are a.element.mass
and traj.top.atoms
?
src/beignet/center_of_mass.py
Outdated
xyz = traj.xyz | ||
|
||
for i, x in enumerate(xyz): | ||
com[i, :] = torch.tensordot(masses, x.double().t(), dims=0) |
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.
tensordot
?
src/beignet/rmsd.py
Outdated
rmsd_result[i] = torch.sqrt( | ||
torch.sum((traj1[i] - traj2[i]) ** 2) / traj1.shape[1]) | ||
|
||
return rmsd_result |
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.
Add newline
src/beignet/rmsd.py
Outdated
@@ -0,0 +1,60 @@ | |||
import torch | |||
from scipy.spatial.transform import Rotation as R |
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.
Use one of our rotation operators.
Adds the following metrics: