Skip to content

Instantly share code, notes, and snippets.

@kyleabeauchamp
Created July 2, 2014 22:15
Show Gist options
  • Save kyleabeauchamp/8fc55c0b8fa11e509a62 to your computer and use it in GitHub Desktop.
Save kyleabeauchamp/8fc55c0b8fa11e509a62 to your computer and use it in GitHub Desktop.
calculate dipole moment
import mdtraj as md
import numpy as np
def dipole_moment(traj, charges):
"""Compute the dipole moment of an MDTraj object."""
xyz = md.compute_displacements(traj, np.array([[0, i] for i in range(traj.n_atoms)])).astype('float')
return xyz.transpose(0, 2, 1).dot(charges)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment