示例#1
0
def TLSMD_Main(struct_file_path  = None,
               sel_chain_ids     = None,
               html_report_dir   = None):

    console.cpu_time_stdoutln("->Starting TLSMD analysis: %s" % time.clock())

    ## create the analysis processor and load the structure, select chains
    analysis = TLSMDAnalysis(
        struct_file_path    = struct_file_path,
        sel_chain_ids       = sel_chain_ids,
        struct2_file_path   = conf.globalconf.target_struct_path,
        struct2_chain_id    = conf.globalconf.target_struct_chain_id)
    console.cpu_time_stdoutln("->LoadStructure: %s" % time.clock())

    IndependentTLSSegmentOptimization(analysis)
    console.cpu_time_stdoutln("->IndependentTLSSegmentOptimization: %s" % (
        time.clock()))

    RecombineIndependentTLSSegments(analysis)
    console.cpu_time_stdoutln("->RecombineIndependentTLSSegments: %s" % (
        time.clock()))

    if analysis.struct2_file_path is not None and \
       analysis.struct2_chain_id is not None:
        console.stdoutln("SUPERIMPOSING HOMOLOGOUS STRUCTURE")
        SuperimposeHomologousStructure(analysis)

    if html_report_dir is not None and analysis.num_chains() > 0:
        FitConstrainedTLSModel(analysis)

        ## generate summary page. Allows the user to see some information
        ## before the analysis is fully complete
        console.stdoutln("GENERATING SUMMARY PAGE")
        summary = html.HTMLSummaryReport(analysis)
        summary.write_summary(html_report_dir)
        console.cpu_time_stdoutln("->HTMLSummaryReport: %s" % time.clock())

        if not conf.globalconf.skip_html:
            ## generate in-depth HTML report pages
            console.stdoutln("GENERATING ANALYSIS/REPORT HTML PAGES")
            report = html.HTMLReport(analysis)
            report.write(html_report_dir)

        ## TODO: Figure out a way to gzip all TXT files once TLSMD is done
        ## with them. 2010-09-24
        #import fnmatch
        #import gzip
        #abs_report_path = "%s/%s/%s" % (
        #    conf.TLSMD_WORK_DIR, conf.globalconf.job_id, html_report_dir)
        #console.stdoutln("GZIP: Attempting to gzip all TXT files in: %s" % abs_report_path)
        #for path, dirs, files in os.walk(abs_report_path):
        #    console.stdoutln("GZIP: report_dir = %s" % abs_report_path)
        #    for f in files:
        #        if fnmatch.fnmatch(f, '*.txt'):
        #            console.stdoutln("GZIP: found a TXT file: %s" % f)
        #            ## If we find a TXT file, gzip it
        #            f_in = open('%s/%s' % (abs_report_path, f), 'rb')
        #            f_out = gzip.open('%s/%s.gz' % (abs_report_path, f), 'wb')
        #            f_out.writelines(f_in)
        #            f_out.close()
        #            f_in.close()
        #            os.remove(f)

    console.cpu_time_stdoutln("->TLSMD::Total_time: %s" % time.clock())
示例#2
0
    def run_minimization(self):
        """Run the HCSSSP minimization on the self.V, self.E graph, resulting
        in the creation of the self.D, self.P, and self.T arrays which
        contain 
        """
        chain = self.chain
        chain_id = self.chain.chain_id
        min_subsegment_len = self.min_subsegment_len
        num_vertex = len(chain) + 1

        ## choose the TLS Model to fit for the chain
        fit_method = self.get_fit_method(chain)

        ## build the vertex labels to reflect the protein structure
        ## the graph spans
        vertices = []
        for i in xrange(num_vertex):
            ## add the vertex label for i at Vi
            if i == 0 :
                vertex_label = "N-TERM"
            elif i == num_vertex - 1:
                vertex_label = "C-TERM"
            else:
                vertex_label = "%s{%s:%s}" % (
                    chain_id, chain[i-1].fragment_id, chain[i].fragment_id)
            vertex_label = "V%d[%s]" % (i, vertex_label)
            vertices.append(vertex_label)

        ## fit chain segments with TLS model and build residual graph to 
        ## minimize
        total_num_subsegments = calc_num_subsegments(chain.count_fragments(), 
                                                     min_subsegment_len)
        num_subsegments = 0
        pcomplete = 0
        pcomplete_old = 0
        edges = []
        console.stdoutln("=" * 80)
        console.stdoutln("BUILDING RESIDUAL GRAPH TO MINIMIZE: chain_id=%s" % chain_id)
        for frag_id1, frag_id2, i, j in iter_chain_subsegment_descs(chain, min_subsegment_len):
            tlsdict = fit_method(frag_id1, frag_id2)

            num_subsegments += 1
            pcomplete = round(100.0 * num_subsegments / total_num_subsegments)
            if pcomplete != pcomplete_old:
                console.stdoutln("(%10d/%10d) %2d%% Complete" % (
                    num_subsegments, total_num_subsegments, pcomplete))
                pcomplete_old = pcomplete

            if tlsdict == None:
                console.stderrln("no TLS group %s{%s..%s}" % (
                    chain_id, frag_id1, frag_id2))
                raise SystemExit

            if tlsdict.has_key("error") is True:
                continue

            if not tlsdict.has_key("residual"):
                console.stderrln("no residual! %s{%s..%s}" % (
                    chain_id, frag_id1, frag_id2))
                raise SystemExit

            residual = tlsdict["residual"]
            num_atoms = tlsdict["num_atoms"]
            num_residues = tlsdict["num_residues"]

            if residual < 0.0:
                console.stdoutln("ERROR: Residual is negative!")
                continue

            msd = residual / num_residues
            rmsd = math.sqrt(msd)
            rmsd_b = rmsd * Constants.U2B
            chi2 = msd * num_atoms

            ## XXX: Why is this set to 40? 2010-08-20
            if num_atoms < 40:
                continue

            cost = residual

            frag_range = (frag_id1, frag_id2)
            edge = (i, j, cost, frag_range, tlsdict)
            edges.append(edge)

        console.cpu_time_stdoutln("->ResidualGraphMinimized chain_id=%s: %s" % (
            chain_id, time.clock()))

        ## perform the minimization
        if len(edges) > 0:
            console.stdoutln("HCSSSP Minimizing: chain_id=%s" % (chain_id))

            D, P, T = self.HCSSSP_minimize(vertices, edges, self.nparts)

            self.minimized = True
            self.V = vertices
            self.D = D
            self.P = P
            self.T = T
        else:
            console.stdoutln("HCSSSP Minimizing: Unable to minimize chain_id=%s" % (
                chain_id))
            self.minimized = False
            raise SystemExit

        ## free memory taken up from edges
        edges = None
        gc.collect()
示例#3
0
                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()

    console.cpu_time_stdoutln("->FitConstrainedTLSModel: %s" % time.clock())
    console.endln()


def SuperimposeHomologousStructure(analysis):
    """
    """
    import structcmp

    target_struct = FileIO.LoadStructure(fil = analysis.struct2_file_path)
    target_chain = target_struct.get_chain(analysis.struct2_chain_id)

    if target_chain is None:
        console.stderrln(
            "UNABLE TO LOAD TARGET STRUCTURE/CHAIN: %s:%s" % (
            target_struct, target_chain))