Kinetic Monte Carlo Simulation with Python (kMCpy) is an open-source Python package for studying ion diffusion using the kinetic Monte Carlo (kMC) technique. It offers a comprehensive Python-based approach to compute kinetic properties, suitable for research, development, and prediction of new functional materials.
Key features include a local cluster expansion model toolkit, a rejection-free kinetic Monte Carlo (rf-kMC) solver, and tools to extract ion transport properties like diffusivities and conductivities. The local cluster expansion model toolkit facilitates model fitting from ab initio or empirical barrier calculations. Post-training, the local cluster expansion model can compute migration barriers in crystalline materials within the transition state theory.
Advantages of using kMCpy:
- Written entirely in Python with a modular design, promoting developer-centricity and easy feature addition.
- Cross-platform compatibility, supporting Windows, macOS, and Linux.
- Performance-optimized kMC routines using Numba, resulting in significant speed improvements.
Release notes are maintained in the changelog.
Installation
Install with pip
You can install the latest PyPI release directly into a Python environment:
pip install kmcpy
Using a virtual environment is recommended:
python -m venv kmcpy-env
source kmcpy-env/bin/activate # On Windows use `kmcpy-env\Scripts\activate`
pip install kmcpy
Install with uv pip
If you manage Python environments with uv, use the same PyPI package:
uv venv kmcpy-env
source kmcpy-env/bin/activate
uv pip install kmcpy
Install with Conda
Use Conda to create the Python environment, then install the PyPI package inside that environment:
conda create -n kmcpy python=3.11 pip
conda activate kmcpy
python -m pip install kmcpy
Install from source
You can install kMCpy from source using either pip or uv. First, clone the
repository and navigate to its root directory.
To install normally with pip:
pip install .
For development with pip:
pip install -e ".[dev]"
For development with uv:
uv sync
uv sync --extra dev
uv pip install -e .
Build documentation
You can access the documentation at https://kmcpy.readthedocs.io/. However, if you want to build the documentation locally, you can do so by following these steps:
uv sync --extra doc
python scripts/build_doc.py
Quickstart
Run a minimal end-to-end simulation with bundled example files:
uv sync
uv run python -c "from kmcpy.simulator.config import Configuration; Configuration.help_fields()"
uv run python example/minimal_example.py
Configuration routes arguments into two groups:
systemfields define what you simulate after loader inputs have been read.runtimefields define how you simulate (temperature, passes, random seed).
If you pass an unknown keyword, kMCpy raises a clear error and points to Configuration.help_fields().
Unit conventions are explicit in code via kmcpy.units,
Configuration.field_units(), and tracker.result_units. Common units are:
barriers in meV, rates/probabilities in Hz, time in s, distance in Angstrom,
diffusivity in cm^2/s, and conductivity in mS/cm.
Run kMCpy
API usage
You can run kMC through API. See the example directory for scripts and notebook workflows covering setup, event generation, and simulations.
For a one-call simulation:
from kmcpy import Configuration, run
config = Configuration.from_file("input.yaml")
tracker = run(config)
You can also attach custom property callbacks during a run:
from kmcpy.simulator.kmc import KMC
kmc = KMC.from_config(config)
def custom_property(state, step, sim_time):
occupied = sum(1 for occ in state.occupations if occ < 0)
return occupied / len(state.occupations)
kmc.attach(custom_property, interval=100, name="occupied_fraction")
kmc.set_property_enabled("conductivity", False) # Optional: disable selected built-in fields
tracker = kmc.run()
# Stored custom callback records
records = tracker.get_property_records("occupied_fraction")
Command line usage
A wrapper is provided if you want to run kMCpy from the command line.
- Generate a commented template input file:
kmcpy init --output input_template.yaml
-
Edit the required file paths and simulation settings in
input_template.yaml. -
Run the simulation:
run_kmc --input input_template.yaml
To print out all arguments, you can run:
run_kmc --help
Build local barrier models
For direct barrier logic, use LocalBarrierModel. It supports constant barriers,
count rules, species-count rules, wildcard patterns, and exact catalog-style
matches. Barrier values are in meV.
Constant barrier:
from kmcpy.models import LocalBarrierModel
model = LocalBarrierModel.constant_barrier(300.0)
model.to("model.json")
Species-count rule, for example "more than 3 Si in the local environment":
model = LocalBarrierModel(
default_barrier=300.0,
site_species={
1: {-1: "P", 1: "Si"},
2: {-1: "Si", 1: "P"},
3: {-1: "Si", 1: "P"},
4: {-1: "Al", 1: "Si"},
},
)
model.add_species_count_rule(
name="si_rich",
sites="local_env",
species="Si",
min_count=4,
barrier=420.0,
)
model.to("model.json")
Exact catalog-style match:
model = LocalBarrierModel.from_exact_entries([
{
"mobile_ion_indices": [0, 1],
"local_env_indices": [1, 2, 3],
"occupations": [1, -1, 1, -1],
"properties": {"barrier": 250.0},
}
])
Use the generated model file in simulation config by pointing to it:
model_file: "model.json"
Exact catalog-style data should be represented as LocalBarrierModel exact
rules rather than a separate catalog model.
Citation
If you use kMCpy in your research, please cite it as follows:
@article{deng2022fundamental,
title={Fundamental investigations on the sodium-ion transport properties of mixed polyanion solid-state battery electrolytes},
author={Deng, Zeyu and Mishra, Tara P and Mahayoni, Eunike and Ma, Qianli and Tieu, Aaron Jue Kang and Guillon, Olivier and Chotard, Jean-No{\"e}l and Seznec, Vincent and Cheetham, Anthony K and Masquelier, Christian and Gautam, Gopalakrishnan Sai and Canepa, Pieremanuele},
journal={Nature Communications},
volume={13},
number={1},
pages={1--14},
year={2022},
publisher={Nature Publishing Group}
}
@article{deng2023kmcpy,
title = {kMCpy: A python package to simulate transport properties in solids with kinetic Monte Carlo},
journal = {Computational Materials Science},
volume = {229},
pages = {112394},
year = {2023},
issn = {0927-0256},
doi = {https://doi.org/10.1016/j.commatsci.2023.112394},
author = {Zeyu Deng and Tara P. Mishra and Weihang Xie and Daanyal Ahmed Saeed and Gopalakrishnan Sai Gautam and Pieremanuele Canepa},
}
Metadata
Release files for kmcpy 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kmcpy-0.3.0.tar.gz | 169.0 kB | With provenance | Details for kmcpy-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kmcpy-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for kmcpy-0.3.0-py3-none-any.whl |
Total release size: 313.9 kB
Release files / kmcpy-0.3.0.tar.gz
| Download URL | kmcpy-0.3.0.tar.gz |
|---|---|
| Size | 169.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a4351d0b118bf0913f7208ac6e4ddba186320573c4679243fb25b1dd03b2b96
|
|
BLAKE2b-256 checksum How to use checksums |
4ea24082c1b7d927cf4e8705468f70e9a7a6e00ba0d9f30f4fe7554a1b3c704d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 27, 2026.
Transparency logRelease files / kmcpy-0.3.0-py3-none-any.whl
| Download URL | kmcpy-0.3.0-py3-none-any.whl |
|---|---|
| Size | 144.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f315136a7389c83a499360b8f9e2132d25f7df7c4de1923e455b8634651df59
|
|
BLAKE2b-256 checksum How to use checksums |
7deb606c0d45794307a69e31bc7b35125590a525259977afab62f8545f5bd472
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 27, 2026.
Transparency logSecurity for kmcpy 0.3.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for kmcpy-0.3.0.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 May 27, 2026.
Transparency logA 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.