Skip to content

Commit 90fc102

Browse files
author
Kiran Vaddi
committed
installable package
1 parent f437925 commit 90fc102

13 files changed

+5223
-318
lines changed

Readme.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a python wrapper for [MECSim](http://www.garethkennedy.net/MECSim.html)
44
It works completely in python in a Linux environment. I wrote this while working on [GPCV](https://github.com/kiranvad/gpcv) related work.
55

66
If you use this software in your work please cite the original MECSim software along with this repository:
7-
```
7+
```bibtex
88
@misc{pymecsim,
99
author = {Kiran Vaddi},
1010
title = {{pyMECSim: A Python wrapper for MECSim}},
@@ -15,17 +15,17 @@ If you use this software in your work please cite the original MECSim software a
1515
url = {https://github.com/kiranvad/pyMECSim}
1616
}
1717
```
18-
19-
This repository is arranged as follows:
20-
1. src : Contains the original MECSim software distributed under the same license as MECSim
21-
2. notebooks : An example usage of pyMECSim is shown.
22-
3. mechanisms : Folder where you can host a original mechanism as an input file
18+
To install as a package, run
19+
```bash
20+
pip install git+https://github.com/kiranvad/pyMECSim#egg=pyMECSIM.`
21+
```
22+
Dependencies will be checked and installed from the setup.py file.
2323

2424
A sample usage is as follows:
2525

2626
Import `pymecsim` using the following:
2727
```python
28-
from src.pymecsim import MECSIM, pysed, plotcv
28+
from pymecsim import MECSIM, pysed
2929
```
3030
We can perform a simulation on a one electron transfer mechanism and visualize the effect of changing the formal potential using the following code:
3131

@@ -42,26 +42,32 @@ dirname = os.getcwd()
4242
for i,e0 in enumerate(E0):
4343
outfile = dirname + '/outfile.sk'
4444
pysed('$E0', str(e0), configfile, outfile)
45-
out = MECSIM(outfile)
46-
ax = plotcv(out['current'],out['voltage'], ax = ax)
45+
model = MECSIM(outfile)
46+
ax = model.plot(ax = ax)
4747
ax.set_label("E0 = "+str(e0))
4848
plt.legend([r'$E_0=0.5$',r'$E_0=0.1$',r'$E_0=1e-2$'],loc='lower right')
4949
#plt.savefig('cvexample.png',dpi=500,bbox_inches='tight')
5050
plt.show()
5151
```
5252
5353
This will plot the following:
54-
<img src="notebooks/cvexample.png" width="600">
54+
<img src="notebooks/cvexample.png" width="400">
5555
5656
5757
Naturally, you would want to be able to run simulations for different mechanisms and confgurations. You can do that by just defining a mechanism that MECSim can model(see examples for some possible reaction mechanisms [here](http://www.garethkennedy.net/MECSimScripts.html)).
5858
5959
Once you have the mechanism file in say `/path/to/folder/mechanism.sk` format, turn it in as an input to pyMECSim using the following:
6060
```python
61-
out = MECSIM('/path/to/folder/mechanism.sk')
62-
plotcv(out['current'],out['voltage'])
61+
model = MECSIM('/path/to/folder/mechanism.sk')
62+
model.plot()
63+
plt.show()
6364
```
6465
66+
One can also get concentration profiles by first indicating `MECSIM` to return concentration profiles in the configuration file by setting `1 ! show debug output files as well as MECSimOutput.txt (1=yes; 0=no)`. `pymecsim` will then be able to return concentration profiles as numpy arrays. see `notebooks/Cyclic Voltammetry Simulation Example for Single Electron Transfer Mechanism.ipynb` for an example use case.
67+
68+
69+
## Notes
70+
Please free to contribute to this repository both interms of code and documetation or simple example use cases in jupyter notebook. Submit a pull request and I would be happy to integrate into this repository.
6571
6672
6773

__init__.py

Whitespace-only changes.

mechanisms/cvexamples.sk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
10.0 ! Dstar_min
1616
0.005e0 ! max voltage step
1717
25.6e0 ! time resolution experimentally to correct vscan/f (us)
18-
0 ! show debug output files as well as MECSimOutput.txt (1=yes; 0=no)
18+
1 ! show debug output files as well as MECSimOutput.txt (1=yes; 0=no)
1919
0 ! use advanced voltage ramp (0 = E_start=E_end, 1 = use advanced ramp below, 2=From file "EInput.txt")
2020
2 ! number of E_rev lines for advanced ramp (if enter 0 then first E_rev value is the final time
2121
0.0 ! E_start (V)

notebooks/.ipynb_checkpoints/Cyclic Voltammetry Simulation Example for Single Electron Transfer Mechanism-checkpoint.ipynb

Lines changed: 2412 additions & 93 deletions
Large diffs are not rendered by default.

notebooks/Cyclic Voltammetry Simulation Example for Single Electron Transfer Mechanism.ipynb

Lines changed: 2412 additions & 93 deletions
Large diffs are not rendered by default.

notebooks/log.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
*****************************************************
3+
MECSim - GK 7/08/2016
4+
*****************************************************
5+
6+
7+
8+
General parameters:
9+
Temperature = 298.2000
10+
Uncompensated R = 0.0
11+
12+
Voltage ramp (V):
13+
E_start = 0.5000
14+
E_rev = -0.5000
15+
E_end = 0.5000
16+
Cycles = 1
17+
Total range = 2.0000
18+
19+
Scan rate (V/s) = 1.00000000E+01
20+
Final time (s) = 2.00000000E-01
21+
22+
Found 1 AC signal(s). Max frequency = 0.0000 Hz
23+
0.0000 mV at 180.0000 Hz
24+
25+
No capacitor requested
26+
27+
28+
Found a total of 2 species
29+
30+
No pre-equilibriation; use entered concentrations
31+
32+
Summary of solution reactions:
33+
Charge transfer = 1
34+
1st Order Chem = 0
35+
2nd Order Chem = 0
36+
Summary of surface confined reactions:
37+
Charge transfer = 0
38+
1st Order Chem = 0
39+
2nd Order Chem = 0
40+
41+
Charge transfer reaction(s):
42+
A + 1e = B ; E0 = 0.250 , ks = 1.0000E+04 cm/s , alpha = 0.50
43+
; K_eqm = 1.6794E+04
44+
45+
Electrode geometry:
46+
Planar with area = 1.00000000E+00 cm^2
47+
48+
Technical details of simulation
49+
Using Butler-Volmer Theory
50+
Points in time = 2^14 = 16384
51+
delt = 1.2207E-05 and delE = 1.2207E-04
52+
Exponential spatial grid with 57 points and delx(0) = 3.4939E-06
53+
x = 1.7033E-06 5.3763E-06 9.4355E-06 1.3922E-05 | 9.4112E-03
54+
55+
Solution phase:
56+
Initial scaled concentrations and diffusion coeff (cm2/s)
57+
[A] = 1.00000000E-06 ; D = 1.00000000E-05
58+
(1.00000000)
59+
[B] = 0.00000000E+00 ; D = 1.00000000E-05
60+
(0.00000000)
61+
Concentrations scaled by 1.00000000E-06 mol/cm3
62+
1.00000000E+00 mM
63+
64+
65+
************** Starting Time Loop ******************
66+
67+
Done 10%; t,Eapp,i = 2.00E-02 3.00E-01 -7.11E-04, C_err= -2.87E-12
68+
0.8752 0.1248 0.0000 0.0000 0.0000 0.0000
69+
Done 20%; t,Eapp,i = 4.00E-02 1.00E-01 -1.47E-03, C_err= -1.78E-12
70+
0.0029 0.9971 0.0000 0.0000 0.0000 0.0000
71+
Done 30%; t,Eapp,i = 6.00E-02 -1.00E-01 -9.27E-04, C_err= -1.26E-12
72+
0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
73+
Done 40%; t,Eapp,i = 8.00E-02 -3.00E-01 -7.36E-04, C_err= -1.42E-12
74+
0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
75+
Done 50%; t,Eapp,i = 1.00E-01 -5.00E-01 -6.29E-04, C_err= -1.62E-12
76+
0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
77+
Done 60%; t,Eapp,i = 1.20E-01 -3.00E-01 -5.59E-04, C_err= -1.83E-12
78+
0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
79+
Done 70%; t,Eapp,i = 1.40E-01 -1.00E-01 -5.08E-04, C_err= -2.06E-12
80+
0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
81+
Done 80%; t,Eapp,i = 1.60E-01 1.00E-01 -4.51E-04, C_err= -3.06E-12
82+
0.0029 0.9971 0.0000 0.0000 0.0000 0.0000
83+
Done 90%; t,Eapp,i = 1.80E-01 3.00E-01 2.10E-03, C_err= -6.10E-13
84+
0.8747 0.1253 0.0000 0.0000 0.0000 0.0000
85+
Done 100%; t,Eapp,i = 2.00E-01 5.00E-01 6.93E-04, C_err= -2.34E-12
86+
0.9999 0.0001 0.0000 0.0000 0.0000 0.0000
87+
88+
Concentration min/max values:
89+
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
90+
1.0000 1.0000 0.0000 0.0000 0.0000 0.0000
91+
92+
****************************************************
93+
94+
Current minimum = -2.68622429E-03 and maximum = 2.24577576E-03
95+
Voltage minimum = 2.21557617E-01 and maximum = 2.78686523E-01
96+
97+
Average number of iterations at electrode surface = 1.000
98+
Average number of iterations for chemical reactions = 1.000
99+
Average ODE calculations for iterating surface conf = 0.000
100+
Average ODE calculations for bounding surface conf = 0.000
101+
102+
Final scaled concentrations on spatial grid
103+
[A] = 9.99940454E-01 9.98716251E-01 9.96076410E-01 | 9.99998347E-01
104+
[B] = 5.95460837E-05 1.28374882E-03 3.92359046E-03 | 1.65337954E-06
105+
106+
Error in concentration sum (=0 if D_A = D_B etc)
107+
-2.34245956E-12 -2.34312569E-12 -2.34601227E-12 | 6.50146603E-13
108+
109+
110+
Output file written to MECSimOutput_Pot.txt
111+
112+
113+
Additional files written to
114+
EC_Model.tvc - time, Eapp and concentrations for all time steps (first number is #species)
115+
EC_Model.fin - final concentrations against distance from electrode
116+

notebooks/outfile.sk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
10.0 ! Dstar_min
1616
0.005e0 ! max voltage step
1717
25.6e0 ! time resolution experimentally to correct vscan/f (us)
18-
0 ! show debug output files as well as MECSimOutput.txt (1=yes; 0=no)
18+
1 ! show debug output files as well as MECSimOutput.txt (1=yes; 0=no)
1919
0 ! use advanced voltage ramp (0 = E_start=E_end, 1 = use advanced ramp below, 2=From file "EInput.txt")
2020
2 ! number of E_rev lines for advanced ramp (if enter 0 then first E_rev value is the final time
2121
0.0 ! E_start (V)

setup.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from setuptools import setup,find_packages
2+
import sys, os
3+
4+
setup(name="pymecsim",
5+
description="Python Cyclic Voltammetry Simulator",
6+
version='1.0',
7+
author='Kiran Vaddi',
8+
author_email='[email protected]',
9+
license='MIT',
10+
python_requires='>=3.6',
11+
install_requires=['numpy','scipy', 'pandas'],
12+
extras_require = {},
13+
packages=find_packages(),
14+
long_description=open('Readme.md').read()
15+
)

src/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .pymecsim import *
1+
#from .pymecsim import *
2+
from .utils import pysed
3+
from .core import MECSIM
-3.44 KB
Binary file not shown.

0 commit comments

Comments
 (0)