Skip to main content

Monte Carlo Simulations with Machine-Learned Interatomic Potentials

Project description

MLIP-MC

ASE framework for Monte Carlo simulations with universal Machine-Learned Interatomic Potentials (MLIP).

Overview

MLIP-MC is a Python package for performing Monte Carlo simulations of gas adsorption in porous materials using machine-learned interatomic potentials. The package integrates seamlessly with the ASE (Atomic Simulation Environment) framework and supports MLIP models from FAIRChem, MACE-Torch and Orbital backends.

Installation

Backend Selection

MLIP-MC supports three MLIP backends. You must install one of them:

  • FAIRChem: For models trained with FAIRChem (e.g., OC20, OC22 models)
  • MACE-Torch: For MACE models (e.g., MACE-MP models)
  • Orbital: For Orbital models (e.g. orb_v3_conservative_inf_omat)

Install from PyPI (Recommended)

Install MLIP-MC with your preferred backend directly from PyPI:

With FAIRChem backend:

pip install "mlip-mc[fairchem]"

With MACE-Torch backend:

pip install "mlip-mc[mace-torch]"

With Orbital backend:

pip install "mlip-mc[orb-models]"

ROCm users: Install the ROCm version of PyTorch first before installing MLIP-MC:

pip install torch==2.8.0 torchvision==0.23.0 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/rocm6.4

Install from Source

Clone the repository and install locally:

git clone https://github.com/jackevansadl/MLIP-MC.git
cd MLIP-MC
pip install ".[fairchem]"   # or ".[mace-torch]" or ".[orb-models]"

Development mode (includes test tooling):

pip install -e ".[BACKEND_OF_YOUR_CHOICE,dev]"

Usage

Command-Line Interface

GCMC Isotherm Simulation

# Multiple pressure points (auto-distributed across GPUs)
mlip_mc \\
    --mode gcmc \\
    --adsorbent framework.xyz \\
    --adsorbate-molecule CO2 \\
    --temperature 298.0 \\
    --pressures 0.1,0.5,1.0,2.0,5.0,10.0,20.0 \\
    --n-equil 10000 \\
    --n-prod 20000 \\
    --model models/model.pt \\
    --output-dir results \\
    --checkpoint-interval 10000 \\
    --write-trajectory \\
    --trajectory-interval 100

Widom Insertion

# Basic Widom insertion calculation
mlip_mc \\
    --mode widom \\
    --adsorbent framework.xyz \\
    --adsorbate-molecule CO2 \\
    --temperature 298.0 \\
    --n-trials 10000 \\
    --model models/model.pt \\
    --output-dir widom_results

Command-Line Arguments:

  • --mode: Simulation mode: gcmc (Grand Canonical Monte Carlo) or widom (Widom insertion) (default: gcmc)
  • --adsorbent: Path to adsorbent structure file (.xyz, .cif, etc.) (required)
  • --adsorbate-path: Path to adsorbate structure file (optional). The chemical formula will be automatically extracted to match with the fugacity table.
  • --adsorbate-molecule: Molecule name (e.g., CO2, CH4) if not using file. This name will be used to match with the fugacity table.
  • --temperature: Temperature in Kelvin (required)
  • --pressures: Comma-separated pressures in bar, or single number (required for GCMC mode)
  • --n-equil: Number of equilibration steps for GCMC (default: 10000)
  • --n-prod: Number of production steps for GCMC (default: 20000)
  • --n-trials: Number of Widom insertion trials (default: 10000)
  • --checkpoint-interval: Interval for saving history checkpoints in GCMC (default: 10000)
  • --model: Path to MLIP model file (required). Can be a local path or a Hugging Face URI (e.g., hf://your-org/your-repo or hf://your-org/your-repo:model.pt). When using the hf:// scheme, files are automatically downloaded and cached. The model format should match your installed backend (FAIRChem .pt files or MACE .model files).
  • --output-dir: Output directory (default: results)
  • --write-trajectory: Specifies to write out simulation trajectory every --trajectory-interval steps (default: False)
  • --trajectory-interval: Interval for saving structures into trajectory file (default: 100)
  • --hf-token: Hugging Face access token for downloading private models or bypassing interactive login (optional)
  • --gpu-id: GPU device ID to use (for Widom mode, default: 0, use -1 for CPU)
  • overwrite_checkpoints: Specifies to overwrite checkpoint files every --checkpoint-interval steps (default: False)

Model caching: When using the hf:// scheme, downloads are cached under ~/.cache/mlip-mc/<repo>/<filename> (or a custom directory set via the MLIP_MC_CACHE environment variable). Subsequent runs reuse the cached file even when launched from different working directories.

Note: The adsorbate name for EOS (fugacity) calculation is automatically determined:

  • If --adsorbate-molecule is provided, that name is used to match with the fugacity table
  • If --adsorbate-path is provided, the chemical formula is extracted from the structure file using ASE
  • If the name/formula doesn't match any entry in the fugacity table, the simulation falls back to ideal gas approximation

Python Interface

You can also use the package programmatically for more control and integration into your workflows:

GCMC Isotherm

from mlip_mc import run_gcmc

# Run GCMC simulation
results = run_gcmc(
    adsorbent_path="framework.xyz",
    adsorbate_molecule="CO2",
    temperature=298.0,
    pressure_points=[0.1, 1.0, 5.0],
    n_equilibration_steps=10000,
    n_production_steps=20000,
    model_path="models/model.pt",  # or use hf://your-org/your-repo
    output_dir="results",
    write_trajectory=True,
    trajectory_interval=100,
    checkpoint_interval=10000
)

# Access results
print(f"Pressures: {results['pressures']}")
print(f"Uptakes: {results['uptakes']}")
print(f"Temperature: {results['temperature']} K")

Widom Insertion

from mlip_mc import run_widom

# Run Widom insertion calculation
results = run_widom(
    adsorbent_path="framework.xyz",
    adsorbate_molecule="CO2",
    temperature=298.0,
    n_trials=10000,
    model_path="models/model.pt",  # or use hf://your-org/your-repo
    output_dir="widom_results"
)

Output Files

Simulations generate output files in the specified output directory (default: results/):

  • GCMC Isotherm (using run_gcmc()):

    • isotherm_data.json: Complete isotherm data (pressures, uptakes, energies, etc.)
    • log_{pressure}bar.bin: Binary log file containing all iteration data with trajectory (step, uptake, interaction_energy, total_energy)
    • traj_{pressure}bar.xyz: Simulation trajectory
    • restart/restart_{pressure}bar.xyz and .json: Restart information (updated every step for crash recovery)
    • checkpoints_{pressure}bar/checkpoint_{step}/: History checkpoints saved at intervals specified by --save-interval
      • traj.xyz: Snapshot trajectory
      • results.json: Snapshot results (n_iter, uptake, interaction_energy, total_energy)
  • GCMC (direct class usage):

    • log_{pressure}bar.bin: Binary log file with all iteration data
    • restart/restart_{pressure}bar.xyz and .json: Restart information
    • checkpoints_{pressure}bar/checkpoint_{step}/: History checkpoints
    • traj_{pressure}bar.xyz: simulation trajectory
  • Widom Insertion:

    • widom_results.json: Adsorption energies and calculated properties (Henry's constant, weighted average energy, etc.)
    • log_widom.bin: Binary log file containing all valid insertions with trajectory data (trial number, adsorption energy, total energy, atomic structure) - one record per valid insertion
    • widom_trajectory.xyz: Last valid insertion structure saved at the end of simulation
    • restart/restart_widom.xyz and .json: Restart information (updated every step for crash recovery)

Isotherm Data Format

The isotherm_data.json file contains:

{
    "temperature": 298.0,
    "pressures": [0.1, 0.5, 1.0, ...],
    "uptakes": [0.5, 1.2, 2.1, ...],
    "uptake_stds": [0.1, 0.2, 0.3, ...],
    "adsorption_energies": [-0.15, -0.18, -0.20, ...],
    "unit_cell_volume_A3": 1234.5,
    "unit_cell_volume_cm3": 1.234e-21,
    "adsorbent_file": "tests/zif8.xyz",
    "n_equilibration_steps": 10000,
    "n_production_steps": 20000
}

Supported Compounds

The Peng-Robinson EOS supports the following compounds (via PREOS.from_name()):

H2 (hydrogen) He (helium) NH3 (ammonia) H2O (water)
CH4 (methane) N2 (nitrogen) O2 (oxygen) Ar (argon)
CO (carbon monoxide) CO2 (carbon dioxide) C2H2 (acetylene) C2H6 (ethane)
C3H8 (propane) C4H10 (butane) C6H6 (benzene) C6H14 (n-hexane)

Citation

If you use this code in your research, please cite:

@software{mlip_mc,
  title = {MLIP-MC: Monte Carlo Simulations with Machine-Learned Interatomic Potentials},
  author = {Edwards, Connor W. and Yang, Fengxu and Stracke, Konstantin and Evans, Jack D.},
  year = {2025},
  license = {MIT}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

Much of the code in this repository is based on or derived from the work published at:

Additional acknowledgments:

  • Built on the ASE framework
  • Supports MLIP models from FAIRChem, MACE-Torch and Orbital

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

mlip_mc-0.1.1.tar.gz (51.1 kB view details)

Uploaded Source

Built Distribution

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

mlip_mc-0.1.1-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file mlip_mc-0.1.1.tar.gz.

File metadata

  • Download URL: mlip_mc-0.1.1.tar.gz
  • Upload date:
  • Size: 51.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlip_mc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b7b47b4fbd31836c2a5432ed5602c0516842577b162c23c0e23395266c48d2b5
MD5 aa2661ef5b792430e2f37dba0d4c24a5
BLAKE2b-256 b81dcae31b546db7b63a0b585ed2ac997323a9d06db822f104f1c84a8feea676

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlip_mc-0.1.1.tar.gz:

Publisher: publish.yml on jackevansadl/MLIP-MC

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

File details

Details for the file mlip_mc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mlip_mc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlip_mc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c259fd87a775c71469898bc4687f2b27c5ab3f91ba7e5dfa71bec809c2fdde5
MD5 1e16a4ab08bf6951e3c59f5314a2c718
BLAKE2b-256 859e685372b83f32b9d583d82b3338c47a1607962b020e580666ca714a10b326

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlip_mc-0.1.1-py3-none-any.whl:

Publisher: publish.yml on jackevansadl/MLIP-MC

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