def get_reference_structure(path, selection_str, expected_num_res): reference = parsePDB(path) reference_structure = reference.select(selection_str) writePDB("ref.pdb.chunk", reference_structure) #The reference chunk must NOT have RESIDUE GAPS assert expected_num_res == reference_structure.getHierView().numResidues(),\ "[ERROR] There are gaps in the reference structure inside this residue range.%d %d"%(options.final_res - options.initial_res +1, reference_structure.getHierView().numResidues())
def main(): parser = argparse.ArgumentParser( description= 'Project the calpha coordinates of a PDB file by a projection matrix and output the new PDB file with only calpahs' ) parser.add_argument('pdbFile', help='The pdb file') parser.add_argument('P', help='the projection matrix') parser.add_argument( '-outputName', help= 'name of the output file, default is beforeP_P_pdbFile and afterP_P_pdbFile' ) if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() assert os.path.isfile(args.pdbFile) assert os.path.isfile(args.P) if args.outputName: outputName = args.outputName else: outputName = os.path.basename(args.P) + "_" + os.path.basename( args.pdbFile) # read files pdbFile = parsePDB(args.pdbFile) pdbFile_ca = pdbFile.select('calpha') P = np.loadtxt(args.P) writePDB("beforeP_" + outputName, pdbFile_ca) coord_shape = pdbFile_ca.getCoords().shape coords_P = P.dot(pdbFile_ca.getCoords().flatten()) coords_P = coords_P.reshape(coord_shape) pdbFile_ca.setCoords(coords_P) writePDB("afterP_" + outputName, pdbFile_ca) referenceSegment = "R" referenceOfComplex = pdbFile_ca.select('segment \"' + referenceSegment + '.\"') print "Center of fixed (receptor) frame is: ", calcCenter( referenceOfComplex.select('calpha')) print "calphas before projection written to: ", "beforeP_" + outputName print "calphas after projection written to: ", "afterP_" + outputName
def writeSampleResults(self, basePath, experimentName, utils, cCase=None): np.set_printoptions(threshold=np.nan) utils.mkdir_p(basePath) utils.mkdir_p(basePath+experimentName+"/") if not cCase: path = basePath+experimentName+"/" else: path = basePath+experimentName+"/"+str(cCase)+"/" utils.mkdir_p(path) try: writePDB(path+"Ensemble.pdb", self.Ensemble) except AttributeError, err: print "Exception AttributeError occurred: ", err print traceback.format_exc()
else: print "Correspondence not found for residue %d of template in pdb %s" % ( r_id, pdb_path) index = index + 1 center = center / len(res_selection) # Center coordinates for i in range(num_res): offset = i * 3 if sequence[i] != "GAP": coords[offset] -= center[0] coords[offset + 1] -= center[1] coords[offset + 2] -= center[2] sequences.append(sequence) all_ca_coords.append(coords) if options.chunk_path is not None: pdb_name = os.path.basename(pdb_path) # Extract the chunk res_sel_string = "resid " + " ".join( [str(residue_index) for residue_index in res_selection]) selected_residues_structure = pdb.select(res_sel_string) writePDB(os.path.join(options.chunk_path, pdb_name + ".chunk"), selected_residues_structure) all_ca_coords = numpy.array(all_ca_coords) numpy.savetxt("%s.coords" % (options.output), all_ca_coords, fmt="%.5f") open("%s.seq" % (options.output), "w").write("\n".join([" ".join(sequence) for sequence in sequences]))
for pdb_path in open(options.db_list).readlines(): sequence = [] pdb_path = pdb_path.rstrip('\r\n') res_mapping = get_best_res_mapping(options.reference, pdb_path) pdb = parsePDB(pdb_path) angles, sequence, res_selection = get_angles_and_sequence_for_pdb_with_mapping(pdb, res_mapping, pdb_path, options) sequences.append(sequence) all_angles.append(angles) # Extract the chunk res_sel_string ="resid "+" ".join( [str(r_id) for r_id in res_selection]) selected_residues_structure = pdb.select(res_sel_string) writePDB(pdb_path+".chunk", selected_residues_structure) all_angles = numpy.array(all_angles) # # Eliminate first column and change inf by mean values # angle_means = get_means_for_non_inf(numpy.array(all_angles)) # <-- must be calculated with circular stats! # all_new_angles = [] # for i in range(1, len(all_angles.T)): # angles = all_angles.T[i] # new_angles = [] # for j in range(len(angles)): # if angles[j] == inf: # new_angles.append( angle_means[i]) # else: # new_angles.append( angles[j]) # all_new_angles.append(new_angles)
colors = sns.hls_palette(15, l=.3, s=.8) # VMD execution template template = open("/home/victor/git/PhD-GPCR/PhD-GPCR-2/data/load_script_representatives.tcl").read() for line in open(options.input): protein, drug, folder = line.strip().split() # sorted clusters and same color generation always make the same cluster_id, color pair representatives_file = os.path.join(folder, "representatives.pdb") output_folder = os.path.join(options.output_folder, drug, protein) create_directory(output_folder) pdb = parsePDB(representatives_file) writePDB(os.path.join(output_folder,"protein.pdb"), pdb.select("protein"), csets = [0]) writePDB(os.path.join(output_folder,"ligands.pdb"), pdb.select("resname %s"%drug)) num_clusters = pdb.numCoordsets() clusters_file = open(os.path.join(output_folder,"cluster_colors"), "w") for i in range(num_clusters): clusters_file.write("%.2f %.2f %.2f%s"%( colors[i][0], colors[i][1], colors[i][2], ("\n" if i <(num_clusters-1) else ""))) clusters_file.close() camera_settings = ""; camera_settings_zoomed = ""; option_camera = "#"; pre_render_file = ""; rendered_file = ""; option_zoom = "#" if options.camera is not None: camera_settings = camera[protein][0] camera_settings_zoomed = camera[protein][1]
parser.error('You must define the results folder') output = open(options.output,"w") if not options.prototypes: for line in open(options.input): protein, drug, folder = line.strip().split() files = glob.glob(os.path.join(folder, "cluster_*.pdb")) results_folder = os.path.join(options.results, drug, protein) create_directory(results_folder) output.write("%s %s %s\n"%(protein, drug, results_folder)) for i, filename in enumerate(sorted(files)): pdb = parsePDB(filename) if i == 0: # Extract first frame prot = pdb.select("protein") writePDB(os.path.join(results_folder, "%s.pdb"%protein), prot, csets=[0]) # Extract ligands ligands = pdb.select("resname %s"%drug) writePDB(os.path.join(results_folder, "ligand_%s"%os.path.basename(filename)), ligands) else: # Input file contains the folders with prototypes file for line in open(options.input): protein, drug, folder = line.strip().split() filename = os.path.join(folder, "representatives.pdb") results_folder = os.path.join(options.results, drug, protein) # Look for "REMARK cluster id :" # Parse once to get correct ordering of clusters cluster_ids = [] for line in open(filename): if "REMARK cluster id :" in line: cluster_ids.append(line.split()[4])
''' Created on Dec 10, 2015 @author: victor ''' from prody.proteins.pdbfile import parsePDB, writePDB import sys from histogram import parse_motifs import urllib if __name__ == '__main__': pdb = parsePDB(sys.argv[1]) motifs = parse_motifs(sys.argv[2]) prot_name = sys.argv[3] for motif in motifs[prot_name]: motif_struct = pdb.select("resid %d to %d"%motifs[prot_name][motif]) writePDB("%s.pdb"%urllib.quote(motif, safe=""),motif_struct) print motif, sorted(list(set(motif_struct.getResnums())))