Skip to main content

pymatgen-analysis-defects

testing codecov zenodo pypi

📄 Full Documentation Paper

This package is an extension to pymatgen for performing defect analysis. The package is designed to work with VASP inputs and output files and is meant to be used as a namespace package extension to the main pymatgen library. The new module has been redesigned to work closely with atomate2.

While the atomate2 automation framework is not required for this code to be useful, users are strongly encouraged to to adopt the atomate2 framework as it contains codified "best practices" for running defect calculations as well as orchestrating the running of calculations and storing the results.

The package serves as an object-oriented interface to defect physics and is capable of generating a list of non-equivalent defect objects directly from the Materials Project API.

from pymatgen.analysis.defects.generators import ChargeInterstitialGenerator, generate_all_native_defects
from mp_api.client import MPRester
with MPRester() as mpr:
chgcar = mpr.get_charge_density_from_material_id("mp-804")
for defect in generate_all_native_defects(chgcar):
    print(defect)

Non-exhaustive list of features:

Reproducible definition of defects

Defects are defined based on the physical concept they represent, independent of the calculation details such as simulation cell size. As an example, a Vacancy defect is defined by the primitive cell of the pristine material plus a single site that represents the vacancy site in the unit cell.

Formation energy calculations

The formation energy diagram is a powerful tool for understanding the thermodynamics of defects. This package provides a simple interface for calculating the formation energy diagram from first-principles results. This package handles the energy accounting of the chemical species for the chemical potential calculations, which determines the y-offset of the formation energy. This package also performs finite-size corrections for the formation energy which is required when studying charged defects in periodic simulation cells.

Defect Position

Identification of the defect positions in a simulation cell after atomic relaxation is not trivial since the many atoms can collectively shift in response to the creation of the defect. Yet the exact location of the defect is required for the calculation of finite-size corrections as well as other physical properties. We devised a method based on calculating a SOAP-based distortion field that can be used to identify the defect position in a simulation cell. Note, this method only requires the reference pristine supercell and does not need prior knowledge of how the defect was created.

Defect Complexes

Multiple defects can be composed into defect complexes. The complex is can be treated as a normal defect object for subsequent analysis.

Defect Interactions

Simulation of defect-photon and defect-phonon interactions under the independent particle approximation.

Previous versions of the defects code

This package replaces the older pymatgen.analysis.defects modules. The previous module was used by pyCDT code which will continue to work with version 2022.7.8 of pymatgen.

Contributing

The source code can be downloaded from the GitHub repository at

$ git clone https://github.com/materialsproject/pymatgen-analysis-defects.git

All code contributions are welcome. Please submit a pull request on GitHub. To make maintenance easier, please use a workflow similar to the automated CI workflow.

Specifically, please make sure to run the following commands for linting:

$ uvx pre-commit install
$ uvx pre-commit run --all-files

And run these commands for testing:

$ uv sync --extra optional
$ uv run pytest -n auto --cov=pymatgen
$ uv run pytest -n auto --nbmake ./docs/source/content

Dependencies are pinned in uv.lock; after changing them in pyproject.toml, run uv lock and commit the result (CI installs with uv sync --locked).

Contributors

  • Lead developer: Dr. Jimmy-Xuan Shen
  • This code contains contributions from the original defects analysis module of pymatgen from Dr. Danny Broberg and Dr. Shyam Dwaraknath.

Metadata

Release files for pymatgen-analysis-defects 2026.10.24

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

Source distribution (sdist)

Source distribution for pymatgen-analysis-defects 2026.10.24
File Size Uploaded Provenance
pymatgen_analysis_defects-2026.10.24.tar.gz 76.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pymatgen-analysis-defects 2026.10.24
File Interpreter ABI Platform
pymatgen_analysis_defects-2026.10.24-py3-none-any.whl Python 3 none any Details

Total release size: 158.0 kB

Release files / pymatgen_analysis_defects-2026.10.24.tar.gz

Download URL pymatgen_analysis_defects-2026.10.24.tar.gz
Size 76.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0fbf16ca02a890322c348e8bd2f74b099de6dfcceaef51e09941a0ddb43675a1
BLAKE2b-256 checksum
How to use checksums
3c5b2fa6039961eb5328654defab231a48948e8945404248fce397b8b81226a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / pymatgen_analysis_defects-2026.10.24-py3-none-any.whl

Download URL pymatgen_analysis_defects-2026.10.24-py3-none-any.whl
Size 81.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c61f8bb01c118fbde1c6bd51fabb62f335df237be66bb7478964cc1cc5a73eff
BLAKE2b-256 checksum
How to use checksums
aea67b0787e296d5d2f501382ed87d5f4c9159a8e1e0df56679a8974f86f5863
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for pymatgen-analysis-defects 2026.10.24

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pymatgen_analysis_defects-2026.10.24.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

2026.10.24 This release

2 release files Full 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