Skip to main content

Pymatgen extension for defects analysis

Project description

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 pymatgen.ext.matproj 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:

$ pip install -e .[strict]
$ pip install -e .[dev]
$ pre-commit install
$ pre-commit run --all-files

And run these commands for testing:

$ pip install -e .[strict]
$ pip install -e .[tests]
$ pytest --cov=pymatgen
$ pytest --nbmake ./docs/source/content

For more details about what is actually installed with each of the pip install .[arg] commands, please inspect the pyproject.toml file.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymatgen_analysis_defects-2025.9.26.tar.gz (75.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymatgen_analysis_defects-2025.9.26-py3-none-any.whl (79.9 kB view details)

Uploaded Python 3

File details

Details for the file pymatgen_analysis_defects-2025.9.26.tar.gz.

File metadata

File hashes

Hashes for pymatgen_analysis_defects-2025.9.26.tar.gz
Algorithm Hash digest
SHA256 b85594ae6d5721030b9c22c8d78d1e0bfc3d1ade97c7b0dc80e76d11b960e7cd
MD5 db033a39bd6d51593e94465bbe0afaec
BLAKE2b-256 487e016e8b63a8c852c864c1a06379fbe58ee45636069f97ffc5ccc8c1b02568

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymatgen_analysis_defects-2025.9.26.tar.gz:

Publisher: python-publish.yml on materialsproject/pymatgen-analysis-defects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymatgen_analysis_defects-2025.9.26-py3-none-any.whl.

File metadata

File hashes

Hashes for pymatgen_analysis_defects-2025.9.26-py3-none-any.whl
Algorithm Hash digest
SHA256 cb811b0acddbdbaf01c1ade5db57740c24ba493e1e7fd9145fce1301c9416fdb
MD5 3e80743f0dc3d68252620c03b0be4ea3
BLAKE2b-256 ae21659f99d70dcc25093e497143dfcc41c898691f5a62992f84fc09e0bb3104

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymatgen_analysis_defects-2025.9.26-py3-none-any.whl:

Publisher: python-publish.yml on materialsproject/pymatgen-analysis-defects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page