Hex and square lattice KMC classes.
Project description
kmclab
A lightweight Python package for lattice-based kinetic Monte Carlo (KMC) utilities.
Currently includes simple hexagonal and square lattice KMC classes.
Installation
(Optional) Create a new conda environment:
conda create -n test_env python=3.11
conda activate test_env
(Optional) If you use the Spyder IDE you need to also:
conda install spyder-kernels
Install using pip
pip install kmclab
To upgrade to the latest version
pip install -U kmclab
Or you may clone the repository and install in editable mode:
git clone https://github.com/shirinasadix/kmclab.git
cd kmclab
pip install -e .
Usage
Package Structure
kmclab/
├── src/
│ └── kmclab/
│ ├── hexa.py
│ ├── square.py
│ └── __init__.py
├── tests/
├── pyproject.toml
└── README.md
Examples
Minimal Example
from kmclab import hexa_kmc
KMC = hexa_kmc(n_atoms = 5, n_defects = 4, n_adsorbates = 4, lattice_size = 10)
KMC.run(n_steps = 30)
KMC.anim1panel()
KMC.anim2panel()
KMC.msdplot()
Square Lattice - Single Run
Here is the step by step guide:
from square import square_kmc
Now to define system parameters:
square_params = {
# System composition
'n_atoms': 5, # Number of mobile adatoms
'n_defects': 5, # Number of surface defects
'n_adsorbates': 5, # Number of surface adsorbates
# Lattice and simulation control
'lattice_size': 10, # Linear size of the lattice
'T': 300, # Temperature (K)
'seed': 1, # Random number seed
'len_vertical' : 0.297e-3, # Vertical lattice hop distances (µm)
'len_horizontal' : 0.660e-3, # Horizontal lattice hop distances (µm)
'adsorbates_freq' : 3, # Adsorbate redistribution frequency (required only if n_adsorbates > 0) (-1 disables)
# Defect behavior
'defect_type': 1, # 1 = trapping defects, 2 = blocking defects (required only if n_defects > 0 )
# Kinetic prefactor
'k_0': 1,
# Diffusion energy barriers on stoichiometric sites along defferent directions (eV)
'energy_barrier_north' : 0.26,
'energy_barrier_south' : 0.26,
'energy_barrier_east' : 0.91,
'energy_barrier_west' : 0.91,
'energy_barrier_northeast' : 0.91,
'energy_barrier_northwest' : 0.91,
'energy_barrier_southeast' : 0.91,
'energy_barrier_southwest' : 0.91,
# Trapping defect energy barriers (required only if n_defects > 0 and defect_type == 1)
'energy_barrier_trapping_defect_north' : 0.99,
'energy_barrier_trapping_defect_south' : 0.99,
'energy_barrier_trapping_defect_northeast' : 0.99,
'energy_barrier_trapping_defect_northwest' : 0.99,
'energy_barrier_trapping_defect_southeast' : 0.99,
'energy_barrier_trapping_defect_southwest' : 0.99,
# Blocking defect energy barriers (required only if n_defects > 0 and defect_type == 2)
'energy_barrier_blocking_defect_north' : 0.99,
'energy_barrier_blocking_defect_south' : 0.99,
'energy_barrier_blocking_defect_east' : 0.99,
'energy_barrier_blocking_defect_west' :0.99,
'energy_barrier_blocking_defect_northeast' : 0.99,
'energy_barrier_blocking_defect_northwest' : 0.99,
'energy_barrier_blocking_defect_southeast' : 0.99,
'energy_barrier_blocking_defect_southwest' : 0.99,
# Adsorbate-related diffusion barriers (required only if n_adsorbates > 0)
'energy_barrier_adsorbate_north' : 0.72,
'energy_barrier_adsorbate_south' : 0.72,
'energy_barrier_adsorbate_east' : 0.72,
'energy_barrier_adsorbate_west' : 0.72,
'energy_barrier_adsorbate_northeast' : 0.72,
'energy_barrier_adsorbate_northwest' : 0.72,
'energy_barrier_adsorbate_southeast' : 0.72,
'energy_barrier_adsorbate_southwest' : 0.72}
Now to run the actual KMC:
KMC = square_kmc(**square_params)
KMC.run(n_steps = 30) # Total KMC steps (must be > 10)
Now to see the results you have multiple options:
KMC.anim1panel()
KMC.anim2panel()
KMC.msdplot()
Hexagonal Lattice - Multi Run (Histograms)
Here is the step by step guide:
from hexa import hexa_kmc
import numpy as np
from pathlib import Path
import shutil
rs_p = Path("random_seeds")
if rs_p.exists():
shutil.rmtree(rs_p)
(rs_p / "time").mkdir(parents=True)
(rs_p / "msd").mkdir(parents=True)
n_seeds = 5 # Number of trials
hexa_params = {
# System composition
'n_atoms': 5, # Number of mobile adatoms
'n_defects': 5, # Number of surface defects
'n_adsorbates': 5, # Number of surface adsorbates
# Lattice and simulation control
'lattice_size': 10, # Linear size of the lattice
'T': 300, # Temperature (K)
'seed': 1, # Random number seed
'len_vertical' : 0.38e-3, # Vertical lattice hop distances (µm)
'len_horizontal' : 0.51e-3, # Horizontal lattice hop distances (µm)
'adsorbates_freq' : 3, # Adsorbate redistribution frequency (required only if n_adsorbates > 0) (-1 disables)
# Defect behavior
'defect_type': 1, # 1 = trapping defects, 2 = blocking defects (required only if n_defects > 0 )
# Kinetic prefactor
'k_0': 1,
# Diffusion energy barriers on stoichiometric sites along defferent directions (eV)
'energy_barrier_north': 0.46,
'energy_barrier_south': 0.46,
'energy_barrier_northeast': 0.65,
'energy_barrier_northwest': 0.65,
'energy_barrier_southeast': 0.65,
'energy_barrier_southwest': 0.65,
# Trapping defect energy barriers (required only if n_defects > 0 and defect_type == 1)
'energy_barrier_trapping_defect_north': 1.2,
'energy_barrier_trapping_defect_south': 1.2,
'energy_barrier_trapping_defect_east': 1.1,
'energy_barrier_trapping_defect_west': 1.1,
'energy_barrier_trapping_defect_northeast': 1.1,
'energy_barrier_trapping_defect_northwest': 1.1,
'energy_barrier_trapping_defect_southeast': 1.1,
'energy_barrier_trapping_defect_southwest': 1.1,
# Blocking defect energy barriers (required only if n_defects > 0 and defect_type == 2)
'energy_barrier_blocking_defect_north': 1.2,
'energy_barrier_blocking_defect_south': 1.2,
'energy_barrier_blocking_defect_northeast': 1.2,
'energy_barrier_blocking_defect_northwest': 1.2,
'energy_barrier_blocking_defect_southeast': 1.2,
'energy_barrier_blocking_defect_southwest': 1.2,
# Adsorbate-related diffusion barriers (required only if n_adsorbates > 0)
'energy_barrier_adsorbate_north': 0.72,
'energy_barrier_adsorbate_south': 0.72,
'energy_barrier_adsorbate_northeast': 0.72,
'energy_barrier_adsorbate_northwest': 0.72,
'energy_barrier_adsorbate_southeast': 0.72,
'energy_barrier_adsorbate_southwest': 0.72
}
for i in range(n_seeds):
hexa_params['seed'] = i,
print(f'current random_seed = {i}')
KMC = hexa_kmc(**hexa_params)
time, msd = KMC.run(n_steps = 2500)
msd_path = f'random_seeds/msd/rs_{i}'
time_path = f'random_seeds/time/rs_{i}'
np.save(msd_path, msd)
np.save(time_path, time)
KMC.msd_histogram(n_seeds = n_seeds)
Demo
License
XXX
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kmclab-0.1.8.tar.gz.
File metadata
- Download URL: kmclab-0.1.8.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0634569d17eaf8693d8b0eff58e267feab5d8c817fbb5ea5ab458914ef03b2d5
|
|
| MD5 |
807dd58c9efa3b8302ada2fedd1e920a
|
|
| BLAKE2b-256 |
67b970ec572069337b778a178fea96fed6e71828059dbf00f2459563ac5a9603
|
Provenance
The following attestation bundles were made for kmclab-0.1.8.tar.gz:
Publisher:
publish.yml on shirinasadix/kmclab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kmclab-0.1.8.tar.gz -
Subject digest:
0634569d17eaf8693d8b0eff58e267feab5d8c817fbb5ea5ab458914ef03b2d5 - Sigstore transparency entry: 932527436
- Sigstore integration time:
-
Permalink:
shirinasadix/kmclab@ade5902a9a21e03044e066b987ba62e04f7a2fee -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/shirinasadix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ade5902a9a21e03044e066b987ba62e04f7a2fee -
Trigger Event:
release
-
Statement type:
File details
Details for the file kmclab-0.1.8-py3-none-any.whl.
File metadata
- Download URL: kmclab-0.1.8-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d8f920f45c9d033fb10b8ce6c40586751160e8746a0ecf082208d4c0a2ae344
|
|
| MD5 |
f43af24a935ae0eaf3b0dc59862dbd31
|
|
| BLAKE2b-256 |
9fe64e9796e5609a300eff5aeec0081ef0e8003d92374e1505cc9e5f3af81cf2
|
Provenance
The following attestation bundles were made for kmclab-0.1.8-py3-none-any.whl:
Publisher:
publish.yml on shirinasadix/kmclab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kmclab-0.1.8-py3-none-any.whl -
Subject digest:
4d8f920f45c9d033fb10b8ce6c40586751160e8746a0ecf082208d4c0a2ae344 - Sigstore transparency entry: 932527455
- Sigstore integration time:
-
Permalink:
shirinasadix/kmclab@ade5902a9a21e03044e066b987ba62e04f7a2fee -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/shirinasadix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ade5902a9a21e03044e066b987ba62e04f7a2fee -
Trigger Event:
release
-
Statement type: