def rdf_compare(plot_panel, filename1, filename2, ibi_iteration_number, molecule1, molecule2): i = 0 rdf_average = lmp_io.read_lammps_rdf(filename1, 4, ibi_iteration_number, timestep_limit=i, write_rdf_files=False, timestep_threshold=0) rdf_average2 = lmp_io.read_lammps_rdf(filename2, 4, ibi_iteration_number, timestep_limit=i, write_rdf_files=False, timestep_threshold=0) plot_panel.plot(range(0, len(rdf_average[molecule1][molecule2])), rdf_average[molecule1][molecule2], label="previous: target %d %d step %d" % (molecule1, molecule2, i)) plot_panel.plot(range(0, len(rdf_average2[molecule1][molecule2])), rdf_average2[molecule1][molecule2], label="current: target %d %d step %d" % (molecule1, molecule2, i)) pylab.legend(loc=4)
def rdf_compare(plot_panel, filename1, filename2, ibi_iteration_number, molecule1, molecule2): i = 0 rdf_average = lmp_io.read_lammps_rdf(filename1, 4, ibi_iteration_number, timestep_limit=i, write_rdf_files=False, timestep_threshold=0) rdf_average2 = lmp_io.read_lammps_rdf(filename2, 4, ibi_iteration_number, timestep_limit=i, write_rdf_files=False, timestep_threshold=0) plot_panel.plot(range(0,len(rdf_average[molecule1][molecule2])),rdf_average[molecule1][molecule2], label="previous: target %d %d step %d" % (molecule1, molecule2, i)) plot_panel.plot(range(0,len(rdf_average2[molecule1][molecule2])),rdf_average2[molecule1][molecule2], label="current: target %d %d step %d" % (molecule1, molecule2, i)) pylab.legend(loc=4)
def txt_rdf(iter, molecule1, molecule2): if molecule2 > 0: d1, d2, d3, d4 = lmp_io.load_target_and_cg_rdf("rdf.%d.%d" % (molecule1, molecule2), "rdf_%d.%d.%d" % (iter-1, molecule1, molecule2)) print iter, " for particles ", molecule1, molecule2, "ave. diff: %f, quad. diff: %f" % (d3, d4) else: ave_diff_tot = 0.0 quad_diff_tot = 0.0 for i in xrange(1, molecule1+1): for j in xrange(i, molecule1+1): d1, d2, d3, d4 = lmp_io.load_target_and_cg_rdf("rdf.%d.%d" % (i, j), "rdf_%d.%d.%d" % (iter-1, i, j)) ave_diff_tot += d3 quad_diff_tot += d4 #print iter, i, j, "ave.: %f, quad.: %f" % (d3, d4) print iter, "Average difference (total): %f, Squared difference (total): %f" % (ave_diff_tot, quad_diff_tot)
def basic_test_suite(): """ Simple testing of various functions in the script.""" print "read_lammps_data_file" lattice, type_list = lmp_io.read_lammps_data_file("CG_first_interaction.lammps05") print "read_lammps_rdf" rdf_average = lmp_io.read_lammps_rdf("tmp.1.rdf", 3, 1) print "read_CG_log_file" final_pressure = read_CG_log_file("new_CG.prod1.log") print "smooth_data" smoothed = dm.smooth_data(rdf_average[1][1]) print "read_in_rdf_file" rdf_array, numofbins, cutoff = read_in_rdf_file("rdf", 3, [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]) print "read_in_interaction_files" distance, potential, derivative, pot_file_list, cutoff = lmp_io.read_in_interaction_files("./pot", 3, [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]], 1)
def add_rdf_plot(iter, molecule1, molecule2, row, column, index, fig): print "add_rdf_plot: ", iter, molecule1, molecule2, "d1: rdf.%d.%d" % ( molecule1, molecule2), "d2: rdf_%d.%d.%d" % (iter - 1, molecule1, molecule2) d1, d2, d3, d4 = lmp_io.load_target_and_cg_rdf( "rdf.%d.%d" % (molecule1, molecule2), "rdf_%d.%d.%d" % (iter - 1, molecule1, molecule2), averaging="no") ax2 = fig.add_subplot(row, column, index) ax2.plot(d1[:, 0], d1[:, 2], label="target %d %d" % (molecule1, molecule2)) ax2.plot(d2[:, 0], d2[:, 1], label="fit iteration %d" % (iter - 1)) # ax2.plot(d2[:,0],np.absolute(d3), label="error iteration %d" % (iter-1)) #plot the error if needed: y_coord = (pylab.ylim())[1] - 0.1 ax2.text(0.1, y_coord, "ave. diff: %f, quad. diff: %f" % (np.average(np.absolute(d3)), np.average(d4)), style='italic') set_small_legend()
def basic_test_suite(): """ Simple testing of various functions in the script.""" print "read_lammps_data_file" lattice, type_list = lmp_io.read_lammps_data_file( "CG_first_interaction.lammps05") print "read_lammps_rdf" rdf_average = lmp_io.read_lammps_rdf("tmp.1.rdf", 3, 1) print "read_CG_log_file" final_pressure = read_CG_log_file("new_CG.prod1.log") print "smooth_data" smoothed = dm.smooth_data(rdf_average[1][1]) print "read_in_rdf_file" rdf_array, numofbins, cutoff = read_in_rdf_file( "rdf", 3, [[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]]) print "read_in_interaction_files" distance, potential, derivative, pot_file_list, cutoff = lmp_io.read_in_interaction_files( "./pot", 3, [[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]], 1)
def analyse_and_plot_lammps_rdf_file(plot_panel, filename, ibi_iteration_number, molecule1, molecule2): for i in [0, 5000, 100000, 250000]: print i rdf_average = lmp_io.read_lammps_rdf(filename, 3, ibi_iteration_number, timestep_limit=i, write_rdf_files=False, timestep_threshold=0) plot_panel.plot(range(0,len(rdf_average[molecule1][molecule2])),rdf_average[molecule1][molecule2], label="target %d %d step %d" % (molecule1, molecule2, i)) pylab.legend(loc=4)
def calc_ave_press(iter, tag="Press"): d1,d2 = lmp_io.load_quantity_from_file("new_CG.prod%d.log" % (iter-1), tag) offset = 100 pave = np.average(d2[100:]) pstdev = np.std(d2[100:]) print "READ: new_CG.prod%d.log" % (iter-1) print "%s information iteration #%d, average pressure: %f, stdev: %f, initial values: %f %f %f" % (tag, iter-1,pave,pstdev,d2[0],d2[1],d2[2])
def txt_rdf(iter, molecule1, molecule2): if molecule2 > 0: d1, d2, d3, d4 = lmp_io.load_target_and_cg_rdf( "rdf.%d.%d" % (molecule1, molecule2), "rdf_%d.%d.%d" % (iter - 1, molecule1, molecule2)) print iter, " for particles ", molecule1, molecule2, "ave. diff: %f, quad. diff: %f" % ( d3, d4) else: ave_diff_tot = 0.0 quad_diff_tot = 0.0 for i in xrange(1, molecule1 + 1): for j in xrange(i, molecule1 + 1): d1, d2, d3, d4 = lmp_io.load_target_and_cg_rdf( "rdf.%d.%d" % (i, j), "rdf_%d.%d.%d" % (iter - 1, i, j)) ave_diff_tot += d3 quad_diff_tot += d4 #print iter, i, j, "ave.: %f, quad.: %f" % (d3, d4) print iter, "Average difference (total): %f, Squared difference (total): %f" % ( ave_diff_tot, quad_diff_tot)
def calc_ave_press(iter, tag="Press"): d1, d2 = lmp_io.load_quantity_from_file("new_CG.prod%d.log" % (iter - 1), tag) offset = 100 pave = np.average(d2[100:]) pstdev = np.std(d2[100:]) print "READ: new_CG.prod%d.log" % (iter - 1) print "%s information iteration #%d, average pressure: %f, stdev: %f, initial values: %f %f %f" % ( tag, iter - 1, pave, pstdev, d2[0], d2[1], d2[2])
def add_rdf_plot(iter, molecule1, molecule2, row, column, index, fig): print "add_rdf_plot: ", iter, molecule1, molecule2, "d1: rdf.%d.%d" % (molecule1, molecule2), "d2: rdf_%d.%d.%d" % (iter-1, molecule1, molecule2) d1, d2, d3, d4 = lmp_io.load_target_and_cg_rdf("rdf.%d.%d" % (molecule1, molecule2), "rdf_%d.%d.%d" % (iter-1, molecule1, molecule2), averaging="no") ax2 = fig.add_subplot(row, column, index) ax2.plot(d1[:,0],d1[:,2], label="target %d %d" % (molecule1, molecule2)) ax2.plot(d2[:,0],d2[:,1], label="fit iteration %d" % (iter-1)) # ax2.plot(d2[:,0],np.absolute(d3), label="error iteration %d" % (iter-1)) #plot the error if needed: y_coord = (pylab.ylim())[1] - 0.1 ax2.text(0.1, y_coord, "ave. diff: %f, quad. diff: %f" % (np.average(np.absolute(d3)), np.average(d4)), style='italic') set_small_legend()
def analyse_and_plot_lammps_rdf_file(plot_panel, filename, ibi_iteration_number, molecule1, molecule2): for i in [0, 5000, 100000, 250000]: print i rdf_average = lmp_io.read_lammps_rdf(filename, 3, ibi_iteration_number, timestep_limit=i, write_rdf_files=False, timestep_threshold=0) plot_panel.plot(range(0, len(rdf_average[molecule1][molecule2])), rdf_average[molecule1][molecule2], label="target %d %d step %d" % (molecule1, molecule2, i)) pylab.legend(loc=4)
def read_in_rdf_file(filename, number_of_types, interaction_list): """ subroutine to read in the RDF file - note, the format must be distance is first column, and RDF is the third column ASSUMPTION: ALL RDF FILES HAVE THE SAME NUMBER OF BINS AND CUTOFF. """ index = 0 print "reading RDF %s" % (filename) numofbins, cutoff, o = lmp_io.get_number_of_bins_and_cutoff("%s.1.1" % (filename), 0) rdf_array = np.zeros((number_of_types+1, number_of_types+1, numofbins+1)) for i in interaction_list: LIST_IN = open("%s.%d.%d" % (filename, i[0], i[1]), 'r') index = 0 for line in LIST_IN: NewRow = (line.strip()).split() mystring = NewRow[0][0:1] if mystring != "#": if len(NewRow)>2: index += 1 rdf_array[i[0]][i[1]][index] = float(NewRow[2]) LIST_IN.close() return rdf_array, int(numofbins), float(cutoff)
def read_in_rdf_file(filename, number_of_types, interaction_list): """ subroutine to read in the RDF file - note, the format must be distance is first column, and RDF is the third column ASSUMPTION: ALL RDF FILES HAVE THE SAME NUMBER OF BINS AND CUTOFF. """ index = 0 print "reading RDF %s" % (filename) numofbins, cutoff, o = lmp_io.get_number_of_bins_and_cutoff( "%s.1.1" % (filename), 0) rdf_array = np.zeros( (number_of_types + 1, number_of_types + 1, numofbins + 1)) for i in interaction_list: LIST_IN = open("%s.%d.%d" % (filename, i[0], i[1]), 'r') index = 0 for line in LIST_IN: NewRow = (line.strip()).split() mystring = NewRow[0][0:1] if mystring != "#": if len(NewRow) > 2: index += 1 rdf_array[i[0]][i[1]][index] = float(NewRow[2]) LIST_IN.close() return rdf_array, int(numofbins), float(cutoff)
def production(): """ This script will create the next interation of coarse-grained potentials using the Iterative Boltzmann Inversion to match to a user-supplied radial distribution function (normally from atomistic simulation). It will also attempt a correction for the pressure. The script will also extrapolate the potentials at low distance values by fitting to a soft Lennard-Jones potential. Note, this fitting is somewhat unstable (CurveFit.pm) and can cause the IBI to fail. """ print "ARGUMENTS TO THE IBI ARE: ", sys.argv # user-supplied arguments to the IBI. Note, not all of these arguments are required depending on what analysis is need and files are provided. lammps_input_file = "" # LAMMPS input file for the current CG iteration. correct_rdf_base = "" # User-supplied Radial Distribution Function to match to (normally derived from atomistic simulation) - distance is column 1 and the RDF is column 3. potential_base = "" # the file base-name for the potential energy files. The format is such: pot.<iteration_number>.new.<type1><type2>. In this case the base-name is "pot". number = 0 # the current IBI iteration number lammps_data_file = "" # LAMMPS CG data file lammps_rdf_file = "" # the CG RDF file if calculated by LAMMPS - this is a series of snapshot values, which need to be averaged. p_target = 1.0 # pressure target for the CG simulation. p_flag = 0.0 # flag to indicate whether to apply pressure correction - set to one if a pressure target is set by the user. CG_output_file = "" # LAMMPS thermodynamic log file for the current CG simulation. Used to calculate the current average CG pressure. p_now = 0 # current CG pressure read from (and averaged) the CG lammps thermodynamic log file; temperature = 300 # temperature the simulations are run at; default is 300K LJ_file_flag = 0 # if this flag is set to one, the parameters used in the extrapolation by fitting to a Lennard-Jones potential are read from a file (called LJ_parameters) rather than computed from fitting to the potential / forces. num_of_bins = 0 DeltaR = 0.0 number_of_arguments = len(sys.argv) mode = "default" num_of_types = 0 for i in xrange(0, number_of_arguments): if sys.argv[i].lower() == "lammps_input_file": lammps_input_file = sys.argv[i + 1] print "THE LAMMPS INPUT FILE IS ", lammps_input_file elif sys.argv[i].lower() == "lammps_output_file": lammps_output_file = sys.argv[i + 1] print "THE LAMMPS OUTPUT FILE IS ", lammps_input_file elif sys.argv[i].lower() == "lammps_data_file": lammps_data_file = sys.argv[i + 1] print "THE LAMMPS DATA FILE IS ", lammps_data_file elif ((sys.argv[i] == "potential_base") or (sys.argv[i] == "potential")): potential_base = sys.argv[i + 1] elif sys.argv[i].lower() == "lammps_rdf_file": lammps_rdf_file = sys.argv[i + 1] print "THE RDFS WILL BE READ FROM LAMMPS OUTPUT", lammps_rdf_file elif (sys.argv[i] == "correct_rdf_base"): correct_rdf_base = sys.argv[i + 1] print "THE RDFS TO MATCH TO HAVE THE FILE BASE ", correct_rdf_base elif ((sys.argv[i] == "number") or (sys.argv[i] == "current_number") or (sys.argv[i] == "iteration_number")): number = int(sys.argv[i + 1]) print "THE CURRENT ITERATION NUMBER IS ", number elif ((sys.argv[i] == "pressure_flag") or (sys.argv[i] == "p_flag")): p_flag = float(sys.argv[i + 1]) print "THE PRESSURE FLAG is ", p_flag elif ((sys.argv[i] == "pressure_target") or (sys.argv[i] == "p_target")): p_target = float(sys.argv[i + 1]) if abs(p_flag) < 0.00001: p_flag = 1 print "THE PRESSURE TARGET is ", p_target elif ((sys.argv[i] == "CG_log_file") or (sys.argv[i] == "CG_logfile")): CG_output_file = sys.argv[i + 1] p_now = read_CG_log_file(CG_output_file, label="Press") #TODO: this is only a temp hack! print "THE CURRENT PRESSURE WILL BE CALCULATED FROM THE LOG FILE ", CG_output_file, p_now elif (sys.argv[i] == "temperature"): temperature = float(sys.argv[i + 1]) elif (sys.argv[i] == "LJ_param_file"): LJ_file_flag = 1 elif sys.argv[i].lower() == "numofbins": num_of_bins = int(sys.argv[i + 1]) print "THE NUMBER OF BINS IS ", num_of_bins elif sys.argv[i].lower() == "deltar": DeltaR = float(sys.argv[i + 1]) print "DeltaR IS ", DeltaR elif sys.argv[i] == "mode": mode = sys.argv[i + 1] elif sys.argv[i].lower() == "numoftypes": num_of_types = int(sys.argv[i + 1]) # read in the lammps data file to identify the number of CG types and lattice parameters. lattice, type_list = lmp_io.read_lammps_data_file(lammps_data_file) num_of_types = len(type_list) print "Num of types = ", num_of_types #num_of_types = 4 number_of_types_array = np.zeros((num_of_types + 1)) for n in xrange(1, num_of_types + 1): number_of_types_array[n] = len(type_list["%s" % n]) if mode == "pressure_correct": num_of_bins, cutoff, offset = lmp_io.get_number_of_bins_and_cutoff( potential_base, 1) print "Potential numofbins and cutoff:", num_of_bins, cutoff pots = (potential_base.strip()).split('.') atom1 = int(pots[-2]) atom2 = int(pots[-1]) print "ATOMS are:", atom1, atom2 potential = np.zeros((num_of_bins + 1)) volume = float(lattice[0]) * float(lattice[1]) * float(lattice[2]) hist_rdf = lmp_io.read_lammps_rdf(lammps_rdf_file, num_of_types, number) pressure_pot = calc_pressure_correction(hist_rdf[atom1][atom2], num_of_bins, DeltaR, number_of_types_array[atom1], number_of_types_array[atom2], abs(p_flag), p_now, p_target, volume, temperature) old_distance, old_potential, old_derivative = lmp_io.read_in_interaction_file( potential_base, num_of_bins) potential = apply_pressure_correction(old_potential, pressure_pot, num_of_bins + 1, old_distance[1], DeltaR) potential[0] = potential[ 1] # TODO: change this temporary workaround into something more systematic. The workaround reduces anomalies in the derivative at the start of the potential. new_derivatives = da.derivatives(np.arange(offset, cutoff, DeltaR), potential) print "dy lens:", num_of_bins, len(new_derivatives), len( np.arange(offset - DeltaR, cutoff, DeltaR)), len(potential) write_pot_file( "%s/pot.%d.new.%d.%d" % (os.path.dirname(lammps_output_file), number + 1, atom1, atom2), new_derivatives[1:], potential[1:], num_of_bins, DeltaR, atom1, atom2, num_of_bins, offset, smoothing="no", selection="no") #note: we use an offset here! elif mode == "default": # Either read an interaction list from a file in the atom_dir (useful if you want to parametrize only a subset of interactions), or generate one on the fly. interaction_filename = os.path.dirname( correct_rdf_base) + "/interaction_list" if os.path.exists(interaction_filename): interaction_list = interaction_list_from_file(interaction_filename) else: interaction_list = generate_interaction_list(num_of_types) first_array, num_of_bins, cutoff2 = read_in_rdf_file( correct_rdf_base, num_of_types, interaction_list) # read in the rdfs to match to. print "THE CUTOFF in the RDF files is", cutoff2, ", with", len( first_array[1][1]) - 1, "number of bins " print "THIS IS ITERATION NUMBER", number deltaR = cutoff2 / num_of_bins # bin spacing from the RDF previous_position, previous_potential, previous_derivative, old_pot_files, cutoff = lmp_io.read_in_interaction_files( potential_base, num_of_types, interaction_list, number) num_of_bins = int(cutoff / deltaR) print deltaR, cutoff2, num_of_bins, correct_rdf_base print "THE CUTOFF in the POS FILES is", cutoff, "and number of bins are", num_of_bins # read in the RDFs of the CG calculated by LAMMPS. hist_rdf = lmp_io.read_lammps_rdf(lammps_rdf_file, num_of_types, number) # print lammps_rdf_file, len(hist_rdf[1][1]) DeltaR = cutoff / num_of_bins # calculate the IBI compute_update(os.path.dirname(lammps_output_file), first_array, hist_rdf, previous_position, previous_potential, num_of_types, number, DeltaR, num_of_bins, number_of_types_array, lattice, LJ_file_flag, p_flag, p_now, p_target, temperature, interaction_list) # modify the lammps input file, ready for the next iteration modify_lammps_in_file(lammps_input_file, lammps_output_file, number, interaction_list, num_of_types) else: print "ERROR: mode is incorrectly set in IBI.py. Should be e.g., default or pressure_correct" sys.exit()
elif mode == "rdf_compare": atom1 = int(sys.argv[3]) atom2 = int(sys.argv[4]) plot_panel = fig.add_subplot(1, 1, 1) rdf_compare(plot_panel, "tmp.%d.rdf" % (iter), "tmp.1.rdf", iter, atom1, atom2) elif mode == "lammps_rdf": if len(sys.argv)>4: atom1 = int(sys.argv[3]) atom2 = int(sys.argv[4]) plot_panel = fig.add_subplot(1, 1, 1) analyse_and_plot_lammps_rdf_file(plot_panel, "tmp.%d.rdf" % (iter), iter, atom1, atom2) elif len(sys.argv) == 4: k=1 rdf_average = lmp_io.read_lammps_rdf("tmp.%d.rdf" % (iter), int(sys.argv[3]), iter, timestep_limit=200000, write_rdf_files=False, timestep_threshold=0) for i in range(1,int(sys.argv[3])): for j in range(i,int(sys.argv[3])): # Create panel plot_panel = fig.add_subplot(int(sys.argv[3]),(int(sys.argv[3])+1)/2, k) # plot target RDF d1 = np.loadtxt("rdf.%d.%d" % (i,j)) print "add_rdf_plot: ", iter, i, j, "d1: rdf.%d.%d" % (i,j) #plot_panel.plot(d1[:,0],d1[:,2], label="target %d %d" % (i,j)) plot_panel.plot(xrange(0,len(d1)),d1[:,2], label="target %d %d" % (i,j)) # plot CG approximation plot_panel.plot(xrange(0,len(rdf_average[i][j])),rdf_average[i][j], label="CG %d %d" % (i,j)) k += 1 pylab.legend(loc=4)
plot_panel = fig.add_subplot(1, 1, 1) rdf_compare(plot_panel, "tmp.%d.rdf" % (iter), "tmp.1.rdf", iter, atom1, atom2) elif mode == "lammps_rdf": if len(sys.argv) > 4: atom1 = int(sys.argv[3]) atom2 = int(sys.argv[4]) plot_panel = fig.add_subplot(1, 1, 1) analyse_and_plot_lammps_rdf_file(plot_panel, "tmp.%d.rdf" % (iter), iter, atom1, atom2) elif len(sys.argv) == 4: k = 1 rdf_average = lmp_io.read_lammps_rdf("tmp.%d.rdf" % (iter), int(sys.argv[3]), iter, timestep_limit=200000, write_rdf_files=False, timestep_threshold=0) for i in range(1, int(sys.argv[3])): for j in range(i, int(sys.argv[3])): # Create panel plot_panel = fig.add_subplot(int(sys.argv[3]), (int(sys.argv[3]) + 1) / 2, k) # plot target RDF d1 = np.loadtxt("rdf.%d.%d" % (i, j)) print "add_rdf_plot: ", iter, i, j, "d1: rdf.%d.%d" % (i, j) #plot_panel.plot(d1[:,0],d1[:,2], label="target %d %d" % (i,j)) plot_panel.plot(xrange(0, len(d1)), d1[:, 2],
def production(): """ This script will create the next interation of coarse-grained potentials using the Iterative Boltzmann Inversion to match to a user-supplied radial distribution function (normally from atomistic simulation). It will also attempt a correction for the pressure. The script will also extrapolate the potentials at low distance values by fitting to a soft Lennard-Jones potential. Note, this fitting is somewhat unstable (CurveFit.pm) and can cause the IBI to fail. """ print "ARGUMENTS TO THE IBI ARE: ", sys.argv # user-supplied arguments to the IBI. Note, not all of these arguments are required depending on what analysis is need and files are provided. lammps_input_file = "" # LAMMPS input file for the current CG iteration. correct_rdf_base = "" # User-supplied Radial Distribution Function to match to (normally derived from atomistic simulation) - distance is column 1 and the RDF is column 3. potential_base = "" # the file base-name for the potential energy files. The format is such: pot.<iteration_number>.new.<type1><type2>. In this case the base-name is "pot". number = 0 # the current IBI iteration number lammps_data_file = "" # LAMMPS CG data file lammps_rdf_file = "" # the CG RDF file if calculated by LAMMPS - this is a series of snapshot values, which need to be averaged. p_target = 1.0 # pressure target for the CG simulation. p_flag = 0.0 # flag to indicate whether to apply pressure correction - set to one if a pressure target is set by the user. CG_output_file = "" # LAMMPS thermodynamic log file for the current CG simulation. Used to calculate the current average CG pressure. p_now = 0 # current CG pressure read from (and averaged) the CG lammps thermodynamic log file; temperature = 300 # temperature the simulations are run at; default is 300K LJ_file_flag = 0 # if this flag is set to one, the parameters used in the extrapolation by fitting to a Lennard-Jones potential are read from a file (called LJ_parameters) rather than computed from fitting to the potential / forces. num_of_bins = 0 DeltaR = 0.0 number_of_arguments = len(sys.argv) mode = "default" num_of_types = 0 for i in xrange(0, number_of_arguments): if sys.argv[i].lower() == "lammps_input_file": lammps_input_file = sys.argv[i+1] print "THE LAMMPS INPUT FILE IS ", lammps_input_file elif sys.argv[i].lower() == "lammps_output_file": lammps_output_file = sys.argv[i+1] print "THE LAMMPS OUTPUT FILE IS ", lammps_input_file elif sys.argv[i].lower() == "lammps_data_file": lammps_data_file = sys.argv[i+1] print "THE LAMMPS DATA FILE IS ", lammps_data_file elif ((sys.argv[i] == "potential_base") or (sys.argv[i] == "potential")): potential_base = sys.argv[i+1] elif sys.argv[i].lower() == "lammps_rdf_file": lammps_rdf_file = sys.argv[i+1] print "THE RDFS WILL BE READ FROM LAMMPS OUTPUT", lammps_rdf_file elif (sys.argv[i] == "correct_rdf_base"): correct_rdf_base = sys.argv[i+1] print "THE RDFS TO MATCH TO HAVE THE FILE BASE ", correct_rdf_base elif ((sys.argv[i] == "number") or (sys.argv[i] == "current_number") or (sys.argv[i] == "iteration_number")): number = int(sys.argv[i+1]) print "THE CURRENT ITERATION NUMBER IS ", number elif ((sys.argv[i] == "pressure_flag") or (sys.argv[i] == "p_flag")): p_flag = float(sys.argv[i+1]) print "THE PRESSURE FLAG is ", p_flag elif ((sys.argv[i] == "pressure_target") or (sys.argv[i] == "p_target")): p_target = float(sys.argv[i+1]) if abs(p_flag) < 0.00001: p_flag = 1 print "THE PRESSURE TARGET is ", p_target elif ((sys.argv[i] == "CG_log_file") or (sys.argv[i] == "CG_logfile")): CG_output_file = sys.argv[i+1] p_now = read_CG_log_file(CG_output_file, label="Press") #TODO: this is only a temp hack! print "THE CURRENT PRESSURE WILL BE CALCULATED FROM THE LOG FILE ", CG_output_file , p_now elif (sys.argv[i] == "temperature"): temperature = float(sys.argv[i+1]) elif (sys.argv[i] == "LJ_param_file"): LJ_file_flag = 1 elif sys.argv[i].lower() == "numofbins": num_of_bins = int(sys.argv[i+1]) print "THE NUMBER OF BINS IS ", num_of_bins elif sys.argv[i].lower() == "deltar": DeltaR = float(sys.argv[i+1]) print "DeltaR IS ", DeltaR elif sys.argv[i] == "mode": mode = sys.argv[i+1] elif sys.argv[i].lower() == "numoftypes": num_of_types = int(sys.argv[i+1]) # read in the lammps data file to identify the number of CG types and lattice parameters. lattice, type_list = lmp_io.read_lammps_data_file(lammps_data_file) num_of_types = len(type_list) print "Num of types = ", num_of_types #num_of_types = 4 number_of_types_array = np.zeros((num_of_types+1)) for n in xrange(1, num_of_types+1): number_of_types_array[n] = len(type_list["%s" % n]) if mode=="pressure_correct": num_of_bins, cutoff, offset = lmp_io.get_number_of_bins_and_cutoff(potential_base, 1) print "Potential numofbins and cutoff:", num_of_bins, cutoff pots = (potential_base.strip()).split('.') atom1 = int(pots[-2]) atom2 = int(pots[-1]) print "ATOMS are:", atom1, atom2 potential = np.zeros((num_of_bins+1)) volume = float(lattice[0]) * float(lattice[1]) * float(lattice[2]) hist_rdf = lmp_io.read_lammps_rdf(lammps_rdf_file, num_of_types, number) pressure_pot = calc_pressure_correction(hist_rdf[atom1][atom2], num_of_bins, DeltaR, number_of_types_array[atom1], number_of_types_array[atom2], abs(p_flag), p_now, p_target, volume, temperature) old_distance, old_potential, old_derivative = lmp_io.read_in_interaction_file(potential_base, num_of_bins) potential = apply_pressure_correction(old_potential, pressure_pot, num_of_bins+1, old_distance[1], DeltaR) potential[0]=potential[1] # TODO: change this temporary workaround into something more systematic. The workaround reduces anomalies in the derivative at the start of the potential. new_derivatives = da.derivatives(np.arange(offset, cutoff, DeltaR), potential) print "dy lens:", num_of_bins, len(new_derivatives), len(np.arange(offset-DeltaR, cutoff, DeltaR)), len(potential) write_pot_file("%s/pot.%d.new.%d.%d" % (os.path.dirname(lammps_output_file), number+1, atom1, atom2), new_derivatives[1:] , potential[1:], num_of_bins, DeltaR, atom1, atom2, num_of_bins, offset, smoothing="no", selection="no") #note: we use an offset here! elif mode=="default": # Either read an interaction list from a file in the atom_dir (useful if you want to parametrize only a subset of interactions), or generate one on the fly. interaction_filename = os.path.dirname(correct_rdf_base) + "/interaction_list" if os.path.exists(interaction_filename): interaction_list = interaction_list_from_file(interaction_filename) else: interaction_list = generate_interaction_list(num_of_types) first_array, num_of_bins, cutoff2 = read_in_rdf_file(correct_rdf_base, num_of_types, interaction_list) # read in the rdfs to match to. print "THE CUTOFF in the RDF files is", cutoff2, ", with", len(first_array[1][1])-1, "number of bins "; print "THIS IS ITERATION NUMBER", number deltaR = cutoff2 / num_of_bins # bin spacing from the RDF previous_position, previous_potential, previous_derivative, old_pot_files, cutoff = lmp_io.read_in_interaction_files(potential_base, num_of_types, interaction_list, number) num_of_bins = int(cutoff / deltaR) print deltaR, cutoff2, num_of_bins, correct_rdf_base print "THE CUTOFF in the POS FILES is", cutoff, "and number of bins are", num_of_bins # read in the RDFs of the CG calculated by LAMMPS. hist_rdf = lmp_io.read_lammps_rdf(lammps_rdf_file, num_of_types, number) # print lammps_rdf_file, len(hist_rdf[1][1]) DeltaR = cutoff / num_of_bins # calculate the IBI compute_update(os.path.dirname(lammps_output_file), first_array, hist_rdf, previous_position, previous_potential, num_of_types, number, DeltaR, num_of_bins, number_of_types_array, lattice, LJ_file_flag, p_flag, p_now, p_target, temperature, interaction_list) # modify the lammps input file, ready for the next iteration modify_lammps_in_file(lammps_input_file, lammps_output_file, number, interaction_list, num_of_types) else: print "ERROR: mode is incorrectly set in IBI.py. Should be e.g., default or pressure_correct" sys.exit()
def update_one_file(out_path, target_g_r, new_g_r, old_distance, old_potential, num_of_types, number, DeltaR, numofbins, number_of_types1, number_of_types2, lattice, LJ_file_flag, p_flag, p_now, p_target, temperature, atom1, atom2): number = int(number) potential = np.zeros((numofbins+1)) derivative = np.zeros((numofbins+1)) new_number = number + 1 volume = float(lattice[0]) * float(lattice[1]) * float(lattice[2]) print "Lengths: ", len(target_g_r), len(new_g_r), len(old_distance), len(old_potential), numofbins index = length = 0 x_data = np.zeros((numofbins+1)) y_data = np.zeros((numofbins+1)) success = 0 # smooth the new CG radial distribution function and calculate where the old CG rdf starts (it will be zero at low distance values). filtered_rdf = dm.smooth_data(new_g_r) np.append(filtered_rdf, 1) conversion_extrapolate_tmp = {} pressure_pot = np.zeros((numofbins+1)) if abs(float(p_flag)) > 0.00001: print "FabMD: P+) Applying pressure function." pressure_pot = calc_pressure_correction(new_g_r, numofbins, DeltaR, number_of_types1, number_of_types2, abs(p_flag), p_now, p_target, volume, temperature) else: print "FabMD: P-) Not applying any pressure correction." # use_data = 0 if float(p_flag) < -0.00001: print "FabMD: I-) IBI is disabled!" pot_write_threshold = -1 # slot where we start the pot functions kB = 0.0019858775 for i in xrange(0, numofbins+1): # print old_distance[1], i, i*DeltaR if old_distance[1] <= ((i+0.1) * DeltaR): #0.1 is here to prevent tiny bugs in float comparisons, causing the list to get shorter and shorter... if pot_write_threshold == -1: pot_write_threshold = i length += 1 # the IBI update to the potential target_g_r_i = 1.0 if len(target_g_r) > i: target_g_r_i = target_g_r[i] fri = 1.0 #filtered rdf shorthand for beyond the cutoff. if len(filtered_rdf) > i: fri = filtered_rdf[i] if float(p_flag) < -0.00001: # Disable IBI part. print "old potential:", old_potential[length] print "pressure modification:", pressure_pot[i-1] potential[i] = old_potential[length] + pressure_pot[i-1] #print i, (abs(target_g_r_i) > 0), (fri > 0.15), i*DeltaR, old_potential[length], pressure_pot[i] if (abs(target_g_r_i) > 0) and (fri > 0.15): if float(p_flag) > -0.00001: # Enable IBI part. # print "FabMD: I+) IBI is enabled!" potential[i] = old_potential[length] + (kB * temperature) * math.log(fri / target_g_r_i) + pressure_pot[i-1] # Debug check # if abs(old_distance[length] - i*DeltaR)>0.00001: # print "Error: old_distance seems to be wrongly mapped!" # exit() x_data[index] = i * DeltaR y_data[index] = potential[i] index += 1 #print i, potential[i] else: # this array indicates which values we need to an extrapolation for the potential and for the forces (negative of the potential derivative) - defined as where # the RDF is less than 0.15, yet is defined in the old potential file. conversion_extrapolate_tmp[i] = 1 #exit() x_data.resize((index)) y_data.resize((index)) dy = da.derivatives(x_data, y_data) # print y_data, dy, len(y_data), len(dy) # exit() parameters = {} square_residual = 0 if LJ_file_flag == 1: # read in Lennard-Jones parameters from file if requested. parameters = {} LJ_IN = open("LJ_parameters", 'r') for line in LJ_IN: NewRow = (line.strip()).split() if (NewRow[2] == atom1) and (NewRow[3] == atom2): parameters[0][1] = NewRow[6] parameters[1][1] = NewRow[9] LJ_IN.close() else: # fitting the potential derivative (i.e. negative forces) using CurveFit.pm to a Lennard Jones 6 - 3 potential (i.e. 7 - 4 when differentiated ) fitfunc = lambda p, x: - 6 * (( ( 4 * p[0] * p[1]**6) / x**7) - ( (4 * p[0] * p[1]**3) / (2*x**4)) ) errfunc = lambda p, x, y: fitfunc(p, x) - y #print "X_DATA = ", x_data, dy, y_data p0 = np.array([0.5, 4.5]) #was 0.5,4.5 p1, success = scipy.optimize.leastsq(errfunc, p0[:], maxfev=5000, args=(x_data, dy)) #use [:int(4.0/DeltaR)] to optimize up to a cutoff of 4. if success == 0: print "Scipy.optimize did not manage to converge the fit on dataset", atom1, atom2, "! Exiting now." exit() LJ_OUT = open("%s/LJ_parameters" % (out_path),'w') LJ_OUT.write("LJ PARAMETERS %d %d p0 = %f, p1 = %f\n" % (atom1, atom2, p1[0], p1[1])) LJ_OUT.close() for i in xrange(numofbins+1, 1, -1): if i in conversion_extrapolate_tmp.keys(): #77-31 #print i if conversion_extrapolate_tmp[i] > 0: new_distance = i * DeltaR # These Lennard-Jones forces are then numerically integrated to get the potential derivative[i] = -np.abs(fitfunc(p1, new_distance)) diff = x_data[0] - new_distance ave = 0.5 * fitfunc(p1, new_distance) - 0.5 * dy[0] r_y = np.abs(y_data[0] - diff * ave) potential[i] = r_y # print i, derivative[i], potential[i], "!" index = 0 for i in xrange(pot_write_threshold, numofbins+1): if i not in conversion_extrapolate_tmp.keys(): derivative[i] = dy[index] index += 1 index = 0 for i in xrange(0, numofbins+1): if len(derivative) > i: if abs(derivative[i]) > 0: index += 1 # determining the number of potential values lmp_io.write_pot_file("%s/pot.%d.new.%d.%d" % (out_path, new_number, atom1, atom2), derivative, potential, numofbins, DeltaR, atom1, atom2, index)
if __name__ == "__main__": parser = argparse.ArgumentParser(description='Modify a potential.') parser.add_argument("-i", "--inputfile", help='name of the potential file to read') parser.add_argument("-m", "--mode", default='smooth', help='type of filter used', choices=["smooth", "remove_tail", "append_zeroes", "amplify", "xshift", "yshift", "prepend", "append_linear"]) parser.add_argument("-r", "--repeat", help='number of repetitions', type=int, default=1) parser.add_argument("-a", "--atom1", help='atom number 1', type=int, default=1) parser.add_argument("-b", "--atom2", help='atom number 2', type=int, default=1) parser.add_argument("-o", "--outputfile", help='name of the potential file to write') parser.add_argument("parameter", type=float, help='specifies a key parameter to associate with the mode. Should be at least 1e-10.', default=0.0) args = parser.parse_args() print args num_of_bins, cutoff, offset = lmp_io.get_number_of_bins_and_cutoff(args.inputfile, 1) print "Potential numofbins and cutoff:", num_of_bins, cutoff dis, pot, der = lmp_io.read_in_interaction_file(args.inputfile, num_of_bins) dis = dis[1:] pot = pot[1:] der = der[1:] for i in xrange(0,args.repeat): if args.mode == "smooth": pot = dm.smooth_data(pot,window_len=int(args.parameter),window='flat') elif args.mode == "remove_tail": pot, der = dm.remove_tail(pot, der) elif args.mode == "append_zeroes": if abs(args.parameter) < 1e-10: args.parameter = 20
def update_one_file(out_path, target_g_r, new_g_r, old_distance, old_potential, num_of_types, number, DeltaR, numofbins, number_of_types1, number_of_types2, lattice, LJ_file_flag, p_flag, p_now, p_target, temperature, atom1, atom2): number = int(number) potential = np.zeros((numofbins + 1)) derivative = np.zeros((numofbins + 1)) new_number = number + 1 volume = float(lattice[0]) * float(lattice[1]) * float(lattice[2]) print "Lengths: ", len(target_g_r), len(new_g_r), len(old_distance), len( old_potential), numofbins index = length = 0 x_data = np.zeros((numofbins + 1)) y_data = np.zeros((numofbins + 1)) success = 0 # smooth the new CG radial distribution function and calculate where the old CG rdf starts (it will be zero at low distance values). filtered_rdf = dm.smooth_data(new_g_r) np.append(filtered_rdf, 1) conversion_extrapolate_tmp = {} pressure_pot = np.zeros((numofbins + 1)) if abs(float(p_flag)) > 0.00001: print "FabMD: P+) Applying pressure function." pressure_pot = calc_pressure_correction(new_g_r, numofbins, DeltaR, number_of_types1, number_of_types2, abs(p_flag), p_now, p_target, volume, temperature) else: print "FabMD: P-) Not applying any pressure correction." # use_data = 0 if float(p_flag) < -0.00001: print "FabMD: I-) IBI is disabled!" pot_write_threshold = -1 # slot where we start the pot functions kB = 0.0019858775 for i in xrange(0, numofbins + 1): # print old_distance[1], i, i*DeltaR if old_distance[1] <= ( (i + 0.1) * DeltaR ): #0.1 is here to prevent tiny bugs in float comparisons, causing the list to get shorter and shorter... if pot_write_threshold == -1: pot_write_threshold = i length += 1 # the IBI update to the potential target_g_r_i = 1.0 if len(target_g_r) > i: target_g_r_i = target_g_r[i] fri = 1.0 #filtered rdf shorthand for beyond the cutoff. if len(filtered_rdf) > i: fri = filtered_rdf[i] if float(p_flag) < -0.00001: # Disable IBI part. print "old potential:", old_potential[length] print "pressure modification:", pressure_pot[i - 1] potential[i] = old_potential[length] + pressure_pot[i - 1] #print i, (abs(target_g_r_i) > 0), (fri > 0.15), i*DeltaR, old_potential[length], pressure_pot[i] if (abs(target_g_r_i) > 0) and (fri > 0.15): if float(p_flag) > -0.00001: # Enable IBI part. # print "FabMD: I+) IBI is enabled!" potential[i] = old_potential[length] + ( kB * temperature) * math.log( fri / target_g_r_i) + pressure_pot[i - 1] # Debug check # if abs(old_distance[length] - i*DeltaR)>0.00001: # print "Error: old_distance seems to be wrongly mapped!" # exit() x_data[index] = i * DeltaR y_data[index] = potential[i] index += 1 #print i, potential[i] else: # this array indicates which values we need to an extrapolation for the potential and for the forces (negative of the potential derivative) - defined as where # the RDF is less than 0.15, yet is defined in the old potential file. conversion_extrapolate_tmp[i] = 1 #exit() x_data.resize((index)) y_data.resize((index)) dy = da.derivatives(x_data, y_data) # print y_data, dy, len(y_data), len(dy) # exit() parameters = {} square_residual = 0 if LJ_file_flag == 1: # read in Lennard-Jones parameters from file if requested. parameters = {} LJ_IN = open("LJ_parameters", 'r') for line in LJ_IN: NewRow = (line.strip()).split() if (NewRow[2] == atom1) and (NewRow[3] == atom2): parameters[0][1] = NewRow[6] parameters[1][1] = NewRow[9] LJ_IN.close() else: # fitting the potential derivative (i.e. negative forces) using CurveFit.pm to a Lennard Jones 6 - 3 potential (i.e. 7 - 4 when differentiated ) fitfunc = lambda p, x: -6 * (((4 * p[0] * p[1]**6) / x**7) - ((4 * p[0] * p[1]**3) / (2 * x**4))) errfunc = lambda p, x, y: fitfunc(p, x) - y #print "X_DATA = ", x_data, dy, y_data p0 = np.array([0.5, 4.5]) #was 0.5,4.5 p1, success = scipy.optimize.leastsq( errfunc, p0[:], maxfev=5000, args=( x_data, dy)) #use [:int(4.0/DeltaR)] to optimize up to a cutoff of 4. if success == 0: print "Scipy.optimize did not manage to converge the fit on dataset", atom1, atom2, "! Exiting now." exit() LJ_OUT = open("%s/LJ_parameters" % (out_path), 'w') LJ_OUT.write("LJ PARAMETERS %d %d p0 = %f, p1 = %f\n" % (atom1, atom2, p1[0], p1[1])) LJ_OUT.close() for i in xrange(numofbins + 1, 1, -1): if i in conversion_extrapolate_tmp.keys(): #77-31 #print i if conversion_extrapolate_tmp[i] > 0: new_distance = i * DeltaR # These Lennard-Jones forces are then numerically integrated to get the potential derivative[i] = -np.abs(fitfunc(p1, new_distance)) diff = x_data[0] - new_distance ave = 0.5 * fitfunc(p1, new_distance) - 0.5 * dy[0] r_y = np.abs(y_data[0] - diff * ave) potential[i] = r_y # print i, derivative[i], potential[i], "!" index = 0 for i in xrange(pot_write_threshold, numofbins + 1): if i not in conversion_extrapolate_tmp.keys(): derivative[i] = dy[index] index += 1 index = 0 for i in xrange(0, numofbins + 1): if len(derivative) > i: if abs(derivative[i]) > 0: index += 1 # determining the number of potential values lmp_io.write_pot_file( "%s/pot.%d.new.%d.%d" % (out_path, new_number, atom1, atom2), derivative, potential, numofbins, DeltaR, atom1, atom2, index)
type=int, default=1) parser.add_argument("-o", "--outputfile", help='name of the potential file to write') parser.add_argument( "parameter", type=float, help= 'specifies a key parameter to associate with the mode. Should be at least 1e-10.', default=0.0) args = parser.parse_args() print args num_of_bins, cutoff, offset = lmp_io.get_number_of_bins_and_cutoff( args.inputfile, 1) print "Potential numofbins and cutoff:", num_of_bins, cutoff dis, pot, der = lmp_io.read_in_interaction_file(args.inputfile, num_of_bins) dis = dis[1:] pot = pot[1:] der = der[1:] for i in xrange(0, args.repeat): if args.mode == "smooth": pot = dm.smooth_data(pot, window_len=int(args.parameter), window='flat') elif args.mode == "remove_tail": pot, der = dm.remove_tail(pot, der)
def production(): print "ARGUMENTS to the PMF calculation are: ", sys.argv wham_correct_file = "" number="" atom_type1="" atom_type2="" out_path="" CG_in_file_base="" pot_base="" wham_executable="" lammps_input_file = "" number_of_arguments = len(sys.argv) for i in xrange(0, number_of_arguments): if sys.argv[i].lower() == "wham_correct_file": wham_correct_file = sys.argv[i+1] print "THE WHAM CORRECT FILE IS ", wham_correct_file elif ((sys.argv[i] == "potential_base") or (sys.argv[i] == "potential") or (sys.argv[i] == "pot_base")): pot_base_full = os.path.split(sys.argv[i+1]) pot_base_file = pot_base_full[1] pot_base_dir=pot_base_full[0] pot_base=sys.argv[i+1] elif ((sys.argv[i].lower() == "atom_type1") or (sys.argv[i].lower() == "atom1") or (sys.argv[i].lower() == "type1")): atom_type1 = int(sys.argv[i+1]) elif ((sys.argv[i].lower() == "atom_type2") or (sys.argv[i].lower() == "atom2") or (sys.argv[i].lower() == "type2")): atom_type2 = int(sys.argv[i+1]) elif ((sys.argv[i] == "number") or (sys.argv[i] == "current_number") or (sys.argv[i] == "iteration_number")): number = int(sys.argv[i+1]) print "THE CURRENT ITERATION NUMBER IS ", number elif ((sys.argv[i] == "CG_in_file") or (sys.argv[i] == "CG_lammps_file") or (sys.argv[i] == "CG_input")): CG_in_file = sys.argv[i+1] elif ((sys.argv[i].lower() == "lammps_in_file") or (sys.argv[i] == "lammps_input_file") or (sys.argv[i] == "lammps_input")): lammps_input_file_full=os.path.split(sys.argv[i+1]) lammps_input_file = lammps_input_file_full[1] lammps_input_file_dir=lammps_input_file_full[0] lammps_input_file_full=sys.argv[i+1] elif ((sys.argv[i] == "wham_executable") or (sys.argv[i] == "wham_executable_path") or (sys.argv[i] == "wham_path")): wham_executable = sys.argv[i+1] elif ((sys.argv[i] == "out_directory") or (sys.argv[i] == "out")): out_path = sys.argv[i+1] if not os.path.isdir(out_path): os.makedirs(out_path) #wham_correct_file=sys.argv[1] #number=sys.argv[2] #atom_type_1=int(sys.argv[3]) #atom_type_2=int(sys.argv[4]) #out_path=sys.argv[5] #CG_in_file_base="in.CG.lammps.1" wham_array_correct, wham_array_distance_correct, numofbins_wham, cutoff_wham= read_in_WHAM_file(wham_correct_file) dir_value_dict, dir_spring_const_dict, dir_log_file_dict, dir_data_file_dict =find_dir_value_dict(CG_in_file,lammps_input_file_dir) print "LAMMPS input_dir", lammps_input_file_dir wham_spacing=wham_array_distance_correct[1]-wham_array_distance_correct[0] wham_minimum=wham_array_distance_correct[0]-(wham_spacing/2) wham_maximum=wham_array_distance_correct[numofbins_wham-1]+(wham_spacing/2) wham_list_base="wham_list_CG" wham_list=os.path.join(lammps_input_file_dir, str(wham_list_base + '.' + str(number))) wham_output=os.path.join(lammps_input_file_dir, str("wham_output"+ '.' + str(number))) print "WHAMLIST", wham_list, wham_output pot_file=pot_base + str(number) new_number=int(number)+1 print "NEW NUMBER", new_number, number pot_new=pot_base_file+str(new_number) pot_file_new=os.path.join(out_path,pot_new) print "POT_FILE NEW", pot_file_new, out_path print "NUMOFBINS IS ", numofbins_wham create_WHAM_files(dir_value_dict, dir_spring_const_dict,dir_log_file_dict,dir_value_dict,wham_list,lammps_input_file_dir) print "WHAM", wham_list, wham_output call("'%s' '%f' '%f' '%d' 0.0001 500 0 '%s' '%s' " % (wham_executable, wham_minimum, wham_maximum, numofbins_wham, wham_list, wham_output), shell=True) #2.875 20.125 69 0.0001 500 0 wham_list_CG.number wham_output.number') wham_array_new, wham_array_distance_new, numofbins_new, cutoff_wham_new= read_in_WHAM_file(wham_output,lammps_input_file_dir) num_of_pot_bins, cutoff_pot, offset_pot = lmp_io.get_number_of_bins_and_cutoff(pot_file,0) pot_distance, pot_potential, pot_derivative=lmp_io.read_in_interaction_file(pot_file,num_of_pot_bins) update_one_file_wham(number, num_of_pot_bins, wham_array_distance_new, wham_array_new, wham_array_distance_correct, wham_array_correct, pot_distance, pot_potential,atom_type1,atom_type2,dir_value_dict,pot_file_new,CG_in_file,out_path,lammps_input_file_dir) new_lammps_input_file=os.path.join(out_path,lammps_input_file) shutil.copy2(lammps_input_file_full, new_lammps_input_file)
def production(): print "ARGUMENTS to the PMF calculation are: ", sys.argv wham_correct_file = "" number = "" atom_type1 = "" atom_type2 = "" out_path = "" CG_in_file_base = "" pot_base = "" wham_executable = "" lammps_input_file = "" number_of_arguments = len(sys.argv) for i in xrange(0, number_of_arguments): if sys.argv[i].lower() == "wham_correct_file": wham_correct_file = sys.argv[i + 1] print "THE WHAM CORRECT FILE IS ", wham_correct_file elif ((sys.argv[i] == "potential_base") or (sys.argv[i] == "potential") or (sys.argv[i] == "pot_base")): pot_base_full = os.path.split(sys.argv[i + 1]) pot_base_file = pot_base_full[1] pot_base_dir = pot_base_full[0] pot_base = sys.argv[i + 1] elif ((sys.argv[i].lower() == "atom_type1") or (sys.argv[i].lower() == "atom1") or (sys.argv[i].lower() == "type1")): atom_type1 = int(sys.argv[i + 1]) elif ((sys.argv[i].lower() == "atom_type2") or (sys.argv[i].lower() == "atom2") or (sys.argv[i].lower() == "type2")): atom_type2 = int(sys.argv[i + 1]) elif ((sys.argv[i] == "number") or (sys.argv[i] == "current_number") or (sys.argv[i] == "iteration_number")): number = int(sys.argv[i + 1]) print "THE CURRENT ITERATION NUMBER IS ", number elif ((sys.argv[i] == "CG_in_file") or (sys.argv[i] == "CG_lammps_file") or (sys.argv[i] == "CG_input")): CG_in_file = sys.argv[i + 1] elif ((sys.argv[i].lower() == "lammps_in_file") or (sys.argv[i] == "lammps_input_file") or (sys.argv[i] == "lammps_input")): lammps_input_file_full = os.path.split(sys.argv[i + 1]) lammps_input_file = lammps_input_file_full[1] lammps_input_file_dir = lammps_input_file_full[0] lammps_input_file_full = sys.argv[i + 1] elif ((sys.argv[i] == "wham_executable") or (sys.argv[i] == "wham_executable_path") or (sys.argv[i] == "wham_path")): wham_executable = sys.argv[i + 1] elif ((sys.argv[i] == "out_directory") or (sys.argv[i] == "out")): out_path = sys.argv[i + 1] if not os.path.isdir(out_path): os.makedirs(out_path) #wham_correct_file=sys.argv[1] #number=sys.argv[2] #atom_type_1=int(sys.argv[3]) #atom_type_2=int(sys.argv[4]) #out_path=sys.argv[5] #CG_in_file_base="in.CG.lammps.1" wham_array_correct, wham_array_distance_correct, numofbins_wham, cutoff_wham = read_in_WHAM_file( wham_correct_file) dir_value_dict, dir_spring_const_dict, dir_log_file_dict, dir_data_file_dict = find_dir_value_dict( CG_in_file, lammps_input_file_dir) print "LAMMPS input_dir", lammps_input_file_dir wham_spacing = wham_array_distance_correct[ 1] - wham_array_distance_correct[0] wham_minimum = wham_array_distance_correct[0] - (wham_spacing / 2) wham_maximum = wham_array_distance_correct[numofbins_wham - 1] + (wham_spacing / 2) wham_list_base = "wham_list_CG" wham_list = os.path.join(lammps_input_file_dir, str(wham_list_base + '.' + str(number))) wham_output = os.path.join(lammps_input_file_dir, str("wham_output" + '.' + str(number))) print "WHAMLIST", wham_list, wham_output pot_file = pot_base + str(number) new_number = int(number) + 1 print "NEW NUMBER", new_number, number pot_new = pot_base_file + str(new_number) pot_file_new = os.path.join(out_path, pot_new) print "POT_FILE NEW", pot_file_new, out_path print "NUMOFBINS IS ", numofbins_wham create_WHAM_files(dir_value_dict, dir_spring_const_dict, dir_log_file_dict, dir_value_dict, wham_list, lammps_input_file_dir) print "WHAM", wham_list, wham_output call("'%s' '%f' '%f' '%d' 0.0001 500 0 '%s' '%s' " % (wham_executable, wham_minimum, wham_maximum, numofbins_wham, wham_list, wham_output), shell=True) #2.875 20.125 69 0.0001 500 0 wham_list_CG.number wham_output.number') wham_array_new, wham_array_distance_new, numofbins_new, cutoff_wham_new = read_in_WHAM_file( wham_output, lammps_input_file_dir) num_of_pot_bins, cutoff_pot, offset_pot = lmp_io.get_number_of_bins_and_cutoff( pot_file, 0) pot_distance, pot_potential, pot_derivative = lmp_io.read_in_interaction_file( pot_file, num_of_pot_bins) update_one_file_wham(number, num_of_pot_bins, wham_array_distance_new, wham_array_new, wham_array_distance_correct, wham_array_correct, pot_distance, pot_potential, atom_type1, atom_type2, dir_value_dict, pot_file_new, CG_in_file, out_path, lammps_input_file_dir) new_lammps_input_file = os.path.join(out_path, lammps_input_file) shutil.copy2(lammps_input_file_full, new_lammps_input_file)