def run_fit_procedure(args): # run_fit_proecdure runs the actual fitting procedure, currently TSVD method. # load files and set necessary directories cwd = os.getcwd() new = model.langevin_model(args.name) # load the model cwd = os.getcwd() new = model.langevin_model(args.name) iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir os.chdir(newtondir) lambda_index = get_lambda_index(args.cutoff) # get the lambda index for the cutoff value param_changes = np.loadtxt("xp_%d.dat" % lambda_index) # load the correct file # now re-scale the solution so that it is not too large. if np.max(param_changes) > args.scale: param_changes *= args.scale / np.max(param_changes) # apply the changes to the parameters count = 0 for i in new.fit_indices: new.params[i] += param_changes[count] count += 1 # save the changes np.savetxt("params", new.params)
def run_fit_procedure(args): #run_fit_proecdure runs the actual fitting procedure, currently TSVD method. #load files and set necessary directories cwd = os.getcwd() new = model.langevin_model(args.name) #load the model cwd = os.getcwd() new = model.langevin_model(args.name) iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir os.chdir(newtondir) lambda_index = get_lambda_index( args.cutoff) #get the lambda index for the cutoff value param_changes = np.loadtxt("xp_%d.dat" % lambda_index) #load the correct file #now re-scale the solution so that it is not too large. if np.max(np.abs(param_changes)) > args.scale: param_changes *= (args.scale / np.max(np.abs(param_changes))) #apply the changes to the parameters count = 0 for i in new.fit_indices: new.params[i] += param_changes[count] count += 1 new.params[new.params < args.pmin] = args.pmin #save the changes np.savetxt("params", new.params)
def run_jac_procedure(args): # run_jac runs a jacobian calculating procedure. Currently only implemented for a FRET fitting # Set file locations and load necessary files target_feature = np.loadtxt(args.target) cwd = os.getcwd() new = model.langevin_model(args.name) # load the model iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir try: os.mkdir(newtondir) except: pass os.chdir(iterdir) x = np.loadtxt("position.dat") range_hist = (-1.0 * args.histrange, 1.0 * args.histrange) sim_feature, bincenters, slices, spacing = compute.plot_x_histogram( x, "iteration_%d" % new.iteration, nbins=args.nbins, histrange=range_hist ) # plot histogram and return histogram values Jacobian = compute.compute_jacobian( new, x, slices, sim_feature, args.nbins, spacing ) # compute the jacobian the FRET way # save the files os.chdir(newtondir) np.savetxt("sim_feature.dat", sim_feature) np.savetxt("target_feature.dat", target_feature) np.savetxt("Jacobian.dat", Jacobian) compute.fit_jacobian()
def run_jac_procedure(args): #run_jac runs a jacobian calculating procedure. Currently only implemented for a FRET fitting #Set file locations and load necessary files target_feature = np.loadtxt(args.target) cwd = os.getcwd() new = model.langevin_model(args.name) #load the model iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir try: os.mkdir(newtondir) except: pass os.chdir(iterdir) x = np.loadtxt("position.dat") range_hist = (-1.0 * args.histrange, 1.0 * args.histrange) sim_feature, bincenters, slices, spacing = compute.plot_x_histogram( x, "iteration_%d" % new.iteration, nbins=args.nbins, histrange=range_hist) #plot histogram and return histogram values Jacobian = compute.compute_jacobian( new, x, slices, sim_feature, args.nbins, spacing) #compute the jacobian the FRET way #save the files os.chdir(newtondir) np.savetxt("sim_feature.dat", sim_feature) np.savetxt("target_feature.dat", target_feature) np.savetxt("Jacobian.dat", Jacobian) compute.fit_jacobian()
def run_next_step(args): #run_next_step takes the previously found params in iteration_i/newton/params and sets up the ini file for iteration i+1 #set necessary directories cwd = os.getcwd() new = model.langevin_model(args.name) #load the model cwd = os.getcwd() new = model.langevin_model(args.name) iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir new.iteration += 1 new.save_params_file = "%s/params" % newtondir #save ini file with new location of the new model params if args.start: new.save_ini_file()
def run_next_step(args): # run_next_step takes the previously found params in iteration_i/newton/params and sets up the ini file for iteration i+1 # set necessary directories cwd = os.getcwd() new = model.langevin_model(args.name) # load the model cwd = os.getcwd() new = model.langevin_model(args.name) iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir new.iteration += 1 new.save_params_file = "%s/params" % newtondir # save ini file with new location of the new model params if args.start: new.save_ini_file()
def run_sim(args): # run_sim runs a stanard simulation based on the args given. cwd = os.getcwd() new = model.langevin_model(args.name) # load the model x, v = compute.run_langevin(new, nsteps=args.steps) # run the actual computation # save the results below and make the appropriate directories iterdir = "iteration_%d" % new.iteration try: os.mkdir(iterdir) except: pass np.savetxt("%s/position.dat" % iterdir, x) np.savetxt("%s/velocity.dat" % iterdir, v) os.chdir(iterdir) compute.plot_x_inverted(new, x) new.save_parameter_files()
def run_sim(args): #run_sim runs a stanard simulation based on the args given. cwd = os.getcwd() new = model.langevin_model(args.name) #load the model x, v = compute.run_langevin(new, nsteps=args.steps) #run the actual computation #save the results below and make the appropriate directories iterdir = "iteration_%d" % new.iteration try: os.mkdir(iterdir) except: pass np.savetxt("%s/position.dat" % iterdir, x) np.savetxt("%s/velocity.dat" % iterdir, v) os.chdir(iterdir) compute.plot_x_inverted(new, x) new.save_parameter_files()
def run_energy_plotting(name, savedir, iters, plot_range, plot_step, axis, title): #plot the potnetial energy of several different iterations cwd = os.getcwd() new = model.langevin_model(name) plot_values = np.arange(plot_range[0], plot_range[1], plot_step) netdir = "%s/net_potential" % savedir paramdir = "%s/individual_potentials" % savedir if not os.path.isdir(netdir): os.mkdir(netdir) if not os.path.isdir(paramdir): os.mkdir(paramdir) individual_scaled_values = [] individual_scaled_potentials = [] label = [] for j in range(len(new.params)): individual_scaled_values.append(plot_values) individual_scaled_potentials.append(new.potential_functions[j](plot_values)) label.append("p-%d"%j) os.chdir(savedir) plot_simple(individual_scaled_values, individual_scaled_potentials, label, "all-potentials", "position", "potential energy", axis=axis, marker_type="", use_legend=False) for i in iters: os.chdir(cwd) individual_scaled_values = [] individual_scaled_potentials = [] label = [] new.params = np.loadtxt("iteration_%d/params"%i) potential_values = new.net_potential(plot_values) os.chdir(netdir) plot_one_simple(plot_values, potential_values, "net-potential_iteration-%d"%i, "position", "potential energy", axis=axis) os.chdir(paramdir) for j in range(len(new.params)): individual_scaled_values.append(plot_values) individual_scaled_potentials.append(new.params[j]*new.potential_functions[j](plot_values)) label.append("p-%d"%j) plot_simple(individual_scaled_values, individual_scaled_potentials, label, "potentials_iteration-%d"%i, "position", "potential energy", axis=axis, marker_type="", use_legend=False) os.chdir(cwd)
def run_jac_procedure(args): #run_jac runs a jacobian calculating procedure. #Set file locations and load necessary files target_feature = np.loadtxt(args.target) cwd = os.getcwd() new = model.langevin_model(args.name) #load the model iterdir = "%s/iteration_%d" % (cwd, new.iteration) newtondir = "%s/newton" % iterdir try: os.mkdir(newtondir) except: pass os.chdir(iterdir) x = np.loadtxt("position.dat") range_hist = (-1.0 * args.histrange, 1.0 * args.histrange) sim_feature, bincenters, slices, spacing = compute.plot_x_histogram( x, "iteration_%d" % new.iteration, nbins=args.nbins, histrange=range_hist) #plot histogram and return histogram values if args.data_type == "FRET": Jacobian = compute.compute_jacobian( new, x, slices, sim_feature, args.nbins, spacing) #compute the jacobian the FRET way else: sim_feature, bincenters, slices, ran_size, spacing = compute.plot_tmatrix( x, "iteration_%d" % new.iteration, nbins=args.nbins, histrange=range_hist, framestep=args.fstep) slices -= (ran_size[0] + 1) nbins_use = np.shape(sim_feature)[0] #number of bins in trimmed matrix sim_feature = np.ndarray.flatten(sim_feature) #trim and flatten target_feature target_feature = target_feature[ran_size[0]:ran_size[1], ran_size[0]:ran_size[1]] if not np.shape(target_feature)[0] == nbins_use: raise ValueError( "target_feature and sim_feature have different dimensions!") target_feature = np.ndarray.flatten(target_feature) if args.data_type == "tmatrix": Jacobian = compute.compute_tmatrix_jacobian( new, x, slices, sim_feature, nbins_use, spacing, framestep=args.fstep) #compute Jacobian the tmatrix way if args.data_type == "new_tmatrix": Jacobian = compute.compute_tmatrix_jac_new( new, x, slices, sim_feature, nbins_use, spacing, framestep=args.fstep) #testing new tmatrix procedure #save the files os.chdir(newtondir) np.savetxt("sim_feature.dat", sim_feature) np.savetxt("target_feature.dat", target_feature) np.savetxt("Jacobian.dat", Jacobian) if args.data_type == "new_tmatrix": compute.fit_temp() else: compute.fit_jacobian()