mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

AtomGroup Dipole and Quadrupole Moment

Open jaclark5 opened this issue 3 years ago • 1 comments

Is your feature request related to a problem?

It would be convenient to obtain the dipole or quadrupole moment of a group or compounds within a group.

Describe the solution you'd like

import MDAnalysis as mda
u = mda.Universe("peptide.data") # From LAMMPS example data.peptide
peptide = u.select_atoms("not type 13 and not type 14")
water = u.select_atoms("type 13 or type 14")tmp_dpl = peptide.dipole_moment()
print("Peptide Dipole", np.sqrt(np.sum(tmp_dpl**2)), tmp_dpl)
print("Peptide Quadrupole", peptide.quadrupole_moment())
print("Peptide Dipole", np.sqrt(np.sum(tmp_dpl**2))/0.2081943, "Debye")
print("Peptide Quadrupole", peptide.quadrupole_moment()/0.2081943, "Debye*A")

> Peptide Dipole 2.2182727658215424 [-0.10292139 -2.21468175 -0.07297934]
> Peptide Quadrupole 18.4693874744808
> Peptide Dipole 10.654819876536209 Debye
> Peptide Quadrupole 88.7122628932723 Debye*A

water = u.select_atoms("type 13 or type 14")
water = water.residues[:5]
tmp_dpl = water.dipole_moment(compound="residues", unwrap=True)
tmp_qud = water.quadrupole_moment(compound="residues", unwrap=True)
print("Water Dipole", np.sqrt(np.sum(tmp_dpl**2, axis=1))/0.2081943, "Debye")
print("Water Quadrupole", tmp_qud/0.2081943, "Debye*A")

> Water Dipole [2.34705817 2.34703033 2.34697288 2.34697048 2.34709711] Debye
> Water Quadrupole [1.98943791 1.9893828  1.98939536 1.98937966 1.98941399] Debye*A

ag = peptide + mda.AtomGroup(water.atoms.ix, u)
tmp_dpl = ag.dipole_moment(compound="residues", unwrap=True)
tmp_qud = ag.quadrupole_moment(compound="residues", unwrap=True)
print("Dipole Moments:", np.sqrt(np.sum(tmp_dpl**2, axis=1))/0.2081943, "Debye")
print("Quad Moments:", tmp_qud/0.2081943, "Debye*A")

> Dipole Moments: [10.65481988  2.34705817  2.34703033  2.34697288  2.34697048  2.34709711] Debye
> Quad Moments: [88.71226289  1.98943791  1.9893828   1.98939536  1.98937966  1.98941399] Debye*A

jaclark5 avatar Sep 21 '22 13:09 jaclark5

This looks like a sensible addition.

orbeckst avatar Sep 22 '22 16:09 orbeckst