def compute_packing(traj): """ Measure APT frame by frame """ if not os.path.isfile("apt_permeation.dat"): lipid_tails, _ = bilayer_analysis_functions.identify_groups( traj, forcefield='charmm36') n_lipid = len( [res for res in traj.topology.residues if not res.is_water]) n_lipid_tails = len(lipid_tails.keys()) n_tails_per_lipid = n_lipid_tails / n_lipid _, _, apl_list = bilayer_analysis_functions.calc_APL(traj, n_lipid, blocked=False) _, _, angle_list = bilayer_analysis_functions.calc_tilt_angle( traj, traj.topology, lipid_tails, blocked=False) _, _, apt_list = bilayer_analysis_functions.calc_APT(traj, apl_list, angle_list, n_tails_per_lipid, blocked=False) np.savetxt('apt_permeation.dat', apt_list) else: apt_list = np.loadtxt("apt_permeation.dat") return apt_list
def _get_headgroup_indices(traj): """ Return a giant list of all indices that correspond ot headgroups""" #lipid_dict, headgroup_dict = bilayer_analysis_functions.get_lipids(traj.topology) lipid_dict, headgroup_dict = bilayer_analysis_functions.identify_groups( traj, forcefield='charmm36') #forcefield='gromos53a6') headgroup_indices = [] for key, val in headgroup_dict.items(): for a in val: headgroup_indices.append(a) return headgroup_indices
def analysis_routine(trajfile, grofile, pdbfile): import json from collections import OrderedDict import bilayer_analysis_functions import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages traj = mdtraj.load(trajfile, top=grofile) traj_pdb = mdtraj.load(trajfile, top=pdbfile) topol = traj.topology # Compute system information lipid_tails, headgroup_dict = bilayer_analysis_functions.identify_groups( traj, forcefield='charmm36') n_lipid = len([res for res in traj.topology.residues if not res.is_water]) n_lipid_tails = len(lipid_tails.keys()) n_tails_per_lipid = n_lipid_tails / n_lipid # Vectorized Calculations start here apl_avg, apl_std, apl_list = bilayer_analysis_functions.calc_APL( traj, n_lipid, blocked=True) np.savetxt('apl.dat', apl_list) angle_avg, angle_std, angle_list = bilayer_analysis_functions.calc_tilt_angle( traj, topol, lipid_tails, blocked=True) np.savetxt('angle.dat', angle_list) apt_avg, apt_std, apt_list = bilayer_analysis_functions.calc_APT( traj, apl_list, angle_list, n_tails_per_lipid, blocked=True) np.savetxt('apt.dat', apt_list) s2_ave, s2_std, s2_list = bilayer_analysis_functions.calc_nematic_order( traj, blocked=True) np.savetxt('s2.dat', s2_list) headgroup_distance_dict = bilayer_analysis_functions.compute_headgroup_distances( traj, topol, headgroup_dict, blocked=True) Hpp_ave, Hpp_std, Hpp_list = bilayer_analysis_functions.calc_bilayer_height( traj, headgroup_distance_dict, blocked=True, anchor='DSPC') np.savetxt('height.dat', Hpp_list) offset_dict = bilayer_analysis_functions.calc_offsets( traj, headgroup_distance_dict, blocked=True, anchor='DSPC') d_a, d_t, d_b, bins, interdig_list,interdig_avg, interdig_std = \ bilayer_analysis_functions.calc_density_profile(traj, topol, blocked=True) np.savetxt('idig.dat', interdig_list) ##print('Calculating hydrogen bonds...') ##hbond_matrix_avg, hbond_matrix_std, hbond_matrix_list, labelmap = bilayer_analysis_functions.calc_hbonds(traj, traj_pdb, topol, lipid_dict, headgroup_dict) # # Printing properties outpdf = PdfPages(('bilayeranalysis.pdf')) datafile = OrderedDict() datafile['trajectory'] = trajfile datafile['structure'] = grofile datafile['n_frames'] = traj.n_frames datafile['lipids'] = n_lipid datafile['tails'] = n_lipid_tails datafile['APL'] = OrderedDict() datafile['APL']['unit'] = str(apl_avg.unit) datafile['APL']['mean'] = float(apl_avg._value) datafile['APL']['std'] = float(apl_std._value) datafile['APT'] = OrderedDict() datafile['APT']['unit'] = str(apt_avg.unit) datafile['APT']['mean'] = float(apt_avg._value) datafile['APT']['std'] = float(apt_std._value) datafile['Bilayer Height'] = OrderedDict() datafile['Bilayer Height']['unit'] = str(Hpp_ave.unit) datafile['Bilayer Height']['mean'] = float(Hpp_ave._value) datafile['Bilayer Height']['std'] = float(Hpp_std._value) datafile['Tilt Angle'] = OrderedDict() datafile['Tilt Angle']['unit'] = str(angle_avg.unit) datafile['Tilt Angle']['Bilayer'] = OrderedDict() datafile['Tilt Angle']['Bilayer']['mean'] = float(angle_avg._value) datafile['Tilt Angle']['Bilayer']['std'] = float(angle_std._value) datafile['S2'] = OrderedDict() datafile['S2']['mean'] = s2_ave datafile['S2']['std'] = s2_std datafile['Interdigitation'] = OrderedDict() datafile['Interdigitation']['unit'] = str(interdig_avg.unit) datafile['Interdigitation']['mean'] = float(interdig_avg._value) datafile['Interdigitation']['std'] = float(interdig_std._value) datafile['Offset'] = OrderedDict() for key in offset_dict.keys(): datafile['Offset']['unit'] = str(offset_dict[key][0].unit) datafile['Offset'][key] = OrderedDict() datafile['Offset'][key]['mean'] = float(offset_dict[key][0]._value) datafile['Offset'][key]['std'] = float(offset_dict[key][1]._value) #datafile['Offset (A)'][key] = [str(offset_dict[key][0]), str(offset_dict[key][1])] datafile['Tilt Angle']['Leaflet 1'] = OrderedDict() datafile['Tilt Angle']['Leaflet 1']['mean'] = float( np.mean(angle_list[:, 0:int(np.floor(n_lipid_tails / 2))])._value) datafile['Tilt Angle']['Leaflet 1']['std'] = float( np.std(angle_list[:, 0:int(np.floor(n_lipid_tails / 2))])._value) datafile['Tilt Angle']['Leaflet 2'] = OrderedDict() datafile['Tilt Angle']['Leaflet 2']['mean'] = float( np.mean(angle_list[:, int(np.floor(n_lipid_tails / 2)):])._value) datafile['Tilt Angle']['Leaflet 2']['std'] = float( np.std(angle_list[:, int(np.floor(n_lipid_tails / 2)):])._value) #for row_label in labelmap.keys(): # for col_label in labelmap.keys(): # row_index = labelmap[row_label] # col_index = labelmap[col_label] # hbond_avg = hbond_matrix_avg[row_index, col_index] # hbond_std = hbond_matrix_std[row_index, col_index] # outfile.write('{:<20s}: {} ({})\n'.format(str(row_label+"-"+ col_label), hbond_avg, hbond_std)) # Plotting fig1 = plt.figure(1) plt.subplot(3, 2, 1) plt.plot(apl_list) plt.title('APL') plt.subplot(3, 2, 2) plt.plot(np.mean(angle_list, axis=1)) plt.title('Tilt Angle ($^o$)') plt.subplot(3, 2, 3) plt.plot(np.mean(apt_list, axis=1)) plt.title('APT') plt.subplot(3, 2, 4) plt.plot(Hpp_list) plt.title('H$_{PP}$') plt.subplot(3, 2, 5) plt.plot(s2_list) plt.title('S2') plt.subplot(3, 2, 6) plt.plot(interdig_list) plt.title('Interdigitation (A)') plt.tight_layout() outpdf.savefig(fig1) plt.close() density_profile_top_avg = np.mean(d_t, axis=0) density_profile_bot_avg = np.mean(d_b, axis=0) density_profile_avg = np.mean(d_a, axis=0) # # fig2 = plt.figure(2) plt.subplot(2, 1, 1) plt.plot(bins, density_profile_avg) plt.xlabel('Depth (nm)') plt.title('Density Profile (kg m$^{-3}$)') plt.subplot(2, 1, 2) #plt.plot(bins,density_profile_bot_avg) #plt.plot(bins,density_profile_top_avg) plt.hist(np.mean(angle_list[:, 0:int(np.floor(n_lipid_tails / 2))], axis=0)._value, bins=50, alpha=0.5, facecolor='blue', normed=True) plt.hist(np.mean(angle_list[:, int(np.floor(n_lipid_tails / 2)):], axis=0)._value, bins=50, alpha=0.5, facecolor='red', normed=True) plt.title('Angle Distribution by Leaflet') plt.xlabel('Angle ($^o$)') plt.tight_layout() outpdf.savefig(fig2) plt.close() outpdf.close() with open('data.txt', 'w') as f: json.dump(datafile, f, indent=2)
(options, args) = parser.parse_args() trajfile = options.trajfile grofile = options.grofile pdbfile = options.pdbfile outfilename = options.outfilename print('Loading trajectory <{}>...'.format(trajfile)) print('Loading topology <{}>...'.format(grofile)) traj = mdtraj.load(trajfile, top=grofile) print('Loading topology <{}>...'.format(pdbfile)) traj_pdb = mdtraj.load(trajfile, top=pdbfile) topol = traj.topology # Compute system information print('Gathering system information <{}>...'.format(grofile)) lipid_tails, headgroup_dict = bilayer_analysis_functions.identify_groups(traj, forcefield='charmm36') n_lipid = len([res for res in traj.topology.residues if not res.is_water]) n_lipid_tails = len(lipid_tails.keys()) n_tails_per_lipid = n_lipid_tails/n_lipid # Vectorized Calculations start here print('Calculating area per lipid...') apl_avg, apl_std, apl_list = bilayer_analysis_functions.calc_APL(traj,n_lipid, blocked=options.blocked) np.savetxt('apl.dat', apl_list) print('Calculating tilt angles...') angle_avg, angle_std, angle_list = bilayer_analysis_functions.calc_tilt_angle(traj, topol, lipid_tails, blocked=options.blocked) np.savetxt('angle.dat', angle_list) print('Calculating area per tail...') apt_avg, apt_std, apt_list = bilayer_analysis_functions.calc_APT(traj, apl_list, angle_list, n_tails_per_lipid,
def moving_s2_routine(traj, forcefield='charmm36', window_size=3): """ For each residue compute a moving S2 value Parameters --------- traj : MTraj trajectory forcefield : str, default 'charmm36' window_size : int, default 3 Returns ------- results : dict keys: residue indices For one-tailed molecules, this is simple For two-tailed molecules (PC), this is done by adding 'a' to the key values: dict keys: 's2_mean' and 's2_err' values: respective quantities, down the chain. i.e. results[resid]['s2_mean'][3] gets the s2 for resid between carbons [3, 3 + window_size) """ tail_groups, head_groups = bilayer_analysis_functions.identify_groups( traj, forcefield='charmm36') unique_resnames = set(r.name for r in traj.topology.residues if not r.is_water and 'PC' not in r.name) pc_resnames = set(r.name for r in traj.topology.residues if not r.is_water and 'PC' in r.name) results = {} for resname in unique_resnames: selected_keys = _select_tails(traj, tail_groups, resname, tail=None) all_s2 = calc_moving_s2(traj, tail_groups, selected_keys, window_size=3) results[resname] = { 's2_mean': np.mean(all_s2, axis=0), 's2_err': np.std(all_s2, axis=0) } for pc in pc_resnames: selected_keys = _select_tails(traj, tail_groups, pc, tail='a') all_s2 = calc_moving_s2(traj, tail_groups, selected_keys, window_size=3) results[pc + 'a'] = { 's2_mean': np.mean(all_s2, axis=0), 's2_err': np.std(all_s2, axis=0) } selected_keys = _select_tails(traj, tail_groups, pc, tail='b') all_s2 = calc_moving_s2(traj, tail_groups, selected_keys, window_size=3) results[pc + 'b'] = { 's2_mean': np.mean(all_s2, axis=0), 's2_err': np.std(all_s2, axis=0) } return results