def __init__(self, grofile, pfafile, label, folder): self.PER_ATOM_FORCE = {} self.PER_RESIDUE_FORCE = {} self._folder = folder self._out_file = self._folder + "/" + "PRF-" + label + ".prf" self._out_forces = "" ''' create gro object create pfa object ''' self.gro_object = gro_reader.Gro_Reader(grofile) self.pfa_object = pfa.PFA(pfafile, label) ''' making a copy of PER_ATOM_FORCE ''' self.PER_ATOM_FORCE = self.pfa_object.PER_ATOM_FORCE ''' map forces to each residue ''' self._per_resid_force() ''' dump forces to a file ''' fda_utils.write_file(self._out_file, self._out_forces)
def plot_fun(a, b, FOL, label): global PNGFOL fda_gen_util.check_folder(PNGFOL) xmin = 0 xmax = 200 xgap = 5 fig = plt.figure() fig.set_size_inches(12, 4) #N=len(a); #ind=np.arange(N); width = 0.5 plt.plot(a, b, color="#02FF00") #plt.show() ylab = r'$\Delta\hspace{0.5}\mathrm{Avg.}\hspace{0.5}\mathrm{Force}\hspace{0.5}\mathrm{(pN)}$' plt.xlabel("Residue id") plt.ylabel(ylab) plt.xticks(np.arange(xmin, xmax + xgap, xgap)) plt.xlim(xmin, xmax) sfname = "%s/%s.png" % (FOL, label) plt.savefig(sfname, dpi=300) print("%s saved" % (sfname))
def net_force_calc(ave_force_ref, ave_force_pert, std_ref, std_pert, label, diff_res): global FASTA N = len(ave_force_ref) net_force_list = [] fac = 1.0 / math.sqrt(N) wout_data = "%4s %12s %12s %12s %12s\n" % ("ResI", "Net Force", "DELTA F", "E Ref", "E Pert") for i in range(N): error_ref = std_ref[i] * fac error_pert = 1 #std_pert[i]*fac; #e_fac=1.0/error_ref e_fac = 1 i_resid = diff_res[i] #C=ave_force_pert[i]; D = ave_force_ref[i] i_diff = 1 #(ave_force_pert[i]-ave_force_ref[i]); #print i_resid,ave_force_pert[i], ave_force_ref[i] #wout_data+="%12d %12.2f %12.2f\n"%(diff_res[i],diff_data[i],diff_err[i]) i_net_force = D * e_fac wout_data += "%4d %12.2f %12.2f %12.2f %12.2f\n" % ( i_resid, i_net_force, i_diff, error_ref, error_pert) #wout_data+="%4d %12.2f %12.2f %12.2f %12.2f %12.2f\n"%(i_resid,ave_force_ref,ave_force_pert,i_diff,error_ref,error_pert); if (0 >= i_net_force) or (i_net_force >= 0): d = [diff_res[i], D] else: #d=[FASTA[i],diff_res[i],0] d = [diff_res[i], 0] #d=[diff_res[i],i_net_force] net_force_list.append(d) osd = fda_gen_util.prep_2d_list_for_writing(net_force_list) fname = "%s/Net_force-%s.dat" % (os.getcwd(), label) fda_gen_util.write_file(fname, osd) return net_force_list
def calc_diff_mode_forces(res_mode_forces_1, res_mode_forces_2, label): FOL = "/home/mugdha/Projects/TFAM/analysis/fda/png" print("abra ka dabra") diff_force_list = [] file_force_list = [] N_1 = len(res_mode_forces_1) N_2 = len(res_mode_forces_2) if (N_1 != N_2): print( "Residue numbers of PFA1 and PFA2 files are not the ssame. Please check." ) exit() for i in range(N_1): force_diff = res_mode_forces_1[i][1] - res_mode_forces_2[i][1] diff_force_list.append([res_mode_forces_1[i][0], force_diff]) d = [ i + 1, res_mode_forces_1[i][1], res_mode_forces_2[i][1], force_diff ] file_force_list.append(d) osd = fda_gen_util.prep_4d_list_for_writing(file_force_list) fname = "%s/%s-diff_force_list.dat" % (FOL, label) fda_gen_util.write_file(fname, osd) return diff_force_list
def mode_per_resid(force_list, label): global DUMP_FILES res_force_list = [] FORCE_LIST = [] N_FRAMES = len(force_list) for x in range(1): frame_num = force_list[x][0] i_resid_force_list = force_list[x][1] #resid,forces=extract_resid_forces(i_resid_force_list); resid, forces = fda_gen_util.extract_2d_list(i_resid_force_list) N_resid = len(resid) count = 0 FOL = "/home/mugdha/Projects/TFAM/analysis/fda/dat" for i in range(N_resid): cur_resid = resid[i] res_force = [] time_data = [] for j in range(N_FRAMES): i_data = force_list[j][1][i] #print force_list i_resid = int(i_data[0]) i_force = float(i_data[1]) if (i_resid == cur_resid): res_force.append(i_force) d = [j, i_force] time_data.append(d) #contains time series data per residue can be dumped #write a dump function for this #print time_data ''''' if(DUMP_FILES==True): osd=fda_gen_util.prep_2d_list_for_writing(time_data) fname="%s/%s-TvF-%d-TFAM.dat"%(FOL,label,cur_resid) fda_gen_util.write_file(fname,osd) new_lab="%s-%s-TimeVsForce"%(label,cur_resid) a,b=fda_gen_util.extract_2d_list(time_data) plot_util.plot_fun(a,b,FOL,new_lab) ''' '' #modforce=stats.mode(res_force) #d=[cur_resid,modforce[0][0]] modforce = np.average(res_force) d = [cur_resid, modforce] FORCE_LIST.append(d) return FORCE_LIST
def avg_force_per_frame(force_list): FORCE_LIST = [] N_FRAMES = len(force_list) for i in range(N_FRAMES): frame_num = force_list[i][0] i_resid_force_list = force_list[i][1] #resid,forces=extract_resid_forces(i_resid_force_list); resid, forces = fda_gen_util.extract_2d_list(i_resid_force_list) ave_force = np.average(forces) d = [frame_num, ave_force] print(ave_force[0]) exit() FORCE_LIST.append(d) return FORCE_LIST
def _proc_line(self, line): resid = int(line[0:5].strip()) x = line[20:28].strip() y = line[28:36].strip() z = line[36:44].strip() coord = [x, y, z] atom_name = line[10:15].strip() atom_id = int(line[15:20].strip()) res_name = line[5:10].strip() res_name = utils.aa_map(res_name) self.ATOM_NAME.append(atom_name) self.ATOM_ID.append(atom_id) self.X_Y_Z.append(coord) self.RES_NAME[resid] = res_name self._mapping(resid, atom_id)
def _process_meta_file(self): fda_gen_util.check_file(self._metafile); meta_open=open(self._metafile,'r'); for i in meta_open: grofile=self._folder+"/"+i.split()[0]; #indi pfa pfa_file=self._folder+"/"+i.split()[1]; #indi gro f_label=i.split()[2]; #indi file label fda_gen_util.check_file(grofile); fda_gen_util.check_file(pfa_file); punc_stress_object=calc_punc_stress.Punctual_Stress(grofile,pfa_file,f_label,self._folder)
def average_force_per_forcefile(a, b, c): N = len(a) ave_force_list = [] std_force_list = [] for i in range(N): all_traj_force = [a[i][1], b[i][1], c[i][1]] #total_ave_force=all_traj_force/3 #print all_traj_force total_ave_force = np.average(all_traj_force) error = np.std(all_traj_force) #print error #print total_ave_force#, all_traj_force d = [a[i][0], error] s = [a[i][0], total_ave_force] std_force_list.append(d) ave_force_list.append(s) osd = fda_gen_util.prep_2d_list_for_writing(ave_force_list) #print ave_force_list #fname="%s/protein-dna-wt_forces.dat"%(os.getcwd()); #fda_gen_util.write_file(fname,osd) return std_force_list, ave_force_list
def bar_plots(BAR_PLOT_DATA): #Fol="/home/mugdha/Projects/TFAM/analysis/fda/png/barplots"; global PNGFOL, BPFOL bar_color = "#0000FF" fda_gen_util.check_folder(PNGFOL) #This is a redundant check since BPFOL is nested in PNGFOL fda_gen_util.check_folder(BPFOL) fig = plt.figure() #fig.set_size_inches(12,4) bar_width = 0.50 opacity = 0.9 labels = [] lab_pos = [] prop = fm.FontProperties( fname='/usr/share/matplotlib/mpl-data/fonts/ttf/cmb10.ttf') #prop=fm.FontProperties(fname='/home/mugdha/Downloads/arial.ttf') N = len(BAR_PLOT_DATA) ymin = -4000 ymax = 3000 ygap = 1000 title_fs = 12 y_fs = 10 ax1 = plt.subplot(321) ax_c_data = BAR_PLOT_DATA[0] ax_label = ax_c_data[0] ax_plot_data = ax_c_data[1] N = len(ax_plot_data) pos_array = [] labels = [] index = np.arange(0, len(ax_plot_data)) for i in range(N): i_data = ax_plot_data[i] pos = index[i] + (bar_width * i) labels.append(i_data[0]) pos_array.append(pos) plt.bar(pos, i_data[1], bar_width, alpha=opacity, color=bar_color, label=i_data[0], yerr=i_data[2], ecolor="#000000", align='center') plt.xticks(pos_array, labels, fontproperties=prop, fontsize=0) plt.yticks(np.arange(ymin, ymax + ygap, ygap), fontproperties=prop, fontsize=y_fs) plt.title(ax_label, fontproperties=prop, fontsize=title_fs) ax2 = plt.subplot(322) ax_c_data = BAR_PLOT_DATA[1] ax_label = ax_c_data[0] ax_plot_data = ax_c_data[1] N = len(ax_plot_data) pos_array = [] labels = [] index = np.arange(0, len(ax_plot_data)) for i in range(N): i_data = ax_plot_data[i] pos = index[i] + (bar_width * i) labels.append(i_data[0]) pos_array.append(pos) plt.bar(pos, i_data[1], bar_width, alpha=opacity, color=bar_color, label=i_data[0], yerr=i_data[2], ecolor="#000000", align='center') plt.xticks(pos_array, labels, fontproperties=prop, fontsize=0) plt.yticks(np.arange(ymin, ymax + ygap, ygap), fontsize=0) plt.title(ax_label, fontproperties=prop, fontsize=title_fs) ax3 = plt.subplot(323) ax_c_data = BAR_PLOT_DATA[2] ax_label = ax_c_data[0] ax_plot_data = ax_c_data[1] N = len(ax_plot_data) pos_array = [] labels = [] index = np.arange(0, len(ax_plot_data)) for i in range(N): i_data = ax_plot_data[i] pos = index[i] + (bar_width * i) labels.append(i_data[0]) pos_array.append(pos) plt.bar(pos, i_data[1], bar_width, alpha=opacity, color=bar_color, label=i_data[0], yerr=i_data[2], ecolor="#000000", align='center') plt.xticks(pos_array, labels, fontproperties=prop, fontsize=0) plt.yticks(np.arange(ymin, ymax + ygap, ygap), fontproperties=prop, fontsize=y_fs) plt.title(ax_label, fontproperties=prop, fontsize=title_fs) ax4 = plt.subplot(324) ax_c_data = BAR_PLOT_DATA[3] ax_label = ax_c_data[0] ax_plot_data = ax_c_data[1] N = len(ax_plot_data) pos_array = [] labels = [] index = np.arange(0, len(ax_plot_data)) for i in range(N): i_data = ax_plot_data[i] pos = index[i] + (bar_width * i) labels.append(i_data[0]) pos_array.append(pos) plt.bar(pos, i_data[1], bar_width, alpha=opacity, color=bar_color, label=i_data[0], yerr=i_data[2], ecolor="#000000", align='center') plt.xticks(pos_array, labels, fontproperties=prop, fontsize=0) plt.yticks(np.arange(ymin, ymax + ygap, ygap), fontsize=0) plt.title(ax_label, fontproperties=prop, fontsize=title_fs) ax5 = plt.subplot(325) ax_c_data = BAR_PLOT_DATA[4] ax_label = ax_c_data[0] ax_plot_data = ax_c_data[1] N = len(ax_plot_data) pos_array = [] labels = [] index = np.arange(0, len(ax_plot_data)) for i in range(N): i_data = ax_plot_data[i] pos = index[i] + (bar_width * i) labels.append(i_data[0]) pos_array.append(pos) plt.bar(pos, i_data[1], bar_width, alpha=opacity, color=bar_color, label=i_data[0], yerr=i_data[2], ecolor="#000000", align='center') plt.title(ax_label, fontproperties=prop, fontsize=title_fs) plt.xticks(pos_array, labels, fontproperties=prop, fontsize=10) plt.yticks(np.arange(ymin, ymax + ygap, ygap), fontproperties=prop, fontsize=y_fs) plt.ylim(ymin, ymax) ax6 = plt.subplot(326) ax_c_data = BAR_PLOT_DATA[5] ax_label = ax_c_data[0] ax_plot_data = ax_c_data[1] N = len(ax_plot_data) pos_array = [] labels = [] index = np.arange(0, len(ax_plot_data)) for i in range(N): i_data = ax_plot_data[i] pos = index[i] + (bar_width * i) labels.append(i_data[0]) pos_array.append(pos) plt.bar(pos, i_data[1], bar_width, alpha=opacity, color=bar_color, label=i_data[0], yerr=i_data[2], ecolor="#000000", align='center') plt.xticks(pos_array, labels, fontproperties=prop, fontsize=10) plt.yticks(np.arange(ymin, ymax + ygap, ygap), fontsize=0) #plt.setp(ax6.get_yticklabels(),visible=False); plt.title(ax_label, fontproperties=prop, fontsize=title_fs) #plt.legend(prop=mplot.font_manager.FontProperties(size=10),frameon=False,ncol=2,mode="expand") plt.tight_layout() sfname = "%s/MutationL6-barPlot.png" % (BPFOL) plt.savefig(sfname, dpi=300) #plt.show() ''''