Library Usage
Creating a model from scratch
Lets assume the following compounds and reactions:
A 0.0 kcal/mol
B 0.0 kcal/mol
C 2.0 kcal/mol
D -2.0 kcal/mol
A + B <=> C !10.0 kcal/mol
C => D !18.0 kcal/mol
Now we create the model from scratch assuming a T of 25ºC.
from pykinetic.classes import (ChemicalSystem, Energy, Compound, Reaction,
TransitionState)
from pykinetic.writers.python import Batch as Writer
# We initialize the ChemicalSystem
chemsys = ChemicalSystem(T=298.15)
# Now we create the compounds
A = Compound(A,Energy(0.0,'kcal/mol'))
B = Compound(B,Energy(1.0,'kcal/mol'))
C = Compound(C,Energy(2.0,'kcal/mol'))
D = Compound(D,Energy(-2.0,'kcal/mol'))
# we can now add them one by one to the system:
# chemsys.cadd(A)
# chemsys.cadd(B)
# ...
# or create a list and add them all
compounds = [A,B,C,D]
chemsys.cextend(compounds,update=True)
# if we dont update=True we will have to do it "manually"
# chemsys.cupdate()
# Now we create the reactions
r1d = Reaction(reactants=(A,B),products=(C,))
r1i = Reaction(reactants=(C,),products=(A,B))
r2 = Reaction(reactants=(C,),products=(D,))
# we can ignore the T parameter as it will be automatically set up by the
# ChemicalSystem object
# We create the TSs and assign them to their reactions
TS1 = TransitionState(Energy(10.0,'kcal/mol'),label='TS1',reactions=[r1d,r1i])
TS2 = TransitionState(Energy(18.0,'kcal/mol'),label='TS2')
TS2.reactions.append(r2)
# Now we add the reactions to the ChemicalSystem. Now we use radd or rextend.
chemsys.radd(r1d)
chemsys.radd(r1i)
chemsys.radd(r2)
# Now we have our chemical system already set up. Now we proceed to write it.
writer = Writer()
writer.write(chemsys,'model.py')
Modifying and loading a model
from pykinetic.classes import (Energy, Compound, Reaction,
TransitionState)
from pykinetic.utils import BiasedChemicalSystem, calc_standard_state_correction
from pykinetic.writers.python import Batch as Writer
from pykinetic.userinput import populate_chemicalsystem_fromfiles
# We initialize the ChemicalSystem and we want to apply a SS correction
# from 1 atm -> 1 M
std_correction = calc_standard_state_correction(T=298.15)
chemsys = BiasedChemicalSystem(unit='kcal/mol',T=298.15)
file_c = 'compounds.txt'
file_r = 'reactions.txt'
# Now we add from the files the compounds, reactions and TSs.
populate_chemicalsystem_fromfiles(chemsys,file_c,file_r,
energy_unit='kcal/mol',
relativeE=True)
# Now we apply the bias. The biased system adds the bias to all the
# compounds and TSs. In this case it is applying the standard state correction
# from 1 atm -> 1 M.
chemsys.apply_bias()
# The default bias is 0.0, but it is important to run this method after
# adding all the compounds and reactions when the bias is not 0.
# we can write the model without the bias now
writer = Writer()
writer.write(chemsys,'model.py')
# Now we can change the bias if we decide so
chemsys.bias = calc_standard_state_correction(T=298.15)
# Now we proceed to write the model with std state correction.
writer.write(chemsys,'model_stdcorr.py')