for id_cluster, ids in clusters.iteritems(): output.write("%d:%d:%8.5f:%d:%s\n" % (id_cluster, len(ids), gso_data[ids[0]].scoring, ids[0], 'lightdock_%d.pdb' % ids[0])) log.info("Cluster result written to %s file" % CLUSTER_REPRESENTATIVES_FILE) if __name__ == '__main__': try: # Parse command line args = parse_command_line() # Read LightDock output data gso_data = read_lightdock_output(args.gso_output_file) # Sort the glowworms data by scoring sorted_data = sorted(gso_data, key=lambda k: k.scoring, reverse=True) # Get the Glowworm ids sorted by their scoring sorted_ids = [g.id_glowworm for g in sorted_data] # Calculate the different clusters clusters = clusterize(sorted_ids) # Write clustering information write_cluster_info(clusters, gso_data) except Exception, e: log.error('Clustering has failed. Please see error:')
def parse_command_line(): parser = argparse.ArgumentParser(prog='lgd_rank_swarm') parser.add_argument("num_swarms", help="number of swarms to consider", type=int, metavar="num_swarms") parser.add_argument("steps", help="steps to consider", type=int, metavar="steps") return parser.parse_args() if __name__ == '__main__': try: current_path = os.getcwd() args = parse_command_line() for swarm_id in range(args.num_swarms): os.chdir(f'{DEFAULT_SWARM_FOLDER}{swarm_id}') result_file_name = GSO_OUTPUT_FILE % args.steps lightdock_output = read_lightdock_output(result_file_name) for g in lightdock_output: g.id_swarm = swarm_id g.pdb_file = f'lightdock_{g.id_glowworm}.pdb' write_ranking_to_file(lightdock_output, order_by="scoring") os.chdir(current_path) except IOError: log.warning("Either num_clusters or steps not found. Exiting...") raise SystemExit()
"""Writes the clustering result""" with open(CLUSTER_REPRESENTATIVES_FILE, 'w') as output: for id_cluster, ids in clusters.iteritems(): output.write("%d:%d:%8.5f:%d:%s\n" % (id_cluster, len(ids), gso_data[ids[0]].scoring, ids[0], 'lightdock_%d.pdb' % ids[0])) log.info("Cluster result written to %s file" % CLUSTER_REPRESENTATIVES_FILE) if __name__ == '__main__': try: # Parse command line args = parse_command_line() # Read LightDock output data gso_data = read_lightdock_output(args.gso_output_file) # Sort the glowworms data by scoring sorted_data = sorted(gso_data, key=lambda k: k.scoring, reverse=True) # Get the Glowworm ids sorted by their scoring sorted_ids = [g.id_glowworm for g in sorted_data] # Calculate the different clusters clusters = clusterize(sorted_ids) # Write clustering information write_cluster_info(clusters, gso_data) except Exception, e: log.error('Clustering has failed. Please see error:')
if not os.path.isfile(EVALUATION_FILE): raise SystemExit("%s file not found" % EVALUATION_FILE) # Get contacts and rmsds contacts, rmsds = read_rmsd_and_contacts_data(EVALUATION_FILE) swarm_id = args.swarm_id log.info("cluster %d" % swarm_id) solutions = [] if args.result_file: result_file_name = os.path.join(DEFAULT_SWARM_FOLDER + str(swarm_id), args.result_file) else: result_file_name = os.path.join(DEFAULT_SWARM_FOLDER + str(swarm_id), GSO_OUTPUT_FILE % args.steps) scoring_file_name = os.path.join(DEFAULT_SWARM_FOLDER + str(swarm_id), SCORING_FILE) results = read_lightdock_output(result_file_name) for result in results: result.id_cluster = swarm_id try: result.rmsd = rmsds[result.id_cluster][result.id_glowworm] result.contacts = contacts[result.id_cluster][result.id_glowworm] result.pdb_file = LIGHTDOCK_PDB_FILE % result.id_glowworm except: pass solutions.append(result) if args.rmsd_file: log.info('Previous RMSD matrix found. Loading...') rmsd_matrix_file = os.path.join(DEFAULT_SWARM_FOLDER + str(swarm_id), CLUSTER_DEFAULT_NAME + DEFAULT_RMSD_EXTENSION + NUMPY_FILE_SAVE_EXTENSION)
atoms, residues, chains = parse_complex_from_file(structure) structures.append({'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': structure}) log.info("%s atoms, %s residues read." % (len(atoms), len(residues))) receptor = Complex.from_structures(structures) # Ligand structures = [] for structure in get_lightdock_structures(args.ligand_structures): log.info("Reading %s ligand PDB file..." % structure) atoms, residues, chains = parse_complex_from_file(structure) structures.append({'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': structure}) log.info("%s atoms, %s residues read." % (len(atoms), len(residues))) ligand = Complex.from_structures(structures) # Read ranking file glowworms = read_lightdock_output(args.lightdock_ranking_file, initial=1, final=args.top) # Destination path is the same as the lightdock output destination_path = os.path.dirname(args.lightdock_ranking_file) # If normal modes used, need to read them nmodes_rec = nmodes_lig = None nm_path = os.path.abspath(os.path.dirname(args.receptor_structures)) # Check NM file for receptor nm_rec_file = os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy') if os.path.exists(nm_rec_file): nmodes_rec = read_nmodes(nm_rec_file) # Check NM file for ligand nm_lig_file = os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy') if os.path.exists(nm_lig_file): nmodes_lig = read_nmodes(nm_lig_file)
structures = [] for structure in get_lightdock_structures(args.ligand_structures): log.info("Reading %s ligand PDB file..." % structure) atoms, residues, chains = parse_complex_from_file(structure) structures.append({ 'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': structure }) log.info("%s atoms, %s residues read." % (len(atoms), len(residues))) ligand = Complex.from_structures(structures) # Read ranking file glowworms = read_lightdock_output(args.lightdock_ranking_file, initial=1, final=args.top) # Destination path is the same as the lightdock output destination_path = os.path.dirname(args.lightdock_ranking_file) # If normal modes used, need to read them nmodes_rec = nmodes_lig = None nm_path = os.path.abspath(os.path.dirname(args.receptor_structures)) # Check NM file for receptor nm_rec_file = os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy') if os.path.exists(nm_rec_file): nmodes_rec = read_nmodes(nm_rec_file) # Check NM file for ligand nm_lig_file = os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy') if os.path.exists(nm_lig_file):