def write_data_file(self): nrows = len(self.cpartition.chain) ncols = self.cpartition.num_tls_segments() + 1 tbl = table.StringTable(nrows, ncols, "?") frag_id_iter = itertools.imap(lambda frag: frag.fragment_id, self.cpartition.chain.iter_fragments()) tbl.set_column(0, 0, frag_id_iter) for itls, tls in enumerate(self.cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T L = tls_group.itls_L S = tls_group.itls_S O = tls_group.origin for frag in tls.iter_fragments(): atm = frag.get_atom("CA") if atm is None: continue i = frag.ifrag b_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) tbl[i, itls + 1] = atm.temp_factor - b_tls open(self.txt_path, "w").write(str(tbl))
def calc_mean_biso_tls(chain, cpartition): """Calculated the mean B value per residue in the chain as calculated in the chain optimization. """ num_res = chain.count_fragments() biso = numpy.zeros(num_res, float) for i, tls in enumerate(cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T L = tls_group.itls_L S = tls_group.itls_S O = tls_group.origin for frag in tls.iter_fragments(): n = 0 b_sum_tls = 0.0 for atm in frag.iter_all_atoms(): if atm.include is False: continue n += 1 b_sum_tls += Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) if n > 0: biso[frag.ifrag] = b_sum_tls / n return biso
def calc_mean_biso_tls(chain, cpartition): """Calculates the mean B value per residue in the chain (as calculated in the chain optimization). It also performs a Skittles evaluation of the junctions between the "C" and "N" atoms of neighbouring residues. """ chain_id = chain.chain_id num_tls = cpartition.num_tls_segments() num_res = chain.count_fragments() biso = numpy.zeros(num_res, float) for i, tls in enumerate(cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T # float(3) L = tls_group.itls_L # array(3,3) S = tls_group.itls_S # array(3): S[0], S[1], S[2] O = tls_group.origin # array(3) for frag in tls.iter_fragments(): n = 0 b_sum_tls = 0.0 for atm in frag.iter_all_atoms(): if atm.include is False: continue n += 1 b_sum_tls += Constants.U2B * TLS.calc_itls_uiso( T, L, S, atm.position - O) if n > 0: biso[frag.ifrag] = b_sum_tls / n return biso
def calc_residue_mean_rmsd(chain, cpartition): """Calculates the mean RMSD value per residue in a given chain. """ num_tls = cpartition.num_tls_segments() num_res = chain.count_fragments() #struct_id = cpartition.struct_id ## TODO: Find out how to get this cmtx = numpy.zeros((num_tls, num_res), float) i_ntls = 0 for i, tls in enumerate(cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T # float(3) L = tls_group.itls_L # array(3,3) S = tls_group.itls_S # array(3): S[0], S[1], S[2] O = tls_group.origin # array(3) for j, frag in enumerate(chain): ## NOTE: j = res_num, frag = Res(ALA,23,A) ## calculate a atom-normalized rmsd deviation for each residue num_atoms = 0 msd_sum = 0.0 for atm in frag.iter_all_atoms(): if atm.include == False: continue num_atoms += 1 b_iso_tls = Constants.U2B * TLS.calc_itls_uiso( T, L, S, atm.position - O) delta = atm.temp_factor - b_iso_tls msd_sum += delta**2 if num_atoms > 0: msd = msd_sum / num_atoms rmsd = math.sqrt(msd) ## set the cross prediction matrix cmtx[i, j] = rmsd return cmtx
def calc_residue_mean_rmsd(chain, cpartition): """Calculates the mean RMSD value per residue in a given chain. """ num_tls = cpartition.num_tls_segments() num_res = chain.count_fragments() #struct_id = cpartition.struct_id ## TODO: Find out how to get this cmtx = numpy.zeros((num_tls, num_res), float) i_ntls = 0 for i, tls in enumerate(cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T # float(3) L = tls_group.itls_L # array(3,3) S = tls_group.itls_S # array(3): S[0], S[1], S[2] O = tls_group.origin # array(3) for j, frag in enumerate(chain): ## NOTE: j = res_num, frag = Res(ALA,23,A) ## calculate a atom-normalized rmsd deviation for each residue num_atoms = 0 msd_sum = 0.0 for atm in frag.iter_all_atoms(): if atm.include == False: continue num_atoms += 1 b_iso_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) delta = atm.temp_factor - b_iso_tls msd_sum += delta**2 if num_atoms > 0: msd = msd_sum / num_atoms rmsd = math.sqrt(msd) ## set the cross prediction matrix cmtx[i,j] = rmsd return cmtx
def calc_residue_mean_rmsd(chain, cpartition): num_tls = cpartition.num_tls_segments() num_res = chain.count_fragments() cmtx = numpy.zeros((num_tls, num_res), float) for i, tls in enumerate(cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T L = tls_group.itls_L S = tls_group.itls_S O = tls_group.origin for j, frag in enumerate(chain): ## calculate a atom-normalized rmsd deviation for each residue num_atoms = 0 msd_sum = 0.0 for atm in frag.iter_all_atoms(): if atm.include == False: continue num_atoms += 1 b_iso_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) delta = atm.temp_factor - b_iso_tls msd_sum += delta**2 if num_atoms > 0: msd = msd_sum / num_atoms rmsd = math.sqrt(msd) ## set the cross prediction matrix cmtx[i,j] = rmsd return cmtx
def write_data_file(self): nrows = len(self.cpartition.chain) ncols = self.cpartition.num_tls_segments() + 1 tbl = table.StringTable(nrows, ncols, "?") frag_id_iter = itertools.imap(lambda frag: frag.fragment_id, self.cpartition.chain.iter_fragments()) tbl.set_column(0, 0, frag_id_iter) for itls, tls in enumerate(self.cpartition.iter_tls_segments()): tls_group = tls.tls_group T = tls_group.itls_T L = tls_group.itls_L S = tls_group.itls_S O = tls_group.origin for frag in tls.iter_fragments(): ## FIXME: This should be able to handle either one atm = frag.get_atom("CA") ## for amino acids # atm = frag.get_atom("P") ## for nucleic acids if atm is None: continue i = frag.ifrag b_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) tbl[i, itls + 1] = atm.temp_factor - b_tls open(self.txt_path, "w").write(str(tbl)) flatfile_write( "CA_TLS_Differance_Plot: data", "CTDP", "DATA", str(tbl), self.chain.chain_id, self.cpartition.num_tls_segments(), )
def make_script(self): console.debug_stdoutln(">gnuplots.py->UIso_vs_UtlsIso_Histogram()") tls = self.tls ## generate data and png paths basename = "%s_CHAIN%s_TLS%s_BoBc" % (self.chain.struct.structure_id, self.chain.chain_id, tls.filename_label()) self.set_basename(basename) ## write out the data file tls_group = tls.tls_group T = tls_group.itls_T L = tls_group.itls_L S = tls_group.itls_S O = tls_group.origin ## create a histogram of (Uiso - Utls_iso) bdiff_min = 0.0 bdiff_max = 0.0 for atm in tls_group: b_iso_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) bdiff = atm.temp_factor - b_iso_tls bdiff_min = min(bdiff_min, bdiff) bdiff_max = max(bdiff_max, bdiff) ## compute the bin width and range to bin over brange = (bdiff_max - bdiff_min) + 2.0 num_bins = int(brange) bin_width = brange / float(num_bins) bins = [0 for n in xrange(num_bins)] ## name the bins with their mean value bin_names = [] for n in xrange(num_bins): bin_mean = bdiff_min + (float(n) * bin_width) + (bin_width / 2.0) bin_names.append(bin_mean) ## count the bins for atm in tls_group: b_iso_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) bdiff = atm.temp_factor - b_iso_tls bin = int((bdiff - bdiff_min) / bin_width) bins[bin] += 1 ## write out the gnuplot input file fil = open(self.txt_path, "w") fil.write("## Histogram of atoms in the TLS group binned by\n") fil.write("## the difference of their isotropic temperature factors\n") fil.write("## from the isotropic values predicted from the TLS model.\n") fil.write("##\n") fil.write("## Structure ----------------: %s\n" % (self.chain.struct.structure_id)) fil.write("## Chain --------------------: %s\n" % (self.chain.chain_id)) fil.write("## TLS Group Residue Range --: %s\n" % (tls.display_label())) job_dir = os.path.join(conf.TLSMD_WORK_DIR, conf.globalconf.job_id, "ANALYSIS") if os.path.basename(os.getcwd()) != "ANALYSIS": flatfile = open("../%s.dat" % conf.globalconf.job_id, "a+") else: flatfile = open("%s.dat" % conf.globalconf.job_id, "a+") flatfile.write("\nCCCC UIso_vs_UtlsIso_Histogram\n") flatfile.write("%s %s,%s.0 <DATA>\n" % ("UVUH", self.chain.chain_id, self.cpartition.num_tls_segments())) for i in xrange(len(bins)): fil.write("%f %d\n" % (bin_names[i], bins[i])) flatfile.write("%f %d\n" % (bin_names[i], bins[i])) flatfile.write("%s %s,%s.0 </DATA>\n" % ("UVUH", self.chain.chain_id, self.cpartition.num_tls_segments())) flatfile.close() fil.close() ## modify script template script = _UISO_VS_UTLSISO_HISTOGRAM_TEMPLATE script = script.replace("<txtfile>", self.txt_path) title = "Histogram of Observed B_{iso} - B_{tls} for TLS Group %s" % (tls.display_label()) script = script.replace("<title>", title) script = script.replace("<rgb>", tls.color.rgbs) flat_script = script.replace("\n", ";") flatfile_write( "UIso_vs_UtlsIso_Histogram: script", "UVUH", "SCRIPT", flat_script, self.chain.chain_id, self.cpartition.num_tls_segments(), ) return script
def make_script(self): tls = self.tls ## generate data and png paths basename = "%s_CHAIN%s_TLS%s_BoBc" % ( self.chain.struct.structure_id, self.chain.chain_id, tls.filename_label()) self.set_basename(basename) ## write out the data file tls_group = tls.tls_group T = tls_group.itls_T L = tls_group.itls_L S = tls_group.itls_S O = tls_group.origin ## create a histogram of (Uiso - Utls_iso) bdiff_min = 0.0 bdiff_max = 0.0 for atm in tls_group: b_iso_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) bdiff = atm.temp_factor - b_iso_tls bdiff_min = min(bdiff_min, bdiff) bdiff_max = max(bdiff_max, bdiff) ## compute the bin width and range to bin over brange = (bdiff_max - bdiff_min) + 2.0 num_bins = int(brange) bin_width = brange / float(num_bins) bins = [0 for n in xrange(num_bins)] ## name the bins with their mean value bin_names = [] for n in xrange(num_bins): bin_mean = bdiff_min + (float(n) * bin_width) + (bin_width / 2.0) bin_names.append(bin_mean) ## count the bins for atm in tls_group: b_iso_tls = Constants.U2B * TLS.calc_itls_uiso(T, L, S, atm.position - O) bdiff = atm.temp_factor - b_iso_tls bin = int((bdiff - bdiff_min)/ bin_width) bins[bin] += 1 ## write out the gnuplot input file fil = open(self.txt_path, "w") fil.write("## Histogram of atoms in the TLS group binned by\n") fil.write("## the difference of their isotropic temperature factors\n") fil.write("## from the isotropic values predicted from the TLS model.\n") fil.write("##\n") fil.write("## Structure ----------------: %s\n" % (self.chain.struct.structure_id)) fil.write("## Chain --------------------: %s\n" % (self.chain.chain_id)) fil.write("## TLS Group Residue Range --: %s\n" % (tls.display_label())) for i in xrange(len(bins)): fil.write("%f %d\n" % (bin_names[i], bins[i])) fil.close() ## modify script template script = _UISO_VS_UTLSISO_HISTOGRAM_TEMPLATE script = script.replace("<txtfile>", self.txt_path) title = "Histogram of Observed B_{iso} - B_{tls} for TLS Group %s" % (tls.display_label()) script = script.replace("<title>", title) script = script.replace("<rgb>", tls.color.rgbs) return script