Exemple #1
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
         newCell.rotateBonds = selectedCell1.rotateBonds[:]
     else:
         newCell.sph_theta = selectedCell2.sph_theta
         newCell.sph_phi = selectedCell2.sph_phi
         newCell.theta = selectedCell2.theta
         newCell.rotateBonds = selectedCell2.rotateBonds[:]
     return newCell
Exemple #2
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
Exemple #3
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