Esempio n. 1
0
 def rotateBBAtomAxis(self, atom1, atom2, angle):
     # sets the blockXYZVals to be rotated about an axis defined by two of the atoms
     # also modifies the refPoint and orienter
     axis = cart.vectorBetweenTwoPoints(self.blockXYZVals[atom1], self.blockXYZVals[atom2], direction='OneToTwo')
     self.blockXYZVals = [ cart.rotPAboutAxisAtPoint(p, self.blockXYZVals[atom1], axis, angle) for p in self.blockXYZVals]
     self.blockRefPoint = cart.rotPAboutAxisAtPoint(self.blockRefPoint, self.blockXYZVals[atom1], axis, angle)
     self.blockDirectorHat = cart.rotPAboutAxis(self.blockDirectorHat, self.blockXYZVals[atom1], axis, angle)
Esempio n. 2
0
    def dihedralTwist(self, xyzVals, maxStepRange):

        # can only do this if there are sufficient atoms in the array
        if len(xyzVals) > 3:
            # pick a random point in the allowedList
            index = rnd.randint(0, len(self.allowedList) - 2)
            # get the atom referred to in the allowedList
            axisAtom1Index = self.allowedList[index]

            # find the relevant atom positions and rotation axis
            atom1 = xyzVals[axisAtom1Index]
            try:
                atom2 = xyzVals[axisAtom1Index + 1]
            except IndexError:
                print("Index Error")
            rotAxis = atom2 - atom1
            rotAxisHat = rotAxis / np.linalg.norm(rotAxis)

            # pick a step size at random from within the current allowed range
            angle = rnd.uniform(maxStepRange * -np.pi, maxStepRange * np.pi)

            # rotate all the remaining points about the atom1 axis place at atom1 by angle
            xyzVals = [
                p if n < axisAtom1Index + 2 else cart.rotPAboutAxisAtPoint(
                    p, atom1, rotAxisHat, angle) for n, p in enumerate(xyzVals)
            ]
        return xyzVals
Esempio n. 3
0
    def dihedralTwist(self, xyzVals, maxStepRange):

        #fIO.saveXYZList(xyzVals, self.blockNames, "preTwist.xyz")
        # can only do this if there are sufficient atoms in the array
        if len(xyzVals) > 3:
            # initialise the axisAtom1Index
            axisAtom1Index = 2
            # keep picking a random atom until we get one in the allowed list.
            while not axisAtom1Index in self.allowedList:
                axisAtom1Index = rnd.randint(0, len(xyzVals) - 3)

            # find the relevant points and rotation axis
            atom1 = xyzVals[axisAtom1Index]
            atom2 = xyzVals[axisAtom1Index + 1]
            rotAxis = atom2 - atom1
            rotAxisHat = rotAxis / np.linalg.norm(rotAxis)

            # pick a step size at random from within the current allowed range
            angle = rnd.uniform(maxStepRange * -np.pi, maxStepRange * np.pi)

            # rotate all the remaining points about the atom1 axis place at atom1 by angle
            xyzVals = [
                p if n < axisAtom1Index + 2 else cart.rotPAboutAxisAtPoint(
                    p, atom1, rotAxisHat, angle) for n, p in enumerate(xyzVals)
            ]

        #fIO.saveXYZ([atom1, atom2], 'O', "atomAxis.xyz")
        #fIO.saveXYZList(xyzVals, self.blockNames, "postTwist.xyz")
        return xyzVals
Esempio n. 4
0
    def crankShaftMove(self, workingXYZVals, indexMin, indexMax, maxStepScale):
        # Performs rotation of random size about the axis between the atoms
        # defined by the two indices.
        # This is known as a crank rotation which preserves the bond lengths.

        # create three working sublists
        lowList = workingXYZVals[0:indexMin]
        workList = workingXYZVals[indexMin:indexMax + 1]
        highList = workingXYZVals[indexMax + 1:]

        # get the angle to move.
        angle = rnd.uniform(-maxStepScale * np.pi, maxStepScale * np.pi)

        # compute the rotation axis of the particles
        n = workList[-1] - workList[0]
        nHat = n / np.linalg.norm(n)
        newVals = [
            cart.rotPAboutAxisAtPoint(p, workList[0], nHat, angle)
            for p in workList
        ]

        validCrank = True  # assume success
        # generate iterator over the product pairs with the new vals in the lower half of the list
        lowListPairs = it.product(newVals, lowList)
        # iterate and compare each pair to see if any match
        for pair in lowListPairs:
            if np.linalg.norm(pair[0] - pair[1]) < self.minDist:
                validCrank = False
                break

        if validCrank:
            # generate iterator over the product pairs with the new vals in the upper half of the list
            highListPairs = it.product(newVals, highList)
            # iterate and compare each pair to see if any match
            for pair in highListPairs:
                if np.linalg.norm(pair[0] - pair[1]) < self.minDist:
                    validCrank = False
                    break

        if validCrank:
            # generate iterator over the product pairs with the new vals and the pointsToAvoid list
            avoidList = it.product(newVals, self.pointsToAvoid)
            # iterate and compare each pair to see if any match
            for pair in avoidList:
                if np.linalg.norm(pair[0] - pair[1]) < self.minDist:
                    validCrank = False
                    break

        # reconstruct workingXYZVals
        if validCrank:
            try:
                workingXYZVals = np.concatenate((lowList, newVals, highList),
                                                0)
            except ValueError:
                validCrank = False

        # if valid Crank is false then the original list is returned intact
        # if valid crank is true then the new vals are inserted into the new list
        return workingXYZVals, validCrank
Esempio n. 5
0
 def rotateBBArbitraryAxis(self, p0, axis, angle):
     # sets building block coords rotated about an axis through p0
     # also modifies the refPoint and orientation 
     self.blockXYZVals = [ cart.rotPAboutAxisAtPoint(p, p0, axis, angle) for p in self.blockXYZVals]
     self.blockRefPoint = cart.rotPAboutAxisAtPoint(self.blockRefPoint, p0, axis, angle)
     self.blockDirectorHat = cart.rotPAboutAxis(self.blockDirectorHat, axis, angle)