def write_tlsout_file(self, chain, cpartition): """Writes the TLSOUT file for the segmentation. """ basename = "%s_CHAIN%s_NTLS%d" % (self.struct_id, chain.chain_id, cpartition.num_tls_segments()) tlsout_path = "%s.tlsout" % (basename) struct_id = self.struct_id chain_id = chain.chain_id tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) for tls in cpartition.iter_tls_segments(): ## don't write out bypass edges if tls.method != "TLS": continue tls_desc = TLS.TLSGroupDesc() tls_file.tls_desc_list.append(tls_desc) tls_desc.set_tls_group(tls.tls_group) for frag_id1, frag_id2 in tls.iter_segment_ranges(): tls_desc.add_range(chain_id, frag_id1, chain_id, frag_id2, "ALL") tls_file.save(open(tlsout_path, "w")) return tlsout_path
def main(tlsin, struct_in, struct_out): struct = FileIO.LoadStructure(file=struct_in) ## make the TLS groups fil = open(tlsin, "r") tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) tls_file.load(fil) tls_group_list = [] for tls_desc in tls_file.tls_desc_list: tls = tls_desc.construct_tls_group_with_atoms(struct) tls.tls_desc = tls_desc tls_group_list.append(tls) print tls.origin for tls in tls_group_list: for atm, Utls in tls.iter_atm_Utls(): atm.U = Utls + (Constants.B2U * atm.temp_factor * numpy.identity(3, float)) atm.temp_factor = Constants.U2B * (numpy.trace(atm.U) / 3.0) ## save the struct FileIO.SaveStructure(file=struct_out, struct=struct)
def main(path, opt_dict): struct = FileIO.LoadStructure(file=path) tls_group_list = [] ## make the TLS groups if opt_dict.has_key("-t"): try: fil = open(opt_dict["-t"], "r") except IOError: print "[ERROR]: TLSIN File not found %s" % (opt_dict["-t"]) sys.exit(-1) tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) tls_file.load(fil) for tls_desc in tls_file.tls_desc_list: tls = tls_desc.construct_tls_group_with_atoms(struct) tls.tls_desc = tls_desc tls_group_list.append(tls) else: ## create one TLS group per chain by default for chain in struct.iter_chains(): if chain.count_amino_acids() < 10: continue try: chain_id1 = chain.chain_id frag_id1 = chain[0].fragment_id frag_id2 = chain[-1].fragment_id except IndexError: continue tls_desc = TLS.TLSGroupDesc() tls_desc.add_range(chain_id1, frag_id1, chain_id1, frag_id2, "ALL") tls = tls_desc.construct_tls_group_with_atoms(struct) tls_group_list.append(tls) tls.tls_desc = tls_desc print "Creating TLS Group: %s" % (tls.name) ## fit TLS groups and write output tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) ## preform a LSQ fit if necessary for tls in tls_group_list: print "[TLS GROUP %s]" % (tls.name) ## if the TLS group is null, then perform a LSQ-TLS fit if tls.is_null(): print "Null Group: Running TLS-LSQ" if len(tls) < 20: print "ERROR: Not Enough Atoms in TLS Group." continue tls.origin = tls.calc_centroid() lsq_residual = tls.calc_TLS_least_squares_fit() tls.shift_COR() tls.tls_desc.set_tls_group(tls) tls_file.tls_desc_list.append(tls.tls_desc) if opt_dict.has_key("-o"): print "Saving TLSIN: %s" % (opt_dict["-o"]) tls_file.save(open(opt_dict["-o"], "w")) ## write out a PDB file with 0.0 tempature factors for all ## atoms in TLS groups if opt_dict.has_key("-p"): for tls in tls_group_list: for atm, Utls in tls.iter_atm_Utls(): if opt_dict.has_key("-s"): atm.temp_factor = 0.0 atm.U = None else: atm.temp_factor = Constants.U2B * numpy.trace(Utls) / 3.0 atm.U = Utls ## save the struct print "Saving XYZIN: %s" % (opt_dict["-p"]) FileIO.SaveStructure(file=opt_dict["-p"], struct=struct)
def main(path, opt_dict): struct = FileIO.LoadStructure(file = path) tls_group_list = [] ## make the TLS groups if opt_dict.has_key("-t"): try: fil = open(opt_dict["-t"], "r") except IOError: print "ERROR: TLSIN File not found %s" % (opt_dict["-t"]) sys.exit(-1) tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) tls_file.load(fil) for tls_desc in tls_file.tls_desc_list: #tls = tls_desc.generate_tls_group(struct) ## old def tls = tls_desc.construct_tls_group_with_atoms(struct) tls.tls_desc = tls_desc tls_group_list.append(tls) print tls.name else: tls_desc = TLS.TLSGroupDesc() tls_desc.add_range("A", "1", "A", "25", "ALL") tls_group = tls_desc.construct_tls_group_with_atoms(struct) tls_group_list.append(tls_group) tls_group.tls_desc = tls_desc tls_group.origin = tls_group.calc_centroid() tls_group.T = rt_random(T1) tls_group.L, tls_group.S = rt_random2(L1, S1) tls_desc = TLS.TLSGroupDesc() tls_desc.add_range("A", "26", "A", "35", "ALL") tls_group = tls_desc.construct_tls_group_with_atoms(struct) tls_group_list.append(tls_group) tls_group.tls_desc = tls_desc tls_group.origin = tls_group.calc_centroid() tls_group.T = rt_random(T2) tls_group.L, tls_group.S = rt_random2(L2, S1) tls_desc = TLS.TLSGroupDesc() tls_desc.add_range("A", "36", "A", "52", "ALL") tls_group = tls_desc.construct_tls_group_with_atoms(struct) tls_group_list.append(tls_group) tls_group.tls_desc = tls_desc tls_group.origin = tls_group.calc_centroid() tls_group.T = rt_random(T3) tls_group.L, tls_group.S = rt_random2(L3, S1) for atm in struct.iter_all_atoms(): atm.U = None ## write out ideal TLS ANISOU records if opt_dict.has_key("-p"): for tls_group in tls_group_list: for atm, Utls in tls_group.iter_atm_Utls(): atm.temp_factor = Constants.U2B * (numpy.trace(Utls) / 3.0) atm.U = Utls ## save the struct FileIO.SaveStructure(file = opt_dict["-p"], struct = struct)
def refmac5_prep(xyzin, tlsin_list, xyzout, tlsout): """Use TLS model + Uiso for each atom. Output xyzout with the residual Uiso only. """ ## load structure struct = FileIO.LoadStructure(fil = xyzin) ## load and construct TLS groups tls_group_list = [] tls_file = TLS.TLSFile() tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) tls_file_format = TLS.TLSFileFormatTLSOUT() for tlsin in tlsin_list: tls_desc_list = tls_file_format.load(open(tlsin, "r")) for tls_desc in tls_desc_list: tls_file.tls_desc_list.append(tls_desc) tls_group = tls_desc.construct_tls_group_with_atoms(struct) tls_group.tls_desc = tls_desc tls_group_list.append(tls_group) ## set the extra Uiso for each atom for tls_group in tls_group_list: ## minimal/maximal amount of Uiso which has to be added ## to the group's atoms to to make Uiso == Uiso_tls min_Uiso = 0.0 max_Uiso = 0.0 for atm, Utls in tls_group.iter_atm_Utls(): tls_tf = numpy.trace(Utls) / 3.0 ref_tf = numpy.trace(atm.get_U()) / 3.0 if ref_tf > tls_tf: max_Uiso = max(ref_tf - tls_tf, max_Uiso) else: min_Uiso = max(tls_tf - ref_tf, min_Uiso) ## reduce the TLS group T tensor by min_Uiso so that ## a PDB file can be written out where all atoms ## Uiso == Uiso_tls ## we must rotate the T tensor to its primary axes before ## subtracting min_Uiso magnitude from it (T_eval, TR) = numpy.linalg.eig(tls_group.T) T = numpy.dot(TR, numpy.dot(tls_group.T, numpy.transpose(TR))) assert numpy.allclose(T[0,1], 0.0) assert numpy.allclose(T[0,2], 0.0) assert numpy.allclose(T[1,2], 0.0) T[0,0] = T[0,0] - min_Uiso T[1,1] = T[1,1] - min_Uiso T[2,2] = T[2,2] - min_Uiso ## now take some of the smallest principal component of T and ## move it into the individual atomic temperature factors min_T = min(T[0,0], min(T[1,1], T[2,2])) sub_T = min_T * 0.50 add_Uiso = min_T - sub_T T[0,0] = T[0,0] - sub_T T[1,1] = T[1,1] - sub_T T[2,2] = T[2,2] - sub_T ## rotate T back to original orientation tls_group.T = numpy.dot( numpy.transpose(TR), numpy.dot(T, TR)) ## reset the TLS tensor values in the TLSDesc object so they can be saved tls_group.tls_desc.set_tls_group(tls_group) ## set atm.temp_factor for atm, Utls in tls_group.iter_atm_Utls(): tls_tf = numpy.trace(Utls) / 3.0 ref_tf = numpy.trace(atm.get_U()) / 3.0 if ref_tf > tls_tf: atm.temp_factor = ((add_Uiso) + ref_tf - tls_tf)*Constants.U2B atm.U = None else: atm.temp_factor = (add_Uiso) * Constants.U2B atm.U = None FileIO.SaveStructure(fil = xyzout, struct = struct) tls_file.save(open(tlsout, "w"))
print_TLSGroup(tls) else: tls_file = TLS.TLSFile() ## get TLS groups from REMARK statments in PDB file if tls_out_path == None: tls_file.set_file_format(TLS.TLSFileFormatPDB()) try: tls_file.load(open(pdb_path, "r"), pdb_path) except IOError, e: print "[Error] %s: %s" % (str(e), pdb_path) ## or get TLS groups from REFMAC TLSOUT file else: tls_file.set_file_format(TLS.TLSFileFormatTLSOUT()) try: tls_file.load(open(tls_out_path, "r"), tls_out_path) except IOError, e: print "[Error] %s: %s" % (str(e), tls_out_path) ## print the TLS groups tls_group_list = tls_file.construct_tls_groups_with_atoms(struct) for tls_group in tls_group_list: print_TLSGroup(tls_group) print if __name__ == "__main__":