Package SloppyCell :: Package ReactionNetworks :: Module Components
[hide private]

Source Code for Module SloppyCell.ReactionNetworks.Components

  1  import logging 
  2  logger = logging.getLogger('ReactionNetworks.Components') 
  3   
  4  import sets 
  5   
  6  import SloppyCell.ExprManip as ExprManip 
  7   
  8  # 
  9  # Containers for the more complex SBML entities. 
 10  # 
 11   
12 -class FunctionDefinition:
13 - def __init__(self, id, variables, math, name = ''):
14 self.id = id 15 self.variables = variables 16 self.math = math 17 self.name = name
18
19 - def __eq__(self, other):
20 return self.__class__ == other.__class__ and \ 21 (self.__dict__ == other.__dict__)
22
23 - def __ne__(self, other):
24 return not (self == other)
25
26 -class Variable:
27 - def __init__(self, id, value, 28 name, typicalValue, 29 is_constant, is_optimizable):
30 31 if typicalValue is None: 32 if value and not isinstance(value, str): 33 typicalValue = abs(value) 34 else: 35 typicalValue = 1 36 37 self.id, self.name = id, name 38 self.value, self.initialValue = value, value 39 self.typicalValue = typicalValue 40 self.is_constant, self.is_optimizable = is_constant, is_optimizable
41
42 - def __eq__(self, other):
43 return self.__class__ == other.__class__ and \ 44 (self.__dict__ == other.__dict__)
45
46 -class Compartment(Variable):
47 - def __init__(self, id, initial_size, name, typical_value, 48 is_constant, is_optimizable):
49 Variable.__init__(self, id, initial_size, name, typical_value, 50 is_constant, is_optimizable)
51
52 -class Species(Variable):
53 - def __init__(self, id, compartment, initial_conc, 54 name, typical_value, 55 is_boundary_condition, 56 is_constant, is_optimizable, uniprot_ids=set()):
57 self.compartment = compartment 58 self.is_boundary_condition = is_boundary_condition 59 self.uniprot_ids = uniprot_ids 60 61 Variable.__init__(self, id, initial_conc, 62 name, typical_value, 63 is_constant, is_optimizable)
64
65 -class Parameter(Variable):
66 - def __init__(self, id, value, name, 67 is_constant, typical_value, is_optimizable):
68 Variable.__init__(self, id, value, 69 name, typical_value, 70 is_constant, is_optimizable)
71
72 -class Event:
73 - def __init__(self, id, trigger, event_assignments, delay, name, 74 buffer):
75 self.id, self.name = id, name 76 self.delay = delay 77 self.is_terminal = (len(event_assignments) > 0) 78 79 self.timeTriggered = False 80 self.parseTrigger(trigger) 81 82 self.event_assignments = event_assignments 83 self.new_values = {} 84 85 self.buffer=buffer 86 if (self.buffer > 0 and self.delay != 0): 87 logger.warn('Event %s has buffer > 0 and delay != 0. This case ' 88 'has not been tested.')
89 90
91 - def __eq__(self, other):
92 # This is a little tricky, because Event objects get modified when their 93 # corresponding event fires. (Probably a poor design.) 94 # So we need to only compare the important attributes. 95 attrs_to_compare = ['__class__', 'id', 'trigger', 'event_assignments', 96 'delay', 'name'] 97 for attr in attrs_to_compare: 98 if getattr(self, attr) != getattr(other, attr): 99 return False 100 return True
101
102 - def __ne__(self, other):
103 return not (self == other)
104
105 - def parseTrigger(self, trigger):
106 if '<' in trigger or '>' in trigger or '=' in trigger: 107 raise ValueError('Event triggers must use the functions gt and lt, ' 108 'rather than the symbols > and <. For example, ' 109 'to trigger when B becomes less than A, use ' 110 'lt(B,A).') 111 112 # Figures out if the event is time-triggered and parses it to niceness. 113 114 # 'and' is a reserved keyword in python, so the parser will break 115 # unless we substitute the name here. 116 trigger = trigger.replace('and(', 'and_func(') 117 118 self.trigger = trigger 119 120 if ExprManip.extract_vars(trigger) == sets.Set(['time']): 121 self.timeTriggered = True 122 ast = ExprManip.AST.strip_parse(trigger) 123 firstArg = ExprManip.AST.ast2str(ast.args[0]) 124 secondArg = ExprManip.AST.ast2str(ast.args[1]) 125 126 if firstArg == 'time': 127 self.triggeringTime = eval(secondArg) 128 elif secondArg == 'time': 129 self.triggeringTime = eval(firstArg) 130 else: 131 raise 'Problem in time triggered events'
132
133 -class ConstraintEvent(Event):
134 - def __init__(self, id, trigger, message, name):
135 self.id, self.name = id, name 136 self.delay = 0.0 137 self.is_terminal = True 138 self.event_assignments = {} 139 self.message = message 140 141 self.timeTriggered = False 142 self.parseTrigger(trigger) 143 self.buffer=0.0
144 145 146 147 148 149 # This is a placeholder object that will be used to store information about 150 # events during integrations.
151 -class event_info(object):
152 pass
153