예제 #1
0
def save_verify(struct, stats):
    """Save structure in all supported formats, then reload it and
    compare structures.
    """
    ## pdb
    print "[temp.pdb]"
    FileIO.SaveStructure(fil="temp.pdb", struct=struct, format="PDB")
    pdb_struct = FileIO.LoadStructure(fil="temp.pdb", library_bonds=True)
    cmp_struct(struct, pdb_struct)

    ## mmCIF
    print "[temp.cif]"
    FileIO.SaveStructure(fil="temp.cif", struct=struct, format="CIF")

    cif_struct = FileIO.LoadStructure(fil="temp.cif", library_bonds=True)
    cmp_struct(struct, cif_struct)
예제 #2
0
 def construct_animation(self, filename):
     """Save the animated structure to the given filename.
     """
     ##self.phase_assignment()
     for phase in (0.5, 1.0, 0.5, 0.0, -0.5, -1.0, -0.5):
         self.construct_frame(phase)
     FileIO.SaveStructure(struct=self.struct, fil=filename)
예제 #3
0
    def write_tls_pdb_file(self, chain, cpartition):
        """Write out a PDB file with the TLS predicted anisotropic ADPs for
        this segmentation.
        """
        basename = "%s_CHAIN%s_NTLS%d_UTLS" % (self.struct_id, chain.chain_id,
                                               cpartition.num_tls_segments())
        pdb_path = "%s.pdb" % (basename)

        ## temporarily set the atom temp_factor and U tensor to the Utls value
        old_temp_factor = {}
        old_U = {}
        for tls in cpartition.iter_tls_segments():
            for atm, Utls in tls.tls_group.iter_atm_Utls():
                old_temp_factor[atm] = atm.temp_factor
                old_U[atm] = atm.U

                atm.temp_factor = Constants.U2B * (numpy.trace(Utls) / 3.0)
                atm.U = Utls

        FileIO.SaveStructure(fil=pdb_path, struct=self.struct)

        ## restore atom temp_factor and U
        for atm, temp_factor in old_temp_factor.iteritems():
            atm.temp_factor = temp_factor
            atm.U = old_U[atm]
예제 #4
0
 def construct_animation(self, filename, raw_r3d_filename):
     """Save the animated structure to the given filename.
     """
     ##self.phase_assignment()
     raw_r3d_file = open(raw_r3d_filename, "w")
     for phase in (0.5, 1.0, 0.5, 0.0, -0.5, -1.0, -0.5):
         self.construct_frame(phase, raw_r3d_file)
     FileIO.SaveStructure(struct = self.struct, fil = filename)
     raw_r3d_file.close()
예제 #5
0
def refmac_pure_tls_prep(xyzin, tlsin_list, wilson, xyzout, tlsout):
    """Use TLS model (without Uiso) for each atom. Output xyzout with the 
    B-factors reset to either the Bmean or the Wilson B value.
    """
    ## 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.TLSFileFormatPureTLSOUT())
    tls_file_format = TLS.TLSFileFormatPureTLSOUT()
    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:

        Bmean = 0.0
        sum_Biso = 0.0
        num_atms = 0
        for atm, Utls in tls_group.iter_atm_Utls():
            num_atms += 1
            sum_Biso += atm.temp_factor

## EAM Aug 2011: num_atms goes to zero if there are atom selection problems.
## The output files will contain empty groups, but at least it doesn't crash.
        if num_atms > 0:
            Bmean = sum_Biso / num_atms

        ## reset the TLS tensor values in the TLSDesc object so they can be
        ## saved
        tls_group.tls_desc.set_tls_group(tls_group)

        ## reset atm.temp_factor to the Bmean for this TLS group
        for atm, Utls in tls_group.iter_atm_Utls():
            atm.temp_factor = Bmean
            atm.temp_factor = wilson

    ## save the new xyzout file with temp_factors reset to "wilson" value
    FileIO.SaveStructure(fil=xyzout, struct=struct)

    ## save the REFMAC-format file, but without T, L, S, and ORIGIN values
    tls_file.save(open(tlsout, "w"))
예제 #6
0
    def write_cwd(self):
        """Write out all the files in the report.
        """
        ## write a local copy of the Structure
        FileIO.SaveStructure(fil=self.struct_path, struct=self.struct)

        ## generate small .png images so  they can be placed in the
        ## TLS group tables to identify the TLS group tabular data
        ## with the generated visualization
        self.init_colors()

        ## a report page comparing the tls group segments of all
        ## chains against each other
        self.write_multi_chain_alignment()

        ## write out all TLSGraph reports
        for chain in self.tlsmd_analysis.iter_chains():
            self.write_tls_chain_optimization(chain)

        self.write_refinement_prep()

        ## write out index page
        self.write_index()
예제 #7
0
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)
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
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"))
예제 #11
0
    print "AUTHORS"
    print "  Jay Painter <*****@*****.**>"


if __name__ == '__main__':
    if "-h" in sys.argv or "--help" in sys.argv:
        usage()
        sys.exit(0)

    cif = "-"
    pdb = "-"

    if len(sys.argv) == 1:
        pass
    elif len(sys.argv) == 2:
        cif = sys.argv[1]
    elif len(sys.argv) == 3:
        cif = sys.argv[1]
        pdb = sys.argv[2]
    else:
        usage()
        sys.exit(1)

    if cif == "-":
        cif = sys.stdin
    if pdb == "-":
        pdb = sys.stdout

    struct = FileIO.LoadStructure(file=cif, format="CIF")
    FileIO.SaveStructure(file=pdb, structure=struct, format="PDB")
예제 #12
0
    print "AUTHORS"
    print "  Jay Painter <*****@*****.**>"


if __name__ == '__main__':
    if "-h" in sys.argv or "--help" in sys.argv:
        usage()
        sys.exit(0)

    infil = "-"
    outfil = "-"

    if len(sys.argv) == 1:
        pass
    elif len(sys.argv) == 2:
        infil = sys.argv[1]
    elif len(sys.argv) == 3:
        infil = sys.argv[1]
        outfil = sys.argv[2]
    else:
        usage()
        sys.exit(1)

    if infil == "-":
        infil = sys.stdin
    if outfil == "-":
        outfil = sys.stdout

    struct = FileIO.LoadStructure(file=infil, format="PDB")
    FileIO.SaveStructure(file=outfil, structure=struct, format="CIF")