mcpy
mcpy runs Grand Canonical Monte Carlo (GCMC) simulations of atomistic systems on top of the Atomic Simulation Environment (ASE).
It predicts the composition and structure of surfaces and nanoparticles in contact with a gas or metal reservoir, with any ASE calculator: classical potentials, DFT, or machine-learned interatomic potentials such as MACE.
Documentation: https://mc-py.readthedocs.io
Features
- Grand-canonical Monte Carlo: atomic insertion and deletion at fixed chemical potential, with the free volume of the insertion region estimated from per-species exclusion radii.
- Molecular adsorbates: whole-molecule insertion, deletion and rigid translate+rotate moves (O2, H2O, CO, NH3, any ASE-buildable template), with per-atom
molecule_idbookkeeping that survives rollback, trajectories and restarts. Atomic and molecular species can coexist in one run. - Insertion regions for every common geometry: the periodic box, a window over a slab, a sphere around a nanoparticle, and a dome over a supported particle.
- Replica exchange along a temperature or chemical-potential ladder, over MPI or in one process on one GPU with batched energy evaluation.
- Relaxed trial energies (the hybrid GCMC scheme of Senftle et al.): each trial can be relaxed before the acceptance test, which makes GCMC workable on dense metal surfaces.
- Canonical Monte Carlo and basin hopping: permutation, displacement, shake and Brownian moves, and a running file of the lowest-energy configurations.
- Optional GPU backend: MACE evaluation and relaxation (FIRE by default,
optimizer=for FIRE2 or LBFGS) through NVIDIA'snvalchemi-toolkit. - Phase diagrams: post-processing of a chemical-potential sweep into surface and nanoparticle phase diagrams.
Validation
mcpy's GCMC sampler reproduces LAMMPS fix gcmc for atomic and rigid-molecule Lennard-Jones systems, and the ideal gas against its analytic result.
The tables, the rerunnable scripts and a MACE comparison are in benchmark/README.md.
Installation
mcpy needs Python 3.11 or later.
The distribution is named mcpy-gcmc (the mcpy name on PyPI belongs to an unrelated package).
You still write import mcpy.
Until the first PyPI release, install from the repository:
git clone https://github.com/farrisric/mcpy.git
cd mcpy
pip install -e .
The base install (ASE, NumPy, SciPy) runs the CPU examples examples/00 to examples/02.
Optional extras:
| Extra | Adds | Needed for |
|---|---|---|
.[mace] |
mace-torch |
MACE_F_Calculator |
.[alchemi] |
nvalchemi-toolkit[mace] |
AlchemiCalculator, AlchemiFCalculator, examples/03 and examples/04 (CUDA GPU) |
.[plot] |
matplotlib |
the phase-diagram utilities |
.[mpi] |
mpi4py |
ReplicaExchange over MPI |
.[test] |
pytest |
the test suite |
A conda-installed mpi4py (conda install mpi4py) is often the safer choice, because it links the MPI library it was built for.
The installation guide covers the GPU backend and the MPI launch.
Quickstart (CPU, about three minutes)
python examples/00_hello_gcmc.py
The script fills an empty periodic box with Lennard-Jones particles from a reservoir and prints the average particle count next to the LAMMPS value for the same conditions. Here is the core of it:
from ase import Atoms
from ase.calculators.lj import LennardJones
from mcpy.cell import Cell
from mcpy.ensembles import GrandCanonicalEnsemble
from mcpy.moves import DeletionMove, DisplacementMove, InsertionMove, MoveSelector
atoms = Atoms(cell=[9.0, 9.0, 9.0], pbc=True) # an empty periodic box
cell = Cell(atoms, seed=6) # insert and delete anywhere in it
move_selector = MoveSelector(
[1, 1, 1],
[InsertionMove(cell, species=['H'], seed=1),
DeletionMove(cell, species=['H'], seed=2),
DisplacementMove(species=['H'], max_displacement=0.3, seed=3)],
seed=4,
)
gcmc = GrandCanonicalEnsemble(
atoms=atoms,
cells=[cell],
calculator=LennardJones(sigma=1.0, epsilon=1.0, rc=3.0, smooth=False),
mu={'H': -3.0}, # reduced chemical potential
species=['H'],
units_type='LJ',
temperature=2.0, # reduced temperature
move_selector=move_selector,
random_seed=5, # every random stream is seeded: the run repeats exactly
outfile='hello_gcmc.out',
traj_file='hello_gcmc.xyz',
outfile_write_interval=100,
trajectory_write_interval=100,
)
gcmc.run(6000)
The tutorial takes the same loop to an O/Ag(111) oxidation phase diagram with MACE.
examples/ has the other runnable scripts, and notebooks/ has worked case studies with executed output.
Citing mcpy
If you use mcpy in published work, please cite it with the metadata in CITATION.cff (GitHub shows a "Cite this repository" button for it).
Contributing
Contributions are welcome. See CONTRIBUTING.md for the development setup, the tests, and how to submit changes. Bug reports and feature requests go to the issue tracker.
License
mcpy is licensed under the MIT License; see LICENSE.
Metadata
Release files for mcpy-gcmc 1.5.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 | |
|---|---|---|---|---|
| mcpy_gcmc-1.5.0.tar.gz | 167.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcpy_gcmc-1.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 272.4 kB
Release files / mcpy_gcmc-1.5.0.tar.gz
| Download URL | mcpy_gcmc-1.5.0.tar.gz |
|---|---|
| Size | 167.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db5a57db1fd6a9508ce58ef1f7be7afb93b3d58655a49a9e27a03bc71d5f1193
|
|
BLAKE2b-256 checksum How to use checksums |
f5d62456e9a4e548f949fcb9ed9d34cd9a0268bea0869304f6f257babd019d93
|
| 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 20, 2026.
Transparency logRelease files / mcpy_gcmc-1.5.0-py3-none-any.whl
| Download URL | mcpy_gcmc-1.5.0-py3-none-any.whl |
|---|---|
| Size | 104.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3137d52a90451c95a5675576f12b31a2cb9b9e3d3e4be392393b0666dc746047
|
|
BLAKE2b-256 checksum How to use checksums |
ca36fdddc8683423d18f885f9717afebfc97649a17e66ec52bff070250480fcc
|
| 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 20, 2026.
Transparency logSecurity for mcpy-gcmc 1.5.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mcpy_gcmc-1.5.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 Oct 20, 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.