def main(): curr_dir = os.getcwd() all_nums = np.arange(0, 20, dtype=int) all_simnums = np.arange(0, 5, dtype=int) all_sweeps = ['sweep{}'.format(num) for num in all_nums] all_sims = ['Sim{}'.format(num) for num in all_simnums] all_s2 = [] all_apt = [] for sweep in all_sweeps: for sim in all_sims: os.chdir(os.path.join(curr_dir, sweep, sim)) print("Converting in {}".format((sweep, sim))) trajfile, grofile = prepare_traj(trajname='combined_nopbc.xtc') traj = mdtraj.load(trajfile, top=grofile) print("Analyzing in {}".format((sweep, sim))) s2list = compute_disorder(traj) aptlist = compute_packing(traj) all_s2.append(s2list) all_apt.append(aptlist) os.chdir(curr_dir) all_s2 = prune_arrays(all_s2) fig, ax = plt.subplots(1, 1) frames = np.arange(all_s2.shape[1]) l, = ax.plot(frames, np.mean(all_s2, axis=0)) ax.fill_between(frames, np.mean(all_s2, axis=0) - np.std(all_s2, axis=0), np.mean(all_s2, axis=0) + np.std(all_s2, axis=0), color=l.get_color(), alpha=0.4) ax.set_xlabel("Frame") ax.set_ylabel("S2") plot_ay.tidyUp(fig, ax, gridArgs={}, tightLayoutArgs={}) fig.savefig('permeation_order.png') np.savetxt( "s2_permeation.dat", np.column_stack((frames, np.mean(all_s2, axis=0), np.std(all_s2, axis=0)))) plt.close(fig) all_apt = prune_arrays(all_apt) fig, ax = plt.subplots(1, 1) frames = np.arange(all_apt.shape[1]) l, = ax.plot(frames, np.mean(all_apt, axis=0)) ax.fill_between(frames, np.mean(all_apt, axis=0) - np.std(all_apt, axis=0), np.mean(all_apt, axis=0) + np.std(all_apt, axis=0), color=l.get_color(), alpha=0.4) ax.set_xlabel("Frame") ax.set_ylabel("APT [$\AA^2$]") plot_ay.tidyUp(fig, ax, gridArgs={}, tightLayoutArgs={}) fig.savefig('permeation_apt.png') np.savetxt( "apt_permeation.dat", np.column_stack((frames, np.mean(all_apt, axis=0), np.std(all_apt, axis=0)))) plt.close(fig)
def test_grid(): import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt x_data = np.arange(0, 10) linear = (5 * x_data) + 2 quadratic = x_data**2 fig, ax = plt.subplots(1, 1) ax.plot(x_data, linear, label='linear') ax.plot(x_data, quadratic, label='quadratic') gridArgs = {} gridArgs['color'] = 'r' gridArgs['linestyle'] = '--' gridArgs['linewidth'] = 5 ax.set_xlabel("x") plot_ay.tidyUp(fig, ax, gridArgs=gridArgs) plt.close(fig)
def test_legend(): import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt x_data = np.arange(0, 10) linear = (5 * x_data) + 2 quadratic = x_data**2 fig, ax = plt.subplots(1, 1) ax.plot(x_data, linear, label='linear') ax.plot(x_data, quadratic, label='quadratic') legendArgs = {} legendArgs['loc'] = 1 legendArgs['fancybox'] = True legendArgs['ncol'] = 2 legendArgs['edgecolor'] = 'black' ax.set_xlabel("x") plot_ay.tidyUp(fig, ax, legendArgs=legendArgs) plt.close(fig)
def test_tightlayout(): import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt x_data = np.arange(0, 10) linear = (5 * x_data) + 2 quadratic = x_data**2 fig, ax = plt.subplots(1, 2) ax[0].plot(x_data, linear, label='linear') ax[0].plot(x_data, quadratic, label='quadratic') ax[1].plot(x_data, linear, label='linear') ax[1].plot(x_data, quadratic, label='quadratic') tightLayoutArgs = {} tightLayoutArgs['pad'] = 0.2 tightLayoutArgs['w_pad'] = 10 tightLayoutArgs['h_pad'] = 2 plot_ay.tidyUp(fig, ax[0], tightLayoutArgs=tightLayoutArgs) plot_ay.tidyUp(fig, ax[1], tightLayoutArgs=tightLayoutArgs) plt.close(fig)
second_color = '#ff7f0e' ax2.semilogy(rxn_coordinates, bootstrap_diff_profile, color=second_color) ax2.fill_between(rxn_coordinates, bootstrap_diff_profile - bootstrap_diff_err_profile, bootstrap_diff_profile + bootstrap_diff_err_profile, alpha=0.4, color=second_color) ax2.axhline(y=5.87e-5, color='r', linestyle='--') ax2.set_ylim(ylim) for ytick in ax2.get_yticklabels(): ytick.set_color(second_color) #ax.axvline(x=top_interface, color='k', linestyle=':') #ax.axvline(x=bot_interface, color='k', linestyle=':') ax2.set_ylabel(r"Diffusion (cm$^2$/sec)", color=second_color) plot_ay.tidyUp(fig, ax, tightLayoutArgs={}, gridArgs={}) fig.tight_layout() fig.savefig('stacked_profiles.png', transparent=True) plt.close(fig) fig, ax = plt.subplots(1, 1) l, = ax.plot(rxn_coordinates, bootstrap_resist_profile) ax.fill_between(rxn_coordinates, bootstrap_resist_profile - bootstrap_resist_err_profile, bootstrap_resist_profile + bootstrap_resist_err_profile, alpha=0.4, color=l.get_color()) #ax.axvline(x=top_interface, color='k', linestyle=':') #ax.axvline(x=bot_interface, color='k', linestyle=':') ax.set_xlabel(r"Reaction Coordinate (nm)") ax.set_ylabel("Resistance (sec/cm$^2$)")
oh_bars = ax.bar(oh_x_vals, ohbar_vals, bar_width, yerr=ohyerr_vals, label='67% OH, 33% DSPC') ffa_bars = ax.bar(ffa_x_vals, ffabar_vals, bar_width, yerr=ffayerr_vals, label='67% FFA, 33% DSPC') ax.set_xticks(xtick_vals) ax.set_xticklabels(['12', '16', '24']) ax.set_ylabel("O-H relaxation (ps)") ax.set_xlabel("Tail length") plot_ay.tidyUp(fig, ax, legendArgs={'loc': 3}, tightLayoutArgs={}) fig.savefig("oh_relaxation.png") plt.close(fig) ############################ ### H-H vector correlation ### ############################ fig, ax = plt.subplots(1, 1) ffabar_vals = [] ffayerr_vals = [] ffa_components = ['ffa12', 'ffa16', 'ffa24'] for component in ffa_components: thing = df.loc[(df[component] == 43.0) & (df['DSPC'] == 21.0)] ffabar_vals.append(thing['hh_tau_mean'].values[0]) ffayerr_vals.append(thing['hh_tau_std'].values[0])
def analyze_time_aggregation(xtc='npt_nopbc.xtc', gro='npt.gro'): traj = mdtraj.load('npt_nopbc.xtc', top='npt.gro') gra_atoms = [ a.index for r in traj.topology.residues if 'GRA_5' in r.name for a in r.atoms ] dopc_residues = [r for r in traj.topology.residues if 'DOPC' in r.name] chol_residues = [r for r in traj.topology.residues if 'CHL1' in r.name] gra_centers = mdtraj.compute_center_of_mass(traj.atom_slice(gra_atoms)) dopc_centers = np.zeros((traj.n_frames, len(dopc_residues), 3)) chol_centers = np.zeros((traj.n_frames, len(chol_residues), 3)) dopc_distances = np.zeros((traj.n_frames, len(dopc_residues))) chol_distances = np.zeros((traj.n_frames, len(chol_residues))) frame_step = 5 # one frame is 5 ps for i, dopc in enumerate(dopc_residues): dopc_atoms = [a.index for a in dopc.atoms] dopc_centers[:, i, :] = mdtraj.compute_center_of_mass( traj.atom_slice(dopc_atoms)) for i, chol in enumerate(chol_residues): chol_atoms = [a.index for a in chol.atoms] chol_centers[:, i, :] = mdtraj.compute_center_of_mass( traj.atom_slice(chol_atoms)) for i, gra_center in enumerate(gra_centers): for j in range(len(dopc_residues)): chol_distances[i, j] = euclidean(gra_center, chol_centers[i, j, :]) for j in range(len(chol_residues)): dopc_distances[i, j] = euclidean(gra_center, dopc_centers[i, j, :]) fig, ax = plt.subplots(1, 1) l, = ax.plot(frame_step * np.arange(traj.n_frames), np.mean(dopc_distances, axis=1), label='Avg dopc distance') ax.fill_between( frame_step * np.arange(traj.n_frames), np.mean(dopc_distances, axis=1) - np.std(dopc_distances, axis=1), np.mean(dopc_distances, axis=1) + np.std(dopc_distances, axis=1), alpha=0.4, color=l.get_color()) np.savetxt( 'dopc_distances.dat', np.column_stack((frame_step * np.arange(traj.n_frames), np.mean(dopc_distances, axis=1), np.std(dopc_distances, axis=1)))) l, = ax.plot(frame_step * np.arange(traj.n_frames), np.mean(chol_distances, axis=1), label='Avg chol distance') ax.fill_between( frame_step * np.arange(traj.n_frames), np.mean(chol_distances, axis=1) - np.std(chol_distances, axis=1), np.mean(chol_distances, axis=1) + np.std(chol_distances, axis=1), alpha=0.4, color=l.get_color()) np.savetxt( 'chol_distances.dat', np.column_stack((frame_step * np.arange(traj.n_frames), np.mean(chol_distances, axis=1), np.std(chol_distances, axis=1)))) ax.set_ylabel("Distance (nm)") ax.set_xlabel("Time (ps)") plot_ay.tidyUp(fig, ax, gridArgs={}, legendArgs={}, tightLayoutArgs={}) fig.savefig('Distances.png')