def plot_2D_Free_Energy(rc1, rc2, rc1n, rc2n, name, args, weights=None, temp=300, extra=None): print "Starting the Plot" nbins = args.bins if args.method == "arb": axis = None elif args.method == "same": axis = args.axis ##Plot a scatter plot if not args.contour_only: plt.figure() plot_style = "scatter" x, y, z = hist2d.make(rc1, rc2, nbins, nbins, temperature=temp, weight=weights, plot_style=plot_style, free_energy_plot=True, idx_smoothing=1) cp = plt.scatter(x, y, s=10, c=z, marker='o', linewidth=0.) if not extra == None: plt.plot(extra[:,0], extra[:,1], "^k", markersize=6) #vmax=7 if not axis == None: plt.axis(axis) plt.xlabel(rc1n, size=16) plt.ylabel(rc2n, size=16) cb = plt.colorbar(cp) pad = 10 cb.set_label(r'Free Energy (kT units)',labelpad=pad) plt.savefig("%s/%s_%s-%s-%s.png"%(args.save_dir, name, rc1n, rc2n, plot_style)) plt.close() ##Plot a contour plot if not args.scatter_only: ensure("%s/contour"%args.save_dir) plt.figure() plot_style = "contour" xc, yc, zc = hist2d.make(rc1, rc2, nbins, nbins, temperature=temp, weight=weights, plot_style=plot_style, free_energy_plot=True, idx_smoothing=1) cp = plt.contourf(xc, yc, zc, 20) plt.contour(xc, yc, zc, cp.levels, colors='k', hold='on') if not extra == None: plt.plot(extra[:,0], extra[:,1], "^k", markersize=6) if not axis == None: plt.axis(axis) plt.xlabel(rc1n, size=16) plt.ylabel(rc2n, size=16) cb = plt.colorbar(cp) pad = 10 cb.set_label(r'Free Energy (kT units)',labelpad=pad) plt.savefig("%s/contour/%s_%s-%s-%s.png"%(args.save_dir, name, rc1n, rc2n, plot_style)) plt.close()
def run(): parser = create_arg_parser() args = parser.parse_args() #read input files x = [] for input_file in args.input_file_x: file = reader.open(input_file) vals = file.readlines() # using readlines() of lsdmap reader, each row of x is a list # corresponding to the coordinates of each config, thus # needs to concatenate. vals = np.concatenate(vals, axis=0) x.append(vals) x = np.hstack(np.array(x)) y = [] for input_file in args.input_file_y: file = reader.open(input_file) vals = file.readlines() # using readlines() of lsdmap reader, each row of y is a list # corresponding to the coordinates of each config, thus # needs to concatenate. vals = np.concatenate(vals, axis=0) y.append(vals) y = np.hstack(np.array(y)) if not args.nbins: npoints = x.shape[0] nbins = int(np.sqrt(npoints)) else: nbins = args.nbins if args.wfile is not None: weight = [] for wfile in args.wfile: file = reader.open(wfile) vals = file.readlines() weight.append(vals) weight = np.hstack(np.array(weight)) else: weight = None plot_style = args.plot_style free_energy_plot = args.free_energy_plot idx_smoothing = args.idx_smoothing x, y, z = hist2d.make(x, y, nbins, nbins, weight=weight, plot_style=plot_style, free_energy_plot=free_energy_plot, idx_smoothing=idx_smoothing) if plot_style == 'scatter': cp = plt.scatter(x, y, s=10, c=z, marker='o', linewidth=0., vmax=3.5) elif plot_style == 'contour': cp = plt.contourf(x, y, z) plt.contour(x, y, z, cp.levels, colors='k', hold='on') plt.xlabel(args.xlabel, size=16) plt.ylabel(args.ylabel, size=16) cb = plt.colorbar(cp) pad = 10 if free_energy_plot is True: cb.set_label(r'Free Energy (kcal/mol)',labelpad=pad) else: cb.set_label(r'Density', labelpad=pad) plt.show()
subprocess.call("echo 0 | g_gyrate -xvg none -f " + gro_file + " -s " + gro_file + " 1>/dev/null 2>&1", shell=True) tphi = np.loadtxt('rmsd.xvg') tpsi = np.loadtxt('gyrate.xvg') weight = np.loadtxt(w_file) x = tphi[:, 1] y = tpsi[:, 1] nbins = 100 x, y, z = hist2d.make(x, y, nbins, nbins, plot_style='scatter', weight=weight, free_energy_plot=True, idx_smoothing=3) cp = plt.scatter(x, y, s=10, c=z, marker='o', linewidth=0.) #, vmax=3.5) print "Free energy in range:", min(z), max(z) plt.xlabel('RMSD (nm)', size=16) plt.ylabel('Rg (nm)', size=16) cb = plt.colorbar(cp) pad = 10 cb.set_label(r'Free Energy (kcal/mol units)', labelpad=pad) plt.axis([0.0, 1.0, 0.4, 1.4]) plt.savefig('plot_rgrmsd_iter' + str(i) + '.png', bbox_inches='tight')
dcs = np.loadtxt("results/iter" + str(i) + ".ev") dcs = dcs[:, 0:3] #prevent flipping if max(dcs[:, 1]) < min(dcs[:, 1]) * -1: dc1s = -dcs[:, 1] else: dc1s = dcs[:, 1] if max(dcs[:, 2]) < min(dcs[:, 2]) * -1: dc2s = -dcs[:, 2] else: dc2s = dcs[:, 2] dc1s, dc2s, z = hist2d.make(dc1s, dc2s, 100, 100, plot_style='scatter', free_energy_plot=True, idx_smoothing=3) cp = plt.scatter(dc1s, dc2s, s=10, c=z, marker='o', linewidth=0.) plt.xlabel('DC1', size=16) plt.ylabel('DC2', size=16) cb = plt.colorbar(cp) pad = 10 cb.set_label(r'population', labelpad=pad, size=16) #cb.set_label(r'phi',labelpad=pad,size=16) plt.savefig("plot_lsdmap_iter" + str(i) + '.png', bbox_inches='tight')
for i in c: print i plt.clf() plt.xlabel('DC1', size=16) plt.ylabel('DC2', size=16) dcs = np.loadtxt("results/iter"+str(i)+".ev") dcs = dcs[:,0:3] #prevent flipping if max(dcs[:,1])<min(dcs[:,1])*-1: dc1s = -dcs[:,1] else: dc1s = dcs[:,1] if max(dcs[:,2])<min(dcs[:,2])*-1: dc2s = -dcs[:,2] else: dc2s = dcs[:,2] dc1s, dc2s, z = hist2d.make(dc1s, dc2s, 100, 100, plot_style='scatter', free_energy_plot=True, idx_smoothing=3) cp = plt.scatter(dc1s, dc2s, s=10, c=z, marker='o', linewidth=0.) plt.xlabel('DC1', size=16) plt.ylabel('DC2', size=16) cb = plt.colorbar(cp) pad = 10 cb.set_label(r'population',labelpad=pad,size=16) #cb.set_label(r'phi',labelpad=pad,size=16) plt.savefig("plot_lsdmap_iter"+str(i)+'.png', bbox_inches='tight')
c=np.append(a,b) c=np.append(c,b2) for i in c: plt.clf() w_file='results/iter'+str(i)+'.w' gro_file='results/iter'+str(i)+'.gro' subprocess.call("echo 0 0 | g_rms -xvg none -f " +gro_file+ " -s "+ref_file+".gro 1>/dev/null 2>&1", shell=True) subprocess.call("echo 0 | g_gyrate -xvg none -f " +gro_file+ " -s " +gro_file+ " 1>/dev/null 2>&1", shell=True) tphi = np.loadtxt('rmsd.xvg') tpsi = np.loadtxt('gyrate.xvg') weight = np.loadtxt(w_file) x = tphi[:,1] y = tpsi[:,1] nbins = 100 x, y, z = hist2d.make(x, y, nbins, nbins, plot_style='scatter', weight=weight, free_energy_plot=True, idx_smoothing=3) cp = plt.scatter(x, y, s=10, c=z, marker='o', linewidth=0.)#, vmax=3.5) print "Free energy in range:", min(z), max(z) plt.xlabel('RMSD (nm)', size=16) plt.ylabel('Rg (nm)', size=16) cb = plt.colorbar(cp) pad = 10 cb.set_label(r'Free Energy (kcal/mol units)',labelpad=pad) plt.axis([0.0,1.0, 0.4,1.4]) plt.savefig('plot_rgrmsd_iter'+str(i)+'.png', bbox_inches='tight')