Skip to main content

pymultibinit

A Python package for building and evaluating MULTIBINIT effective-potential models of lattice dynamics. It provides a native pure-Python implementation of the harmonic (IFC) and anharmonic effective potential, plus an optional CFFI backend that wraps the ABINIT Fortran library for bit-exact parity.

Features

  • Pure-Python effective potential (pyeffpot): reads a DDB file directly, builds the supercell IFCs with Fourier interpolation, dipole-dipole Ewald correction, acoustic sum rule, and optional anharmonic XML coefficients. No Fortran compilation required.
  • ASE calculator interface: energy, forces, and stress through the standard atoms.get_potential_energy() / get_forces() / get_stress() API.
  • CFFI backend (optional): wraps libabinit.so for bit-exact agreement with the standalone MULTIBINIT binary.
  • Energy/force/stress decomposition into dipdip, harmonic, anharmonic terms.
  • DDB → phonopy export without running ABINIT.
  • Model training: pure-Python least-squares fitting or binary-based training.

Installation

pip install pymultibinit
# or from source:
pip install -e .

That's it for the pure-Python backend. No Fortran compilation needed.

Optional: CFFI backend (libabinit)

The CFFI backend wraps the ABINIT shared library. It is required only for from_abi, from_abi_spawned, from_params, and from_config_file. from_pyeffpot works without it.

# 1. Build ABINIT with shared library
cd abinit
rm -rf build && mkdir build && cd build
CC=mpicc FC=mpif90 cmake -DBUILD_SHARED_LIBS=ON ..
make -j8

# 2. Set library path (choose one):
export LIBABINIT_PATH=/path/to/abinit/build/src/98_main/libabinit.so
# or:
export LD_LIBRARY_PATH=/path/to/abinit/build/src/98_main:$LD_LIBRARY_PATH

Optional dependencies

pip install pymultibinit[jax]          # JAX acceleration for anharmonic evaluation
pip install pymultibinit[longrangefy]  # optional downstream consistency checks

The longrangefy extra is one-way: pymultibinit may import that package in pymultibinit.longrangefy_parity, never the reverse. Importing and using the rest of pymultibinit does not require it.

Quick Start

from pymultibinit import MultibinitCalculator
from ase import Atoms
from ase.optimize import BFGS

# Create calculator from DDB (pure Python, no libabinit needed)
calc = MultibinitCalculator.from_pyeffpot(
    ddb_file="system.DDB",
    ncell=(2, 2, 2),     # supercell size
    dipdip=True,         # dipole-dipole long-range correction
    asr=True,            # acoustic sum rule
)

# Get the reference supercell structure
atoms = calc.get_reference_atoms()

# Evaluate energy, forces, stress (eV, eV/Å, eV/ų)
atoms.calc = calc
print(atoms.get_potential_energy())
print(atoms.get_forces())
print(atoms.get_stress())

# Optimize
opt = BFGS(atoms)
opt.run(fmax=0.01)

calc.close()

Calculator Backends

Reads the DDB directly, builds IFCs with Fourier interpolation, applies the dipole-dipole Ewald correction, and evaluates energy/forces/stress in Python. No Fortran library required.

calc = MultibinitCalculator.from_pyeffpot(
    ddb_file="system.DDB",
    xml_file="coeffs.xml",   # optional anharmonic coefficients
    ncell=(2, 2, 2),
    dipdip=True,
    asr=True,
)

CFFI (Fortran, optional)

Wraps libabinit.so for bit-exact parity with the standalone MULTIBINIT binary. Requires the ABINIT shared library.

# From .abi input file
calc = MultibinitCalculator.from_abi("input.abi", lib_path="libabinit.so")

# Spawned (isolated child process, safe for repeated initialization)
calc = MultibinitCalculator.from_abi_spawned("input.abi", lib_path="libabinit.so")

# From direct parameters
calc = MultibinitCalculator.from_params(
    ddb_file="system_DDB",
    ncell=(2, 2, 2),
    ngqpt=(4, 4, 4),
)

from_abi_spawned runs the libabinit initialization in a child process, avoiding the process-global state limitation where a second from_abi call crashes after the first calculator is closed.

Dipole-Dipole (dipdip) Correction

When dipdip=True, the long-range dipole-dipole contribution is subtracted from the DDB dynamical matrix in q-space, Fourier-interpolated, then re-added in real space via anisotropic Ewald summation (ewald9).

  • ncell == ngqpt: subtraction and re-addition cancel exactly (energy-neutral).
  • ncell > ngqpt: extends the dipdip to longer range, correctly modifying forces and energy.
  • ncell < ngqpt: dipdip has no additional effect (the q-grid already resolves the supercell).

The Python Ewald implementation matches the Fortran ewald9 kernel: reciprocal-space term with dielectric-weighted norm $K_\mu \varepsilon_{\mu\nu} K_\nu$, real-space term with anisotropic screened distance, and self-interaction correction.

Downstream longrangefy consistency (optional)

pymultibinit.longrangefy_parity compares the q-grid Fourier builder with the independent longrangefy matched correction. It aligns units, atom/image order, phase, Wigner-Seitz weights, ASR policy and the conducting Gamma boundary, then reports component-level IFC and energy/force differences. It does not declare a parity tolerance: inspect the reported values against your own predeclared bound.

from pymultibinit.longrangefy_parity import compare_matched_correction

report = compare_matched_correction(
    unitcell,              # pyeffpot UnitcellData with qpoints/dynmat
    matching_reps=(2, 2, 2),
    target_reps=(2, 2, 4),
    accept_measured_symmetry_violation=True,  # records the measured value
)
print(report.as_dict()["matrices"])

By default both representations are built from the same downstream-accepted Hermitian-projected matching-grid samples (use_accepted_phi0=True). Set it to False to compare raw upstream samples. The unit-constant difference (~9e-9 relative) and the recorded projection scale are reported as measured floors, not as parity tolerances. Non-orthogonal cells with unequal target repetitions are rejected if the upstream builder's atom positions do not match the declared image-major tiling.

ASR is reported separately: the downstream matched construction applies no acoustic projection, so asr=True is a measured difference, not an aligned comparison.

Energy / Force / Stress Decomposition

The pyeffpot backend can split the total energy, forces, and stress into per-term contributions:

atoms.calc = calc
contrib = calc.get_contributions(atoms)

contrib.energy["dipdip"]            # eV
contrib.forces["harmonic_local"]    # (natom, 3), eV/Å
contrib.stress["anharmonic"]        # (6,) Voigt, eV/ų

contrib.total_forces()   # == atoms.get_forces(), exactly

See docs/ENERGY_FORCE_STRESS_DECOMPOSITION.md.

DDB → Phonopy Export

Export ABINIT DDB harmonic data to phonopy_params.yaml without running ABINIT:

from pymultibinit import write_phonopy_from_ddb

result = write_phonopy_from_ddb("system_DDB", "phonopy_from_ddb")
mbtools ddb-to-phonopy system_DDB phonopy_from_ddb

Model Training

Pure-Python fitting

mbtools train-python system.ddb training_HIST.nc \
  --basis-xml candidate_basis.xml \
  --output-xml fit_coeffs.xml \
  --ncell 2 2 2 \
  --selection greedy \
  --ncoeff 20

See docs/PURE_PYTHON_TRAINING.md.

Binary-based training

mbtools train system.ddb training_HIST.nc \
  --config train.abi \
  --output-dir model_out \
  --executable /path/to/multibinit

API Reference

MultibinitCalculator (ASE interface)

Constructor Backend Requires
from_pyeffpot(ddb_file, ...) Pure Python DDB file
from_abi(abi_file, ...) CFFI libabinit
from_abi_spawned(abi_file, ...) CFFI (child process) libabinit
from_params(ddb_file, ...) CFFI libabinit
from_config_file(config_file) CFFI libabinit

Key methods:

  • get_reference_atoms() → ASE Atoms for the reference supercell
  • calculate(atoms) → energy, forces, stress (called automatically by ASE)
  • close() / context manager → release resources
  • get_contributions(atoms) → per-term decomposition (pyeffpot only)

Unit Conventions

Quantity API
Length Angstrom
Energy eV
Force eV/Å
Stress eV/ų (Voigt: xx, yy, zz, yz, xz, xy)

Examples

  • examples/contributions_decomposition/ — energy/force/stress decomposition
  • debugs/BFO_arijit_harmonic_update/compare_3x3x3_rattle.py — three-backend BFO parity
  • debugs/BFO_arijit_harmonic_update/compare_hist_pyeffpot.py — HIST energy comparison

License

GPL v3 (same as ABINIT)

Citation

Metadata

Release files for pymultibinit 0.3.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymultibinit 0.3.16
File Size Uploaded Provenance Actions
pymultibinit-0.3.16.tar.gz 404.7 kB Without provenance Details for pymultibinit-0.3.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymultibinit 0.3.16
File Interpreter ABI Platform Actions
pymultibinit-0.3.16-py3-none-any.whl Python 3 none any Details for pymultibinit-0.3.16-py3-none-any.whl

Total release size: 602.4 kB

Release files / pymultibinit-0.3.16.tar.gz

Download URL pymultibinit-0.3.16.tar.gz
Size 404.7 kB
Tags Source
SHA-256 checksum
How to use checksums
004f3ee2b05710c5271c28b9012bb64219338a5f73e5f2ae463026930be1f8e0
BLAKE2b-256 checksum
How to use checksums
3ae1faf44d4b7ef0c337087a1c8c124fda51a33444bba52466e9838063f7bb89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / pymultibinit-0.3.16-py3-none-any.whl

Download URL pymultibinit-0.3.16-py3-none-any.whl
Size 197.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a654475c0ed67fc723e5453c4c679aeaa05deeee86d199c524be4a70dd456944
BLAKE2b-256 checksum
How to use checksums
b7b9854335b327bad297889714664cbb8512614f47266e2f8f8a2addc3167506
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for pymultibinit 0.3.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page