Organic-Kinetics (okin) is a collection of chemistry-related Python tools
Project description
OKIN
Organic Kinetics is a package to perform tasks useful for understanding kinetic behaviour in organic chemistry.
Requires python >= 3.9 unless CMake is available then python >=3.8.
Installation
From PyPI:
pip install okin
Usage
1. ChemDraw Parser
Parse reactions/mechanistic cycles directly from ChemDraw .cdxml files, allowing you to extract and work with reaction information.
Example:
from okin.cd_parser.cd_parser import CDParser
# Load a ChemDraw file
cd_parser = CDParser(file_path="base_cycle.cdxml", draw=True)
# Extract all reactions
reactions = cd_parser.find_reactions()
print(f"Reactions found in {cd_parser.file_path}:")
for rct in reactions:
print(rct)
file_path: Path to your ChemDraw.cdxmlfile.draw=True: Optionally renders the Chemdraw File with the bounding boxes. These determine which parts to treat as one reaction or a new one.find_reactions(): Returns a list of reaction objects parsed from the file, which can be used for other functions of this package (simulation, VTNA, or modeling).
2. Rate Equations
Calculate the Steady-State rate equation for a given mechanism.
Example:
from okin.simulation.rate_equation import RateEquation
# Define reactions (reversible or irreversible)
reactions = ["A + cat <==> cat1", "cat1 + B -> cat + P", "B + cat -> cat_I"]
rate_eq = RateEquation(reactions)
# Display LaTeX rate law
print(rate_eq.debug_string)
rate_eq.show_latex_rate_law()
- The used catalytic species need to be named
catfor base catalyst andcat<nr>e.g.cat1for all intermediates. Deactivated cat needs to be namedcatI. - Reversible reactions should use
<==>; irreversible reactions use->. show_latex_rate_law()renders the final rate law in LaTeX format. If latex is not available it prints the LaTeX string.rate_eq.debug_stringshows the math that has been performed
3. Simulation
Okin allows you to simulate chemical reaction kinetics over time with specified rate constants and initial concentrations.
Example:
from okin.simulation.simulator import Simulator
import matplotlib.pyplot as plt
from okin.base.chem_plot_utils import apply_acs_layout
# Define reactions, rate constants, and initial concentrations
reactions = ["A + cat -> cat1", "cat1 + B -> cat + P", "X + cat -> cat_deact"]
k_dict = {"k1": 10, "kN1": 5, "k2": 3, "kN2": 0, "k3": 0.005, "kN3": 0}
c_dict = {"A": 1.0, "B": 1.2, "cat": 0.05, "P": 0.0, "X": 0.1}
# Setup and run simulation
sim = Simulator()
sim.setup(reactions, k_dict, c_dict)
sim.simulate(start=0, stop=80, nr_time_points=40)
# Access results
df = sim.result
# Plot results
plt.scatter(df["time"], df["A"])
plt.scatter(df["time"], df["B"])
plt.scatter(df["time"], df["P"])
plt.xlabel("time")
plt.ylabel("concentration")
apply_acs_layout()
plt.show()
setup()takes reactions as strings, rate constants (k_dict), and initial concentrations (c_dict).simulate()runs the time evolution over a specified range with a given number of points.- Results are stored in
sim.resultas a DataFrame for plotting or further analysis. - Reversibility is determined by k-values and not by arrows.
4. VTNA (Variable Time Normalization Analysis)
Determine reaction orders via VTNA (https://pubs.rsc.org/en/content/articlelanding/2019/sc/c8sc04698k).
Example:
from okin.kinetics.vtna import ClassicVTNA
# Assuming df1 and df2 are results from two simulations or experiments
vtna = ClassicVTNA(df_rct1=df1, df_rct2=df2, species_col_name="cat", product_col_name="P", time_col_name="time")
# Best kinetic order for the species
print(f"Best order for cat: {vtna.best_order}")
# Plot normalized VTNA data
vtna.show_plot()
df_rct1,df_rct2: DataFrames containing time-course data for two experiments that only vary in one concentration.species_col_name: Name of the species for which the initial concentration was changed. Same name as the provided data.product_col_name: Name of the column used to track reaction progress. Same name as the provided data.time_col_name: Name of the time column. Same name as the provided data.show_plot(): Visualizes the normalized reaction rates for comparison.
5. Modeling with COPASI
Okin integrates with COPASI (https://copasi.org/) to build and fit kinetic models from experimental data.
Example:
from okin.model.modler import Modler
# Initialize Modler with local COPASI path
modler = Modler(copasi_path=r"D:\python_code\hein_modules\local_copasi")
# Set reaction mechanism
reactions = ["A + cat -> cat1", "cat1 + B -> cat + P", "X + cat -> cat_I"]
modler.set_m_reactions(reactions)
# Add experimental CSV data
modler.add_experiment_csv(["data1.csv","data2.csv"])
# Specify species for model fitting
modler.set_species_for_model(["P","A"])
modler.set_species_to_match(["P","A","B"])
# Configure COPASI optimization settings
modler.set_copasi_settings({"number_of_generations":50,"population_size":50})
# Create and fit the model
modler.create_single_model()
modler.show_model_fit(save_modeled_data=True, show_all=True)
copasi_path: Path to the local COPASI folder (LINK WILL BE ADDED SOON)reactions: List of reactions defining the mechanism.experiment CSV files: Paths to one or more CSV files with experimental data .species_for_model: Species used for internal error calculations.species_to_match: Species used by COPASI to fit the model.copasi_settings: Dictionary of COPASI optimization parameterscreate_single_model(): Runs COPASI.show_model_fit(): Displays the fitted model and optionally saves modeled data.
License
This project is licensed under the MIT License.
Future
This project will receive updates in the near future.
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 okin-0.1.2.tar.gz.
File metadata
- Download URL: okin-0.1.2.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d71a1fcee3be779ba8a6520589110d72577d53266612007030a9e0537e32b604
|
|
| MD5 |
3e158a4ebd1e4e14c1bf20b06e8c88af
|
|
| BLAKE2b-256 |
9770403d37f3bf687d43e04493436a9d3cbe4a950598871223c005e1f2783396
|
File details
Details for the file okin-0.1.2-py3-none-any.whl.
File metadata
- Download URL: okin-0.1.2-py3-none-any.whl
- Upload date:
- Size: 64.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c78a39c3db4fc940f67d61c1e5d4d77ac92a3ea44aea833e1f2390a3e059c396
|
|
| MD5 |
9a82597df4c73246d4d7fe5e9e12fe1c
|
|
| BLAKE2b-256 |
d9b0d9ff1eabe83b9714a6dd060941b8482a300860656b3b90e1b919816cd5d1
|