Ejemplo n.º 1
0
    def calculates(self, np):
        if(self.__isLocalSearch):
            np = self.__LocalSearch.initLocalProcess(np, self.__Ligand)
            auxLigand = copy.deepcopy(self.__Ligand)
            auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + np.x),
                                       (self.__newSpaceCenter[1] + np.y),
                                       (self.__newSpaceCenter[2] + np.z)])
            auxLigand.rotateByVector(Methods.spherePoint(1, np.sph_theta, np.sph_phi), np.theta)
            for r in xrange(len(self.__rotateAtoms)):
                auxLigand.rotateSegment(r, np.rotateAtoms[r])
            self.__ScoreFx.traceScoring(auxLigand,np.score)
        else:
            auxLigand = copy.deepcopy(self.__Ligand)
            auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + np.x),
                                       (self.__newSpaceCenter[1] + np.y),
                                       (self.__newSpaceCenter[2] + np.z)])
            auxLigand.rotateByVector(Methods.spherePoint(1, np.sph_theta, np.sph_phi), np.theta)
            for r in xrange(len(self.__rotateAtoms)):
                auxLigand.rotateSegment(r, np.rotateAtoms[r])

            'Score'
            auxPose = rosetta.core.pose.Pose()
            auxPose.assign(self.__pose_ligand)
            for atom in xrange(auxPose.residue(auxPose.total_residue()).natoms()):
                atomV = rosetta.numeric.xyzVector_Real()
                atomV.x = round(auxLigand.x[atom],3)
                atomV.y = round(auxLigand.y[atom],3)
                atomV.z = round(auxLigand.z[atom],3)
                auxPose.residue(auxPose.total_residue()).set_xyz(auxLigand.atom[atom], atomV)
            np.score = self.__ScoreFx.generateScoringByPose(auxPose, auxLigand)
        return np
Ejemplo n.º 2
0
    def calculates(self, np):
        if (self.__isLocalSearch):
            np = self.__LocalSearch.initLocalProcess(np, self.__Ligand)
            auxLigand = copy.deepcopy(self.__Ligand)
            auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + np.x),
                                       (self.__newSpaceCenter[1] + np.y),
                                       (self.__newSpaceCenter[2] + np.z)])
            auxLigand.rotateByVector(
                Methods.spherePoint(1, np.sph_theta, np.sph_phi), np.theta)
            for r in xrange(len(self.__rotateAtoms)):
                auxLigand.rotateSegment(r, np.rotateAtoms[r])
            self.__ScoreFx.traceScoring(auxLigand, np.score)
        else:
            auxLigand = copy.deepcopy(self.__Ligand)
            auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + np.x),
                                       (self.__newSpaceCenter[1] + np.y),
                                       (self.__newSpaceCenter[2] + np.z)])
            auxLigand.rotateByVector(
                Methods.spherePoint(1, np.sph_theta, np.sph_phi), np.theta)
            for r in xrange(len(self.__rotateAtoms)):
                auxLigand.rotateSegment(r, np.rotateAtoms[r])

            'Score'
            auxPose = rosetta.core.pose.Pose()
            auxPose.assign(self.__pose_ligand)
            for atom in xrange(
                    auxPose.residue(auxPose.total_residue()).natoms()):
                atomV = rosetta.numeric.xyzVector_Real()
                atomV.x = round(auxLigand.x[atom], 3)
                atomV.y = round(auxLigand.y[atom], 3)
                atomV.z = round(auxLigand.z[atom], 3)
                auxPose.residue(auxPose.total_residue()).set_xyz(
                    auxLigand.atom[atom], atomV)
            np.score = self.__ScoreFx.generateScoringByPose(auxPose, auxLigand)
        return np
Ejemplo n.º 3
0
    def generateFinalLog(self):
        self.__timer.stop()

        'Writes Files'
        ligand_PDB_name = "Ligand_score_" + "{0:.3f}".format(self.__scoreFx.getBestScore()) + ".pdb"
        ligandProtein_PDB_name = "LigandProtein_score_" + "{0:.3f}".format(self.__scoreFx.getBestScore()) + ".pdb"
        IO.writePDB(ligand_PDB_name,self.__scoreFx.getBestLigand(),self.__fileDir)
        IO.writeAllPDB(ligandProtein_PDB_name, self.__protein, self.__scoreFx.getBestLigand(), self.__fileDir)

        initLog = "Molecule Name: " + self.__moleculeName + "\n"
        initLog += "Test Pdb: " + self.__testPdb + "\n"
        initLog += "Population: " + str(len(self.population)) + "\n"
        initLog += "Generations: " + str(self.__generations) + "\n"
        initLog += "Time to Stop: " + str(self.__timeStop) + "\n"
        initLog += "Space Size: " + str(self.__spaceLen) + "\n"
        initLog += "Point: ( " + str(self.__spaceCenter[0]) + " , " + str(self.__spaceCenter[1]) + " , " + str(self.__spaceCenter[2]) + " )\n"
        initLog += "Local Search: " + str(self.__localS) + "\n"
        initLog += "Rotate Atoms: " + str(self.__rotateAtoms) + "\n"
        initLog += "\n- Best Score: " + str(self.__scoreFx.getBestScore()) + "\n"
        initLog += "- Reach Best Score: " + str(self.__bestLoop) + "\n"
        auxRMSD = str(self.__scoreFx.getRMSD("original_" + self.__moleculeName + ".pdb", ligandProtein_PDB_name, self.__tmpDir, self.__fileDir))
        initLog += "- RMSD: " + auxRMSD + "\n"
        initLog += "- Timer: " + str(self.__timer.getTimeChronometer()) + "\n" + "\n"
        self.__log = initLog + self.__log

        'Data Log'
        IO.writeLog("iterations.log", self.__log, self.__fileDir)
        IO.writeLog("data.log", self.__dataLog, self.__fileDir)
        IO.writeHistoricLog("historic.log", str(self.__scoreFx.getBestScore()) + ";" + auxRMSD + ";" + str(self.__bestLoop) + ";" + str(self.__loop) , self.__fileDir)

        'Delete files'
        Methods.deleteTempFiles(self.__scoreFx.getLigandName(), self.__moleculeName)
Ejemplo n.º 4
0
    def recalculate(self, selectedPop, changeId=False):
        if(len(selectedPop)>0):

            for j in xrange(len(selectedPop)):
                auxLigand = copy.deepcopy(self.__ligand)
                auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + selectedPop[j].x),
                                           (self.__newSpaceCenter[1] + selectedPop[j].y),
                                           (self.__newSpaceCenter[2] + selectedPop[j].z)])

                auxLigand.rotateByVector(Methods.spherePoint(1, selectedPop[j].sph_theta, selectedPop[j].sph_phi), selectedPop[j].theta)
                for r in xrange(len(self.__rotateAtoms)):
                    auxLigand.rotateSegment(r, selectedPop[j].rotateAtoms[r])

                'Score'
                auxPose = rosetta.core.pose.Pose()
                auxPose.assign(self.__pose_ligand)
                for atom in xrange(auxPose.residue(auxPose.total_residue()).natoms()):
                    atomV = rosetta.numeric.xyzVector_Real()
                    atomV.x = round(auxLigand.x[atom],3)
                    atomV.y = round(auxLigand.y[atom],3)
                    atomV.z = round(auxLigand.z[atom],3)
                    auxPose.residue(auxPose.total_residue()).set_xyz(auxLigand.atom[atom], atomV)
                selectedPop[j].score = self.__scoreFx.generateScoringByPose(auxPose, auxLigand)

            selectedPop.sort(key=lambda x: x.score, reverse=False)

            if(changeId):
                for k in xrange(len(selectedPop)):
                    selectedPop[k].id = k

        return selectedPop
Ejemplo n.º 5
0
    def getScoring(self, solution):
        auxLigand = copy.deepcopy(self.__ligand)
        auxLigand.traslateToPoint([(self.__spaceCenter[0] + solution.x),
                                   (self.__spaceCenter[1] + solution.y),
                                   (self.__spaceCenter[2] + solution.z)])
        auxLigand.rotateByVector(
            Methods.spherePoint(1, solution.sph_theta, solution.sph_phi),
            solution.theta)
        for r in range(len(self.__ligand.rotationsPoints)):
            auxLigand.rotateSegment(r, solution.rotateAtoms[r])

        'Score'
        auxPose = rosetta.core.pose.Pose()
        auxPose.assign(self.__pose_ligand)
        for atom in xrange(auxPose.residue(auxPose.total_residue()).natoms()):
            atomV = rosetta.numeric.xyzVector_Real()
            atomV.x = round(auxLigand.x[atom], 3)
            atomV.y = round(auxLigand.y[atom], 3)
            atomV.z = round(auxLigand.z[atom], 3)
            auxPose.residue(auxPose.total_residue()).set_xyz(
                auxLigand.atom[atom], atomV)
        result = self.__scoreFx.generateScoringByPose(auxPose, auxLigand,
                                                      False)

        return result
Ejemplo n.º 6
0
    def generateFinalLog(self):
        self.__timer.stop()

        'Writes Files'
        ligand_PDB_name = "Ligand_score_" + "{0:.3f}".format(
            self.__scoreFx.getBestScore()) + ".pdb"
        ligandProtein_PDB_name = "LigandProtein_score_" + "{0:.3f}".format(
            self.__scoreFx.getBestScore()) + ".pdb"
        IO.writePDB(ligand_PDB_name, self.__scoreFx.getBestLigand(),
                    self.__fileDir)
        IO.writeAllPDB(ligandProtein_PDB_name, self.__protein,
                       self.__scoreFx.getBestLigand(), self.__fileDir)

        initLog = "Molecule Name: " + self.__moleculeName + "\n"
        initLog += "Test Pdb: " + self.__testPdb + "\n"
        initLog += "Population: " + str(len(self.population)) + "\n"
        initLog += "Generations: " + str(self.__generations) + "\n"
        initLog += "Time to Stop: " + str(self.__timeStop) + "\n"
        initLog += "Space Size: " + str(self.__spaceLen) + "\n"
        initLog += "Point: ( " + str(self.__spaceCenter[0]) + " , " + str(
            self.__spaceCenter[1]) + " , " + str(
                self.__spaceCenter[2]) + " )\n"
        initLog += "Local Search: " + str(self.__localS) + "\n"
        initLog += "Rotate Atoms: " + str(self.__rotateAtoms) + "\n"
        initLog += "\n- Best Score: " + str(
            self.__scoreFx.getBestScore()) + "\n"
        initLog += "- Reach Best Score: " + str(self.__bestLoop) + "\n"
        auxRMSD = str(
            self.__scoreFx.getRMSD("original_" + self.__moleculeName + ".pdb",
                                   ligandProtein_PDB_name, self.__tmpDir,
                                   self.__fileDir))
        initLog += "- RMSD: " + auxRMSD + "\n"
        initLog += "- Timer: " + str(
            self.__timer.getTimeChronometer()) + "\n" + "\n"
        self.__log = initLog + self.__log

        'Data Log'
        IO.writeLog("iterations.log", self.__log, self.__fileDir)
        IO.writeLog("data.log", self.__dataLog, self.__fileDir)
        IO.writeHistoricLog(
            "historic.log",
            str(self.__scoreFx.getBestScore()) + ";" + auxRMSD + ";" +
            str(self.__bestLoop) + ";" + str(self.__loop), self.__fileDir)

        'Delete files'
        Methods.deleteTempFiles(self.__scoreFx.getLigandName(),
                                self.__moleculeName)
Ejemplo n.º 7
0
    def applyChanges(self, solution):
        auxLigand = copy.deepcopy(self.__Ligand)
        auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + solution.x),
                                   (self.__newSpaceCenter[1] + solution.y),
                                   (self.__newSpaceCenter[2] + solution.z)])
        auxLigand.rotateByVector(Methods.spherePoint(1, solution.sph_theta, solution.sph_phi), solution.theta)
        for r in xrange(len(self.__Ligand.rotationsPoints)):
            auxLigand.rotateSegment(r, solution.rotateAtoms[r])

        return auxLigand
Ejemplo n.º 8
0
    def applyChanges(self, solution):
        auxLigand = copy.deepcopy(self.__Ligand)
        auxLigand.traslateToPoint([(self.__newSpaceCenter[0] + solution.x),
                                   (self.__newSpaceCenter[1] + solution.y),
                                   (self.__newSpaceCenter[2] + solution.z)])
        auxLigand.rotateByVector(
            Methods.spherePoint(1, solution.sph_theta, solution.sph_phi),
            solution.theta)
        for r in xrange(len(self.__Ligand.rotationsPoints)):
            auxLigand.rotateSegment(r, solution.rotateAtoms[r])

        return auxLigand
Ejemplo n.º 9
0
    def rouletteWheel_selection(self, population, newPopulation):
        self.calculateProbabilities(population)

        selectedPop = []
        lenPop = len(population)
        lenNewPop = len(newPopulation)

        if((lenNewPop+1) == lenPop):
            for k in xrange(lenPop):
                if(not Methods.containsId(population[k],newPopulation)):
                    selectedPop.append(copy.deepcopy(population[k]))
        else:
            while(1):
                roulettePoint = random.uniform(0, 1)
                for k in xrange(lenPop):
                    if(not Methods.containsId(population[k],selectedPop) and
                       not Methods.containsId(population[k],newPopulation) and
                       roulettePoint <= population[k].probScore):
                        selectedPop.append(copy.deepcopy(population[k]))
                        break
                if(len(selectedPop)==2):
                    break
        return selectedPop
Ejemplo n.º 10
0
    def rouletteWheel_selection(self, population, newPopulation):
        self.calculateProbabilities(population)

        selectedPop = []
        lenPop = len(population)
        lenNewPop = len(newPopulation)

        if ((lenNewPop + 1) == lenPop):
            for k in xrange(lenPop):
                if (not Methods.containsId(population[k], newPopulation)):
                    selectedPop.append(copy.deepcopy(population[k]))
        else:
            while (1):
                roulettePoint = random.uniform(0, 1)
                for k in xrange(lenPop):
                    if (not Methods.containsId(population[k], selectedPop)
                            and not Methods.containsId(population[k],
                                                       newPopulation)
                            and roulettePoint <= population[k].probScore):
                        selectedPop.append(copy.deepcopy(population[k]))
                        break
                if (len(selectedPop) == 2):
                    break
        return selectedPop
Ejemplo n.º 11
0
    def getScoring(self, solution):
        auxLigand = copy.deepcopy(self.__ligand)
        auxLigand.traslateToPoint([(self.__spaceCenter[0] + solution.x),
                                   (self.__spaceCenter[1] + solution.y),
                                   (self.__spaceCenter[2] + solution.z)])
        auxLigand.rotateByVector(Methods.spherePoint(1, solution.sph_theta, solution.sph_phi), solution.theta)
        for r in range(len(self.__ligand.rotationsPoints)):
            auxLigand.rotateSegment(r, solution.rotateAtoms[r])

        'Score'
        auxPose = rosetta.core.pose.Pose()
        auxPose.assign(self.__pose_ligand)
        for atom in xrange(auxPose.residue(auxPose.total_residue()).natoms()):
            atomV = rosetta.numeric.xyzVector_Real()
            atomV.x = round(auxLigand.x[atom],3)
            atomV.y = round(auxLigand.y[atom],3)
            atomV.z = round(auxLigand.z[atom],3)
            auxPose.residue(auxPose.total_residue()).set_xyz(auxLigand.atom[atom], atomV)
        result = self.__scoreFx.generateScoringByPose(auxPose, auxLigand, False)

        return result
Ejemplo n.º 12
0
    def recalculate(self, selectedPop, changeId=False):
        if (len(selectedPop) > 0):

            for j in xrange(len(selectedPop)):
                auxLigand = copy.deepcopy(self.__ligand)
                auxLigand.traslateToPoint([
                    (self.__newSpaceCenter[0] + selectedPop[j].x),
                    (self.__newSpaceCenter[1] + selectedPop[j].y),
                    (self.__newSpaceCenter[2] + selectedPop[j].z)
                ])

                auxLigand.rotateByVector(
                    Methods.spherePoint(1, selectedPop[j].sph_theta,
                                        selectedPop[j].sph_phi),
                    selectedPop[j].theta)
                for r in xrange(len(self.__rotateAtoms)):
                    auxLigand.rotateSegment(r, selectedPop[j].rotateAtoms[r])

                'Score'
                auxPose = rosetta.core.pose.Pose()
                auxPose.assign(self.__pose_ligand)
                for atom in xrange(
                        auxPose.residue(auxPose.total_residue()).natoms()):
                    atomV = rosetta.numeric.xyzVector_Real()
                    atomV.x = round(auxLigand.x[atom], 3)
                    atomV.y = round(auxLigand.y[atom], 3)
                    atomV.z = round(auxLigand.z[atom], 3)
                    auxPose.residue(auxPose.total_residue()).set_xyz(
                        auxLigand.atom[atom], atomV)
                selectedPop[j].score = self.__scoreFx.generateScoringByPose(
                    auxPose, auxLigand)

            selectedPop.sort(key=lambda x: x.score, reverse=False)

            if (changeId):
                for k in xrange(len(selectedPop)):
                    selectedPop[k].id = k

        return selectedPop
Ejemplo n.º 13
0
protein = copy.deepcopy(moleculeList[0])
ligand = copy.deepcopy(moleculeList[1])

'Writes a new clean structure'
IO.writePDB("ligand.pdb", ligand, tempPath)
IO.writePDB("protein.pdb", protein, tempPath)

'Gets Connection Matrix'
connectMatrix = ligand.connectMatrix

'Init Scoring Function'
scoringFx = ScoringFunction.ScoringFunction()
scoringFx.defineLigandStructure("ligand.pdb", __LigandName, tempPath)

'Recover Connection Matrix'
ligand = IO.readPDB("ligand.pdb", 'HETATM', tempPath)
ligand.connectMatrix = connectMatrix
newLigand = Methods.replacePositionLigand(newLigand, ligand)
IO.writeAllPDB("original.pdb", protein, ligand, tempPath)
IO.writeAllPDB("new.pdb", protein, newLigand, tempPath)

'Score'
minScore = scoringFx.generateScoring(protein, ligand, False)
newScore = scoringFx.generateScoring(protein, newLigand, False)
rmsdScore = scoringFx.getRMSD("original.pdb", "new.pdb", tempPath, tempPath)

print "\n************************** Results **************************"
print "- Ligand PDB: " + __pdbLigand
print "- Best Score: " + "{0:.3f}".format(minScore)
print "- Score: " + "{0:.3f}".format(newScore)
print "- RMSD: " + "{0:.3f}".format(rmsdScore)
Ejemplo n.º 14
0
'Gets Connection Matrix'
connectMatrix = ligand.connectMatrix

'Init Scoring Function'
scoringFx = ScoringFunction()
scoringFx.defineLigandStructure("ligand.pdb", __LigandName,
                                os.path.join(ROOTPATH, 'temp'))
ligand = IO.readPDB("ligand.pdb", 'HETATM', os.path.join(ROOTPATH, 'temp'))

'Recover Connection Matrix'
ligand.connectMatrix = connectMatrix

'Original'
IO.createsOriginalMolecule(__MoleculeName, __LigandName, connectMatrix)

'Generate Params'
__params = Methods.generatesParams(
    __searchSpaceSize, __searchCenterPoint, alterCenterPoint, __MoleculeName,
    __testPDB, __algorithmType, __treeNodes, __treeLevels, __castPercent,
    __rotateAtoms, __Population, __generations, __localSearch,
    __initTemperature, __minTemperature, __alphaTemperature, __innerLoop,
    __hours, __loopReset)

'Init Evolutionary algorithm'
EvolutionMethods.startAlgorithm(__params, scoringFx, protein, ligand)

'Timer Stop'
timer.stop()
timer.printTimeMinuts('*Timer: ')
Ejemplo n.º 15
0
ligand.connectMatrix = connectMatrix

'Original'
IO.createsOriginalMolecule(__MoleculeName, __LigandName, connectMatrix)

'Generate Params'
__params = Methods.generatesParams(__searchSpaceSize,
                                   __searchCenterPoint,
                                   alterCenterPoint,
                                   __MoleculeName,
                                   __testPDB,
                                   __algorithmType,
                                   __treeNodes,
                                   __treeLevels,
                                   __castPercent,
                                   __rotateAtoms,
                                   __Population,
                                   __generations,
                                   __localSearch,
                                   __initTemperature,
                                   __minTemperature,
                                   __alphaTemperature,
                                   __innerLoop,
                                   __hours,
                                   __loopReset)


'Init Evolutionary algorithm'
EvolutionMethods.startAlgorithm(__params, scoringFx, protein, ligand)

'Timer Stop'
Ejemplo n.º 16
0
protein = copy.deepcopy(moleculeList[0])
ligand = copy.deepcopy(moleculeList[1])

'Writes a new clean structure'
IO.writePDB("ligand.pdb", ligand, tempPath)
IO.writePDB("protein.pdb", protein, tempPath)

'Gets Connection Matrix'
connectMatrix = ligand.connectMatrix

'Init Scoring Function'
scoringFx = ScoringFunction.ScoringFunction()
scoringFx.defineLigandStructure("ligand.pdb", __LigandName, tempPath)

'Recover Connection Matrix'
ligand = IO.readPDB("ligand.pdb", 'HETATM', tempPath)
ligand.connectMatrix = connectMatrix
newLigand = Methods.replacePositionLigand(newLigand, ligand)
IO.writeAllPDB("original.pdb", protein, ligand, tempPath)
IO.writeAllPDB("new.pdb", protein, newLigand, tempPath)

'Score'
minScore = scoringFx.generateScoring(protein, ligand, False)
newScore = scoringFx.generateScoring(protein, newLigand, False)
rmsdScore = scoringFx.getRMSD("original.pdb", "new.pdb", tempPath, tempPath)

print "\n************************** Results **************************"
print "- Ligand PDB: " + __pdbLigand
print "- Best Score: " + "{0:.3f}".format(minScore)
print "- Score: " + "{0:.3f}".format(newScore)
print "- RMSD: " + "{0:.3f}".format(rmsdScore)
Ejemplo n.º 17
0
alterCenterPoint = [
    __SearchCenterPoint[0] + (originPoint[0] * -1),
    __SearchCenterPoint[1] + (originPoint[1] * -1),
    __SearchCenterPoint[2] + (originPoint[2] * -1)
]

'Traslate search center point'
alterLigandPoint = [
    ligandPoint[0] + (originPoint[0] * -1),
    ligandPoint[1] + (originPoint[1] * -1),
    ligandPoint[2] + (originPoint[2] * -1)
]

print "\n------------------ Values ------------------"
print "-Search Point"
Methods.printPoint(__SearchCenterPoint)
Methods.printPoint(alterCenterPoint)
print "-Ligand Point"
Methods.printPoint(ligandPoint)
Methods.printPoint(alterLigandPoint)
print "-Distance"
print str(Methods.euclideanDistance(ligandPoint, __SearchCenterPoint))
print "--------------------------------------------\n"

'Writes a new clean structure'
IO.writePDB("ligand.pdb", ligand, tempPath)
IO.writePDB("protein.pdb", protein, tempPath)

'Gets Connection Matrix'
connectMatrix = ligand.connectMatrix
Ejemplo n.º 18
0
#ligandOri.translate([originPoint[0] * -1, originPoint[1] * -1, originPoint[2] * -1])

'Traslate search center point'
alterCenterPoint = [__SearchCenterPoint[0] + (originPoint[0]*-1),
                    __SearchCenterPoint[1] + (originPoint[1]*-1),
                    __SearchCenterPoint[2] + (originPoint[2]*-1)]

'Traslate search center point'
alterLigandPoint = [ligandPoint[0] + (originPoint[0]*-1),
                    ligandPoint[1] + (originPoint[1]*-1),
                    ligandPoint[2] + (originPoint[2]*-1)]


print "\n------------------ Values ------------------"
print "-Search Point"
Methods.printPoint(__SearchCenterPoint)
Methods.printPoint(alterCenterPoint)
print "-Ligand Point"
Methods.printPoint(ligandPoint)
Methods.printPoint(alterLigandPoint)
print "-Distance"
print str(Methods.euclideanDistance(ligandPoint,__SearchCenterPoint))
print "--------------------------------------------\n"


'Writes a new clean structure'
IO.writePDB("ligand.pdb", ligand, tempPath)
IO.writePDB("protein.pdb", protein, tempPath)

'Gets Connection Matrix'
connectMatrix = ligand.connectMatrix