Electron density analysis

Dipole moment of a molecule

Compute the dipole moment of an isolated molecule from the electron density and the valence charges of the pseudo-atoms.

Category
Electron density analysis
APIs used
calc.rhocalc.aofdft.atomic_data.species().zvalkin_model="Molecule26"
Script
dipole_moment.py

The dipole moment is the sum of the contributions of the ions (pseudo-atom cores) and of the electrons.

μ=∑AZARA−∫rρ(r)dr

Here ZA is the valence charge of the pseudopotential, RA the atomic position and ρ the electron density. Propyne (CH3–C≡CH) is used as the example.

dipole_moment.pyDownload
"""
Advance/OF-DFT example: dipole moment of a molecule from the electron density.

    mu = sum_A Z_A R_A - integral r rho(r) dr

Z_A is the valence charge of the pseudo-atom A.

Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""

import numpy as np
from ase.build import molecule
from ase.units import Bohr, Debye

from aofdft.calculator import AOFDFTCalculator

VPS_DIR = "path/to/DFT_DATA19_AS/VPS"  # edit these two paths for your environment
PAO_DIR = "path/to/DFT_DATA19_AS/PAO"

# isolated molecule at the centre of a box: propyne (CH3-CCH), with the molecular axis along z
atoms = molecule("C3H4_C3v")
atoms.center(vacuum=4.0)

atoms.calc = AOFDFTCalculator(
    console      = False,
    logging_file = "propyne.log",
    kin_type     = "AS26",
    kin_model    = "Molecule26",
    vps_dir      = VPS_DIR,
    pao_dir      = PAO_DIR,
    scf_style    = "molecule",
)
atoms.get_potential_energy()

calc    = atoms.calc
density = calc.rho[0].detach().cpu().numpy()  # e/Bohr^3

# Cartesian coordinates of the grid points (Angstrom)
grids = [np.arange(n) / n for n in density.shape]
frac  = np.stack(np.meshgrid(*grids, indexing="ij"), axis=-1)
r     = frac @ atoms.cell.array

dv = atoms.get_volume() / Bohr**3 / density.size  # volume of a grid cell (Bohr^3)

# valence charge of each pseudo-atom
species = calc.aofdft.atomic_data.species
zval    = np.array([float(species(symbol).zval) for symbol in atoms.get_chemical_symbols()])

n_elec     = density.sum() * dv
mu_ion     = (zval[:, None] * atoms.positions).sum(axis=0)
mu_elec    = -(density[..., None] * r).sum(axis=(0, 1, 2)) * dv
mu         = mu_ion + mu_elec  # e * Angstrom

print(f"Valence charges      : {dict(zip(atoms.get_chemical_symbols(), zval.tolist()))}")
print(f"Number of electrons  : {n_elec:.6f}")
print(f"Dipole vector (Debye): {np.round(mu / Debye, 3)}")
print(f"Dipole moment        : {np.linalg.norm(mu) / Debye:.3f} Debye")

Example output

Results with v1.0.0 (Molecule26).

text
Valence charges      : {'C': 4.0, 'H': 1.0}
Number of electrons  : 16.000000
Dipole vector (Debye): [-0.001  0.005 -0.886]
Dipole moment        : 0.886 Debye

The dipole moment is 0.886 Debye, and the vector lies along the molecular axis (z). In this structure the methyl group is on the −z side, so the methyl end is positive and the acetylenic end is negative.

Notes

  • For molecules, use kin_model="Molecule26" and scf_style="molecule".
  • The valence charge of a pseudo-atom is available as calc.aofdft.atomic_data.species(symbol).zval.
  • The density is defined on a periodic grid. Place the molecule at the centre of the cell (atoms.center) with enough vacuum for the density to vanish at the cell boundary.
  • The dipole moment of a neutral molecule does not depend on the choice of origin.
  • The density is in Bohr⁻³, so the integration uses the grid-cell volume in Bohr³. ase.units.Debye converts e·Angstrom to Debye.
  • molecule("C3H4_C3v") is the structure of propyne registered in ASE, with the molecular axis along z.

The Molecule26 model contains non-local terms, so an SCF step takes longer than with Crystal26. Using a GPU is recommended.

The dipole moments of molecules with lone pairs (H2O, NH3, ...) are not reproduced by Molecule26 of v1.0, nor by Molecule26-large. Improving the kinetic energy functional is part of the development roadmap, and there is room for improvement in future updates of the model.