def get_centroid(points, metric_name, num_confs, labs, traj_file, inputfile): """ Takes the output from DBSCAN and produces the trajectory and centroid from each cluster. Parameters: points (numpy.array): The points fed to the clstering algorithm. metric_name (str): The type of data the points represent. labs (numpy.array): The cluster each point belongs to. traj_file (str): The analyzed trajectory file. inputfile (str): The input file used to run the analyzed simulation. """ print("INFO: splitting clusters...", file=stderr) print("INFO: Will write cluster trajectories to traj_<cluster_number>.dat", file=stderr) print ("cluster\tn\tavg_E\tE_dev\tavg_H\tH_dev\tcentroid_t") for cluster in (set(labs)): if metric_name == "precomputed": masked = points[labs == cluster] in_cluster_id = np.sum(masked, axis = 1).argmin() in_cluster = list(labs).count(cluster) centroid_id = find_element(in_cluster_id, cluster, labs) top_file = get_input_parameter(inputfile, "topology") r = LorenzoReader2(traj_file, top_file) output = r._get_system(N_skip=centroid_id) filename = "centroid"+str(cluster) output.print_lorenzo_output(filename+".dat", filename+".top") make_heatmap(inputfile, output, filename)
def main(): #doesn't actually do anything... import argparse from UTILS.readers import LorenzoReader2, get_input_parameter parser = argparse.ArgumentParser( description= "A python wrapper for getting all vectors between nucleotides from a simulation" ) parser.add_argument('inputfile', type=str, nargs=1, help="The inputfile used to run the simulation") parser.add_argument( 'trajectory', type=str, nargs=1, help= "The file containing the configurations of which the contact map is needed" ) args = parser.parse_args() from oxDNA_analysis_tools.config import check_dependencies check_dependencies(["python", "numpy"]) inputfile = args.inputfile[0] traj_file = args.trajectory[0] top_file = get_input_parameter(inputfile, "topology") if "RNA" in get_input_parameter(inputfile, "interaction_type"): environ["OXRNA"] = "1" else: environ["OXRNA"] = "0" import UTILS.base #this needs to be imported after the model type is set r = LorenzoReader2(traj_file, top_file) system = r._get_system() while system: m = all_vectors(inputfile, system, True) system = r._get_system() print("well, it finished...")
nargs=1, type=int, dest='parallel', help="(optional) How many cores to use") args = parser.parse_args() from config import check_dependencies check_dependencies(["python", "numpy", "matplotlib"]) traj_file = args.trajectory[0] inputfile = args.inputfile[0] parallel = args.parallel if parallel: n_cpus = args.parallel[0] top_file = get_input_parameter(inputfile, "topology") if "RNA" in get_input_parameter(inputfile, "interaction_type"): environ["OXRNA"] = "1" else: environ["OXRNA"] = "0" num_confs = cal_confs(traj_file) import UTILS.base #this needs to be imported after the model type is set r2 = LorenzoReader2(traj_file, top_file) #how do you want to get your eRMSDs? Do you need to do the time-consuming calculation or is it done and you have a pickle? if not parallel: r1 = LorenzoReader2(traj_file, top_file) eRMSDs = get_eRMSDs(r1, r2, inputfile, traj_file, top_file, num_confs) if parallel:
#-o names the output file if args.output: outfile = args.output[0] else: outfile = "forces.txt" print( "INFO: No outfile name provided, defaulting to \"{}\"".format(outfile), file=stderr) if args.pairs: pairsfile = args.pairs[0] else: pairsfile = False #Get relevant parameters from the input file top_file = get_input_parameter(inputfile, "topology") #get base pairs r = LorenzoReader2(conf_file, top_file) mysystem = r._get_system() out = output_bonds(inputfile, mysystem) out = out.split('\n') #Find out the forming bonds series print("INFO: Analyze the output...", file=stderr) Bonded = {} for i in out: if i[0] == '#': continue splitline = i.split(' ') try:
n_dists = sum([len(l) for l in p1s]) #Make sure that the input is correctly formatted if (len(input_files) != len(trajectories)): print( "ERROR: bad input arguments\nPlease supply an equal number of input and, trajectory files", file=stderr) exit(1) if len(p1s) != len(p2s): print( "ERROR: bad input arguments\nPlease supply an even number of particles", file=stderr) exit(1) #get the topology from the input topology_files = [get_input_parameter(i, "topology") for i in input_files] #-o names the output file if args.output: outfile = args.output[0] else: print("INFO: No outfile name provided, defaulting to \"distance.png\"", file=stderr) outfile = "distance.png" #-f defines which type of graph to produce hist = False lineplt = False if args.format: if "histogram" in args.format: hist = True
def split_trajectory(traj_file, inputfile, labs, n_clusters): """ Splits the trajectory into the clustered trajectories Parameters: traj_file (str): The analyzed trajectory file. inputfile (str): The input file used to run the analyzed simulation. labs (numpy.array): The cluster each point belongs to. """ top_file = get_input_parameter(inputfile, "topology") print ("cluster\tmembers") #energies = [] #H_counts = [] for cluster in (set(labs)): in_cluster = list(labs).count(cluster) print ("{}\t{}".format(cluster, in_cluster)) #energies.append([]) #H_counts.append([]) #for making trajectories of each cluster try: remove("cluster_"+str(cluster)+".dat") except: pass confid = 0 r1 = LorenzoReader2(traj_file, top_file) system = r1._get_system() print ("INFO: splitting trajectory...", file=stderr) print ("INFO: Will write cluster trajectories to cluster_<cluster number>.dat", file=stderr) while system != False: system.print_traj_output("cluster_"+str(labs[confid])+".dat", "/dev/null") ########### #If you want to get additional information about a cluster, add that code here #for example, if you want average energy and hydrogen bonds: ''' energies[labs[confid]].append(0) H_counts[labs[confid]].append(0) system.map_nucleotides_to_strands() out = output_bonds(inputfile, system) for line in out.split('\n'): if line[0] != '#' and line[0] != '\n': line = line.split(" ") for m in line[2:9]: energies[labs[confid]][-1] += float(m) if float(line[6]) != 0: H_counts[labs[confid]][-1] += 1 energies[labs[confid]][-1] /= len(system._nucleotides) ''' ############ confid += 1 system = r1._get_system() #This is where you print the information about each cluster '''