base
This module contains the Writer classes that are in charge of translating the provided chemical system to the different languages or formats as well as the Base class to inherit from, 'Writer'. Currently only python and c++ are supported. This module depends on the template files that come with the libary.
- pykinetic.writers._base.Indent(lines, tab=' ', level=1)[source]
Takes an iterable of strings, each representing a line and returns them with the indentation level and character specified.
Writer
- class pykinetic.writers._base.Writer(conc_var='x', mb_var='dxdt', fun_var='model', jac_var='Jac', jac_fun_var='jacobian', header=None, tail=None)[source]
Base class of a writer object. A writer object allows the customized translation of a kinetic model into a script to carry out its simulation in a specific language and under a specific system constraints.
- constant(reaction, value_format)[source]
Takes in a reaction and returns 2 expressions, the string of the variable and the string with the value of the constant. I.e.
# Reaction(1 => 2)
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
'k01', '1.00000000' = PythonWriter.constant(A)
- Parameters:
reaction (Reaction) -- Any reaction
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- fill(chemicalsys)[source]
Reads the information of the chemical system and updates the values needed for writing.
- abstract jacobian_element(Jac_ij)[source]
Takes the partial differential of a MB and returns the variable of the jacobian and the string of the expression. I.e.
# Given a Chemical system with only Reaction('A <=> B')
# d[A]dt = -r1 + r2 = -k01[A] + k2[B]
# being A.key = 0 and B.key = 1
C = <JacobianElement(Reaction(1),Compound(A))>
'Jac[0,0]', '-k01' = PythonWriter.jacobian_element(A)
- Parameters:
Jac_ij (JacobianElement) -- Any JacobianElement object
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- abstract massbalance(Massbalance)[source]
Takes in a mass balance and returns 2 expressions, the string of the variable and the string of the expression. I.e.
# Given a Chemical system with only Reaction('A <=> B')
# d[A]dt = -r1 + r2 = -k01[A] + k2[B]
# being A.key = 0 and B.key = 1
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
'dxdt[0]', '-k01*x[1] +k02[B]' = PythonWriter.massbalance(A)
- Parameters:
reaction (MassBalance) -- Any MassBalance
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- abstract ratelaw(reaction)[source]
Takes in a reaction and returns 2 expressions, the string of the variable and the string of the ratelaw expression. I.e. # Reaction(1 => 2) A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)> 'r01', 'k01*x[1]' = PythonWriter.ratelaw(A)
- Parameters:
reaction (Reaction) -- Any reaction
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- abstract ratelaw_partial(reaction, compound)[source]
Takes in a reaction and returns and the string of the partial derivative the ratelaw with respect to the concentration of compound. I.e.
# Reaction(1 => 2), Compound 1
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
# r01,'k01*x[1]'ratelaw(A)
'k01' = PythonWriter.ratelaw_partial(A)