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

Trajectory operators #16

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Trajectory operators #16

wants to merge 7 commits into from

Conversation

henry-isaacson
Copy link
Collaborator

@henry-isaacson henry-isaacson commented May 3, 2024

Adds the following metrics:

  • rmsd
  • gyration_tensor
  • radius_of_gyration
  • center_of_mass
  • bond_angles
  • dihedrals
  • phi_torsions
  • psi_torsions
  • chi1_torsions
  • chi3_torsions
  • chi4_torsions
  • omega_torsions
  • J3_HN_C
  • J3_HN_CB
  • J3_HN_HA
  • chemical_shifts_shiftx2
  • chemical_shifts_ppm
  • chemical_shifts_spartaplus
  • dipole_moments
  • static_dielectric
  • isothermal_compressability_kappa_T
  • thermal_expansion_alpha_P
  • density
  • shrake_rupley

@0x00b1 0x00b1 changed the title Metrics Trajectory operators May 6, 2024
import torch


def compute_center_of_mass(traj):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

center_of_mass

import torch


def compute_center_of_mass(traj):
Copy link
Collaborator

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.

import torch


def compute_center_of_mass(traj):
Copy link
Collaborator

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.


Returns
-------
com : torch.Tensor, shape=(n_frames, 3)
Copy link
Collaborator

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.


Parameters
----------
traj : Trajectory
Copy link
Collaborator

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.



def compute_center_of_mass(traj):
"""Compute the center of mass for each frame.
Copy link
Collaborator

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).

com = torch.empty((traj.n_frames, 3))

masses = torch.tensor([a.element.mass for a in traj.top.atoms])
masses /= masses.sum()
Copy link
Collaborator

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.

com = torch.empty((traj.n_frames, 3))

masses = torch.tensor([a.element.mass for a in traj.top.atoms])
masses /= masses.sum()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use methods.

Coordinates of the center of mass for each frame
"""

com = torch.empty((traj.n_frames, 3))
Copy link
Collaborator

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.


com = torch.empty((traj.n_frames, 3))

masses = torch.tensor([a.element.mass for a in traj.top.atoms])
Copy link
Collaborator

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?

xyz = traj.xyz

for i, x in enumerate(xyz):
com[i, :] = torch.tensordot(masses, x.double().t(), dims=0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tensordot?

rmsd_result[i] = torch.sqrt(
torch.sum((traj1[i] - traj2[i]) ** 2) / traj1.shape[1])

return rmsd_result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline

@@ -0,0 +1,60 @@
import torch
from scipy.spatial.transform import Rotation as R
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants