def transform_coordinates(self, coordinates, argument): """ Rotate 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 (float): The move distance. """ 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 translation amplitude amplitude = FLOAT_TYPE(argument) # get vector of translation _, _, _, _, X, Y, Z = get_principal_axis(coordinates) vector = [X, Y, Z][self.__axis] # amplify vector vector *= FLOAT_TYPE(amplitude) # translate and return return coordinates + vector
def __get_group_axis__(self, coordinates): if self.__mustComputeGroupAxis: _, _, _, _, X, Y, Z = get_principal_axis(coordinates) axis = [X, Y, Z][self.__groupAxis["symmetry"]] else: axis = self.__groupAxis["fixed"] return axis
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] <= 1: # atoms where removed, fall back to random translation return coordinates + generate_random_vector( minAmp=self.__amplitude[0], maxAmp=self.__amplitude[1]) else: # 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 # get axis of translation _, _, _, _, X, Y, Z = get_principal_axis(coordinates) translationAxis = [X, Y, Z][self.__axis] # 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
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)
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
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)
def __get_group_axis__(self, coordinates): if self.__mustComputeGroupAxis: _,_,_,_,X,Y,Z = get_principal_axis(coordinates) axis = [X,Y,Z][self.__groupAxis["symmetry"]] else: axis = self.__groupAxis["fixed"] return axis
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)
def along_axis_2(): # run engine translation along axis 2 xyzPath="along2.xyz" if os.path.isfile(xyzPath): os.remove(xyzPath) _,_,_,_,X,Y,Z =get_principal_axis(ENGINE.realCoordinates) print("Translation along symmetry axis 2: ", Z) [g.set_move_generator(TranslationAlongSymmetryAxisGenerator(amplitude=0.5, axis=2)) for g in ENGINE.groups] ENGINE.run(numberOfSteps=nsteps, saveFrequency=2*nsteps, xyzFrequency=xyzFrequency, xyzPath=xyzPath, restartPdb=None)
def about_axis_2(): # run engine rotation about axis 2 xyzPath="about2.xyz" if os.path.isfile(xyzPath): os.remove(xyzPath) _,_,_,_,X,Y,Z =get_principal_axis(ENGINE.realCoordinates) print("Rotation about symmetry axis 2: ", Z) [g.set_move_generator(RotationAboutSymmetryAxisGenerator(amplitude=10, axis=2)) for g in ENGINE.groups] ENGINE.run(numberOfSteps=nsteps, saveFrequency=2*nsteps, xyzFrequency=xyzFrequency, xyzPath=xyzPath, restartPdb=None)
def __get_orientation_axis__(self): if self.__mustComputeOrientationAxis: coordinates = self.group._get_engine().realCoordinates[self.__orientationAxis["symmetry"][0]] _,_,_,_,X,Y,Z = get_principal_axis(coordinates) axis = [X,Y,Z][self.__orientationAxis["symmetry"][1]] else: axis = self.__orientationAxis["fixed"] return axis
def __get_orientation_axis__(self): if self.__mustComputeOrientationAxis: coordinates = self.group._get_engine().realCoordinates[ self.__orientationAxis["symmetry"][0]] _, _, _, _, X, Y, Z = get_principal_axis(coordinates) axis = [X, Y, Z][self.__orientationAxis["symmetry"][1]] else: axis = self.__orientationAxis["fixed"] return axis
def about_111_axis(): # run engine rotation about defined axis xyzPath="about111.xyz" axis=(1,1,1) if os.path.isfile(xyzPath): os.remove(xyzPath) _,_,_,_,X,Y,Z =get_principal_axis(ENGINE.realCoordinates) print("Rotation about user defined axis: ",axis) [g.set_move_generator(RotationAboutAxisGenerator(amplitude=10, axis=axis)) for g in ENGINE.groups] ENGINE.run(numberOfSteps=nsteps, saveFrequency=2*nsteps, xyzFrequency=xyzFrequency, xyzPath=xyzPath, restartPdb=None)
def transform_coordinates(self, coordinates, argument): """ Rotate 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 (float): The move distance. """ # get translation amplitude amplitude = FLOAT_TYPE(argument) # get vector of translation _,_,_,_,X,Y,Z =get_principal_axis(coordinates) vector = [X,Y,Z][self.__axis] # amplify vector vector *= FLOAT_TYPE(amplitude) # translate and return return coordinates+vector