00001 "This module contains definitions of basic classes that are used to construct Python based Steppables"
00002
00003
00004
00005 class SimObjectPy:
00006 def __init__(self):pass
00007 def init(self,_simulator):
00008 self.simulator=_simulator
00009 def extraInit(self,_simulator):
00010 self.simulator=_simulator
00011
00012 class SteppablePy(SimObjectPy):
00013 def __init__(self,_frequency=1):
00014 self.frequency=_frequency
00015
00016
00017 def setFrequency(self,_freq):
00018 self.frequency=_freq
00019 def start(self):pass
00020 def step(self,_mcs):pass
00021 def finish(self):pass
00022
00023
00024 class SteppableBasePy(SteppablePy):
00025 def __init__(self,_simulator,_frequency=1):
00026 SteppablePy.__init__(self,_frequency)
00027 self.simulator=_simulator
00028 self.potts=_simulator.getPotts()
00029 self.cellField=self.potts.getCellFieldG()
00030 self.dim=self.cellField.getDim()
00031 self.inventory=self.simulator.getPotts().getCellInventory()
00032 self.cellList=CellList(self.inventory)
00033
00034
00035
00036 class SteppableRegistry(SteppablePy):
00037 def __init__(self):
00038 self.steppableList=[]
00039
00040 def registerSteppable(self,_steppable):
00041 self.steppableList.append(_steppable)
00042
00043 def init(self,_simulator):
00044 for steppable in self.steppableList:
00045 steppable.init(_simulator)
00046
00047 def extraInit(self,_simulator):
00048 for steppable in self.steppableList:
00049 steppable.extraInit(_simulator)
00050
00051 def start(self):
00052 for steppable in self.steppableList:
00053 steppable.start()
00054
00055 def step(self,_mcs):
00056 for steppable in self.steppableList:
00057 if not _mcs % steppable.frequency:
00058 steppable.step(_mcs)
00059
00060 def finish(self):
00061 for steppable in self.steppableList:
00062 steppable.finish()
00063
00064
00065
00066
00067 class CellList:
00068 def __init__(self,_inventory):
00069 self.inventory = _inventory
00070 def __iter__(self):
00071 return CellListIterator(self)
00072
00073 class CellListIterator:
00074 def __init__(self, _cellList):
00075 import CompuCell
00076 self.inventory = _cellList.inventory
00077 self.invItr=CompuCell.STLPyIteratorCINV()
00078 self.invItr.initialize(self.inventory.getContainer())
00079 self.invItr.setToBegin()
00080 def next(self):
00081 if not self.invItr.isEnd():
00082 self.cell = self.invItr.getCurrentRef()
00083 self.invItr.next()
00084 return self.cell
00085 else:
00086 raise StopIteration
00087 def __iter__(self):
00088 return self
00089
00090 class CellNeighborList:
00091 def __init__(self,_neighborTrackerAccessor,_cell):
00092 self.neighborTrackerAccessor = _neighborTrackerAccessor
00093 self.cell=_cell
00094 def __iter__(self):
00095 return CellNeighborIterator(self)
00096
00097
00098 class CellNeighborIterator:
00099 def __init__(self, _cellNeighborList):
00100 import CompuCell
00101 self.neighborTrackerAccessor = _cellNeighborList.neighborTrackerAccessor
00102 self.cell=_cellNeighborList.cell
00103 self.nsdItr=CompuCell.nsdSetPyItr()
00104 self.nTracker=self.neighborTrackerAccessor.get(self.cell.extraAttribPtr)
00105 self.nsdItr.initialize(self.nTracker.cellNeighbors)
00106 self.nsdItr.setToBegin()
00107
00108 def next(self):
00109 if not self.nsdItr.isEnd():
00110 self.neighborCell = self.nsdItr.getCurrentRef().neighborAddress
00111 self.nsdItr.next()
00112 return self.neighborCell
00113 else:
00114 raise StopIteration
00115 def __iter__(self):
00116 return self
00117
00118
00119 class CellNeighborListAuto:
00120 def __init__(self,_neighborPlugin,_cell):
00121 self.neighborPlugin=_neighborPlugin
00122 self.neighborTrackerAccessor=self.neighborPlugin.getNeighborTrackerAccessorPtr()
00123 self.cell=_cell
00124 def __iter__(self):
00125 return CellNeighborIteratorAuto(self)
00126
00127
00128
00129 class CellNeighborIteratorAuto:
00130 def __init__(self, _cellNeighborList):
00131 import CompuCell
00132 self.neighborTrackerAccessor = _cellNeighborList.neighborTrackerAccessor
00133 self.cell=_cellNeighborList.cell
00134 self.nsdItr=CompuCell.nsdSetPyItr()
00135 self.nTracker=self.neighborTrackerAccessor.get(self.cell.extraAttribPtr)
00136 self.nsdItr.initialize(self.nTracker.cellNeighbors)
00137 self.nsdItr.setToBegin()
00138
00139
00140 def next(self):
00141 if not self.nsdItr.isEnd():
00142 self.neighborCell = self.nsdItr.getCurrentRef().neighborAddress
00143 self.currentNsdItr = self.nsdItr.current
00144 self.currentNeighborSurfaceData=self.nsdItr.getCurrentRef()
00145 self.nsdItr.next()
00146 return self.currentNeighborSurfaceData
00147 else:
00148 raise StopIteration
00149
00150 def __iter__(self):
00151 return self
00152
00153
00154 class CellBoundaryPixelList:
00155
00156 def __init__(self,_boundaryPixelTrackerPlugin,_cell):
00157 self.boundaryPixelTrackerPlugin=_boundaryPixelTrackerPlugin
00158 self.boundaryPixelTrackerAccessor=self.boundaryPixelTrackerPlugin.getBoundaryPixelTrackerAccessorPtr()
00159 self.cell=_cell
00160
00161 def __iter__(self):
00162 return CellBoundaryPixelIterator(self)
00163
00164 def numberOfPixels(self):
00165 return self.boundaryPixelTrackerAccessor.get(self.cell.extraAttribPtr).pixelSet.size()
00166
00167
00168
00169 class CellBoundaryPixelIterator:
00170 def __init__(self, _cellPixelList):
00171 import CompuCell
00172 self.boundaryPixelTrackerAccessor = _cellPixelList.boundaryPixelTrackerAccessor
00173 self.boundaryPixelTrackerPlugin=_cellPixelList.boundaryPixelTrackerPlugin
00174 self.cell=_cellPixelList.cell
00175 self.boundaryPixelItr=CompuCell.boundaryPixelSetPyItr()
00176 self.boundaryPixelTracker=self.boundaryPixelTrackerAccessor.get(self.cell.extraAttribPtr)
00177 self.boundaryPixelItr.initialize(self.boundaryPixelTracker.pixelSet)
00178 self.boundaryPixelItr.setToBegin()
00179
00180
00181 def next(self):
00182 if not self.boundaryPixelItr.isEnd():
00183
00184
00185 self.currentBoundaryPixelTrackerData=self.boundaryPixelItr.getCurrentRef()
00186 self.boundaryPixelItr.next()
00187 return self.boundaryPixelTrackerPlugin.getBoundaryPixelTrackerData(self.currentBoundaryPixelTrackerData)
00188
00189 else:
00190 raise StopIteration
00191
00192 def __iter__(self):
00193 return self
00194
00195
00196 class CellPixelList:
00197
00198 def __init__(self,_pixelTrackerPlugin,_cell):
00199 self.pixelTrackerPlugin=_pixelTrackerPlugin
00200 self.pixelTrackerAccessor=self.pixelTrackerPlugin.getPixelTrackerAccessorPtr()
00201 self.cell=_cell
00202
00203 def __iter__(self):
00204 return CellPixelIterator(self)
00205
00206 def numberOfPixels(self):
00207 return self.pixelTrackerAccessor.get(self.cell.extraAttribPtr).pixelSet.size()
00208
00209
00210
00211 class CellPixelIterator:
00212 def __init__(self, _cellPixelList):
00213 import CompuCell
00214 self.pixelTrackerAccessor = _cellPixelList.pixelTrackerAccessor
00215 self.pixelTrackerPlugin=_cellPixelList.pixelTrackerPlugin
00216 self.cell=_cellPixelList.cell
00217 self.pixelItr=CompuCell.pixelSetPyItr()
00218 self.pixelTracker=self.pixelTrackerAccessor.get(self.cell.extraAttribPtr)
00219 self.pixelItr.initialize(self.pixelTracker.pixelSet)
00220 self.pixelItr.setToBegin()
00221
00222
00223 def next(self):
00224 if not self.pixelItr.isEnd():
00225
00226
00227 self.currentPixelTrackerData=self.pixelItr.getCurrentRef()
00228 self.pixelItr.next()
00229 return self.pixelTrackerPlugin.getPixelTrackerData(self.currentPixelTrackerData)
00230
00231 else:
00232 raise StopIteration
00233
00234 def __iter__(self):
00235 return self
00236
00237 class PlasticityDataList:
00238 def __init__(self,_plasticityTrackerPlugin,_cell):
00239 self.plasticityTrackerPlugin=_plasticityTrackerPlugin
00240 self.plasticityTrackerAccessor=self.plasticityTrackerPlugin.getPlasticityTrackerAccessorPtr()
00241 self.cell=_cell
00242 def __iter__(self):
00243 return PlasticityDataIterator(self)
00244
00245
00246 class PlasticityDataIterator:
00247 def __init__(self, _plasticityDataList):
00248 import CompuCell
00249 self.plasticityTrackerAccessor = _plasticityDataList.plasticityTrackerAccessor
00250 self.cell=_plasticityDataList.cell
00251 self.plasticityTrackerPlugin=_plasticityDataList.plasticityTrackerPlugin
00252 self.plasticityTracker=self.plasticityTrackerAccessor.get(self.cell.extraAttribPtr)
00253 self.plasticityDataSetItr=CompuCell.plasticitySetPyItr()
00254 self.plasticityDataSetItr.initialize(self.plasticityTracker.plasticityNeighbors)
00255 self.plasticityDataSetItr.setToBegin()
00256
00257 def next(self):
00258 if not self.plasticityDataSetItr.isEnd():
00259 self.currentPlasticityDataSetItr = self.plasticityDataSetItr.current
00260 self.plasticityData=self.plasticityDataSetItr.getCurrentRef()
00261 self.plasticityDataSetItr.next()
00262 return self.plasticityTrackerPlugin.getPlasticityTrackerData(self.plasticityData)
00263
00264 else:
00265 raise StopIteration
00266
00267 def __iter__(self):
00268 return self
00269
00270
00271 class RealPlasticityDataList:
00272 def __init__(self,_realplasticityTrackerPlugin,_cell):
00273 self.realplasticityTrackerPlugin=_realplasticityTrackerPlugin
00274 self.realplasticityTrackerAccessor=self.realplasticityTrackerPlugin.getRealPlasticityTrackerAccessorPtr()
00275 self.cell=_cell
00276 def __iter__(self):
00277 return RealPlasticityDataIterator(self)
00278
00279
00280 class RealPlasticityDataIterator:
00281 def __init__(self, _realplasticityDataList):
00282 import CompuCell
00283 self.realplasticityTrackerAccessor = _realplasticityDataList.realplasticityTrackerAccessor
00284 self.cell=_realplasticityDataList.cell
00285 self.realplasticityTrackerPlugin=_realplasticityDataList.realplasticityTrackerPlugin
00286 self.realplasticityTracker=self.realplasticityTrackerAccessor.get(self.cell.extraAttribPtr)
00287 self.realplasticityDataSetItr=CompuCell.realplasticitySetPyItr()
00288 self.realplasticityDataSetItr.initialize(self.realplasticityTracker.realplasticityNeighbors)
00289 self.realplasticityDataSetItr.setToBegin()
00290
00291 def next(self):
00292 if not self.realplasticityDataSetItr.isEnd():
00293 self.currentRealPlasticityDataSetItr = self.realplasticityDataSetItr.current
00294 self.realplasticityData=self.realplasticityDataSetItr.getCurrentRef()
00295 self.realplasticityDataSetItr.next()
00296 return self.realplasticityTrackerPlugin.getRealPlasticityTrackerData(self.realplasticityData)
00297
00298 else:
00299 raise StopIteration
00300
00301 def __iter__(self):
00302 return self
00303
00304
00305
00306
00307
00308 def forEachCellInInventory(inventory,singleCellOperation):
00309 import CompuCell
00310 invItr=CompuCell.STLPyIteratorCINV()
00311 invItr.initialize(inventory.getContainer())
00312 invItr.setToBegin()
00313 cell=invItr.getCurrentRef()
00314 while (not invItr.isEnd()):
00315 cell=invItr.getCurrentRef()
00316 singleCellOperation(cell)
00317 invItr.next()