File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff 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( ) ,
Original file line number Diff line number Diff 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 ( )
You canβt perform that action at this time.
0 commit comments