def moveCell(self, cell, shiftVector):
        #we have to make two list of pixels :
        pixelsToDelete = []  #used to hold pixels to delete
        pixelsToMove = []  #used to hold pixels to move

        # If we try to reassign pixels in the loop where we iterate over pixel data we will corrupt the container so in the loop below all we will do is to populate the two list mentioned above
        pixelList = self.getCellPixelList(cell)
        pt = CompuCell.Point3D()
        print " Moving ", pixelList.numberOfPixels(
        ), " pixels of cell.id=", cell.id, " . Shift vector=", shiftVector
        for pixelTrackerData in pixelList:
            pt.x = pixelTrackerData.pixel.x + shiftVector.x
            pt.y = pixelTrackerData.pixel.y + shiftVector.y
            pt.z = pixelTrackerData.pixel.z + shiftVector.z
            # here we are making a copy of the cell
            print "adding pt=", pt
            pixelsToDelete.append(CompuCell.Point3D(pixelTrackerData.pixel))

            if self.checkIfInTheLattice(pt):
                pixelsToMove.append(CompuCell.Point3D(pt))
                # self.cellField.set(pt,cell)

        # Now we will move cell
        for pixel in pixelsToMove:
            #             self.cellField.set(pixel,cell)
            self.cellField[pixel.x, pixel.y, pixel.z] = cell

        # Now we will delete old pixels
        pixelList = self.getCellPixelList(cell)
        pt = CompuCell.Point3D()

        self.mediumCell = CompuCell.getMediumCell()
        print " Deleting ", len(pixelsToDelete), " pixels of cell.id=", cell.id
        for pixel in pixelsToDelete:
            self.cellField[pixel.x, pixel.y, pixel.z] = self.mediumCell
Esempio n. 2
0
    def step(self,mcs):
        for cell in self.cellList:            
            if cell.type==3:                
                    
                pt=CompuCell.Point3D()    
                for x in range (9,17):
                    for y in range (9,17):
                        pt.x=x
                        pt.y=y
                        if int(self.boundaryArray.get(pt)):
                                print 'pt=',pt,' boundary=',int(self.boundaryArray.get(pt))
            if not self.pixelAssigned:
                 
                 pt=CompuCell.Point3D(12,12,0)
                 self.cellField.set(pt,self.mediumCell)
                 self.pixelAssigned=True
            if mcs==3:
                pt=CompuCell.Point3D(12,12,0)
                self.cellField.set(pt,cell)
                print 'REASSIGNMNET COMPLETED'

            if mcs==4:
                pt=CompuCell.Point3D(12 ,10,0)
                self.cellField.set(pt,self.mediumCell)
            if mcs==5:
                pt=CompuCell.Point3D(12 ,11,0)
                self.cellField.set(pt,self.mediumCell)
                
                # print 'REASSIGNMNET COMPLETED'
                
            break
             
    def step(self, mcs):
        if mcs == 10:

            shiftVector = CompuCell.Point3D(20, 20, 0)

            for cell in self.cellList:
                self.moveCell(cell, shiftVector)

        if mcs == 20:
            pt = CompuCell.Point3D(50, 50, 0)
            self.createNewCell(2, pt, 5, 5, 1)

        if mcs == 30:
            for cell in self.cellList:
                self.deleteCell(cell)
Esempio n. 4
0
    def step(self, mcs):
        pass
        # for cell in self.cellList:
        #     cell.targetVolume+=1
        # alternatively if you want to make growth a function of chemical concentration uncomment lines below and comment lines above
        O2field = CompuCell.getConcentrationField(self.simulator, "OXYGEN")
        MMPfield = CompuCell.getConcentrationField(self.simulator, "MMP")
        pt = CompuCell.Point3D()
        for cell in self.cellList:
            pt.x = int(cell.xCOM)
            pt.y = int(cell.yCOM)
            pt.z = int(cell.zCOM)
            O2Conc = O2field.get(pt)
            MMPConc = MMPfield.get(pt)
            if O2Conc < 0: print('--------~~~~~~~~~-----> O2 VERY LOW')
            print '------///------>', cell.targetVolume, O2Conc, MMPConc
            if cell.type == self.NORM and MMPConc > 1:
                print 'MMP CONC IS CRAZY!'
                # raw_input('!')
                cell.targetVolume -= 0.5
                cell.lambdaVolume = 2
                # raw_input('!-->removing a NORM cell')
            else:
                # if True:
                if cell.type == self.TPROL and O2Conc < 0:
                    cell.type = self.TMIGR
                    continue
                # O2Conc = np.abs(O2Conc)

                cell.targetVolume += 0.01 * O2Conc / (
                    0.05 + O2Conc
                )  # you can use here any fcn of concentrationAtCOM
Esempio n. 5
0
    def findMinMax(self, conField, dim):
        import CompuCell
        pt = CompuCell.Point3D()

        maxCon = 0
        minCon = 0
        for k in range(dim[2]):
            for j in range(dim[1]):
                for i in range(dim[0]):
                    pt.x = i
                    pt.y = j
                    pt.z = k

                    con = float(conField.get(pt))

                    if maxCon < con:
                        maxCon = con

                    if minCon > con:
                        minCon = con

        # Make sure that the concentration is positive
        if minCon < 0:
            minCon = 0

        return (minCon, maxCon)
 def generateEllipsoid(self,_semiMinorAxis,_semiMedianAxis,_semiMajorAxis):        
     pt=CompuCell.Point3D(self.dim.x/2,self.dim.y/2,self.dim.z/2)
     cell=self.potts.createCell()
     cell.type=1
     
     for x,y,z in self.everyPixel():
         if (x-self.dim.x/2.0)**2/_semiMinorAxis**2+(y-self.dim.y/2.0)**2/_semiMajorAxis**2+(z-self.dim.z/2.0)**2/_semiMedianAxis**2 <1:
             self.cellField[x,y,z]=cell                        
Esempio n. 7
0
 def getConcentrationFieldAtCell(self, fieldName, cell):
     chemField = CompuCell.getConcentrationField(self.simulator, fieldName)
     pt = CompuCell.Point3D()
     pt.x = int(round(cell.xCOM))
     pt.y = int(round(cell.yCOM))
     pt.z = int(round(cell.zCOM))
     #         pt.x=int(round(cell.xCM/max(float(cell.volume),0.001)))
     #         pt.y=int(round(cell.yCM/max(float(cell.volume),0.001)))
     #         pt.z=int(round(cell.zCM/max(float(cell.volume),0.001)))
     return chemField.get(pt)
Esempio n. 8
0
    def generateEllipse(self, _semiMinorAxis, _semiMajorAxis):
        pt = CompuCell.Point3D(self.dim.x / 2, self.dim.y / 2, 0)
        cell = self.potts.createCellG(pt)
        cell.type = 1

        for x in range(self.dim.x):
            for y in range(self.dim.y):
                if (x - self.dim.x / 2.0)**2 / _semiMinorAxis**2 + (
                        y - self.dim.y / 2.0)**2 / _semiMajorAxis**2 < 1:
                    pt.x = x
                    pt.y = y
                    self.cellField.set(pt, cell)
 def step(self,mcs):
    cell=None
    cellFieldG=self.cellFieldG
    for x in xrange(self.dim.x):
       for y in xrange(self.dim.y):
          for z in xrange(self.dim.z):
             pt=CompuCell.Point3D(x,y,z)
             cell=cellFieldG.get(pt)
             if cell:
                conSpecSet(self.scalarField,x,y,z,self.contactProductPlugin.getJVecValue(cell,0))
             else:
                conSpecSet(self.scalarField,x,y,z,0.0)
Esempio n. 10
0
    def step(self, mcs):
        #    for cell in self.cellList:
        #   cell.targetVolume+=1
        # alternatively if you want to make growth a function of chemical concentration uncomment lines below and comment lines above
        # field=CompuCell.getConcentrationField(self.simulator,"PUT_NAME_OF_CHEMICAL_FIELD_HERE")
        # pt=CompuCell.Point3D()
        field = CompuCell.getConcentrationField(self.simulator, "R")  #####
        comPt = CompuCell.Point3D()  #####

        for cell in self.cellList:
            if cell.type == self.P:  #####
                comPt.x = int(cell.xCOM)
                comPt.y = int(cell.yCOM)
                comPt.z = int(cell.zCOM)
                concentrationAtCOM = field.get(comPt)
                cell.targetVolume += 0.01 * concentrationAtCOM  # you can use here any fcn of concentrationAtCOM
Esempio n. 11
0
    def step(self, mcs):
        field = CompuCell.getConcentrationField(self.simulator, "Sactivator")
        comPt = CompuCell.Point3D()
        meanCon = 0.0

        for cell in self.cellList:
            if cell.id == 1:
                comPt.x = int(round(cell.xCOM))
                comPt.y = int(round(cell.yCOM))
                comPt.z = int(round(cell.zCOM))

                con = field.get(comPt)
                meanCon += con

                # get concentration at comPt

        self.Activator.addDataPoint("Activator", mcs, meanCon)
Esempio n. 12
0
   def outputField(self,_fieldName,_fileName):
      field=CompuCell.getConcentrationField(self.simulator,_fieldName)
      pt=CompuCell.Point3D()
      if field:
         try:
            fileHandle=open(_fileName,"w")
         except IOError:
            print "Could not open file ", _fileName," for writing. Check if you have necessary permissions"

         print "dim.x=",self.dim.x
         for i in xrange(self.dim.x):
            for j in xrange(self.dim.y):
               for k in xrange(self.dim.z):
                  pt.x=i
                  pt.y=j
                  pt.z=k
                  fileHandle.write("%d\t%d\t%d\t%f\n"%(pt.x,pt.y,pt.z,field.get(pt)))
Esempio n. 13
0
    def step(self, mcs):

        field = CompuCell.getConcentrationField(self.simulator,
                                                "Firstinhibitor")
        fielt = CompuCell.getConcentrationField(self.simulator, "Sactivator")
        fiell = CompuCell.getConcentrationField(self.simulator,
                                                "Secondinhibitor")
        comPt = CompuCell.Point3D()
        # concentrationAI=field.get(comPt)
        #concentrationA=fielt.get(comPt)
        for cell in self.cellList:
            if cell.type == self.UD or cell.type == self.G:
                if mcs > 0 and field[
                        cell.xCOM, cell.yCOM, cell.zCOM] < 0.5 and fiell[
                            cell.xCOM, cell.yCOM,
                            cell.zCOM] > 0.5 and fielt[cell.xCOM, cell.yCOM,
                                                       cell.zCOM] > 20:
                    cell.type = self.OF
                if mcs > 0 and fiell[
                        cell.xCOM, cell.yCOM, cell.zCOM] < 0.5 and field[
                            cell.xCOM, cell.yCOM,
                            cell.zCOM] > 0.5 and fielt[cell.xCOM, cell.yCOM,
                                                       cell.zCOM] > 20:
                    cell.type = self.OS

                if mcs > 0 and fiell[
                        cell.xCOM, cell.yCOM, cell.zCOM] < 0.5 and field[
                            cell.xCOM, cell.yCOM,
                            cell.zCOM] < 0.5 and fielt[cell.xCOM, cell.yCOM,
                                                       cell.zCOM] > 20:
                    if random() < 0.5:
                        cell.type = self.OS
                    else:
                        cell.type = self.OF
        #concentration=field[int(round(cell.xCOM)),int(round(cell.yCOM)),int(round(cell.zCOM))]
        #type here the code that will run every _frequency MCS
        for cell in self.cellList:
            currentCellPosition = cell.xCM / float(cell.volume)
            currentCellPositiony = cell.yCM / float(cell.volume)
            firstinhi = field[cell.xCOM, cell.yCOM, cell.zCOM]
            secondinhi = fiell[cell.xCOM, cell.yCOM, cell.zCOM]
            sactivator = fielt[cell.xCOM, cell.yCOM, cell.zCOM]
            print("id=", cell.id, "posx= ", currentCellPosition, "posy= ",
                  currentCellPositiony, "Fi= ", firstinhi, "Si= ", secondinhi,
                  "Sac= ", sactivator)
Esempio n. 14
0
    def step(self, mcs):
        fieldMMP = CompuCell.getConcentrationField(self.simulator,
                                                   self.fieldNameMMP)
        fieldI = CompuCell.getConcentrationField(self.simulator,
                                                 self.fieldNameI)
        fieldGF = CompuCell.getConcentrationField(self.simulator,
                                                  self.fieldNameGF)
        comPt = CompuCell.Point3D()
        state = {}
        global c
        global ck
        global mcsOut
        global c_value
        global varii
        for cell in self.cellList:

            #collagen fibre elongation
            if cell.type == self.C1 and mcs < 5:
                cell.targetVolume += 0.8
                cell.lambdaVolume = 20.0

            if cell.type == self.CANCER:
                neighborList = self.getCellNeighborDataList(cell)
                k = neighborList.commonSurfaceAreaWithCellTypes(
                    cell_type_list=[3])
                s = cell.surface
                g = (s - k) / 40
                GFc = fieldGF[int(round(cell.xCOM)),
                              int(round(cell.yCOM)),
                              int(round(cell.zCOM))]
                cell.targetVolume += varii * (
                    (g / 4 + (GFc / 7)) / 3)  #Growth rate
                cell.lambdaVolume = 20.0  #this term can be changed in correlation with stiffness of neighbors, as a fn of neighbor type,no etc
                if int(round(cell.xCOM)) > 97 or int(round(
                        cell.xCOM)) < 3 or int(round(cell.yCOM)) > 97 or int(
                            round(cell.yCOM)) < 3:
                    self.deleteCell(cell)
                    c += 1
                    if c == 1:
                        mcsOut = mcs

        ck = c
        if ck != 0 and mcs % 5 == 0:
            c_value.append(ck)
    def step(self, mcs):
        antibioticField = CompuCell.getConcentrationField(
            self.simulator, 'Antibiotic')
        for cell in self.cellList:
            if cell.type != self.MEDIUM:
                # get concentration at cells COM
                cellCOM = CompuCell.Point3D()
                cellCOM.x = int(round(cell.xCOM))
                cellCOM.y = int(round(cell.yCOM))
                cellCOM.z = int(round(cell.zCOM))
                antibioticConcentration = antibioticField.get(cellCOM)

                # calculate damage based on concentration and ARF
                cellDict = CompuCell.getPyAttrib(cell)
                cellDict["Damage"] += (
                    1 -
                    cellDict["ARF"]) * antibioticConcentration * DAMAGE_FACTOR
                if cellDict["Damage"] >= 1:  # too much damage -> die
                    cell.targetVolume = 0
                    cell.lambdaVolume = 100
    def calculateHTBL(self):

        cellSurfaceManualCalculation = 0
        pt = CompuCell.Point3D()

        for x in xrange(self.dim.x):
            for y in xrange(self.dim.y):
                for z in xrange(self.dim.z):

                    cell = self.cellField[x, y, z]

                    if cell:
                        for pixelNeighbor in self.getPixelNeighborsBasedOnNeighborOrder(
                                pt, 1):
                            nCell = self.cellField[pixelNeighbor.pt.x,
                                                   pixelNeighbor.pt.y,
                                                   pixelNeighbor.pt.z]
                            if CompuCell.areCellsDifferent(nCell, cell):
                                cellSurfaceManualCalculation += 1

        return cellSurfaceManualCalculation
    def step(self, mcs):
        field = CompuCell.getConcentrationField(self.simulator, "Oxygen")

        FiPyInteractor = FiPyInterface.FiPyInterfaceBase(
            2)  #dimension of lattice (currently, 2D only works)

        FiPyInteractor.fillArray3D(self.solver.phi._getArray(), field)
        doNotDiffuseVec = FiPyInteractor.getDoNoDiffuseVec()
        self.solver.setDoNotDiffuse(doNotDiffuseVec)
        self.solver.iterateDiffusion()

        pt = CompuCell.Point3D(0, 0, 0)
        print '\n', field.get(pt),
        sumField = 0
        for i in xrange(self.dim.x):
            for j in xrange(self.dim.y):
                for k in xrange(self.dim.z):
                    pt.x = i
                    pt.y = j
                    pt.z = k
                    sumField += field.get(pt)
        print sumField
Esempio n. 18
0
 def step(self, mcs):
     cells_to_divide = []
     field = self.getConcentrationField("GROWTH_REPRESSOR")
     #if (mcs > 1400) & (mcs <= 1500):
     #    self.EDU = True
     #else:
     #    self.EDU = False
     comPt = CompuCell.Point3D()
     for cell in self.cellListByType(self.SUPPORTINGCELL):
         cellDict = self.getDictionaryAttribute(cell)
         comPt.x = int(round(cell.xCOM))
         comPt.y = int(round(cell.yCOM))
         comPt.z = int(round(cell.zCOM))
         fv = field.get(comPt)
         if ((cell.volume > div_volume) & (fv < threshold) &
             (cellDict['RefCount'] < 1)):
             cells_to_divide.append(cell)
         if (fv > threshold):
             #cell.lambdaVolume=9.
             cell.targetVolume = max(div_volume, cell.targetVolume - 0.01)
     for cell in cells_to_divide:
         self.divideCellRandomOrientation(
             cell)  #Divide cells at random orientations
Esempio n. 19
0
    def step(self, mcs):

        # print " ||||||||||||| in CompuCell3D steppable:  'HelpfileCellDrawSteppable' step(mcs = %s)"%(mcs)

        if (self.savedPIF is False) and (mcs > 100):

            # open output file, and make sure that it's writable:
            # lCurrentDirectory = os.getcwd()
            # print lCurrentDirectory
            # print os.umask(022)
            # print os.umask(022)

            lFileName = os.path.join(self.theHelperOutputDirectoryForCellDraw,
                                     "helpfileoutputfrompotts.piff")
            try:
                lFile = open(lFileName, 'w')
            except:
                print " ||||||||||||| in CompuCell3D steppable:  'HelpfileCellDrawSteppable' step(mcs = %s) can not write file %s ||||||||||||| " % (
                    mcs, lFileName)
                return False

            # erase any 'flag' file:
            lFlagFileName = "flagfile.text"
            if os.path.isfile(lFlagFileName):
                os.remove(lFlagFileName)

            # this would be Qt's way to open files, but we use plain Python calls here:
#             lOutputFileName=os.path.join(os.getcwd(),"helpfileoutputfrompotts.piff")
#             lFile = QtCore.QFile(lOutputFileName)
#             lOnlyThePathName,lOnlyTheFileName = os.path.split(str(lOutputFileName))
#             if not lFile.open( QtCore.QFile.WriteOnly | QtCore.QFile.Text):
#                 return False
#             # open a QTextStream, i.e. an "interface for reading and writing text":
#             lOutputStream = QtCore.QTextStream(lFile)

# saving PIFF file cell IDs starting from 0 onwards is NOT used,
#    because we use CC3D's own cell IDs:
            lPixelID = 0

            for i in xrange(self.fieldXsize):
                for j in xrange(self.fieldYsize):
                    for k in xrange(self.fieldZsize):
                        lCell = self.cellFieldG.get(CompuCell.Point3D(i, j, k))
                        # avoid printing out Wall cells:
                        if lCell is not None:
                            if lCell.type is not 1:
                                # output one line per pixel to a second helpfile PIFF to be re-read by PIFF Generator:
                                # print "i=",i,"","j=",j,"","k=",k,"","lCell=",lCell
                                # NOTE NOTE NOTE: this is NOT the cell type name (where is that stored?)
                                #    but the cell type number, and PIFF Generator will have to convert it back to the cell name:
                                lTheCellTypeName = lCell.type
                                lTheCellID = lCell.id
                                xmin = i
                                xmax = i
                                ymin = j
                                ymax = j
                                zmin = k
                                zmax = k
                                lOutputLine = str(lTheCellID) + " " + \
                                    str(lTheCellTypeName) + " " + \
                                    str(xmin) + " " + \
                                    str(xmax) + " " + \
                                    str(ymin) + " " + \
                                    str(ymax) + " " + \
                                    str(zmin) + " " + \
                                    str(zmax) + "\n"
                                # print lOutputLine
                                lFile.write(lOutputLine)
                                lPixelID += 1

            lFile.close()

            # create 'flag' file, and make sure that it's writable:
            # erase any 'flag' file:
            lFlagFileName = os.path.join(
                self.theHelperOutputDirectoryForCellDraw, "flagfile.text")
            try:
                lFile = open(lFlagFileName, 'w')
            except:
                print " ||||||||||||| in CompuCell3D steppable:  'HelpfileCellDrawSteppable' step(mcs = %s) can not write file %s ||||||||||||| " % (
                    mcs, lFlagFileName)
                return False
            lFile.write("PIFF output from CC3D done.\n")
            lFile.close()

            self.savedPIF = True
Esempio n. 20
0
from PySteppables import *
   #  D 2D/3D  |   N  | #Pixels 2D/3D
   #  1  /  1  |   1  |    4 / 6
   # 1.5 / 1.5 |   2  |    8 / 18
   #  2  / 1.8 |   3  |   12 / 26
   # 2.3 /  2  |   4  |   20 / 32
   # 2.9 / 2.3 |   5  |   24 / 56
   #  3  / 2.5 |   6  |   28 / 80
   # 3.2 / 2.9 |   7  |   36 / 92
   # 3.7 /  3  |   8  |   44 / 122
   #     / 3.2 |   9  |   48 / 146
   #     / 3.5 |  10  |      / 170
   #     / 3.7 |  11  |      / 178
   #     / 3.8 |  12  |      / 202
   #     /     |  13  |      / 250
   
   pt=CompuCell.Point3D(x,y,z)
   for i in xrange(self.maxNeighborIndex+1): 
     pN=self.boundaryStrategy.getNeighborDirect(pt,i) #pt = original pixel
     cell2=self.cellField.get(pN.pt) #pN.pt = neighbor pixel
 #
 FPP Links Manipulation:
   for fpp in self.getFocalPointPlasticityDataList(cell):
     cell2=fpp.neighborAddress
     targetDistance=fpp.targetDistance
     lambdaDistance=fpp.lambdaDistance
     self.focalPointPlasticityPlugin.createFocalPointPlasticityLink(cell,cell2,lambda,targetDistance,maxDistance)
     self.focalPointPlasticityPlugin.setFocalPointPlasticityParameters(cell,cell2,lambda,targetDistance,maxDistance)
     self.focalPointPlasticityPlugin.deleteFocalPointPlasticityLink(cell,cell2)
   for fpp in self.getInternalFocalPointPlasticityDataList(cell):
     cell2=fpp.neighborAddress
     targetDistance=fpp.targetDistance
Esempio n. 22
0
 def setInjectionPoint(self,_x,_y,_z):
    self.injectionPoint=CompuCell.Point3D(int(_x),int(_y),int(_z))