Skip to content

Commit 5802eb9

Browse files
author
mlund
committed
Print molecular dipole moment
1 parent 960e9fc commit 5802eb9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

β€Žsrc/main.rsβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ fn do_scan(cmd: &Commands) -> Result<()> {
182182
ref_a.net_charge(),
183183
ref_b.net_charge(),
184184
);
185+
186+
const ELECTRON_ANGSTROM_TO_DEBYE: f64 = 4.80320425;
187+
info! {
188+
"Molecular dipole moments: [{:.2} D, {:.2} D]",
189+
ref_a.dipole_moment().norm() * ELECTRON_ANGSTROM_TO_DEBYE,
190+
ref_b.dipole_moment().norm() * ELECTRON_ANGSTROM_TO_DEBYE,
191+
};
192+
185193
info!(
186194
"Molecular masses (g/mol): [{:.2}e, {:.2}e]",
187195
ref_a.total_mass(),

β€Žsrc/structure.rsβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ impl Structure {
152152
self.charges.iter().sum()
153153
}
154154

155+
/// Molecular dipole moment of the structure with respect to the mass center
156+
///
157+
/// The dipole moment is calculated as
158+
/// π’Ž = βˆ‘ π’“α΅’π‘žα΅’ where 𝒓ᡒ = 𝒑ᡒ - π‘ͺ and π‘ͺ is the mass center.
159+
/// Note that if the molecule is not neutral, the dipole moment depends on the
160+
/// choice of origin, here the mass center.
161+
pub fn dipole_moment(&self) -> Vector3 {
162+
let center = self.mass_center();
163+
self.pos
164+
.iter()
165+
.zip(&self.charges)
166+
.map(|(pos, charge)| (pos - center).scale(*charge))
167+
.fold(Vector3::zeros(), |sum, i| sum + i)
168+
}
169+
155170
/// Total mass of the structure
156171
pub fn total_mass(&self) -> f64 {
157172
self.masses.iter().sum()

0 commit comments

Comments
Β (0)