#-------------------------------- # Prepare the clustering for this guy #-------------------------------- ## Load template and modify its contents for this case CLUSTERING_PATH = os.path.join(RESULTS_PATH,"%s_%s_clustering"%(options.drug, options.protein)) MAX_CLUSTERS = 10 SCRIPT_PATH = os.path.join(RESULTS_PATH,"clustering.json") OUT_FILE = os.path.join(RESULTS_PATH, "clustering.out") script = load_dic_in_json(options.template) script["global"]["workspace"]["base"] = CLUSTERING_PATH script["data"]["files"].append(FILTERED_PDB_FILE) script["clustering"]["evaluation"]["maximum_clusters"] = MAX_CLUSTERS save_dic_in_json(script, SCRIPT_PATH) os.system("python -m pyproct.main %s > %s"%(SCRIPT_PATH, OUT_FILE)) best_clustering = Clustering.from_dic(get_best_clustering(CLUSTERING_PATH)["clustering"]) #-------------------------------- # Now calculate the values #-------------------------------- results = {} for cluster in best_clustering.clusters: energies = metrics[1][cluster.all_elements] distances = metrics[0][cluster.all_elements] results[cluster.id] = {} results[cluster.id]["max_energy"] = numpy.max(energies) results[cluster.id]["min_energy"] = numpy.min(energies) results[cluster.id]["mean_energy"] = numpy.mean(energies) results[cluster.id]["mean_distance"] = numpy.mean(distances) results[cluster.id]["population"] = len(cluster.all_elements)
params['global']['workspace']['base'] = working_directory params['data']['files'] = [os.path.join(os.getcwd(), traj_pdb)] params['data']['matrix']['parameters']['path'] = matrix_file save_dic_in_json(params, be_rmsd_clustering_script_path) use_pyproct(working_directory, be_rmsd_clustering_script_path) ####################################################################################################################### # Get 5 representatives. 2 strategies. ####################################################################################################################### ##################################################################### ##################################################################### # Work only with best clustering/ find best cluster ##################################################################### ##################################################################### best_clustering = get_best_clustering(working_directory) best_clustering = Clustering.from_dic(best_clustering["clustering"]) scores = [] for a_cluster in best_clustering.clusters: scores.append((score_cluster(a_cluster, m_handler.distance_matrix, all_metrics), a_cluster)) # Remember: first metric is spawning point, second metric must be energy most_negative = find_most_negative_cluster(scores) most_negative_cluster = most_negative[1] ####################################################################################################################### # Plot clusters ####################################################################################################################### plot_clusters(os.path.join(base_dir, "clusters.svg"), all_metrics, scores, scores.index(most_negative)) #######################################################################################################################