def s_order(job): dim = 1 box_range = [0.167, 1.167] pore_center = (box_range[1]-box_range[0])/2 + box_range[0] fig, ax = plt.subplots() s_list = list() for trj in md.iterload(os.path.join(job.ws, 'nvt.dcd'), top=os.path.join(job.ws, 'init.mol2'), chunk=9000, skip=2001): water_bonds = get_bond_array(trj) bins, s_values = compute_s(trj, dim, pore_center=pore_center, bond_array=water_bonds) s_list.append(s_values) s_mean = np.mean(s_list, axis=0) s_std = np.std(s_list, axis=0) plt.plot(bins, s_mean) plt.fill_between(bins, s_mean + s_std, s_mean - s_std, alpha=0.2) plt.xlabel('z-position (nm)') plt.ylabel('S') with job: plt.savefig('s_order.pdf') np.savetxt('s_order.txt', np.transpose(np.vstack([bins, s_mean, s_std])), header='Bins\tS_mean\tS_std') np.savetxt(f'data/{job.sp.nwater}_mol_s_order.txt', np.transpose(np.vstack([bins, s_mean, s_std])), header='Bins\tS_mean\tS_std')
def s_order(job, symmetrize=False): dim = 1 box_range = [0.167, 1.167] pore_center = (box_range[1] - box_range[0]) / 2 + box_range[0] fig, ax = plt.subplots() s_list = list() if job.sp.nwater == 1: skip = 1 else: skip = 5001 for trj in md.iterload( os.path.join(job.ws, "nvt.trr"), top=os.path.join(job.ws, "init.mol2"), chunk=5000, skip=skip, ): water_bonds = get_bond_array(trj) bins, s_values = compute_s( trj, dim, pore_center=pore_center, bond_array=water_bonds, symmetrize=symmetrize, ) s_list.append(s_values) s_mean = np.mean(s_list, axis=0) s_std = np.std(s_list, axis=0) plt.plot(bins, s_mean) plt.fill_between(bins, s_mean + s_std, s_mean - s_std, alpha=0.2) plt.xlabel("z-position (nm)") plt.ylabel("S") if symmetrize == True: extension = "_symmetrize" else: extension = "" with job: plt.savefig(f"s_order{extension}.pdf") np.savetxt( f"s_order{extension}.txt", np.transpose(np.vstack([bins, s_mean, s_std])), header="Bins\tS_mean\tS_std", ) np.savetxt( f"data/{job.sp.nwater}_mol_s_order{extension}.txt", np.transpose(np.vstack([bins, s_mean, s_std])), header="Bins\tS_mean\tS_std", )
def s_order(job): dim = 1 box_range = [0.5, 1.5] pore_center = (box_range[1] - box_range[0]) / 2 + box_range[0] fig, ax = plt.subplots() s_list = list() trj = md.load(os.path.join(job.ws, "carbon_water-pos-1.pdb")) trj.save(os.path.join(job.ws, "carbon_water-pos-1.xyz"), force_overwrite=True) for trj in md.iterload( os.path.join(job.ws, "carbon_water-pos-1.xyz"), top=os.path.join(job.ws, "init.mol2"), chunk=5000, skip=6000, ): trj = md.Trajectory( trj.xyz, trj.top, unitcell_lengths=np.tile([0.9824, 2.0000, 1.0635], (trj.n_frames, 1)), unitcell_angles=np.tile([90.0, 90.0, 90.0], (trj.n_frames, 1)), ) bins, s_values = compute_s(trj, dim, pore_center=pore_center) s_list.append(s_values) s_mean = np.mean(s_list, axis=0) s_std = np.std(s_list, axis=0) s_stdem = stats.sem(s_list, axis=0) plt.plot(bins, s_mean) plt.fill_between(bins, s_mean + s_std, s_mean - s_std, alpha=0.2) plt.xlabel("z-position (nm)") plt.ylabel("S") with job: plt.savefig( project.root_directory() + "/data/{}/s_order.pdf".format(str(job.sp.nwater) + "water_data")) np.savetxt( project.root_directory() + "/data/{}/s_order.txt".format(str(job.sp.nwater) + "water_data"), np.transpose(np.vstack([bins, s_mean, s_stdem, s_std])), header="Bins\tS_mean\tS_stdem\tS_std", )
def s_order(job): dim = 1 box_range = [0.837, 2.837] pore_center = (box_range[1] - box_range[0]) / 2 + box_range[0] fig, ax = plt.subplots() s_list = list() for trj in md.iterload( os.path.join(job.ws, "nvt.trr"), top=os.path.join(job.ws, "init.mol2"), chunk=5000, skip=5001, ): water_bonds = get_bond_array(trj) bins, s_values = compute_s(trj, dim, pore_center=pore_center, bond_array=water_bonds) s_list.append(s_values) s_mean = np.mean(s_list, axis=0) s_std = np.std(s_list, axis=0) plt.plot(bins, s_mean) plt.fill_between(bins, s_mean + s_std, s_mean - s_std, alpha=0.2) plt.xlabel("z-position (nm)") plt.ylabel("S") plt.ylim((-0.45, 0.45)) with job: plt.savefig("s_order.pdf") np.savetxt( "s_order.txt", np.transpose(np.vstack([bins, s_mean, s_std])), header="Bins\tS_mean\tS_std", ) np.savetxt( f"data/{job.sp.nwater}_mol_s_order.txt", np.transpose(np.vstack([bins, s_mean, s_std])), header="Bins\tS_mean\tS_std", )
def main(): project = signac.get_project("../") for nwater, group in project.groupby("nwater"): # New dataframe to save the results df = pd.DataFrame() # Create pore system pore_width = 1.0 * u.nm filled_pore = mbuild.recipes.GraphenePoreSolvent( pore_length=1.0, pore_depth=1.1, pore_width=pore_width.to_value("nm"), n_sheets=1, slit_pore_dim=2, x_bulk=0, solvent=spce_water, n_solvent=nwater, ) # Translate to centered at 0,0,0 and make box larger in z box_center = filled_pore.periodicity / 2.0 filled_pore.translate(-box_center) filled_pore.periodicity[2] = 2.0 xy_area = filled_pore.periodicity[0] * filled_pore.periodicity[1] top = filled_pore.to_trajectory(residues=["RES", "SOL"]) # Load all trajectories and combine for job in group: run = job.sp.run # Load in full trajectory full_traj = md.load(job.fn("prod.nvt.out.xyz"), top=top) # Add unit cell information full_traj = md.Trajectory( full_traj.xyz, full_traj.top, unitcell_lengths=np.tile(filled_pore.periodicity, (full_traj.n_frames, 1)), unitcell_angles=np.tile([90., 90., 90.], (full_traj.n_frames, 1)), ) # Keep only water slice_water = full_traj.top.select("water and name O H") traj = full_traj.atom_slice(slice_water) slice_ow = traj.top.select("name O") slice_hw = traj.top.select("name H") traj_ow = traj.atom_slice(slice_ow) traj_hw = traj.atom_slice(slice_hw) # Compute the density bin_centers_ow, density_ow = compute_density(traj_ow, xy_area, bin_width=0.005) bin_centers_hw, density_hw = compute_density(traj_hw, xy_area, bin_width=0.005) # Compute the s order parameter bin_centers_s, s_results = compute_s(traj, bin_width=0.005) assert np.allclose(bin_centers_ow, bin_centers_hw) assert np.allclose(bin_centers_ow, bin_centers_s) # Save results tmp_df = pd.DataFrame() tmp_df[f"run"] = run tmp_df[f"z-loc_nm"] = bin_centers_ow tmp_df[f"density-ow_nm^-3"] = density_ow tmp_df[f"density-hw_nm^-3"] = density_hw tmp_df[f"s_value"] = s_results df = df.append(tmp_df) # Compute mean/stdev and save to file means = df.groupby("z-loc_nm").mean().drop( columns=["run"]).add_suffix("_mean") stds = df.groupby("z-loc_nm").std().drop( columns=["run"]).add_suffix("_std") combined = means.merge(stds, on="z-loc_nm") combined.to_csv(f"results_{nwater}-water.csv")