def RecombineIndependentTLSSegments(analysis): console.endln() console.debug_stdoutln(">tlsmd_analysis->RecombineIndependentTLSSegments()") console.stdoutln("TLS SEGMENT RECOMBINATION") for chain in analysis.chains: ## E.g., chain="Segment(1:A, Res(ILE,16,A)...Res(SER,116,A))" cpartition_recombination.ChainPartitionRecombinationOptimization(chain)
def make_script(self): console.debug_stdoutln(">gnuplots.py->LSQR_vs_TLS_Segments_All_Chains_Plot()") struct_id = self.tlsmd_analysis.struct.structure_id ## generate data and png paths basename = "%s_RESID" % (struct_id) self.set_basename(basename) ## prepare gnuplot script script = _LSQR_VS_TLS_SEGMENTS_ALL_CHAINS_TEMPLATE script = script.replace("<nparts>", str(conf.globalconf.nparts)) script = script.replace("<title>", "Least Squares Residual vs. Number of TLS Segments of %s" % (struct_id)) ## re-use the data files of LSQRvsNTLS from the individual ## graphs; to do this the filenames have to be re-constructed plist = [] for chain in self.tlsmd_analysis.iter_chains(): filename = "%s_CHAIN%s_RESID.txt" % (struct_id, chain.chain_id) x = '"%s" using 1:2 title "Chain %s" lw 3 with linespoints' % (filename, chain.chain_id) plist.append(x) script += "plot " + ",\\\n ".join(plist) + "\n" ## Make a thumbnail (half-size) version for the summary page script += "set term png font '%s,8' size 400,320 linewidth 0.5\n" % conf.GNUPLOT_FONT script += "set output 'summary.png'\n" script += "unset title; set ylabel 'Residual' offset 1; replot\n" console.stdoutln("GNUPLot: Saving summary.png") return script
def make_script(self): console.debug_stdoutln(">gnuplots.py->CA_TLS_Differance_Plot()") basename = "%s_CHAIN%s_NTLS%s_CADIFF" % ( self.chain.struct.structure_id, self.chain.chain_id, self.cpartition.num_tls_segments(), ) self.set_basename(basename) self.write_data_file() script = _CA_TLS_DIFFERANCE_TEMPLATE seg_start = create_fractional_residue_number(self.cpartition.first_frag_id()) seg_end = create_fractional_residue_number(self.cpartition.last_frag_id()) script = script.replace("<xrng1>", seg_start) script = script.replace("<xrng2>", seg_end) script = script.replace( "<title>", "Deviation of Observed CA B Factors from TLS Model for %d Group Partition" % (self.cpartition.num_tls_segments()), ) ## line style script += 'set style line 1 lc rgb "#000000" lw 1\n' ls = 1 for itls, tls in enumerate(self.cpartition.iter_tls_segments()): ls += 1 script += 'set style line %d lc rgb "%s" lw 3\n' % (ls, tls.color.rgbs) ## plot list plist = [] plist.append("0.0 notitle ls 1 with lines") ls = 1 for itls in xrange(self.cpartition.num_tls_segments()): ls += 1 x = '"%s" using 1:%d notitle ls %d with lines' % (self.txt_path, itls + 2, ls) plist.append(x) script += "plot " + ",\\\n ".join(plist) + "\n" flat_script = script.replace("\n", ";") flatfile_write( "CA_TLS_Differance_Plot: script", "CTDP", "SCRIPT", flat_script, self.chain.chain_id, self.cpartition.num_tls_segments(), ) return script
def prnt_settings(self): chain_ids = [] for chain in self.chains: chain_ids.append(chain.chain_id) cids = ",".join(chain_ids) console.debug_stdoutln(">tlsmd_analysis->TLSMDAnalysis()") console.kvformat("STRUCTURE ID", self.struct_id) console.kvformat("CHAIN IDs SELECTED FOR ANALYSIS", cids) console.endln()
def make_script(self): console.debug_stdoutln(">gnuplots.py->LibrationAnalysis()") basename = "%s_CHAIN%s_NTLS%s_LIBRATION" % ( self.chain.struct.structure_id, self.chain.chain_id, self.cpartition.num_tls_segments(), ) self.set_basename(basename) self.write_data_file() script = _LIBRATION_ANALYSIS_TEMPLATE seg_start = create_fractional_residue_number(self.cpartition.first_frag_id()) seg_end = create_fractional_residue_number(self.cpartition.last_frag_id()) script = script.replace("<xrng1>", seg_start) script = script.replace("<xrng2>", seg_end) script = script.replace( "<title>", "Screw displacement analysis of backbone atoms using %d TLS Groups" % (self.cpartition.num_tls_segments()), ) ## line style ls = 0 for tls in self.cpartition.iter_tls_segments(): ls += 1 script += 'set style line %d lc rgb "%s" lw 3\n' % (ls, tls.color.rgbs) ## plot list plist = [] ls = 0 for itls in xrange(self.cpartition.num_tls_segments()): ls += 1 for n in (0, 1, 2): col = 2 + 3 * itls + n x = '"%s" using 1:%d smooth bezier notitle ls %d with lines' % (self.txt_path, col, ls) plist.append(x) script += "plot " + ",\\\n ".join(plist) + "\n" flat_script = script.replace("\n", ";") flatfile_write( "LibrationAnalysis: script", "LIAN", "SCRIPT", flat_script, self.chain.chain_id, self.cpartition.num_tls_segments(), ) return script
def FitConstrainedTLSModel(analysis): """Calculates constrained TLS model for visualization. """ console.endln() console.debug_stdoutln(">tlsmd_analysis->FitConstrainedTLSModel()") console.stdoutln("CALCULATING CONSTRAINED TLS MODEL FOR VISUALIZATION") ## EAM Feb 2008 User job was getting stuck in fit_to_chain() ## Obviously it would be nice to fix the actual error, but at least we would ## like to be able to give it a swift non-fatal kick by sending SIGUSR1 signal.signal(signal.SIGUSR1, SIGUSR1_handler) ## Progress tracking ## - assume this portion of the run occupies 0.1 -> 0.5 of the total time progress = 0.1 for chain in analysis.iter_chains(): console.stdoutln("CHAIN %s" % (chain.chain_id)) for cpartition in chain.partition_collection.iter_chain_partitions(): ## cpartition.chain = "Segment(1:A, Res(MET,1,A)...Res(VAL,50,A))" console.stdoutln("TLS GROUPS: %d" % (cpartition.num_tls_segments())) for tls in cpartition.iter_tls_segments(): try: tls.fit_to_chain(cpartition.chain) ## TODO: Write out data for residual plots. #gp = gnuplots.LSQR_vs_TLS_Segments_Pre_Plot(cpartition.chain) #console.stdoutln("FIT_TO_CHAIN_PATH: %s" % analysis.struct2_file_path) except (RuntimeError, numpy.linalg.linalg.LinAlgError), e: msg = " Runtime error for [%s]: %s, " % ( tls, e) msg += "trying to continue..." console.stdoutln(msg) print console.formatExceptionInfo() pass ## Track progress progress += 0.4/analysis.num_chains() progress_report = open("progress","w+") print >> progress_report, progress ## progress_report.write(progress) progress_report.close()
def make_script(self): console.debug_stdoutln(">gnuplots.py->LSQR_vs_TLS_Segments_Plot()") ## generate data and png paths basename = "%s_CHAIN%s_RESID" % (self.chain.partition_collection.struct.structure_id, self.chain.chain_id) self.set_basename(basename) 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 LSQR_vs_TLS_Segments_Plot") column_titles = "Number of TLS Groups\tRMSD B\tResidual" flatfile.write("\nLSQR %s,0.0 #%s\n" % (self.chain.chain_id, column_titles)) tbl = table.StringTable(0, 3, "?", column_titles=["Number of TLS Groups", "RMSD B", "Residual"]) for ntls, cpartition in self.chain.partition_collection.iter_ntls_chain_partitions(): tbl.append_row(ntls, cpartition.rmsd_b(), cpartition.residual()) flatfile.write( "LSQR %s,%s.0 %s\t%s\t%s\n" % (self.chain.chain_id, ntls, ntls, cpartition.rmsd_b(), cpartition.residual()) ) flatfile.close() open(self.txt_path, "w").write(str(tbl)) ## modify script template script = _LSQR_VS_TLS_SEGMENTS_TEMPLATE script = script.replace("<nparts>", str(conf.globalconf.nparts)) script = script.replace("<txtfile>", self.txt_path) script = script.replace( "<title>", "Least Squares Residual vs. Number of TLS Segments for %s Chain %s " % (self.chain.partition_collection.struct.structure_id, self.chain.chain_id), ) return script
def IndependentTLSSegmentOptimization(analysis): """Performs the TLS graph minimization on all TLSGraphs. """ for chain in analysis.chains: isopt = independent_segment_opt.ISOptimization( chain, conf.globalconf.min_subsegment_size, conf.globalconf.nparts) ## TODO: Divide this into two CPU times, 2009-12-10 #console.stdoutln("CPU_TIME ->ISOptResidualGraph: %s" % time.clock()) isopt.run_minimization() if not isopt.minimized: continue console.endln() console.stdoutln("="*79) console.debug_stdoutln(">tlsmd_analysis->IndependentTLSSegmentOptimization()") console.stdoutln("MINIMIZING CHAIN %s" % (chain)) isopt.prnt_detailed_paths() chain.partition_collection = isopt.construct_partition_collection(conf.globalconf.nparts) chain.partition_collection.struct = analysis.struct
def ChainPartitionRecombinationOptimization(chain): console.debug_stdoutln(">cpartition_recombination->ChainPartitionRecombinationOptimization()") visited = {} ntls_best = {} orig_best = {} for ntls, cpartition in chain.partition_collection.iter_ntls_chain_partitions(): ntls_best[ntls] = cpartition orig_best[ntls] = cpartition ## DEBUG: Example output: #for k,v in cpartition.iteritems(): console.stdoutln("cpartition=%s : %s"%(k,v)) ## ntls_best=[1, 2, 3, 4] ## orig_best=[1, 2, 3, 4] ## ntls_best{KEYS : VALUES}= ## 1 : (A:1-50) ## 2 : (A:1-37)(A:38-50) ## 3 : (A:1-9)(A:21-30)(A:31-50) ## 4 : (A:1-9)(A:21-30)(A:31-37)(A:38-50) ## orig_best{KEYS : VALUES}= ## 1 : (A:1-50) ## 2 : (A:1-37)(A:38-50) ## 3 : (A:1-9)(A:21-30)(A:31-50) ## 4 : (A:1-9)(A:21-30)(A:31-37)(A:38-50) for ntls, cpartition in chain.partition_collection.iter_ntls_chain_partitions(): if ntls < 2: if float(cpartition.rmsd_b()) < 0.0: ## FIXME: This doesn't work yet, 2009-06-05 ## Why doesn't it? 2010-04-02 msg = "**** STOP! No need to continue. " msg += "Residual is already best for NTLS=%s ****" % ( cpartition.rmsd_b()) console.stdoutln("%s" % msg) break #console.stdoutln("TYPE: [%s] -> type(%s); float(%s)" % ( # cpartition.rmsd_b(), type(cpartition.rmsd_b()), # float(cpartition.rmsd_b()))) console.stdoutln("RMSD-%sc: %s" % (ntls, cpartition.rmsd_b())) console.stdoutln("RESIDUAL-%sc: %s" % (ntls, cpartition.residual())) continue ## No recombination needed for a single ntls group console.stdoutln("=" * 80) ## LOGLINE console.stdoutln("%d INTO %d TO 2" % (ntls, ntls - 1)) ## LOGLINE search_width = 1 search_depth = 1 proot = tree.Tree() proot.cp = cpartition while True: ExtendRecombinationTree(proot, search_depth, search_width) ## NOTE (by Christoph): ## It seems max_depth is always either "1" or "0" (integers) ## E.g., for "4 INTO 3 TO 2", we would have {1,1,1,0} max_depth = proot.depth() best_at_depth = None for depth, ptree in proot.iter_depth_first(): ## NOTE (by Christoph): E.g., ## ptree.cp = "(A:16-26)(A:27-61)(A:62-74; 95-116)(A:75-94)" ## ptree.cp.residual_delta = "0.00150017006854" if depth == max_depth: if best_at_depth is None or \ ptree.cp.residual_delta < best_at_depth.cp.residual_delta: best_at_depth = ptree tmp_ntls = ptree.cp.num_tls_segments() ## (integer value) if not visited.has_key(ptree): visited[ptree] = True if ntls_best.has_key(tmp_ntls): ## E.g., ntls_best[tmp_ntls] = "(A:16-74; 95-116)(A:75-94)" best_rmsd = "%5.2f" % (ntls_best[tmp_ntls].rmsd_b()) else: best_rmsd = "-----" ## E.g., "(A:2-11; 18-23; 39-52; 58-95)(A:12-17; 24-38; 53-57) 5.42( 4.98) 2" console.stdoutln("%s %5.2f(%s) %d" % ( ptree.cp, ptree.cp.rmsd_b(), best_rmsd, tmp_ntls)) ## NOTE: Example output: ## cpartition="(A:1-9)(A:21-30)(A:31-50)" ## cpartition.chain.chain_id="A" ## cpartition.num_tls_segments()="7" ## table.StringTableFromMatrix(cpartition.rmsd_b_mtx)=" ## 1.19667217259 2.44700956714 2.44363045774 ## 2.44700956714 1.90000136951 2.93313261105 ## 2.44363045774 2.93313261105 1.76763623176" ## NOTE: The above are the same values found in ## 'xxxx_CHAINa_NTLSn_RECOMBINATION.txt' files ## segment_ranges = segment_ranges, ## residual = tlsdict["residual"], ## method = tls1.method, ## num_atoms = tlsdict["num_atoms"], ## num_residues = tlsdict["num_residues"]) if ntls_best.has_key(tmp_ntls): if ptree.cp.residual() < ntls_best[tmp_ntls].residual(): ## E.g., ptree.cp="(A:16-61)(A:62-74; 95-116)(A:75-94)" ntls_best[tmp_ntls] = ptree.cp else: ntls_best[tmp_ntls] = ptree.cp ptree = best_at_depth for i in xrange(max_depth - 1): ptree = ptree.parent() proot = ptree if search_depth > max_depth: break ## insert replacement ChainPartitions if conf.globalconf.recombination: for ntls, cpartition in ntls_best.iteritems(): cp = chain.partition_collection.get_chain_partition(ntls) if cp != cpartition: chain.partition_collection.insert_chain_partition(cpartition)
def make_script(self): console.debug_stdoutln(">gnuplots.py->RMSDPlot()") basename = "%s_CHAIN%s_NTLS%s_RMSD" % ( self.chain.struct.structure_id, self.chain.chain_id, self.cpartition.num_tls_segments(), ) self.set_basename(basename) self.write_data_file() ## Gnuplot Script script = _RMSD_PLOT_TEMPLATE seg_start = create_fractional_residue_number(self.cpartition.first_frag_id()) seg_end = create_fractional_residue_number(self.cpartition.last_frag_id()) script = script.replace("<xrng1>", seg_start) script = script.replace("<xrng2>", seg_end) script = script.replace("<title>", "TLS Model RMSD per Residue ") ## line style line_titles = ["notitle" for x in xrange(self.cpartition.num_tls_segments())] if self.cpartition.num_tls_segments() > 1: script += 'set style line 1 lc rgb "#000000" lw 3\n' ls = 1 for itls, tls in enumerate(self.cpartition.iter_tls_segments()): ls += 1 script += 'set style line %d lc rgb "%s" lw 3\n' % (ls, tls.color.rgbs) title = 'title "%s TLS"' % (tls.display_label()) line_titles.append(title) if self.cpartition.num_tls_segments() > 1: ls += 1 script += 'set style line %d lc rgb "#000000" lw 3\n' % (ls) ## plot list plist = [] if self.cpartition.num_tls_segments() > 1: plist.append('"%s" using 1:2 title "Rigid Chain" ls 1 with lines' % (self.txt_path)) ls = 1 for itls in xrange(self.cpartition.num_tls_segments()): ls += 1 col = itls + 3 x = '"%s" using 1:%d %s ls %d with lines' % (self.txt_path, col, line_titles[itls], ls) plist.append(x) script += "plot " + ",\\\n ".join(plist) + "\n" flat_script = script.replace("\n", ";") flatfile_write( "RMSDPlot: script", "RMPT", "SCRIPT", flat_script, self.chain.chain_id, self.cpartition.num_tls_segments() ) return script
def make_script(self): console.debug_stdoutln(">gnuplots.py->BMeanPlot()") basename = "%s_CHAIN%s_NTLS%s_BMEAN" % ( self.chain.struct.structure_id, self.chain.chain_id, self.cpartition.num_tls_segments(), ) self.set_basename(basename) ## write data file BISO_OBS = tls_calcs.calc_mean_biso_obs(self.chain) BISO = tls_calcs.calc_mean_biso_tls(self.chain, self.cpartition) nrows = len(self.cpartition.chain) ncols = 3 + self.cpartition.num_tls_segments() 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) ifrag_iter = itertools.imap(lambda frag: frag.ifrag, self.cpartition.chain.iter_fragments()) tbl.set_column(0, 1, ifrag_iter) tbl.set_column(0, 2, BISO_OBS) for itls, tls in enumerate(self.cpartition.iter_tls_segments()): for frag in tls.iter_fragments(): i = frag.ifrag tbl[i, itls + 3] = BISO[i] open(self.txt_path, "w").write(str(tbl)) flatfile_write( "BMeanPlot: data", "BMPT", "DATA", str(tbl), self.chain.chain_id, self.cpartition.num_tls_segments() ) ## Gnuplot Script script = _BMEAN_PLOT_TEMPLATE seg_start = create_fractional_residue_number(self.cpartition.first_frag_id()) seg_end = create_fractional_residue_number(self.cpartition.last_frag_id()) script = script.replace("<xrng1>", seg_start) script = script.replace("<xrng2>", seg_end) script = script.replace("<title>", "Observed and TLS Calculated Mean B Factor Per Residue") ## line style line_titles = [] ls = 0 ls += 1 script += 'set style line %d lc rgb "#000000" lw 3\n' % (ls) for tls in self.cpartition.iter_tls_segments(): ls += 1 script += 'set style line %d lc rgb "%s" lw 3\n' % (ls, tls.color.rgbs) if self.tls_group_titles: title = 'title "%s TLS"' % (tls.display_label()) else: title = "notitle" line_titles.append(title) ## plot list plist = [] ls = 0 ## first the observed mean bfactors ls += 1 x = '"%s" using 1:%d title "Observed" ls %d with lines' % (self.txt_path, 2 + ls, ls) plist.append(x) ## second the TLS calculated bfactors for i in xrange(self.cpartition.num_tls_segments()): ls += 1 x = '"%s" using 1:%d %s ls %d with lines' % (self.txt_path, 2 + ls, line_titles[i], ls) plist.append(x) script += "plot " + ",\\\n ".join(plist) + "\n" flat_script = script.replace("\n", ";") flatfile_write( "BMeanPlot: script", "BMPT", "SCRIPT", flat_script, self.chain.chain_id, self.cpartition.num_tls_segments() ) return script
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 ChainPartitionRecombinationOptimization(chain): console.debug_stdoutln( ">cpartition_recombination->ChainPartitionRecombinationOptimization()") visited = {} ntls_best = {} orig_best = {} for ntls, cpartition in chain.partition_collection.iter_ntls_chain_partitions( ): ntls_best[ntls] = cpartition orig_best[ntls] = cpartition ## DEBUG: Example output: #for k,v in cpartition.iteritems(): console.stdoutln("cpartition=%s : %s"%(k,v)) ## ntls_best=[1, 2, 3, 4] ## orig_best=[1, 2, 3, 4] ## ntls_best{KEYS : VALUES}= ## 1 : (A:1-50) ## 2 : (A:1-37)(A:38-50) ## 3 : (A:1-9)(A:21-30)(A:31-50) ## 4 : (A:1-9)(A:21-30)(A:31-37)(A:38-50) ## orig_best{KEYS : VALUES}= ## 1 : (A:1-50) ## 2 : (A:1-37)(A:38-50) ## 3 : (A:1-9)(A:21-30)(A:31-50) ## 4 : (A:1-9)(A:21-30)(A:31-37)(A:38-50) for ntls, cpartition in chain.partition_collection.iter_ntls_chain_partitions( ): if ntls < 2: if float(cpartition.rmsd_b()) < 0.0: ## FIXME: This doesn't work yet, 2009-06-05 ## Why doesn't it? 2010-04-02 msg = "**** STOP! No need to continue. " msg += "Residual is already best for NTLS=%s ****" % ( cpartition.rmsd_b()) console.stdoutln("%s" % msg) break #console.stdoutln("TYPE: [%s] -> type(%s); float(%s)" % ( # cpartition.rmsd_b(), type(cpartition.rmsd_b()), # float(cpartition.rmsd_b()))) console.stdoutln("RMSD-%sc: %s" % (ntls, cpartition.rmsd_b())) console.stdoutln("RESIDUAL-%sc: %s" % (ntls, cpartition.residual())) continue ## No recombination needed for a single ntls group console.stdoutln("=" * 80) ## LOGLINE console.stdoutln("%d INTO %d TO 2" % (ntls, ntls - 1)) ## LOGLINE search_width = 1 search_depth = 1 proot = tree.Tree() proot.cp = cpartition while True: ExtendRecombinationTree(proot, search_depth, search_width) ## NOTE (by Christoph): ## It seems max_depth is always either "1" or "0" (integers) ## E.g., for "4 INTO 3 TO 2", we would have {1,1,1,0} max_depth = proot.depth() best_at_depth = None for depth, ptree in proot.iter_depth_first(): ## NOTE (by Christoph): E.g., ## ptree.cp = "(A:16-26)(A:27-61)(A:62-74; 95-116)(A:75-94)" ## ptree.cp.residual_delta = "0.00150017006854" if depth == max_depth: if best_at_depth is None or \ ptree.cp.residual_delta < best_at_depth.cp.residual_delta: best_at_depth = ptree tmp_ntls = ptree.cp.num_tls_segments() ## (integer value) if not visited.has_key(ptree): visited[ptree] = True if ntls_best.has_key(tmp_ntls): ## E.g., ntls_best[tmp_ntls] = "(A:16-74; 95-116)(A:75-94)" best_rmsd = "%5.2f" % (ntls_best[tmp_ntls].rmsd_b()) else: best_rmsd = "-----" ## E.g., "(A:2-11; 18-23; 39-52; 58-95)(A:12-17; 24-38; 53-57) 5.42( 4.98) 2" console.stdoutln( "%s %5.2f(%s) %d" % (ptree.cp, ptree.cp.rmsd_b(), best_rmsd, tmp_ntls)) ## NOTE: Example output: ## cpartition="(A:1-9)(A:21-30)(A:31-50)" ## cpartition.chain.chain_id="A" ## cpartition.num_tls_segments()="7" ## table.StringTableFromMatrix(cpartition.rmsd_b_mtx)=" ## 1.19667217259 2.44700956714 2.44363045774 ## 2.44700956714 1.90000136951 2.93313261105 ## 2.44363045774 2.93313261105 1.76763623176" ## NOTE: The above are the same values found in ## 'xxxx_CHAINa_NTLSn_RECOMBINATION.txt' files ## segment_ranges = segment_ranges, ## residual = tlsdict["residual"], ## method = tls1.method, ## num_atoms = tlsdict["num_atoms"], ## num_residues = tlsdict["num_residues"]) if ntls_best.has_key(tmp_ntls): if ptree.cp.residual() < ntls_best[tmp_ntls].residual(): ## E.g., ptree.cp="(A:16-61)(A:62-74; 95-116)(A:75-94)" ntls_best[tmp_ntls] = ptree.cp else: ntls_best[tmp_ntls] = ptree.cp ptree = best_at_depth for i in xrange(max_depth - 1): ptree = ptree.parent() proot = ptree if search_depth > max_depth: break ## insert replacement ChainPartitions if conf.globalconf.recombination: for ntls, cpartition in ntls_best.iteritems(): cp = chain.partition_collection.get_chain_partition(ntls) if cp != cpartition: chain.partition_collection.insert_chain_partition(cpartition)
def ConstructSegmentForAnalysis(raw_chain): """Returns a list of Segment instance from the Chain instance which is properly modified for use in the this application. """ console.debug_stdoutln(">tlsmd_analysis->ConstructSegmentForAnalysis(chain %s)" % ( raw_chain.chain_id)) ## NOTE: raw_chain = "Chain(1:A, Res(MET,1,A)...Res(VAL,50,A))" ## Sets that atm.include attribute for each atom in the chains ## being analyzed by tlsmd for atm in raw_chain.iter_all_atoms(): #atm.include = atom_selection.calc_include_atom(atm) atm.include = atom_selection.calc_include_atom(atm, reject_messages = True) ## ok, use the chain but use a segment and cut off ## any leading and trailing non-amino acid residues ## do not include a fragment with no included atoms naa = nna = ota = 0 naa = raw_chain.count_amino_acids() nna = raw_chain.count_nucleic_acids() ota = raw_chain.count_fragments() if naa > nna: ## Probably a protein with (possibly) some nucleic acids. iter_residues = raw_chain.iter_amino_acids() elif nna > naa: ## Probably a nucleic acid with (possibly) some amino acids. iter_residues = raw_chain.iter_nucleic_acids() if naa == 0 and nna == 0 and ota > 0: ## This chain does not have any amino or nucleic acids, so skip. return "" segment = Structure.Segment(chain_id = raw_chain.chain_id) for frag in iter_residues: for atm in frag.iter_all_atoms(): if atm.include: segment.add_fragment(frag) break ## apply data smooth if desired (default is "0") if conf.globalconf.adp_smoothing > 0: adp_smoothing.IsotropicADPDataSmoother(segment, conf.globalconf.adp_smoothing) ## this is useful: for each fragment in the minimization ## set an attribute for its index position for i, frag in enumerate(segment.iter_fragments()): ## NOTE (by Christoph): ## Example output: ## 0 : Res(MET,1,A) ## 1 : Res(ILE,2,A) ## ... frag.ifrag = i ## create a TLSModelAnalyzer instance for the chain, and attach the ## instance to the chain for use by the rest of the program segment.tls_analyzer = tlsmdmodule.TLSModelAnalyzer() xlist = atom_selection.chain_to_xmlrpc_list(segment.iter_all_atoms()) segment.tls_analyzer.set_xmlrpc_chain(xlist) ## INPUT : raw_chain = "Chain(1:A, Res(MET,1,A)...Res(VAL,50,A))" ## OUTPUT: segment = "Segment(1:A, Res(MET,1,A)...Res(VAL,50,A))" return segment
def LoadStructure(struct_source): """Loads Structure, chooses a unique struct_id string. Also, search the REMARK records for TLS group records. If they are found, then add the TLS group ADP magnitude to the B facors of the ATOM records. """ console.debug_stdoutln(">tlsmd_analysis->LoadStructure()") ## determine the argument type if isinstance(struct_source, str): file_path = struct_source console.kvformat("LOADING STRUCTURE", file_path) fobj = open(file_path, "r") elif hasattr(struct_source, "__iter__") and hasattr(struct_source, "seek"): console.kvformat("LOADING STRUCTURE", str(struct_source)) fobj = struct_source else: raise ValueError ## TODO: Is this the same load struct used during the sanity checks? 2009-05-28 ## load struct struct = FileIO.LoadStructure(file = fobj, distance_bonds = True) job_dir = str(os.path.dirname(str(struct_source))) console.kvformat("HEADER", struct.header) console.kvformat("TITLE", struct.title) console.kvformat("EXPERIMENTAL METHOD", struct.experimental_method) console.kvformat("PATH", job_dir) ## set the structure ID if conf.globalconf.struct_id is not None: struct_id = conf.globalconf.struct_id else: struct_id = struct.structure_id conf.globalconf.struct_id = struct_id struct.structure_id = struct_id console.endln() ## if there are REFMAC5 TLS groups in the REMARK records of ## the PDB file, then add those in tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatPDB()) ## return to the beginning of the file and read the REMARK/TLS records fobj.seek(0) tls_file.load(fobj) if len(tls_file.tls_desc_list) > 0: console.stdoutln("ADDING TLS GROUP Bequiv TO ATOM TEMPERATURE FACTORS") console.stdoutln(" NUM TLS GROUPS: %d" % ( len(tls_file.tls_desc_list))) ## assume REFMAC5 groups where Utotal = Utls + Biso(temp_factor) for tls_desc in tls_file.tls_desc_list: try: tls_group = tls_desc.construct_tls_group_with_atoms(struct) except: print console.formatExceptionInfo() console.stdoutln(" TLS GROUP: %s" % (tls_group.name)) for atm, Utls in tls_group.iter_atm_Utls(): bresi = atm.temp_factor atm.temp_factor = bresi + (Constants.U2B * numpy.trace(Utls) / 3.0) atm.U = (Constants.B2U * bresi * numpy.identity(3, float)) + Utls console.endln() return struct