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

AtomGroup Dipole and Quadrupole Moment #3841

Closed
jaclark5 opened this issue Sep 21, 2022 · 1 comment · Fixed by #3842
Closed

AtomGroup Dipole and Quadrupole Moment #3841

jaclark5 opened this issue Sep 21, 2022 · 1 comment · Fixed by #3842

Comments

@jaclark5
Copy link
Contributor

jaclark5 commented Sep 21, 2022

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
@orbeckst
Copy link
Member

This looks like a sensible addition.

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

Successfully merging a pull request may close this issue.

2 participants