def build(cls, data_handler, matrix_creation_parameters): """ Generates a matrix with the method used in the handler creation. @param trajectory_handler: @param matrix_creation_parameters: @return: The created matrix. """ calculator_type = matrix_creation_parameters.get_value("calculator_type", default_value = "QTRFIT_OMP_CALCULATOR") calculator_options = matrix_creation_parameters.get_value("calculator_options", default_value = ProtocolParameters({"number_of_threads":8, "blocks_per_grid":8, "threads_per_block":32})) calculator_options = ProtocolParameters(calculator_options) structure = data_handler.get_data() fit_selection_coordsets = structure.getFittingCoordinates() calc_selection_coordsets = structure.getCalculationCoordinates() if calc_selection_coordsets is None: calculator = RMSDCalculator(calculatorType = calculator_type, fittingCoordsets = fit_selection_coordsets) else: symm_groups = [] if "symmetries" in matrix_creation_parameters: # Then prepare it to handle calculation symmetries # Description of equivalences must have the same number of atoms symm_groups = cls.process_symm_groups(matrix_creation_parameters, structure, calc_selection_coordsets) print "Using symmetries", symm_groups calculator = RMSDCalculator(calculatorType = calculator_type, fittingCoordsets = fit_selection_coordsets, calculationCoordsets = calc_selection_coordsets, calcSymmetryGroups = symm_groups) try: calculator.setNumberOfOpenMPThreads(calculator_options.get_value("number_of_threads", default_value = 8)) except KeyError: pass try: calculator.setCUDAKernelThreadsPerBlock(calculator_options.get_value("threads_per_block", default_value = 32), calculator_options.get_value("blocks_per_grid", default_value = 8)) except KeyError: pass rmsds = calculator.pairwiseRMSDMatrix() return CondensedMatrix(rmsds)
def pairwise_rmsd(coords): """ Returns vector with all pairwise backbone RMSDs from given coordinates coords = numpy array of coordinates generated using ProDy """ calculator = RMSDCalculator("QCP_SERIAL_CALCULATOR", fittingCoordsets = coords) t1 = time.time() rmsds = calculator.pairwiseRMSDMatrix() t2 = time.time() print "With QCP Serial calculator it took: ", t2-t1 ,"s." sys.stdout.flush() #rmsd_matrix = CondensedMatrix(rmsds) return rmsds
def build(cls, trajectory_handler, matrix_creation_parameters): """ Generates a matrix with the method used in the handler creation. @param trajectory_handler: @param matrix_creation_parameters: @return: The created matrix. """ fit_selection_string = matrix_creation_parameters["fit_selection"] fit_selection_coordsets = trajectory_handler.getSelection( fit_selection_string) trajectory_handler.setWorkingCoordinates(fit_selection_string) calculator_type = matrix_creation_parameters[ "calculator_type"] if "calculator_type" in matrix_creation_parameters else "QTRFIT_OMP_CALCULATOR" calculator = RMSDCalculator(calculatorType=calculator_type, fittingCoordsets=fit_selection_coordsets) # Apply calculation selection if needed calc_selection_string = matrix_creation_parameters[ "calc_selection"] if "calc_selection" in matrix_creation_parameters else "" if calc_selection_string != "" and calc_selection_string != fit_selection_string: calc_selection_coordsets = trajectory_handler.getSelection( calc_selection_string) trajectory_handler.setWorkingCoordinates(calc_selection_string) symm_groups = [] if "symmetries" in matrix_creation_parameters: # Then prepare it to handle calculation symmetries # Description of equivalences must have the same number of atoms symm_groups = cls.process_symm_groups( matrix_creation_parameters, trajectory_handler, calc_selection_coordsets) print "Using symmetries", symm_groups calculator = RMSDCalculator( calculatorType=calculator_type, fittingCoordsets=fit_selection_coordsets, calculationCoordsets=calc_selection_coordsets, calcSymmetryGroups=symm_groups) rmsds = calculator.pairwiseRMSDMatrix() return CondensedMatrix(rmsds)
def build(cls, trajectory_handler, matrix_creation_parameters): """ Generates a matrix with the method used in the handler creation. @param trajectory_handler: @param matrix_creation_parameters: @return: The created matrix. """ fit_selection_string = matrix_creation_parameters["fit_selection"] fit_selection_coordsets = trajectory_handler.getSelection(fit_selection_string) trajectory_handler.setWorkingCoordinates(fit_selection_string) calculator_type = matrix_creation_parameters["calculator_type"] if "calculator_type" in matrix_creation_parameters else "QTRFIT_OMP_CALCULATOR" calculator = RMSDCalculator(calculatorType = calculator_type, fittingCoordsets = fit_selection_coordsets) # Apply calculation selection if needed calc_selection_string = matrix_creation_parameters["calc_selection"] if "calc_selection" in matrix_creation_parameters else "" if calc_selection_string != "" and calc_selection_string != fit_selection_string: calc_selection_coordsets = trajectory_handler.getSelection(calc_selection_string) trajectory_handler.setWorkingCoordinates(calc_selection_string) symm_groups = [] if "symmetries" in matrix_creation_parameters: # Then prepare it to handle calculation symmetries # Description of equivalences must have the same number of atoms symm_groups = cls.process_symm_groups(matrix_creation_parameters, trajectory_handler, calc_selection_coordsets) print "Using symmetries",symm_groups calculator = RMSDCalculator(calculatorType = calculator_type, fittingCoordsets = fit_selection_coordsets, calculationCoordsets = calc_selection_coordsets, calcSymmetryGroups=symm_groups) rmsds = calculator.pairwiseRMSDMatrix() return CondensedMatrix(rmsds)
def parse_decoys(decoy_dir, number_of_decoys = None): """ Extracts backbone coordinates from first n pdbs in the given directory and returns their coordinates as a numpy array. If not n is specified, it considers every pdb file. decoy_dir = directory with decoys number_of_decoys = n (optional) """ decoy_list = [] for file in os.listdir(decoy_dir): if file.endswith(".pdb"): decoy_list.append(os.path.join(decoy_dir,file)) decoy_list = sorted(decoy_list) #selecting first n decoys, if n is specified if number_of_decoys != None: decoys_considered = decoy_list[:number_of_decoys] else: decoys_considered = decoy_list # add pdb name to a list #using ProDy to parse PDBs pdb_ref = parsePDB(decoys_considered[0]) #extracting C-alpha coordinates as numpy array coords_ref = np.array((pdb_ref.select("name CA C1").getCoordsets())) # reference pose pdb0 #####PRINT COORDS! rmsd_out=open("all_vs_all_rmsd.txt",'w') rmsd_out.write("ref:"+str(decoys_considered[0])+"\n") rmsd_out.close() for i in range(1,len(decoys_considered)): pdb = parsePDB(decoys_considered[i]) coords_temp = np.array((pdb.select("name CA C1").getCoordsets())) # get the pose2 pdb1 coords = np.vstack((coords_ref, coords_temp)) number_of_conformations = coords.shape[0] number_of_atoms = coords.shape[1] calculator = RMSDCalculator("QCP_SERIAL_CALCULATOR", fittingCoordsets = coords) rmsds = calculator.pairwiseRMSDMatrix() sys.stdout.flush() rmsd_out=open("all_vs_all_rmsd.txt",'a') rmsd_out.write(str(i)+"\t"+str(rmsds)+"\n") rmsd_out.close()
def build(cls, data_handler, matrix_creation_parameters): """ Generates a matrix with the method used in the handler creation. @param trajectory_handler: @param matrix_creation_parameters: @return: The created matrix. """ calculator_type = matrix_creation_parameters.get_value( "calculator_type", default_value="QTRFIT_OMP_CALCULATOR") calculator_options = matrix_creation_parameters.get_value( "calculator_options", default_value=ProtocolParameters({ "number_of_threads": 8, "blocks_per_grid": 8, "threads_per_block": 32 })) calculator_options = ProtocolParameters(calculator_options) structure = data_handler.get_data() fit_selection_coordsets = structure.getFittingCoordinates() calc_selection_coordsets = structure.getCalculationCoordinates() if calc_selection_coordsets is None: calculator = RMSDCalculator( calculatorType=calculator_type, fittingCoordsets=fit_selection_coordsets) else: symm_groups = [] if "symmetries" in matrix_creation_parameters: # Then prepare it to handle calculation symmetries # Description of equivalences must have the same number of atoms symm_groups = cls.process_symm_groups( matrix_creation_parameters, structure, calc_selection_coordsets) print "Using symmetries", symm_groups calculator = RMSDCalculator( calculatorType=calculator_type, fittingCoordsets=fit_selection_coordsets, calculationCoordsets=calc_selection_coordsets, calcSymmetryGroups=symm_groups) try: calculator.setNumberOfOpenMPThreads( calculator_options.get_value("number_of_threads", default_value=8)) except KeyError: pass try: calculator.setCUDAKernelThreadsPerBlock( calculator_options.get_value("threads_per_block", default_value=32), calculator_options.get_value("blocks_per_grid", default_value=8)) except KeyError: pass rmsds = calculator.pairwiseRMSDMatrix() return CondensedMatrix(rmsds)
def print_matrix(input_coordsets, output): # Generate the matrix and print it calculator = RMSDCalculator(calculatorType="QCP_OMP_CALCULATOR", fittingCoordsets=input_coordsets) matrixToImage(CondensedMatrix(calculator.pairwiseRMSDMatrix()), output + ".png")
def print_matrix(input_coordsets, output): # Generate the matrix and print it calculator = RMSDCalculator(calculatorType="QCP_OMP_CALCULATOR", fittingCoordsets = input_coordsets) matrixToImage(CondensedMatrix(calculator.pairwiseRMSDMatrix()), output + ".png")