ic_lattice
Monte Carlo lattice simulation for A-B molecule interactions on a 2D lattice.
Description
ic_lattice is a Python package that simulates the behavior of two types of molecules (A and B) on a 2D square lattice using Monte Carlo methods. The simulation uses the Metropolis algorithm to sample configurations according to their Boltzmann probabilities.
Features
- Efficient numba-accelerated Monte Carlo simulation
- Periodic boundary conditions
- Configurable interaction energies (A-A, A-B, B-B)
- Real-time monitoring of energy and neighbor statistics
- Both library and command-line interfaces
Installation
Using pixi
pixi add ic_lattice
Or add to your pixi.toml:
[dependencies]
ic_lattice = "*"
Using pip
pip install ic_lattice
From source
git clone https://github.com/yourusername/ic-lattice.git
cd ic-lattice
pip install -e .
Usage
Command-line interface
ic-lattice --N 50 --n_A 1250 --E_AA -1.0 --E_AB 0.0 --E_BB -1.0 --beta 1.0 --steps 10000 --print_interval 1000
Parameters:
--N: Lattice size (creates N x N grid)--n_A: Number of A molecules--E_AA: A-A interaction energy--E_AB: A-B interaction energy--E_BB: B-B interaction energy--beta: Inverse temperature (1/kT)--steps: Number of Monte Carlo steps--print_interval: Print statistics every N steps (0 for no printing)
Python API
from ic_lattice import initialize_lattice, run_simulation
# Initialize lattice
N = 50
n_A = 1250
lattice = initialize_lattice(N, n_A)
# Set parameters
E_AA = -1.0
E_AB = 0.0
E_BB = -1.0
beta = 1.0
n_steps = 10000
# Run simulation
results = run_simulation(
lattice, N, beta, E_AA, E_AB, E_BB,
n_steps, print_interval=1000
)
# Access results
print(f"Final energy: {results['final_energy']}")
print(f"Acceptance rate: {results['acceptance_rate']}")
print(f"A-B fraction: {results['final_ab_fraction']}")
Physics
The simulation models a canonical ensemble where:
- The lattice has N×N sites
- Each site contains either an A or B molecule
- Molecules can swap positions via Monte Carlo moves
- Energy depends on nearest-neighbor interactions with periodic boundary conditions
The acceptance probability for a swap follows the Metropolis criterion:
P(accept) = min(1, exp(-β * ΔE))
where β = 1/(kT) is the inverse temperature and ΔE is the energy change.
Development
Setting up development environment with pixi
pixi install
pixi run pytest
Running tests
pytest tests/
Code formatting
black src/
ruff check src/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this package in your research, please cite:
@software{ic_lattice,
author = {Your Name},
title = {ic_lattice: Monte Carlo lattice simulation},
year = {2024},
url = {https://github.com/yourusername/ic-lattice}
}
Metadata
Release files for ic-lattice 0.1.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 |
|---|---|---|---|---|
| ic_lattice-0.1.0.tar.gz | 10.2 kB | Without provenance | Details for ic_lattice-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ic_lattice-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ic_lattice-0.1.0-py3-none-any.whl |
Total release size: 19.7 kB
Release files / ic_lattice-0.1.0.tar.gz
| Download URL | ic_lattice-0.1.0.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ac3f8615e62146880dc44eaa7d5db28f42245908c091d4f5fceb4393225943b
|
|
BLAKE2b-256 checksum How to use checksums |
03686565572f805bfa601e3b673880d9ad2d3dea394a63742fcb83a46d5ed091
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / ic_lattice-0.1.0-py3-none-any.whl
| Download URL | ic_lattice-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
716f274e4e5763c9e7971036aa5ae8e93d2794765ab2870898093625e76d964a
|
|
BLAKE2b-256 checksum How to use checksums |
7897f7e84800dbef13dfa1586471e46e4040c7a65bc6e8f273f234056abf743d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for ic-lattice 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.