Skip to content

Commit

Permalink
Added Reaction class to pyrate.reaction module.
Browse files Browse the repository at this point in the history
The Reaction class can be used to represent a chemical reaction and its
associated properties, e.g. kinetics model.
  • Loading branch information
jwallen committed Feb 11, 2012
1 parent cd2c34a commit 3d1356f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pyrate/reaction.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,22 @@
#
################################################################################

from pyrate.kinetics.model cimport KineticsModel

################################################################################

cdef class TransitionState:

cdef public str label
cdef public object statmech
cdef double _frequency

################################################################################

cdef class Reaction:

cdef public list reactants
cdef public list products
cdef public bint reversible
cdef public TransitionState transitionState
cdef public KineticsModel kinetics
45 changes: 45 additions & 0 deletions pyrate/reaction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,48 @@ cdef class TransitionState:
self._frequency = 0.0
else:
self._frequency = float(units.convertFrequency(value, pq.wavenumber))

################################################################################

cdef class Reaction:
"""
A chemical reaction. The attributes are:
======================= ====================================================
Attribute Description
======================= ====================================================
`reactants` The list of reactant species
`products` The list of product species
`kinetics` The kinetics model to use for the reaction
`reversible` ``True`` if the reaction is reversible, ``False`` if not
`transitionState` Information about the transition state
======================= ====================================================
"""

def __init__(self, reactants=None, products=None, kinetics=None, reversible=True, transitionState=None):
self.reactants = reactants or []
self.products = products or []
self.kinetics = kinetics
self.reversible = reversible
self.transitionState = transitionState

def __str__(self):
"""
Return a string representation of the reaction, in the form 'A + B <=> C + D'.
"""
arrow = ' <=> '
if not self.reversible: arrow = ' -> '
return arrow.join([' + '.join([str(s) for s in self.reactants]), ' + '.join([str(s) for s in self.products])])

def __repr__(self):
"""
Return a string representation of the reaction.
"""
return 'Reaction(reactants={0!r}, products={1!r}, kinetics={2!r}, reversible={3!r}, transitionState={4!r})'.format(self.reactants, self.products, self.kinetics, self.reversible, self.transitionState)

def __reduce__(self):
"""
A helper function used when pickling an object.
"""
return (Reaction, (self.reactants, self.products, self.kinetics, self.reversible, self.transitionState))

0 comments on commit 3d1356f

Please sign in to comment.