示例#1
0
 def transform_coordinates(self, coordinates, argument=None):
     """
     Translate coordinates.
     
     :Parameters:
         #. coordinates (np.ndarray): The coordinates on which to apply the translation.
         
     :Returns:
         #. coordinates (np.ndarray): The new coordinates after applying the translation.
         #. argument (object): Any python object. Not used in this generator.
     """
     # get atoms group center
     center = np.sum(coordinates, 0)/coordinates.shape[0]
     # translate to origin
     rotatedCoordinates = coordinates-center
     # get normalized direction vectors
     leftVector   = FLOAT_TYPE( rotatedCoordinates[1,:]-rotatedCoordinates[0,:] )
     leftVector  /= FLOAT_TYPE( np.linalg.norm(leftVector) )
     rightVector  = FLOAT_TYPE( rotatedCoordinates[2,:]-rotatedCoordinates[0,:] )
     rightVector /= FLOAT_TYPE( np.linalg.norm(rightVector) )
     # get rotation axis
     rotationAxis = np.cross(leftVector, rightVector)
     if rotationAxis[0]==rotationAxis[1]==rotationAxis[2]==0.:
         rotationAxis = np.array(1-2*np.random.random(3), dtype=FLOAT_TYPE)
         rotationAxis /= FLOAT_TYPE( np.linalg.norm(rotationAxis) )
     # create shrink flag
     if self.__shrink is None:
         shrink = (1-2*generate_random_float())>0
     else:
         shrink = self.__shrink    
     # get rotation angles
     if self.__symmetric:
         angleLeft  = angleRight = FLOAT_TYPE(generate_random_float()*self.__amplitude)
     else:
         angleLeft  = FLOAT_TYPE(generate_random_float()*self.__amplitude)
         angleRight = FLOAT_TYPE(generate_random_float()*self.__amplitude)
     # create directions
     if shrink:
         angleLeft  *= FLOAT_TYPE(-1)
         angleRight *= FLOAT_TYPE( 1)            
     else:
         angleLeft  *= FLOAT_TYPE( 1)
         angleRight *= FLOAT_TYPE(-1) 
     # rotate
     if self.__agitate[0]:
         rotationMatrix = get_rotation_matrix(rotationAxis, angleLeft)
         rotatedCoordinates[1,:] = np.dot( rotationMatrix, rotatedCoordinates[1,:])
     if self.__agitate[1]:
         rotationMatrix = get_rotation_matrix(rotationAxis, angleRight)
         rotatedCoordinates[2,:] = np.dot( rotationMatrix, rotatedCoordinates[2,:])
     # translate back from center and return
     return np.array(rotatedCoordinates+center, dtype=FLOAT_TYPE)
     
     
     
     
示例#2
0
    def transform_coordinates(self, coordinates, argument):
        """
        Rotate coordinates.

        :Parameters:
            #. coordinates (np.ndarray): The coordinates on which to apply
               the rotation.
            #. argument (object): The rotation angle.

        :Returns:
            #. coordinates (np.ndarray): The new coordinates after applying
               the rotation.
        """
        if coordinates.shape[0] <= 1:
            # atoms where removed, fall back to random translation
            return coordinates + generate_random_vector(
                minAmp=self.__amplitude[0], maxAmp=self.__amplitude[1])
        else:
            # get atoms group center and rotation axis
            center, _, _, _, X, Y, Z = get_principal_axis(coordinates)
            rotationAxis = [X, Y, Z][self.__axis]
            # get rotation matrix
            rotationMatrix = get_rotation_matrix(rotationAxis, argument)
            # translate to origin
            rotatedCoordinates = coordinates - center
            # rotate
            for idx in range(rotatedCoordinates.shape[0]):
                rotatedCoordinates[idx, :] = np.dot(rotationMatrix,
                                                    rotatedCoordinates[idx, :])
            # translate back to center and return rotated coordinates
            return np.array(rotatedCoordinates + center, dtype=FLOAT_TYPE)
示例#3
0
    def transform_coordinates(self, coordinates, argument=None):
        """
        Rotate coordinates.

        :Parameters:
            #. coordinates (np.ndarray): The coordinates on which to apply
               the rotation.
            #. argument (object): Not used here.

        :Returns:
            #. coordinates (np.ndarray): The new coordinates after
               applying the rotation.
        """
        # get rotation angle
        rotationAngle = (1 - 2 * generate_random_float()) * self.amplitude
        # get rotation matrix
        rotationMatrix = get_rotation_matrix(self.__axis, rotationAngle)
        # get atoms group center and rotation axis
        center, _, _, _, _, _, _ = get_principal_axis(coordinates)
        # translate to origin
        rotatedCoordinates = coordinates - center
        # rotate
        for idx in range(rotatedCoordinates.shape[0]):
            rotatedCoordinates[idx, :] = np.dot(rotationMatrix,
                                                rotatedCoordinates[idx, :])
        # translate back to center and return rotated coordinates
        return np.array(rotatedCoordinates + center, dtype=FLOAT_TYPE)
示例#4
0
 def transform_coordinates(self, coordinates, argument=None):
     """
     Rotate coordinates.
     
     :Parameters:
         #. coordinates (np.ndarray): The coordinates on which to apply the rotation.
         #. argument (object): Any python object. Not used in this generator.
         
     :Returns:
         #. coordinates (np.ndarray): The new coordinates after applying the rotation.
     """
     # get rotation angle
     rotationAngle = (1-2*generate_random_float())*self.amplitude
     # get atoms group center and rotation axis
     center,_,_,_,X,Y,Z =get_principal_axis(coordinates)
     rotationAxis = [X,Y,Z][self.__axis]
     # get rotation matrix
     rotationMatrix = get_rotation_matrix(rotationAxis, rotationAngle)
     # translate to origin
     rotatedCoordinates = coordinates-center
     # rotate
     for idx in range(rotatedCoordinates.shape[0]):
         rotatedCoordinates[idx,:] = np.dot( rotationMatrix, rotatedCoordinates[idx,:])
     # translate back to center and return rotated coordinates
     return np.array(rotatedCoordinates+center, dtype=FLOAT_TYPE) 
示例#5
0
 def transform_coordinates(self, coordinates, argument=None):
     """
     Rotate coordinates.
     
     :Parameters:
         #. coordinates (np.ndarray): The coordinates on which to apply the rotation
         #. argument (object): Any python object. Not used in this generator.
         
     :Returns:
         #. coordinates (np.ndarray): The new coordinates after applying the rotation.
     """
     # get rotation axis
     n = 0
     while n<PRECISION:
         rotationAxis = 1-2*np.random.random(3)
         n = np.linalg.norm(rotationAxis)
     rotationAxis /= n
     # get rotation angle
     rotationAngle = (1-2*generate_random_float())*self.amplitude
     # get rotation matrix
     rotationMatrix = get_rotation_matrix(rotationAxis, rotationAngle)
     # get atoms group center
     center = np.sum(coordinates, 0)/coordinates.shape[0]
     # translate to origin
     rotatedCoordinates = coordinates-center
     # rotate
     for idx in range(rotatedCoordinates.shape[0]):
         rotatedCoordinates[idx,:] = np.dot( rotationMatrix, rotatedCoordinates[idx,:])
     # translate back to center and return rotated coordinates
     return np.array(rotatedCoordinates+center, dtype=FLOAT_TYPE)
示例#6
0
    def transform_coordinates(self, coordinates, argument=None):
        """
        Rotate coordinates.

        :Parameters:
            #. coordinates (np.ndarray): The coordinates on which to apply
               the rotation.
            #. argument (object): Any python object. Not used in this
               generator.

        :Returns:
            #. coordinates (np.ndarray): The new coordinates after applying
               the rotation.
        """
        if coordinates.shape[0] <= 1:
            # atoms where removed, fall back to random translation
            return coordinates + generate_random_vector(
                minAmp=self.__amplitude[0], maxAmp=self.__amplitude[1])
        else:
            # get rotation axis
            n = 0
            while n < PRECISION:
                rotationAxis = 1 - 2 * np.random.random(3)
                n = np.linalg.norm(rotationAxis)
            rotationAxis /= n
            # get rotation angle
            rotationAngle = (1 - 2 * generate_random_float()) * self.amplitude
            # get rotation matrix
            rotationMatrix = get_rotation_matrix(rotationAxis, rotationAngle)
            # get atoms group center
            center = np.sum(coordinates, 0) / coordinates.shape[0]
            # translate to origin
            rotatedCoordinates = coordinates - center
            # rotate
            for idx in range(rotatedCoordinates.shape[0]):
                rotatedCoordinates[idx, :] = np.dot(rotationMatrix,
                                                    rotatedCoordinates[idx, :])
            # translate back to center and return rotated coordinates
            return np.array(rotatedCoordinates + center, dtype=FLOAT_TYPE)
示例#7
0
 def transform_coordinates(self, coordinates, argument=None):
     """
     Translate coordinates.
     
     :Parameters:
         #. coordinates (np.ndarray): The coordinates on which to apply the translation.
         
     :Returns:
         #. coordinates (np.ndarray): The new coordinates after applying the translation.
         #. argument (object): Any python object. Not used in this generator.
     """
     if coordinates.shape[0] != 3:
         # atoms where removed, fall back to random translation
         return coordinates + generate_random_vector(
             minAmp=self.__amplitude[0], maxAmp=self.__amplitude[1])
     else:
         # get atoms group center
         center = np.sum(coordinates, 0) / coordinates.shape[0]
         # translate to origin
         rotatedCoordinates = coordinates - center
         # get normalized direction vectors
         leftVector = FLOAT_TYPE(rotatedCoordinates[1, :] -
                                 rotatedCoordinates[0, :])
         leftVector /= FLOAT_TYPE(np.linalg.norm(leftVector))
         rightVector = FLOAT_TYPE(rotatedCoordinates[2, :] -
                                  rotatedCoordinates[0, :])
         rightVector /= FLOAT_TYPE(np.linalg.norm(rightVector))
         # get rotation axis
         rotationAxis = np.cross(leftVector, rightVector)
         if rotationAxis[0] == rotationAxis[1] == rotationAxis[2] == 0.:
             rotationAxis = np.array(1 - 2 * np.random.random(3),
                                     dtype=FLOAT_TYPE)
             rotationAxis /= FLOAT_TYPE(np.linalg.norm(rotationAxis))
         # create shrink flag
         if self.__shrink is None:
             shrink = (1 - 2 * generate_random_float()) > 0
         else:
             shrink = self.__shrink
         # get rotation angles
         if self.__symmetric:
             angleLeft = angleRight = FLOAT_TYPE(generate_random_float() *
                                                 self.__amplitude)
         else:
             angleLeft = FLOAT_TYPE(generate_random_float() *
                                    self.__amplitude)
             angleRight = FLOAT_TYPE(generate_random_float() *
                                     self.__amplitude)
         # create directions
         if shrink:
             angleLeft *= FLOAT_TYPE(-1)
             angleRight *= FLOAT_TYPE(1)
         else:
             angleLeft *= FLOAT_TYPE(1)
             angleRight *= FLOAT_TYPE(-1)
         # rotate
         if self.__agitate[0]:
             rotationMatrix = get_rotation_matrix(rotationAxis, angleLeft)
             rotatedCoordinates[1, :] = np.dot(rotationMatrix,
                                               rotatedCoordinates[1, :])
         if self.__agitate[1]:
             rotationMatrix = get_rotation_matrix(rotationAxis, angleRight)
             rotatedCoordinates[2, :] = np.dot(rotationMatrix,
                                               rotatedCoordinates[2, :])
         # translate back from center and return
         return np.array(rotatedCoordinates + center, dtype=FLOAT_TYPE)