00001
00002
00003 "This module contains examples of certain more and less useful steppables written in Python"
00004 from CompuCell import NeighborFinderParams
00005
00006
00007 import CompuCell
00008
00009 class InventoryIteration:
00010 def __init__(self,_inventory):
00011 self.inventory=_inventory
00012 def iterate(self):
00013 invItr=CompuCell.STLPyIteratorCINV()
00014 invItr.initialize(self.inventory.getContainer())
00015 invItr.setToBegin()
00016 cell=invItr.getCurrentRef()
00017 while (1):
00018 if invItr.isEnd():
00019 break
00020 cell=invItr.getCurrentRef()
00021 print "CELL ID=",cell.id
00022 invItr.next()
00023
00024
00025
00026 from PySteppables import *
00027
00028 class TargetVolumeSteppable(SteppablePy):
00029 def __init__(self,_frequency=1):
00030 SteppablePy.__init__(self,_frequency)
00031 self.inventory=None
00032 self.inc=0
00033 def setInitialTargetVolume(self,_tv):
00034 self.tv=_tv
00035 def init(self,_simulator):
00036 self.simulator=_simulator
00037 self.inventory=self.simulator.getPotts().getCellInventory()
00038 self.cellList=CellList(self.inventory)
00039
00040 def setIncrement(sel,_inc):
00041 self.inc=_inc
00042
00043 def start(self):
00044 for cell in self.cellList:
00045 print "CELL ID=",cell.id
00046 cell.targetVolume=self.tv
00047
00048 def step(self,mcs):
00049 for cell in self.cellList:
00050 print "CELL ID=",cell.id, "targetVolume=",cell.targetVolume
00051 cell.targetVolume+=self.inc
00052
00053
00054 import CompuCell
00055
00056 class ConcentrationFieldDumper(SteppablePy):
00057 def __init__(self,_simulator,_frequency=1):
00058 SteppablePy.__init__(self,_frequency)
00059 self.simulator=_simulator
00060 self.dim=self.simulator.getPotts().getCellFieldG().getDim()
00061 self.fieldNameList=[]
00062 def setFieldName(self,_fieldName):
00063 self.fieldName=_fieldName
00064 self.fieldNameList.append(_fieldName)
00065 def step(self,mcs):
00066 for name in self.fieldNameList:
00067 fileName=name+"_"+str(mcs)+".dat"
00068 print "Field from the list:",fileName
00069 self.outputField(name,fileName)
00070
00071
00072 def outputField(self,_fieldName,_fileName):
00073 field=CompuCell.getConcentrationField(self.simulator,_fieldName)
00074 pt=CompuCell.Point3D()
00075 if field:
00076 try:
00077 fileHandle=open(_fileName,"w")
00078 except IOError:
00079 print "Could not open file ", _fileName," for writing. Check if you have necessary permissions"
00080
00081 print "dim.x=",self.dim.x
00082 for i in xrange(self.dim.x):
00083 for j in xrange(self.dim.y):
00084 for k in xrange(self.dim.z):
00085 pt.x=i
00086 pt.y=j
00087 pt.z=k
00088 fileHandle.write("%d\t%d\t%d\t%f\n"%(pt.x,pt.y,pt.z,field.get(pt)))
00089
00090
00091 import CompuCell
00092
00093 class TargetVolumeDrosoSteppable(SteppablePy):
00094 def __init__(self,_frequency=1):
00095 SteppablePy.__init__(self,_frequency)
00096 self.inventory=None
00097
00098
00099 def setInitialTargetVolume(self,_tv):
00100 self.tv=_tv
00101 def setInitialLambdaVolume(self,_lambdaVolume):
00102 self.lambdaVolume=_lambdaVolume
00103 def init(self,_simulator):
00104 self.simulator=_simulator
00105 self.inventory=self.simulator.getPotts().getCellInventory()
00106 self.cellList=CellList(self.inventory)
00107
00108 def start(self):
00109
00110 for cell in self.cellList:
00111 print "CELL ID=",cell.id
00112 cell.targetVolume=self.tv
00113 cell.lambdaVolume=self.lambdaVolume
00114
00115 def step(self,mcs):
00116 xCM=0
00117 yCM=0
00118 yCM=0
00119
00120 for cell in self.cellList:
00121 print "Cell.id=",cell.id," volume=",cell.volume
00122 xCM=cell.xCM/float(cell.volume)
00123 yCM=cell.yCM/float(cell.volume)
00124 zCM=cell.zCM/float(cell.volume)
00125 if ((xCM-100)**2+(yCM-100)**2) < 400:
00126 cell.targetVolume+=1
00127
00128 class BlobSimpleTypeInitializer(SteppablePy):
00129 def __init__(self,_simulator,_frequency=1):
00130 SteppablePy.__init__(self,_frequency)
00131 self.simulator=_simulator
00132 self.inventory=self.simulator.getPotts().getCellInventory()
00133 self.cellList=CellList(self.inventory)
00134 def start(self):
00135 for cell in self.cellList:
00136 print "Blob Initializer CELL ID=",cell.id
00137 cell.type=1
00138
00139
00140 from random import randint
00141 class BlobSimpleTypeInitializerRandom(SteppablePy):
00142 def __init__(self,_simulator,_frequency=1):
00143 SteppablePy.__init__(self,_frequency)
00144 self.simulator=_simulator
00145 self.inventory=self.simulator.getPotts().getCellInventory()
00146 self.cellList=CellList(self.inventory)
00147 self.maxType=1
00148 def setMaxType(self,_maxType):
00149 if _maxType>=1:
00150 self.maxType=_maxType
00151 def start(self):
00152 for cell in self.cellList:
00153 print "Blob Initializer CELL ID=",cell.id
00154 cell.type=randint(1,self.maxType)
00155
00156 invItr.next()
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 import sys
00181 import CompuCell
00182 class ModifyAttribute(SteppablePy):
00183 def __init__(self,_simulator,_frequency=1):
00184 SteppablePy.__init__(self,_frequency)
00185 self.simulator=_simulator
00186 self.inventory=self.simulator.getPotts().getCellInventory()
00187 self.cellList=CellList(self.inventory)
00188 def start(self):
00189 for cell in self.cellList:
00190 print " MODIFY ATTRIB CELL ID=",cell.id
00191
00192
00193
00194 pyAttrib=CompuCell.getPyAttrib(cell)
00195 print "ref count=",sys.getrefcount(pyAttrib)
00196
00197
00198 print "length=",len(pyAttrib)
00199 pyAttrib[0:1]=[cell.id*4]
00200 print "Cell attrib=",pyAttrib[0]
00201 print "length=",len(pyAttrib)
00202 pyAttrib.append(14)
00203 print "Cell attrib=",pyAttrib[1]
00204 print "length=",len(pyAttrib)
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 def step(self,mcs):
00220 for cell in self.cellList:
00221
00222 pyAttrib=CompuCell.getPyAttrib(cell)
00223 pyAttrib[0]=[cell.id*mcs,cell.id*(mcs-1)]
00224 if not mcs % 20:
00225 print "CELL ID modified=",pyAttrib," true=",cell.id,
00226 print " ref count=",sys.getrefcount(pyAttrib),
00227 print " ref count=",sys.getrefcount(pyAttrib)
00228
00229
00230 class ModifyDictAttribute(SteppablePy):
00231 def __init__(self,_simulator,_frequency=1):
00232 SteppablePy.__init__(self,_frequency)
00233 self.simulator=_simulator
00234 self.inventory=self.simulator.getPotts().getCellInventory()
00235 self.cellList=CellList(self.inventory)
00236 def start(self):
00237 for cell in self.cellList:
00238 print " MODIFY ATTRIB CELL ID=",cell.id
00239 dictionary=CompuCell.getPyAttrib(cell)
00240 dictionary["newID"]=cell.id*2
00241 print "NewID=",dictionary["newID"]
00242
00243
00244 def step(self,mcs):
00245 for cell in self.cellList:
00246 if not mcs % 20:
00247 dictionary=CompuCell.getPyAttrib(cell)
00248 print "NewID=",dictionary["newID"]
00249
00250
00251 class CellKiller(SteppablePy):
00252 def __init__(self,_simulator,_frequency=10):
00253 SteppablePy.__init__(self,_frequency)
00254 self.simulator=_simulator
00255 self.inventory=self.simulator.getPotts().getCellInventory()
00256 self.cellList=CellList(self.inventory)
00257
00258 def step(self,mcs):
00259 for cell in self.cellList:
00260 print "Step cell.targetVolume=",cell.targetVolume
00261 if mcs==10:
00262 cell.targetVolume=0
00263 print "cell.targetVolume=",cell.targetVolume
00264
00265
00266 import CompuCell
00267
00268 class ContactLocalFlexPrinter(SteppablePy):
00269 def __init__(self,_frequency=1):
00270 SteppablePy.__init__(self,_frequency)
00271 self.inventory=None
00272 self.inc=0
00273
00274
00275 def init(self,_simulator):
00276 self.simulator=_simulator
00277 self.inventory=self.simulator.getPotts().getCellInventory()
00278 self.ContactLocalFlexPlugin=CompuCell.getContactLocalFlexPlugin()
00279 self.cellList=CellList(self.inventory)
00280 def setIncrement(sel,_inc):
00281 self.inc=_inc
00282
00283 def step(self,mcs):
00284 if(mcs<2):
00285 return
00286 if not (mcs %10):
00287 containerAccessor=self.ContactLocalFlexPlugin.getContactDataContainerAccessorPtr()
00288 clfdItr=CompuCell.clfdSetPyItr()
00289 for cell in self.cellList:
00290 container=containerAccessor.get(cell.extraAttribPtr)
00291
00292 clfdItr.initialize(container.contactDataContainer)
00293 clfdItr.setToBegin()
00294
00295 while not clfdItr.isEnd():
00296 print "is End=",clfdItr.isEnd()
00297 neighborCell=clfdItr.getCurrentRef().neighborAddress
00298 if neighborCell:
00299 print "neighbor.id",neighborCell.id," contact energy=",clfdItr.getCurrentRef().J
00300 else:
00301 print "neighbor.id=0 contact energy=",clfdItr.getCurrentRef().J
00302 clfdItr.next()
00303
00304
00305
00306
00307
00308
00309 from CompuCell import Point3D
00310
00311 class AirInjector(SteppablePy):
00312 def __init__(self,_simulator,_frequency=1):
00313 SteppablePy.__init__(self,_frequency)
00314 self.simulator=_simulator
00315 self.potts=self.simulator.getPotts()
00316 self.inventory=self.potts.getCellInventory()
00317 self.cellField=self.potts.getCellFieldG()
00318 self.cellList=CellList(self.inventory)
00319 self.volumeIncrement=0
00320 def start(self):pass
00321
00322 def setInjectionPoint(self,_x,_y,_z):
00323 self.injectionPoint=CompuCell.Point3D(int(_x),int(_y),int(_z))
00324
00325 def setVolumeIncrement(self,_increment):
00326 self.volumeIncrement=_increment
00327 def step(self,mcs):
00328 cell=self.cellField.get(self.injectionPoint)
00329 if cell:
00330 cell.targetVolume+=self.volumeIncrement
00331 print "INCREASED TARGET VOLUME TO:",cell.targetVolume
00332
00333
00334
00335 class BubbleCellRemover(SteppablePy):
00336 def __init__(self,_simulator,_frequency=1):
00337 SteppablePy.__init__(self,_frequency)
00338 self.simulator=_simulator
00339 self.inventory=self.simulator.getPotts().getCellInventory()
00340 self.cellList=CellList(self.inventory)
00341 self.coordName='X'
00342 self.cutoffValue=0;
00343 def start(self):pass
00344
00345 def setCutoffCoordinate(self,_coordName,_cutoffValue):
00346
00347 if _coordName=='x' or _coordName=='X':
00348 self.coordName='X'
00349 elif _coordName=='y' or _coordName=='Y':
00350 self.coordName='Y'
00351 elif _coordName=='z' or _coordName=='Z':
00352 self.coordName='Z'
00353 else:
00354 print "Coordinate Name must be of x or y or z"
00355 return
00356
00357 self.cutoffValue=_cutoffValue
00358
00359 def checkIfOKToRemove(self,cell):
00360 if not cell:
00361 return 0
00362 elif cell.volume==0:
00363 return 1
00364 if self.coordName=='X':
00365 xCM=cell.xCM/float(cell.volume)
00366 if xCM>=self.cutoffValue:
00367 return 1
00368 else:
00369 return 0
00370
00371 if self.coordName=='Y':
00372 yCM=cell.yCM/float(cell.volume)
00373 if yCM>=self.cutoffValue:
00374 return 1
00375 else:
00376 return 0
00377
00378 if self.coordName=='Z':
00379 zCM=cell.zCM/float(cell.volume)
00380 if zCM>=self.cutoffValue:
00381 return 1
00382 else:
00383 return 0
00384
00385 def step(self,mcs):
00386 for cell in self.cellList:
00387
00388 if self.checkIfOKToRemove(cell):
00389 cell.targetVolume=0
00390
00391 from CompuCell import Point3D
00392 from random import randint
00393
00394 class BubbleNucleator(SteppablePy):
00395 def __init__(self,_simulator,_frequency=1):
00396 SteppablePy.__init__(self,_frequency)
00397 self.simulator=_simulator
00398 self.inventory=self.simulator.getPotts().getCellInventory()
00399 self.cellList=CellList(self.inventory)
00400 self.coordName='X'
00401 self.numNewBubbles=0
00402 self.initCellType=0
00403 def start(self):
00404 self.Potts=self.simulator.getPotts()
00405 self.dim=self.Potts.getCellFieldG().getDim()
00406 print "Got here"
00407 def setNucleationAxis(self,_coordName):
00408 if _coordName=='x' or _coordName=='X':
00409 self.coordName='X'
00410 elif _coordName=='y' or _coordName=='Y':
00411 self.coordName='Y'
00412 elif _coordName=='z' or _coordName=='Z':
00413 self.coordName='Z'
00414 else:
00415 print "Coordinate Name must be of x or y or z"
00416 return
00417 def setNumberOfNewBubbles(self,_numNewBubbles):
00418 if _numNewBubbles>0:
00419 self.numNewBubbles=int(_numNewBubbles)
00420 def setInitialTargetVolume(self,_initTargetVolume):
00421 self.initTargetVolume=_initTargetVolume
00422
00423 def setInitialLambdaVolume(self,_initLambdaVolume):
00424 self.initLambdaVolume=_initLambdaVolume
00425
00426 def setInitialCellType(self,_initCellType):
00427 self.initCellType=_initCellType
00428
00429 def createNewCell(self,pt):
00430 print "Nucleated bubble at ",pt
00431 cell=self.Potts.createCellG(pt)
00432 cell.targetVolume=self.initTargetVolume
00433 cell.type=self.initCellType
00434 cell.lambdaVolume=self.initLambdaVolume
00435
00436 def nucleateBubble(self):
00437 pt=Point3D(0,0,0)
00438 if self.coordName=='X':
00439 pt.x=randint(0,self.dim.x-1)
00440 pt.y=3
00441 self.createNewCell(pt)
00442 if self.coordName=='Y':
00443 pt.y=randint(0,self.dim.y-1)
00444 pt.x=3
00445 self.createNewCell(pt)
00446
00447 if self.coordName=='Z':
00448 pt.z=randint(0,self.dim.z-1)
00449 self.createNewCell(pt)
00450
00451 def step(self,mcs):
00452 for i in xrange(self.numNewBubbles):
00453 self.nucleateBubble()
00454
00455
00456 class InitialTargetVolumeSteppable(SteppablePy):
00457 def __init__(self,_frequency=1):
00458 SteppablePy.__init__(self,_frequency)
00459 self.inventory=None
00460 def setInitialTargetVolume(self,_tv):
00461 self.tv=_tv
00462 def init(self,_simulator):
00463 self.simulator=_simulator
00464 self.inventory=self.simulator.getPotts().getCellInventory()
00465 self.cellList=CellList(self.inventory)
00466 def start(self):
00467 for cell in self.cellList:
00468 print "CELL ID=",cell.id
00469 cell.targetVolume=self.tv
00470
00471
00472
00473 import CompuCell
00474 class VolumeLocalFlexSteppableEye(SteppablePy):
00475 def __init__(self,_simulator,_frequency=1):
00476 SteppablePy.__init__(self,_frequency)
00477 self.simulator=_simulator
00478 self.volumeLocalFlexPlugin=CompuCell.getVolumeLocalFlexPlugin()
00479
00480 self.inventory=self.simulator.getPotts().getCellInventory()
00481 self.cellList=CellList(self.inventory)
00482 def start(self):
00483 for cell in self.cellList:
00484
00485
00486
00487 if cell.type==1:
00488 cell.lambdaVolume=50.0
00489 cell.targetVolume=370
00490 print "cell.lambdaVolume",cell.lambdaVolume
00491 elif cell.type==2:
00492 cell.lambdaVolume=2.0
00493 cell.targetVolume=100
00494 else:
00495 cell.lambdaVolume=0
00496 cell.targetVolume=0
00497
00498 def step(self,mcs):
00499 for cell in self.cellList:
00500 if cell.type==1 and cell.targetVolume<770:
00501 cell.targetVolume+=10
00502
00503 import CompuCell
00504 class NeighborInducedKiller(SteppablePy):
00505 def __init__(self,_simulator,_frequency=10):
00506 SteppablePy.__init__(self,_frequency)
00507 self.simulator=_simulator
00508 self.nTrackerPlugin=CompuCell.getNeighborTrackerPlugin()
00509
00510 self.inventory=self.simulator.getPotts().getCellInventory()
00511 self.cellList=CellList(self.inventory)
00512
00513 def step(self,mcs):
00514 for cell in self.cellList:
00515
00516
00517 killFlag=1
00518 if cell.type != 1:
00519 cellNeighborList=CellNeighborListAuto(self.nTrackerPlugin,cell)
00520 for neighborSurfaceData in cellNeighborList:
00521
00522 if neighborSurfaceData.neighborAddress and neighborSurfaceData.neighborAddress.type==1:
00523 killFlag=0
00524 break
00525 if killFlag:
00526 cell.targetVolume=0
00527
00528 from random import random
00529 import types
00530 class ContactLocalProductSteppable(SteppablePy):
00531 def __init__(self,_simulator,_frequency=10):
00532 SteppablePy.__init__(self,_frequency)
00533 self.simulator=_simulator
00534 self.contactProductPlugin=CompuCell.getContactLocalProductPlugin()
00535 self.inventory=self.simulator.getPotts().getCellInventory()
00536 self.cellList=CellList(self.inventory)
00537 def setTypeContactEnergyTable(self,_table):
00538 self.table=_table
00539
00540 def start(self):
00541 for cell in self.cellList:
00542 specificityObj=self.table[cell.type];
00543 if isinstance(specificityObj,types.ListType):
00544 self.contactProductPlugin.setJVecValue(cell,0,(specificityObj[1]-specificityObj[0])*random())
00545 else:
00546 self.contactProductPlugin.setJVecValue(cell,0,specificityObj)
00547
00548
00549 from PlayerPython import fillScalarValue as conSpecSet
00550 class ContactSpecVisualizationSteppable(SteppablePy):
00551 def __init__(self,_simulator,_frequency=10):
00552 SteppablePy.__init__(self,_frequency)
00553 self.simulator=_simulator
00554 self.contactProductPlugin=CompuCell.getContactLocalProductPlugin()
00555 self.cellFieldG=self.simulator.getPotts().getCellFieldG()
00556 self.dim=self.cellFieldG.getDim()
00557
00558 def setScalarField(self,_field):
00559 self.scalarField=_field
00560 def start(self):pass
00561
00562 def step(self,mcs):
00563 cell=None
00564 cellFieldG=self.cellFieldG
00565 for x in xrange(self.dim.x):
00566 for y in xrange(self.dim.y):
00567 for z in xrange(self.dim.z):
00568 pt=CompuCell.Point3D(x,y,z)
00569 cell=cellFieldG.get(pt)
00570 if cell:
00571 conSpecSet(self.scalarField,x,y,z,self.contactProductPlugin.getJVecValue(cell,0))
00572 else:
00573 conSpecSet(self.scalarField,x,y,z,0.0)
00574
00575 class PressureDumperSteppable(SteppablePy):
00576 def __init__(self,_frequency=1):
00577 SteppablePy.__init__(self,_frequency)
00578 self.inventory=None
00579 self.inc=0
00580 self.fixedTargetVolumeFlag=0
00581
00582
00583 def setFileName(self,_fileName):
00584 self.fileName=_fileName
00585 def init(self,_simulator):
00586 self.simulator=_simulator
00587 self.inventory=self.simulator.getPotts().getCellInventory()
00588 self.cellList=CellList(self.inventory)
00589 def setTargetVolume(self,_tv):
00590 self.targetVolume=_tv
00591 self.fixedTargetVolumeFlag=1
00592
00593 def start(self):
00594 self.file=open(self.fileName,"w")
00595
00596 def step(self,mcs):
00597 self.file.write("%d\t" % (mcs) )
00598 for cell in self.cellList:
00599 if self.fixedTargetVolumeFlag:
00600 self.file.write("%f\t" % (self.targetVolume-cell.volume) )
00601 else:
00602 self.file.write("%f\t" % (cell.targetVolume-cell.volume) )
00603 self.file.write("\n")
00604
00605 class IncrementPluginTargetVolume(SteppablePy):
00606 def __init__(self,_simulator,_frequency=1):
00607 SteppablePy.__init__(self,_frequency)
00608 self.simulator=_simulator
00609 self.inventory=self.simulator.getPotts().getCellInventory()
00610 self.cellList=CellList(self.inventory)
00611 def setVolumePlugin(self, _volumeEnergy):
00612 self.volumeEnergy=_volumeEnergy
00613 def step(self,mcs):
00614 self.volumeEnergy.vt+=1
00615
00616
00617