def find_sec_str(self, pdb_hierarchy):
   if self.params.secondary_structure.protein.search_method == "ksdssp":
     pdb_str = pdb_hierarchy.as_pdb_string()
     print >> self.log, "  running ksdssp..."
     (records, stderr) = run_ksdssp_direct(pdb_str)
     return iotbx.pdb.secondary_structure.annotation.from_records(
         records=records,
         log=self.log)
   elif self.params.secondary_structure.protein.search_method == "mmtbx_dssp":
     from mmtbx.secondary_structure import dssp
     print >> self.log, "  running mmtbx.dssp..."
     return dssp.dssp(
       pdb_hierarchy=pdb_hierarchy,
       pdb_atoms=self.pdb_atoms,
       out=null_out()).get_annotation()
   elif self.params.secondary_structure.protein.search_method == "from_ca":
     from mmtbx.secondary_structure import find_ss_from_ca
     print >> self.log, "  running find_ss_from_ca..."
     fss = find_ss_from_ca.find_secondary_structure(
         hierarchy=pdb_hierarchy,
         out=null_out())
     return fss.get_annotation()
   elif self.params.secondary_structure.protein.search_method == "cablam":
     from mmtbx.validation import cablam
     print >> self.log, "  running cablam..."
     cablam_results = cablam.cablamalyze(
         pdb_hierarchy = pdb_hierarchy,
         outliers_only=False,
         out=null_out(),
         quiet=False)
     return cablam_results.as_secondary_structure()
   else:
     print >> self.log, "  WARNING: Unknown search method for SS. No SS found."
     return iotbx.pdb.secondary_structure.annotation.from_records()
Example #2
0
 def find_sec_str(self, pdb_hierarchy):
     if (pdb_hierarchy.atoms_size() > 99999
             and self.params.secondary_structure.protein.search_method
             == "ksdssp"):
         print("Warning!!! ksdssp method is not applicable for" + \
             "structures with more than 99999 atoms!\nSwitching to from_ca.", file=self.log)
         self.params.secondary_structure.protein.search_method = "from_ca"
     if self.params.secondary_structure.protein.search_method == "ksdssp":
         pdb_str = pdb_hierarchy.as_pdb_string()
         print("  running ksdssp...", file=self.log)
         (records, stderr) = run_ksdssp_direct(pdb_str)
         return iotbx.pdb.secondary_structure.annotation.from_records(
             records=records, log=self.log)
     elif self.params.secondary_structure.protein.search_method == "mmtbx_dssp":
         from mmtbx.secondary_structure import dssp
         print("  running mmtbx.dssp...", file=self.log)
         return dssp.dssp(pdb_hierarchy=pdb_hierarchy,
                          pdb_atoms=self.pdb_atoms,
                          out=null_out()).get_annotation()
     elif self.params.secondary_structure.protein.search_method == "from_ca":
         from mmtbx.secondary_structure import find_ss_from_ca
         from_ca_args = []
         ca_label = "liberal"
         if self.params.secondary_structure.from_ca_conservative:
             from_ca_args = [
                 "alpha.rise_tolerance=0.13",
                 "beta.rise_tolerance=0.3",
                 "alpha.dot_min=0.94",
             ]
             ca_label = "conservative"
         print("  running find_ss_from_ca %s..." % ca_label, file=self.log)
         fss = find_ss_from_ca.find_secondary_structure(
             hierarchy=pdb_hierarchy,
             args = from_ca_args,
             ss_by_chain=self.params.secondary_structure.ss_by_chain,
             max_rmsd=self.params.secondary_structure.max_rmsd,
             use_representative_chains=\
              self.params.secondary_structure.use_representative_chains,
             max_representative_chains=\
              self.params.secondary_structure.max_representative_chains,
             out=null_out())
         return fss.get_annotation()
     elif self.params.secondary_structure.protein.search_method == "cablam":
         from mmtbx.validation import cablam
         print("  running cablam...", file=self.log)
         cablam_results = cablam.cablamalyze(pdb_hierarchy=pdb_hierarchy,
                                             outliers_only=False,
                                             out=null_out(),
                                             quiet=False)
         return cablam_results.as_secondary_structure()
     else:
         print("  WARNING: Unknown search method for SS. No SS found.",
               file=self.log)
         return iotbx.pdb.secondary_structure.annotation.from_records()
Example #3
0
 def find_sec_str(self, pdb_hierarchy):
     if (pdb_hierarchy.atoms_size() > 99999
             and self.params.secondary_structure.protein.search_method
             == "ksdssp"):
         print >> self.log, "Warning!!! ksdssp method is not applicable for" + \
             "structures with more than 99999 atoms!\nSwitching to from_ca."
         self.params.secondary_structure.protein.search_method = "from_ca"
     if self.params.secondary_structure.protein.search_method == "ksdssp":
         pdb_str = pdb_hierarchy.as_pdb_string()
         print >> self.log, "  running ksdssp..."
         (records, stderr) = run_ksdssp_direct(pdb_str)
         return iotbx.pdb.secondary_structure.annotation.from_records(
             records=records, log=self.log)
     elif self.params.secondary_structure.protein.search_method == "mmtbx_dssp":
         from mmtbx.secondary_structure import dssp
         print >> self.log, "  running mmtbx.dssp..."
         return dssp.dssp(pdb_hierarchy=pdb_hierarchy,
                          pdb_atoms=self.pdb_atoms,
                          out=null_out()).get_annotation()
     elif self.params.secondary_structure.protein.search_method == "from_ca":
         from mmtbx.secondary_structure import find_ss_from_ca
         print >> self.log, "  running find_ss_from_ca..."
         fss = find_ss_from_ca.find_secondary_structure(
             hierarchy=pdb_hierarchy,
             ss_by_chain=self.params.secondary_structure.ss_by_chain,
             max_rmsd=self.params.secondary_structure.max_rmsd,
             use_representative_chains=\
              self.params.secondary_structure.use_representative_chains,
             max_representative_chains=\
              self.params.secondary_structure.max_representative_chains,
             out=null_out())
         return fss.get_annotation()
     elif self.params.secondary_structure.protein.search_method == "cablam":
         from mmtbx.validation import cablam
         print >> self.log, "  running cablam..."
         cablam_results = cablam.cablamalyze(pdb_hierarchy=pdb_hierarchy,
                                             outliers_only=False,
                                             out=null_out(),
                                             quiet=False)
         return cablam_results.as_secondary_structure()
     else:
         print >> self.log, "  WARNING: Unknown search method for SS. No SS found."
         return iotbx.pdb.secondary_structure.annotation.from_records()
Example #4
0
def stats(model, prefix):
    # Get rid of H, multi-model, no-protein and single-atom residue models
    if (model.percent_of_single_atom_residues() > 20):
        return None
    sel = model.selection(string="protein")
    if (sel.count(True) == 0):
        return None
    ssr = "protein and not (element H or element D or resname UNX or resname UNK or resname UNL)"
    sel = model.selection(string=ssr)
    model = model.select(sel)
    if (len(model.get_hierarchy().models()) > 1):
        return None
    # Add H; this looses CRYST1 !
    rr = run_reduce_with_timeout(
        stdin_lines=model.get_hierarchy().as_pdb_string().splitlines(),
        file_name=None,
        parameters="-oh -his -flip -keep -allalt -pen9999 -",
        override_auto_timeout_with=None)
    # Create model; this is a single-model pure protein with new H added
    pdb_inp = iotbx.pdb.input(source_info=None, lines=rr.stdout_lines)
    model = mmtbx.model.manager(model_input=None,
                                build_grm=True,
                                pdb_hierarchy=pdb_inp.construct_hierarchy(),
                                process_input=True,
                                log=null_out())
    box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
        sites_cart=model.get_sites_cart(), buffer_layer=5)
    model.set_sites_cart(box.sites_cart)
    model._crystal_symmetry = box.crystal_symmetry()
    # Get SS annotations
    SS = find_ss_from_ca.find_secondary_structure(
        hierarchy=model.get_hierarchy(),
        #ss_by_chain = False, # enabling will make it slow.
        out=null_out())
    # Convert SS annotations into bool selections
    alpha_sel = SS.annotation.overall_helix_selection().strip()
    beta_sel = SS.annotation.overall_sheet_selection().strip()
    if (len(alpha_sel) == 0 or alpha_sel == "()"): alpha_sel = None
    if (len(beta_sel) == 0 or beta_sel == "()"): beta_sel = None
    if ([alpha_sel, beta_sel].count(None) == 0):
        alpha_sel = model.selection(string="%s" % alpha_sel)
        beta_sel = model.selection(string="%s" % beta_sel)
        loop_sel = ~(alpha_sel | beta_sel)
    elif (alpha_sel is not None):
        alpha_sel = model.selection(string="%s" % alpha_sel)
        loop_sel = ~alpha_sel
    elif (beta_sel is not None):
        beta_sel = model.selection(string="%s" % beta_sel)
        loop_sel = ~beta_sel
    else:
        loop_sel = model.selection(string="all")
    # Get individual stats
    def get_selected(sel):
        result = None
        if (type(sel) == str and sel == "all"):
            return find(model=model, a_DHA_cutoff=90).get_params_as_arrays()
        elif (sel is not None and sel.count(True) > 0):
            result = find(model=model.select(sel),
                          a_DHA_cutoff=90).get_params_as_arrays()
        return result

    result_dict = {}
    result_dict["all"] = get_selected(sel="all")
    result_dict["alpha"] = get_selected(sel=alpha_sel)
    result_dict["beta"] = get_selected(sel=beta_sel)
    result_dict["loop"] = get_selected(sel=loop_sel)
    # Load histograms for reference high-resolution d_HA and a_DHA
    pkl_fn = libtbx.env.find_in_repositories(
        relative_path="mmtbx") + "/nci/d_HA_and_a_DHA_high_res.pkl"
    assert os.path.isfile(pkl_fn)
    ref = easy_pickle.load(pkl_fn)
    #
    import matplotlib as mpl
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    fig = plt.figure(figsize=(10, 10))
    kwargs = dict(histtype='bar', bins=20, range=[1.6, 3.0], alpha=.8)
    for j, it in enumerate([["alpha", 1], ["beta", 3], ["loop", 5]]):
        key, i = it
        ax = plt.subplot(int("32%d" % i))
        if (j in [0, 1]):
            ax.tick_params(bottom=False)
            ax.set_xticklabels([])
        ax.tick_params(axis="x", labelsize=12)
        ax.tick_params(axis="y", labelsize=12, left=False, pad=-2)
        ax.text(0.98,
                0.92,
                key,
                size=12,
                horizontalalignment='right',
                transform=ax.transAxes)
        HB = result_dict[key]
        if HB is None: continue
        w1 = np.ones_like(HB.d_HA) / HB.d_HA.size()
        ax.hist(HB.d_HA, color="orangered", weights=w1, rwidth=0.3, **kwargs)
        #
        start, end1, end2 = 0, max(ref.distances[key].vals), \
          round(max(ref.distances[key].vals),2)
        plt.yticks([0.01, end1], ["0", end2],
                   visible=True,
                   rotation="horizontal")
        #
        if (j == 0): ax.set_title("Distance", size=15)
        bins = list(flex.double(ref.distances[key].bins))
        ax.bar(bins, ref.distances[key].vals, alpha=.3, width=0.07)
    #
    kwargs = dict(histtype='bar', bins=20, range=[90, 180], alpha=.8)
    for j, it in enumerate([["alpha", 2], ["beta", 4], ["loop", 6]]):
        key, i = it
        ax = plt.subplot(int("32%d" % i))

        if (j in [0, 1]):
            ax.tick_params(bottom=False)
            ax.set_xticklabels([])
        ax.tick_params(axis="x", labelsize=12)
        ax.tick_params(axis="y", labelsize=12, left=False, pad=-2)
        ax.text(0.98,
                0.92,
                key,
                size=12,
                horizontalalignment='right',
                transform=ax.transAxes)

        ax.text(0.98,
                0.92,
                key,
                size=12,
                horizontalalignment='right',
                transform=ax.transAxes)
        #if(j in [0,1]): ax.plot_params(bottom=False)
        HB = result_dict[key]
        if HB is None: continue
        w1 = np.ones_like(HB.a_DHA) / HB.a_DHA.size()
        ax.hist(HB.a_DHA, color="orangered", weights=w1, rwidth=0.3, **kwargs)
        #
        start, end1, end2 = 0, max(ref.angles[key].vals), \
          round(max(ref.angles[key].vals),2)
        plt.yticks([0.01, end1], ["0", end2],
                   visible=True,
                   rotation="horizontal")
        #
        if (j == 0): ax.set_title("Angle", size=15)
        ax.bar(ref.angles[key].bins, ref.angles[key].vals, width=4.5, alpha=.3)
    plt.subplots_adjust(wspace=0.12, hspace=0.025)
    fig.savefig("%s.png" % prefix, dpi=1000)