Skip to main content

Electrostatic Calculator

A python calculator that can calculate the electrostatic long-range forces and stress tensor from Born effective charges and the dielectric tensor.

Citation

If you use this code in your research, please cite:

L. Monacelli and N. Marzari, Electrostatic interactions in atomistic and machine-learned potentials for polar materials, Phys. Rev. B 113, 094101 (2026).
https://doi.org/10.1103/7ygl-8db2

Documentation

Full documentation is available at: https://mesonepigreco.github.io/py-electrostatic/

The documentation includes:

  • Installation guide
  • Tutorials (getting started, supercells, composite calculator, SSCHA integration)
  • API reference
  • Theory guide

Requirements

  1. CellConstructor
  2. ASE
  3. julia

The requirements can be installed as

pip install -r requirements.txt

But julia must be installed on the machine. Julia is not a necessary dependency (the calculator will work anyway) but it may be very slow for computing energies of big systems.

If you are not using anaconda and need root privileges, add the --user flag at the end of the command.

Installation

The code can be installed like any python package with

python setup.py install

also in this case, add the --user option if you need root privileges.

The

Usage

The pyelectrostatic can be used as a simple ASE calculator.

If julia is installed, you can exploit julia acceleration by running with python-jl instead of python command.

It requires to run to have effective charges and the dielectric tensor of a reference structure.

It is interfaced with CellConstructor, and these information can be read from the standard Quantum-Espresso dynamical matrix.

Here an example

    # Load CellConstructor to import the quantum-espresso dynamical matrix
    import cellconstructor as CC, cellconstructor.Phonons    
    import pyelectrostatic, pyelectrostatic.calculator as calc
    import numpy as np

    # The example dynamical matrix is located in tests/BaTiO3/BaTiO3_1
    # It contains the dielectric tensor, centroid structure and effective charges
    dyn = CC.Phonons.Phonons("BaTiO3_")

    # Now setup the calculator and initialize the dielectric tensor and effective charges
    calculator = calc.ElectrostaticCalculator()
    calculator.init_from_phonons(dyn)

    # Get a reference structure (randomize the atomic position to have a non zero dipole moment)
    struct = dyn.structure.copy()
    struct.coords[:,:] += np.random.normal(size = struct.coords.shape, scale = 0.05)

    # Get the ASE Atoms 
    ase_atoms = struct.get_ase_atoms()

    # Setup the calculator
    ase_atoms.set_calculator(calculator)

    # Now use it as a normal calculator:
    print("Energy = ", ase_atoms.get_total_energy(), " eV")
    print("Total forces [eV/A] is:")
    print(ase_atos.get_forces())

We employed cellconstructor Phonon class to read a quantum espresso dinamical matrix. You can setup the calculation even without one, by directly passing the centrinds, effective charges, dielectric tensor and the supercell size:

    calculator.init(centroids = structure, effective_charges = eff_charges, dielectric_tensor = diel_tensor, supercell = (2,2,2))

Where structure is a CellConstructor Structure, eff_charges is a numpy array of size (n_atoms, 3, 3) (atomic index, electric field polarization, cartesian coordinate of the atom) and diel_tensor is a symmetric 3x3 numpy array.

A working example is shown in Examples/compute_energy_forces/compute_energy_forces.py

Run it with

python-jl compute_energy_forces.py

Remember to install julia on the system. The first run needs to compile the julia code, therefore the timing for the first energy/force calculation may take few seconds.

For more info, look at the tests inside the tests directory and see the calculator at work!

Metadata

Release files for py-electrostatic 0.2

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

Source distribution (sdist)

Source distribution for py-electrostatic 0.2
File Size Uploaded Provenance
py_electrostatic-0.2.tar.gz 40.6 kB Without provenance Details

Release files / py_electrostatic-0.2.tar.gz

Download URL py_electrostatic-0.2.tar.gz
Size 40.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7dbc254befbc4b595ecd1350224e0e2967d0b1b8d5c318705ba3980ebbd0b6b9
BLAKE2b-256 checksum
How to use checksums
4459d78c6209f7f2d7e3a78882988a2dfc72de815b4eb869e3d5b19fd758d105
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for py-electrostatic 0.2

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.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

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