# Kinetic Monte Carlo of Systems (kmcos)
[toc]
- [Guide]((https://github.com/kmcos/intro2kmcos)) I followed
- Check for [issues]((https://github.com/kmcos/kmcos/issues)) in [kmcos repo](https://github.com/kmcos/kmcos)
> Note that **kmcos** is the newer version for Python3, while [**kmos**](https://github.com/mhoffman/kmos) is for Python2 (many bugs!!)

## Installation (Ubuntu, Serial)
1. Creating a Python Virtual Environment
```python=
cd ~
sudo apt-get update
sudo apt-get install python3
sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 ~/VENV/kmcos
source ~/VENV/kmcos/bin/acti
```
2. Fetch latest version of kmcos
```python=
sudo apt install git
git clone https://github.com/kmcos/kmcos-installers
cd kmcos-installers
bash install-kmcos-linux-venv.bas
```
他的Viewer GUI現在問題還很多,這部分安裝就先跳過
## Run Interactively
1. 先用`intro2kmcos`的資料試跑
```python=
source ~/VENV/kmcos/bin/activate #確定有在VENV
git clone https://github.com/kmcos/intro2kmcos
cd ~/intro2kmcos/task_material/COoxRuO2_local_smart
```
2. Save + compile the model
```python=
python3 COoxRuO2__build.py
```
This creates:
- folder `COoxRuO2_local_smart` : compiled model
- `COoxRuO2.xml` : contains data defining the model (copy it to `COoxRuO2_local_smart`)
[More about COoxRuO2__build.py](https://hackmd.io/@princesswinnie/B14ey8MJA)
> 如果compile的時候有error `Error: Symbol ‘get_seed’ at (1) has no IMPLICIT type; did you mean ‘get_seedf2pywrap’?`
是因為NumPy的f2py有問題,再裝一次舊版本就可以解決:`pip install numpy==1.24.2`
3. Launch API
```python=
cd COoxRuO2_local_smart
python3 kmc_settings.py run
```
4. Run directly !!
```python=
NSTEPS = 1e6
model.do_steps(NSTEPS)
model.show()
```

## Useful commands
- Parameters
```python=
model #查看所有參數和其當前值
#重設參數
model.parameters.T = 550 #溫度(k)
model.parameters.p_COgas = 0.5 #壓力(bar)
```
- TOFs (in the form of NumPy arrays)
Reaction rate is often expressed as **turnover frequency (TOF)**, the average rate of molecule production per second per surface site (or surface area). In this case we refer to the production rate of $CO_2$ .
```python=
#To get the headers of these arrays
model.get_occupation_header()
model.get_tof_heade
#Sample an average model
model.get_std_sampled_data(samples, sample_size, tof_method='integ',
output='str')
#To get all info in a list
data = model.get_std_sampled_data(samples=10, sample_size=1e6)
L = data.split(' ')
print(L)
#Return info in the form of Python dictionary
output_dict = model.get_std_sampled_data(samples=10, sample_size=1e6,
output = 'dict')
print(output_dict)
TOF_CO = output_dict['CO_oxidation']
print(TOF_CO)
```
- Print details
```python=
#current occupations (averaged coverages)
model.print_coverages ()
#number of times each process has been executed (since the simulation starts)
model.print_procstat ()
```
- Analyze & View model
```python=
atoms = model.get_atoms ()
model.show ()
#Some additional data in the "atoms" object
atoms.occupation
atoms.tof_data
atoms.kmc_time
atoms.kmc_ste
```
## Build models
