Skip to main content

mcpy logo

status Tests License GitHub issues Documentation Status PyPI Open In Colab

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.

pip install mcpy-gcmc

Documentation: https://mc-py.readthedocs.io Try it in the browser, with no install: GCMC basics notebook on Colab.

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_id bookkeeping 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's nvalchemi-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.

pip install mcpy-gcmc
pip install 'mcpy-gcmc[mace]'   # with an extra, see the table below

To run the examples or change the code, install from the repository instead:

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, examples/03 (CPU or GPU)
.[alchemi] nvalchemi-toolkit[mace] AlchemiCalculator, AlchemiFCalculator, examples/04 and examples/05 (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.1

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

Source distribution (sdist)

Source distribution for mcpy-gcmc 1.5.1
File Size Uploaded Provenance Actions
mcpy_gcmc-1.5.1.tar.gz 168.2 kB With provenance Details for mcpy_gcmc-1.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcpy-gcmc 1.5.1
File Interpreter ABI Platform Actions
mcpy_gcmc-1.5.1-py3-none-any.whl Python 3 none any Details for mcpy_gcmc-1.5.1-py3-none-any.whl

Total release size: 273.4 kB

Release files / mcpy_gcmc-1.5.1.tar.gz

Download URL mcpy_gcmc-1.5.1.tar.gz
Size 168.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e599cece54ab915cd1b6c5b53680bd027309c5af21ef990c27139c7e310bd784
BLAKE2b-256 checksum
How to use checksums
3c5ef520c39bb51e9c7853a06f9b59b7ffffb096cae8bb12df0c03eee6eaa470
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 Nov 2, 2026.

Transparency log

Release files / mcpy_gcmc-1.5.1-py3-none-any.whl

Download URL mcpy_gcmc-1.5.1-py3-none-any.whl
Size 105.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
380cbb2579a507440e97962753b62ac50bab5cb10cf64660170b9e5492b23152
BLAKE2b-256 checksum
How to use checksums
472bd9472d849f8b0919f32b576b18ac5ed399db268d01ccbe294e24b2d9f281
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 Nov 2, 2026.

Transparency log

Security for mcpy-gcmc 1.5.1

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.

Select from 2 files

Attestation for mcpy_gcmc-1.5.1.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 Nov 2, 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

1.5.1 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