Пример #1
0
 def transform_coordinates(self, coordinates, argument=None):
     """
     translates 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.
     """
     # generate translation axis
     translationAxis = generate_vectors_in_solid_angle(
         direction=self.axis, maxAngle=self.__angle, numberOfVectors=1)[0]
     # get translation amplitude
     maxAmp = self.amplitude[1] - self.amplitude[0]
     if self.direction is None:
         amplitude = (1 - 2 * generate_random_float()) * maxAmp
     elif self.direction:
         amplitude = generate_random_float() * maxAmp
     else:
         amplitude = -generate_random_float() * maxAmp
     # compute baseVector
     baseVector = FLOAT_TYPE(
         np.sign(amplitude) * translationAxis * self.amplitude[0])
     # compute translation vector
     vector = baseVector + translationAxis * FLOAT_TYPE(amplitude)
     # translate and return
     return coordinates + vector
Пример #2
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 axis
     _,_,_,_,X,Y,Z =get_principal_axis(coordinates)
     axis = [X,Y,Z][self.axis]
     # generate translation axis
     translationAxis = generate_vectors_in_solid_angle(direction=axis,
                                                       maxAngle=self.__angle,
                                                       numberOfVectors=1)[0]  
     # get translation amplitude
     maxAmp = self.amplitude[1]-self.amplitude[0]
     if self.direction is None:
         amplitude = (1-2*generate_random_float())*maxAmp
     elif self.direction:
         amplitude = generate_random_float()*maxAmp
     else:
         amplitude = -generate_random_float()*maxAmp
     # compute baseVector
     baseVector = FLOAT_TYPE(np.sign(amplitude)*translationAxis*self.amplitude[0])
     # compute translation vector
     vector = baseVector + translationAxis*FLOAT_TYPE(amplitude)
     # translate and return
     return coordinates+vector
Пример #3
0
 def __get_translation_axis(self, direction):
     # normalize direction
     norm = np.sqrt(np.add.reduce(direction**2))
     direction[0] /= norm
     direction[1] /= norm
     direction[2] /= norm
     # get vector
     if self.__angle is None:
         vector = direction
     else:
         vector = generate_vectors_in_solid_angle(direction=direction,
                                                  maxAngle=self.__angle,
                                                  numberOfVectors=1)[0]
     # return
     return vector
Пример #4
0
 def __get_translation_axis(self, direction):
     # normalize direction
     norm = np.sqrt(np.add.reduce(direction**2))
     direction[0] /= norm
     direction[1] /= norm
     direction[2] /= norm
     # get vector
     if self.__angle is None:
         vector = direction
     else:
         vector = generate_vectors_in_solid_angle(direction=direction,
                                                  maxAngle=self.__angle,
                                                  numberOfVectors=1)[0]  
     # return
     return vector
Пример #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): Not used here.

        :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:
            # create flip flag
            if self.__flip is None:
                flip = FLOAT_TYPE(np.sign(1 - 2 * generate_random_float()))
            elif self.__flip:
                flip = FLOAT_TYPE(-1)
            else:
                flip = FLOAT_TYPE(1)
            # get group axis
            groupAxis = self.__get_group_axis__(coordinates)
            # get align axis within offset angle
            orientationAxis = flip * self.__get_orientation_axis__()
            orientationAxis = generate_vectors_in_solid_angle(
                direction=orientationAxis,
                maxAngle=self.__maximumOffsetAngle,
                numberOfVectors=1)[0]
            # get coordinates center
            center = np.array(np.sum(coordinates, 0) / coordinates.shape[0],
                              dtype=FLOAT_TYPE)
            # translate to origin
            rotatedCoordinates = coordinates - center
            # align coordinates
            rotatedCoordinates = orient(rotatedCoordinates, groupAxis,
                                        orientationAxis)
            # 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):
        """
        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): Not used here.
        """
        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 axis
            _,_,_,_,X,Y,Z =get_principal_axis(coordinates)
            axis = [X,Y,Z][self.axis]
            # generate translation axis
            translationAxis = generate_vectors_in_solid_angle(direction=axis,
                                                              maxAngle=self.__angle,
                                                              numberOfVectors=1)[0]
            # get translation amplitude
            maxAmp = self.amplitude[1]-self.amplitude[0]
            if self.direction is None:
                amplitude = (1-2*generate_random_float())*maxAmp
            elif self.direction:
                amplitude = generate_random_float()*maxAmp
            else:
                amplitude = -generate_random_float()*maxAmp
            # compute baseVector
            baseVector = FLOAT_TYPE(np.sign(amplitude)*translationAxis*self.amplitude[0])
            # compute translation vector
            vector = baseVector + translationAxis*FLOAT_TYPE(amplitude)
            # translate and return
            return coordinates+vector
Пример #7
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.
     """
      # create flip flag
     if self.__flip is None:
         flip = FLOAT_TYPE( np.sign(1-2*generate_random_float()) )
     elif self.__flip:
         flip = FLOAT_TYPE(-1)
     else:
         flip = FLOAT_TYPE(1)
     # get group axis
     groupAxis = self.__get_group_axis__(coordinates)
     # get align axis within offset angle
     orientationAxis = flip*self.__get_orientation_axis__()
     orientationAxis = generate_vectors_in_solid_angle(direction=orientationAxis,
                                                       maxAngle=self.__maximumOffsetAngle,
                                                       numberOfVectors=1)[0]  
     # get coordinates center
     center = np.array(np.sum(coordinates, 0)/coordinates.shape[0] , dtype=FLOAT_TYPE)
     # translate to origin
     rotatedCoordinates = coordinates-center
     # align coordinates
     rotatedCoordinates = orient(rotatedCoordinates, groupAxis, orientationAxis)
     # translate back to center and return rotated coordinates
     return np.array(rotatedCoordinates+center, dtype=FLOAT_TYPE)