Beispiel #1
0
 def calculates(self, cell):
     if self.__isLocalSearch:
         newcell = self.__LocalSearch.initLocalSearch(cell)
     else:
         newcell = Gene()
         newcell.copyGene(cell)  #copy.deepcopy(cell)
     auxLigand = copy.deepcopy(self.__ligand)
     if self.__isKB:
         for i in range(len(auxLigand.branch)):
             torAngle = auxLigand.rotateBranchKB(i, newcell.rotateBonds[i])
             auxLigand.rotateAtomsBranch(i, torAngle)
     else:
         for i in range(len(auxLigand.branch)):
             auxLigand.rotateAtomsBranch(i, newcell.rotateBonds[i])
     auxLigand.translateToPoint([
         self.__centerSpace[0] + newcell.x,
         self.__centerSpace[1] + newcell.y,
         self.__centerSpace[2] + newcell.z
     ])
     sphVect = spherePoint(1, newcell.sph_theta, newcell.sph_phi)
     auxLigand.rotateByVector(sphVect, newcell.theta)
     auxLigand.writePDBQT(self.__temporalDir + "ligand.pdbqt")
     newcell.score = calculateFreeEnergy()
     self.__numberScoring += 1
     return newcell  #copy.deepcopy(newcell)
Beispiel #2
0
 def getNeighbor(self, cell):
     newCell = Gene()
     newCell.copyGene(cell)
     if self.__typeLS == 0:
         newCell = self.mutationBlock(newCell)
     elif self.__typeLS == 1:
         alpha = self.__tempIterative
         newCell = self.mutationReduce(newCell, alpha)
     elif self.__typeLS == 2:
         newCell = self.mutationRot(newCell)
     newCell = self.calculates(newCell)
     return newCell
Beispiel #3
0
    def crossoverSPC(self, selectedCell1, selectedCell2):
        pop1 = []
        pop2 = []

        pop1.append(selectedCell1.x)
        pop1.append(selectedCell1.y)
        pop1.append(selectedCell1.z)
        pop1.append(selectedCell1.sph_theta)
        pop1.append(selectedCell1.sph_phi)
        pop1.append(selectedCell1.theta)

        for angle in selectedCell1.rotateBonds:
            pop1.append(angle)

        pop2.append(selectedCell2.x)
        pop2.append(selectedCell2.y)
        pop2.append(selectedCell2.z)
        pop2.append(selectedCell2.sph_theta)
        pop2.append(selectedCell2.sph_phi)
        pop2.append(selectedCell2.theta)

        for angle in selectedCell2.rotateBonds:
            pop2.append(angle)

        genSize = len(pop1)
        cutPoint = random.randint(0, genSize - 1)
        length = random.randint(0, genSize - 1)
        if length == 0:
            return selectedCell1
        elif length > (genSize - cutPoint):
            newPop = pop1[cutPoint:]
            turnTop = length - (genSize - cutPoint)
            for i in range(0, turnTop):
                newPop.insert(i, pop1[i])
            for i in range(turnTop, cutPoint):
                newPop.insert(i, pop2[i])
        else:
            newPop = pop1[cutPoint:cutPoint + length]
            for i in range(0, cutPoint):
                newPop.insert(i, pop2[i])
            for i in range(cutPoint + length, genSize):
                newPop.insert(i, pop2[i])

        newCell = Gene()
        newCell.x = newPop[0]
        newCell.y = newPop[1]
        newCell.z = newPop[2]
        newCell.sph_theta = newPop[3]
        newCell.sph_phi = newPop[4]
        newCell.theta = newPop[5]
        newCell.rotateBonds = newPop[6:]
        return newCell
    def randomCell(self):
        gen = Gene()
        gen.x = random.uniform(-self.__searchSpaceSize, self.__searchSpaceSize)
        gen.y = random.uniform(-self.__searchSpaceSize, self.__searchSpaceSize)
        gen.z = random.uniform(-self.__searchSpaceSize, self.__searchSpaceSize)
        gen.sph_theta = math.pi * random.randint(0, 200) / 100.0
        gen.sph_phi = math.pi * random.randint(0, 100) / 100.0
        gen.theta = math.pi * random.randint(0, 200) / 100.0

        for r in xrange(len(self.__rotateAtoms)):
            gen.rotateAtoms.append(math.pi * random.randint(0, 200) / 100.0)

        return copy.deepcopy(gen)
    def randomPopulation(self, sizePop):
        population = []
        for i in xrange(sizePop):
            gen = Gene()
            gen.id = i
            gen.x = random.uniform(-self.__spaceLen, self.__spaceLen)
            gen.y = random.uniform(-self.__spaceLen, self.__spaceLen)
            gen.z = random.uniform(-self.__spaceLen, self.__spaceLen)
            gen.sph_theta = math.pi * random.randint(0, 200) / 100.0
            gen.sph_phi = math.pi * random.randint(0, 100) / 100.0
            gen.theta = math.pi * random.randint(0, 200) / 100.0

            for r in xrange(len(self.__rotateAtoms)):
                gen.rotateAtoms.append(math.pi * random.randint(0, 200) /
                                       100.0)

            population.append(gen)
        return population[:]
    def randomCell(self):
        gen = Gene()
        gen.x = random.uniform(-self.__searchSpaceSize, self.__searchSpaceSize)
        gen.y = random.uniform(-self.__searchSpaceSize, self.__searchSpaceSize)
        gen.z = random.uniform(-self.__searchSpaceSize, self.__searchSpaceSize)
        gen.sph_theta = math.pi * random.randint(0, 200) / 100.0
        gen.sph_phi = math.pi * random.randint(0, 100) / 100.0
        gen.theta = math.pi * random.randint(0, 200) / 100.0

        for r in xrange(len(self.__rotateAtoms)):
            gen.rotateAtoms.append(math.pi * random.randint(0, 200) / 100.0)

        return copy.deepcopy(gen)
    def randomPopulation(self, sizePop):
        population = []
        for i in xrange(sizePop):
            gen = Gene()
            gen.id = i
            gen.x = random.uniform(-self.__spaceLen, self.__spaceLen)
            gen.y = random.uniform(-self.__spaceLen, self.__spaceLen)
            gen.z = random.uniform(-self.__spaceLen, self.__spaceLen)
            gen.sph_theta = math.pi * random.randint(0, 200) / 100.0
            gen.sph_phi = math.pi * random.randint(0, 100) / 100.0
            gen.theta = math.pi * random.randint(0, 200) / 100.0

            for r in xrange(len(self.__rotateAtoms)):
                gen.rotateAtoms.append(math.pi * random.randint(0, 200) / 100.0)

            population.append(gen)
        return population[:]
Beispiel #8
0
	def getNeighbor(self, cell):
		newCell = Gene()
		newCell.copyGene(cell)
		if self.__typeLS == 0:
			newCell = self.mutationBlock(newCell)
		elif self.__typeLS == 1:
			alpha = self.__tempIterative
			newCell = self.mutationReduce(newCell, alpha)
		elif self.__typeLS == 2:
			newCell = self.mutationRot(newCell)
		elif self.__typeLS == 3:
			localOpt = random.randint(1,3)
			if localOpt == 1:
				newCell = self.mutationBlock(newCell)
				self.__normalLSCount+=1
			elif localOpt == 2:
				alpha = self.__tempIterative
				newCell = self.mutationReduce(newCell, alpha)
				self.__redLSCount+=1
			elif localOpt == 3:
				newCell = self.mutationRot(newCell)
				self.__rotLSCount+=1
		elif self.__typeLS == 4:
			localOpt = random.uniform(0,1)
			if localOpt <= 0.1:
				newCell == self.mutationBlock(newCell)
				self.__normalLSCount+=1
			elif localOpt <= 0.35:
				alpha = self.__tempIterative
				newCell = self.mutationReduce(newCell, alpha)
				self.__redLSCount+=1
			elif localOpt > 0.35:
				newCell == self.mutationRot(newCell)
				self.__rotLSCount+=1
		newCell = self.calculates(newCell)
		return newCell
Beispiel #9
0
 def initLocalSearch(self, cell):
     #print "Init Local Search..."
     self.__tempIterative = 1.0
     T = self.__temp
     oldCell = Gene()
     oldCell.copyGene(cell)
     while T > self.__tempMin:
         j = 1
         while j <= self.__numIteration:
             newCell = self.getNeighbor(oldCell)
             criteria = self.accptance(oldCell, newCell, T)
             if criteria > random.random():
                 oldCell.copyGene(newCell)
             j += 1
         T *= self.__tempAlpha
         self.__tempIterative *= self.__alphaIt
     return oldCell
Beispiel #10
0
 def crossover50(self, selectedCell1, selectedCell2):
     newCell = Gene()
     #switch center of ligand
     centrand = random.randint(0, 5)
     if centrand == 0:
         newCell.x = selectedCell1.x
         newCell.y = selectedCell2.y
         newCell.z = selectedCell2.z
     elif centrand == 1:
         newCell.x = selectedCell1.x
         newCell.y = selectedCell1.y
         newCell.z = selectedCell2.z
     elif centrand == 2:
         newCell.x = selectedCell1.x
         newCell.y = selectedCell1.y
         newCell.z = selectedCell1.z
     elif centrand == 3:
         newCell.x = selectedCell2.x
         newCell.y = selectedCell2.y
         newCell.z = selectedCell2.z
     elif centrand == 4:
         newCell.x = selectedCell2.x
         newCell.y = selectedCell1.y
         newCell.z = selectedCell1.z
     else:
         newCell.x = selectedCell2.x
         newCell.y = selectedCell2.y
         newCell.z = selectedCell1.z
     #switch rotation of ligand
     rotrand = random.randint(0, 5)
     if rotrand == 0:
         newCell.sph_theta = selectedCell1.sph_theta
         newCell.sph_phi = selectedCell2.sph_phi
         newCell.theta = selectedCell2.theta
     elif rotrand == 1:
         newCell.sph_theta = selectedCell1.sph_theta
         newCell.sph_phi = selectedCell1.sph_phi
         newCell.theta = selectedCell2.theta
     elif rotrand == 2:
         newCell.sph_theta = selectedCell1.sph_theta
         newCell.sph_phi = selectedCell1.sph_phi
         newCell.theta = selectedCell1.theta
     elif rotrand == 3:
         newCell.sph_theta = selectedCell2.sph_theta
         newCell.sph_phi = selectedCell2.sph_phi
         newCell.theta = selectedCell2.theta
     elif rotrand == 4:
         newCell.sph_theta = selectedCell2.sph_theta
         newCell.sph_phi = selectedCell1.sph_phi
         newCell.theta = selectedCell1.theta
     else:
         newCell.sph_theta = selectedCell2.sph_theta
         newCell.sph_phi = selectedCell2.sph_phi
         newCell.theta = selectedCell1.theta
     #switch rotational bonds
     bondrand = random.randint(0, (len(selectedCell1.rotateBonds) - 1))
     if random.randint(0, 1) == 1:
         newCell.rotateBonds = selectedCell1.rotateBonds[:
                                                         bondrand] + selectedCell2.rotateBonds[
                                                             bondrand:]
     else:
         newCell.rotateBonds = selectedCell2.rotateBonds[:
                                                         bondrand] + selectedCell1.rotateBonds[
                                                             bondrand:]
     return newCell
Beispiel #11
0
	def crossoverCenter(self, selectedCell1, selectedCell2):
		newCell = Gene()
		if random.randint(0,1) == 1:
			newCell.x = selectedCell1.x
		else:
			newCell.x = selectedCell2.x
		if random.randint(0,1) == 1:
			newCell.y = selectedCell1.y
		else:
			newCell.y = selectedCell2.y
		if random.randint(0,1) == 1:
			newCell.z = selectedCell1.z
		else:
			newCell.z = selectedCell2.z
		if random.randint(0,1) == 1:
			newCell.sph_theta = selectedCell1.sph_theta
			newCell.sph_phi = selectedCell1.sph_phi
			newCell.theta = selectedCell1.theta
		else:
			newCell.sph_theta = selectedCell2.sph_theta
			newCell.sph_phi = selectedCell2.sph_phi
			newCell.theta = selectedCell2.theta
		return newCell
Beispiel #12
0
'Init Scoring Function'
scoringFx = ScoringFunction.ScoringFunction()
scoringFx.defineLigandStructure("ligand.pdb", __LigandName, tempPath)
ligand = IO.readPDB("ligand.pdb", 'HETATM', tempPath)

'Recover Connection Matrix'
ligand.connectMatrix = connectMatrix
ligand.addRotationsAtoms(__rotateAtoms)
IO.writeAllPDB("original_" + __MoleculeName + ".pdb", protein, ligand,
               tempPath)

'Random Change'
listaGenes = []
for r in range(__numberResult):
    gen = Gene.Gene()
    gen.id = r
    #gen.x = random.uniform(-__SearchSpaceSize, __SearchSpaceSize)
    #gen.y = random.uniform(-__SearchSpaceSize, __SearchSpaceSize)
    #gen.z = random.uniform(-__SearchSpaceSize, __SearchSpaceSize)
    gen.sph_theta = math.pi * random.randint(0, 200) / 100.0
    gen.sph_phi = math.pi * random.randint(0, 100) / 100.0
    gen.theta = math.pi * random.randint(0, 200) / 100.0
    for j in range(len(ligand.rotationsPoints)):
        gen.rotateAtoms.append(math.pi * random.randint(0, 200) / 100.0)
    listaGenes.append(gen)

'Molecule Name'
score = scoringFx.generateScoring(protein, ligand)
ligandName = __MoleculeName + "_Score_" + "{0:.3f}".format(
    score) + "_original.pdb"
Beispiel #13
0
	def crossover50(self, selectedCell1, selectedCell2):
		newCell = Gene()
		#switch center of ligand
		centrand = random.randint(0,5)
		if centrand == 0:
			newCell.x = selectedCell1.x
			newCell.y = selectedCell2.y
			newCell.z = selectedCell2.z
		elif centrand == 1:
			newCell.x = selectedCell1.x
			newCell.y = selectedCell1.y
			newCell.z = selectedCell2.z
		elif centrand == 2:
			newCell.x = selectedCell1.x
			newCell.y = selectedCell1.y
			newCell.z = selectedCell1.z
		elif centrand == 3:
			newCell.x = selectedCell2.x
			newCell.y = selectedCell2.y
			newCell.z = selectedCell2.z
		elif centrand == 4:
			newCell.x = selectedCell2.x
			newCell.y = selectedCell1.y
			newCell.z = selectedCell1.z
		else:
			newCell.x = selectedCell2.x
			newCell.y = selectedCell2.y
			newCell.z = selectedCell1.z
		#switch rotation of ligand
		rotrand = random.randint(0,5)
		if rotrand == 0:
			newCell.sph_theta = selectedCell1.sph_theta
			newCell.sph_phi = selectedCell2.sph_phi
			newCell.theta = selectedCell2.theta
		elif rotrand == 1:
			newCell.sph_theta = selectedCell1.sph_theta
			newCell.sph_phi = selectedCell1.sph_phi
			newCell.theta = selectedCell2.theta
		elif rotrand == 2:
			newCell.sph_theta = selectedCell1.sph_theta
			newCell.sph_phi = selectedCell1.sph_phi
			newCell.theta = selectedCell1.theta
		elif rotrand == 3:
			newCell.sph_theta = selectedCell2.sph_theta
			newCell.sph_phi = selectedCell2.sph_phi
			newCell.theta = selectedCell2.theta
		elif rotrand == 4:
			newCell.sph_theta = selectedCell2.sph_theta
			newCell.sph_phi = selectedCell1.sph_phi
			newCell.theta = selectedCell1.theta
		else:
			newCell.sph_theta = selectedCell2.sph_theta
			newCell.sph_phi = selectedCell2.sph_phi
			newCell.theta = selectedCell1.theta
		return newCell
Beispiel #14
0
	def resetPopulation(self):
		for node in self.__leafNode:
			bestCell = node.getBest()
			node.resetAgent()
			node.addToPocket(bestCell)
		for node in self.__fatherNode:
			bestCell = node.getBest()
			node.resetAgent()
			node.addToPocket(bestCell)
		bestCell = self.__rootNode.getBest()
		self.__rootNode.resetAgent()
		self.__rootNode.addToPocket(bestCell)

		gene = Gene()
		gene.randomCell(len(self.__ligand.branchSegment), self.__searchSpace)
		gene = self.calculates(gene)
		self.__rootNode.addToPocket(copy.deepcopy(gene))

		for n in range(len(self.__fatherNode)):
			gene = Gene()
			gene.randomCell(len(self.__ligand.branchSegment), self.__searchSpace)
			gene = self.calculates(gene)
			self.__fatherNode[n].addToPocket(copy.deepcopy(gene))
		for n in range(len(self.__leafNode)):
			gene = Gene()
			gene.randomCell(len(self.__ligand.branchSegment), self.__searchSpace)
			gene = self.calculates(gene)
			self.__leafNode[n].addToPocket(copy.deepcopy(gene))
Beispiel #15
0
 def initPopulation(self, first=True):
     if self.__isKB:
         gene = Gene()
         gene.randomCellKB(len(self.__ligand.branchSegment),
                           self.__searchSpace, self.__ligand.anglesArray,
                           self.__kbProb)
         gene = self.calculatesInit(gene)
         self.__rootNode.addToPocket(gene)  #flag cpy
         for n in range(len(self.__fatherNode)):
             gene = Gene()
             gene.randomCellKB(len(self.__ligand.branchSegment),
                               self.__searchSpace,
                               self.__ligand.anglesArray, self.__kbProb)
             gene = self.calculatesInit(gene)
             self.__fatherNode[n].addToPocket(gene)  #flag cpy
         for n in range(len(self.__leafNode)):
             gene = Gene()
             gene.randomCellKB(len(self.__ligand.branchSegment),
                               self.__searchSpace,
                               self.__ligand.anglesArray, self.__kbProb)
             gene = self.calculatesInit(gene)
             self.__leafNode[n].addToPocket(gene)  #flag cpy
         if first:
             self.initLog()
     else:
         gene = Gene()
         gene.randomCell(len(self.__ligand.branchSegment),
                         self.__searchSpace)
         gene = self.calculatesInit(gene)
         self.__rootNode.addToPocket(gene)  #flag cpy
         for n in range(len(self.__fatherNode)):
             gene = Gene()
             gene.randomCell(len(self.__ligand.branchSegment),
                             self.__searchSpace)
             gene = self.calculatesInit(gene)
             self.__fatherNode[n].addToPocket(gene)  #flag cpy
         for n in range(len(self.__leafNode)):
             gene = Gene()
             gene.randomCell(len(self.__ligand.branchSegment),
                             self.__searchSpace)
             gene = self.calculatesInit(gene)
             self.__leafNode[n].addToPocket(gene)  #flag cpy
         if first:
             self.initLog()
Beispiel #16
0
    def resetPopulation(self):

        for node in self.__leafNode:
            #bestCell = node.getBest()
            node.resetAgent()
            #node.addToPocket(bestCell)
        for node in self.__fatherNode:
            #bestCell = node.getBest()
            node.resetAgent()
            #node.addToPocket(bestCell)

        #bestCell = self.__rootNode.getBest()
        #self.__rootNode.resetAgent()
        #self.__rootNode.addToPocket(bestCell)

        if self.__isKB:
            #gene = Gene()
            #gene.randomCellKB(len(self.__ligand.branchSegment), self.__searchSpace, self.__ligand.anglesArray, self.__kbProb)
            #gene = self.calculates(gene)
            #self.__rootNode.addToPocket(copy.deepcopy(gene))

            for n in range(len(self.__fatherNode)):
                gene = Gene()
                gene.randomCellKB(len(self.__ligand.branchSegment),
                                  self.__searchSpace,
                                  self.__ligand.anglesArray, self.__kbProb)
                gene = self.calculatesInit(gene)
                self.__fatherNode[n].addToPocket(gene)  #cpyflag
            for n in range(len(self.__leafNode)):
                gene = Gene()
                gene.randomCellKB(len(self.__ligand.branchSegment),
                                  self.__searchSpace,
                                  self.__ligand.anglesArray, self.__kbProb)
                gene = self.calculatesInit(gene)
                self.__leafNode[n].addToPocket(gene)  #cpyflag
        else:
            #gene = Gene()
            #gene.randomCell(len(self.__ligand.branchSegment), self.__searchSpace)
            #gene = self.calculates(gene)
            #self.__rootNode.addToPocket(copy.deepcopy(gene))

            for n in range(len(self.__fatherNode)):
                gene = Gene()
                gene.randomCell(len(self.__ligand.branchSegment),
                                self.__searchSpace)
                gene = self.calculatesInit(gene)
                self.__fatherNode[n].addToPocket(gene)  #cpyflag
            for n in range(len(self.__leafNode)):
                gene = Gene()
                gene.randomCell(len(self.__ligand.branchSegment),
                                self.__searchSpace)
                gene = self.calculatesInit(gene)
                self.__leafNode[n].addToPocket(gene)  #cpyflag
Beispiel #17
0
 def crossoverUniform(self, selectedCell1, selectedCell2):
     newCell = Gene()
     if random.randint(0, 1) == 1:
         newCell.x = selectedCell1.x
     else:
         newCell.x = selectedCell2.x
     if random.randint(0, 1) == 1:
         newCell.y = selectedCell1.y
     else:
         newCell.y = selectedCell2.y
     if random.randint(0, 1) == 1:
         newCell.z = selectedCell1.z
     else:
         newCell.z = selectedCell2.z
     if random.randint(0, 1) == 1:
         newCell.sph_theta = selectedCell1.sph_theta
     else:
         newCell.sph_theta = selectedCell2.sph_theta
     if random.randint(0, 1) == 1:
         newCell.sph_phi = selectedCell1.sph_phi
     else:
         newCell.sph_phi = selectedCell2.sph_phi
     if random.randint(0, 1) == 1:
         newCell.theta = selectedCell1.theta
     else:
         newCell.theta = selectedCell2.theta
     for i in range(len(selectedCell1.rotateBonds)):
         if random.randint(0, 1) == 1:
             newCell.rotateBonds.append(selectedCell1.rotateBonds[i])
         else:
             newCell.rotateBonds.append(selectedCell2.rotateBonds[i])
     return newCell
Beispiel #18
0
	def initPopulation(self, first = True):
		gene = Gene()
		gene.rigidRandomCell(self.__searchSpace)
		gene = self.calculates(gene)
		self.__rootNode.addToPocket(copy.deepcopy(gene))
		for n in range(len(self.__fatherNode)):
			gene = Gene()
			gene.rigidRandomCell(self.__searchSpace)
			gene = self.calculates(gene)
			self.__fatherNode[n].addToPocket(copy.deepcopy(gene))
		for n in range(len(self.__leafNode)):
			gene = Gene()
			gene.rigidRandomCell(self.__searchSpace)
			gene = self.calculates(gene)
			self.__leafNode[n].addToPocket(copy.deepcopy(gene))
		if first:
			self.initLog()
Beispiel #19
0
 def crossoverBlock(self, selectedCell1, selectedCell2):
     newCell = Gene()
     if random.randint(0, 1) == 1:
         newCell.x = selectedCell1.x
         newCell.y = selectedCell1.y
         newCell.z = selectedCell1.z
     else:
         newCell.x = selectedCell2.x
         newCell.y = selectedCell2.y
         newCell.z = selectedCell2.z
     if random.randint(0, 1) == 1:
         newCell.sph_theta = selectedCell1.sph_theta
         newCell.sph_phi = selectedCell1.sph_phi
         newCell.theta = selectedCell1.theta
     else:
         newCell.sph_theta = selectedCell2.sph_theta
         newCell.sph_phi = selectedCell2.sph_phi
         newCell.theta = selectedCell2.theta
     if random.randint(0, 1) == 1:
         newCell.rotateBonds = selectedCell1.rotateBonds[:]
     else:
         newCell.rotateBonds = selectedCell2.rotateBonds[:]
     return newCell