def electron_density_mdanalysis(self): '''This function calulate the charge density through MDAnalaysis''' u = mda.Universe(self.tprpath, self.trjpath) lipid_types_first = ''.join(self.molecules[0]) print(lipid_types_first) self.lipid_type_items = ' '.join(self.molecules) print(lipid_types_first) selection = u.select_atoms('resname {}'.format(self.lipid_type_items)) ref_selection = u.select_atoms( 'resname {} and name P'.format(lipid_types_first)) print(self.times[2]) interval_of_frames = str(self.times[2]) print(interval_of_frames) if self.times[2] == '1000': start_frame = 100 frame_intervals = 1 end_frame = 300 else: start_frame = 1000 frame_intervals = 10 end_frame = 3000 Idens = LinearDensity(selection, grouping='atoms', binsize=0.25, start=start_frame, step=frame_intervals, stop=end_frame) Idens.run() Idens.save(description='densprof', form='txt') # subtracting the center of geometry of the lipid from the first column of the data # calculating center of geometry of lipids u = self.universe cog = [] for i_ts, ts in enumerate(u.trajectory[start_frame::frame_intervals]): ref_selection_xyz = ref_selection.center_of_geometry() cog.append(ref_selection_xyz[2]) centerofgeometry_z = np.mean(cog) #### dat = np.loadtxt('{}_{}.densprof_atoms.ldens'.format(self.system, self.temperature, skiprows=2)) dat[:, 0] = dat[:, 0] - centerofgeometry_z np.savetxt('{}_{}.densprof_atoms_centered.ldens'.format( self.system, self.temperature), dat, delimiter=' ', fmt='%.5f')
sel.append("name OW and (around %.4f resname %s)" % (anion[1], anion[0])) sel.append("name OW and (around %.4f resname %s) and name OW and (not \ around %.4f resname %s)" % (anion[2], anion[0], anion[1], anion[0])) # Water mass density analysis print("#------------------------------------------------------#") print("Start Water mass density analysis") os.system("mkdir Mass-Density") resid = int((u.select_atoms("resname SOL").n_atoms) / 3) u = mda.Universe(TPR, TRR) water = u.select_atoms("resid 0-%d" % (resid)) watermassdensity = LA(water) watermassdensity.run() watermassdensity.save(description='watermassdensity', form='txt') data = np.loadtxt("nvtnemd.watermassdensity_atoms.ldens", skiprows=2) labels = ["x", "y", "z"] colors = ["chartreuse", "deepskyblue", "r"] for i in range(len(labels)): if i == 0: plt.plot(data[:, 0] / 10.0, data[:, i + 1], color=colors[i], lw=2.0, label=labels[i]) if i == 1: plt.plot(data[:, 0] / 10.0, data[:, i + 2],