示例#1
0
def exclude_h_on_SS(model):
    rm = model.get_restraints_manager()
    bond_proxies_simple, asu = rm.geometry.get_all_bond_proxies(
        sites_cart=model.get_sites_cart())
    els = model.get_hierarchy().atoms().extract_element()
    ss_i_seqs = []
    all_proxies = [p for p in bond_proxies_simple]
    for proxy in asu:
        all_proxies.append(proxy)
    for proxy in all_proxies:
        if (isinstance(proxy, ext.bond_simple_proxy)): i, j = proxy.i_seqs
        elif (isinstance(proxy, ext.bond_asu_proxy)):
            i, j = proxy.i_seq, proxy.j_seq
        else:
            assert 0  # never goes here
        if ([els[i], els[j]
             ].count("S") == 2):  # XXX may be coordinated if metal edits used
            ss_i_seqs.extend([i, j])
    sel_remove = flex.size_t()
    for proxy in all_proxies:
        if (isinstance(proxy, ext.bond_simple_proxy)): i, j = proxy.i_seqs
        elif (isinstance(proxy, ext.bond_asu_proxy)):
            i, j = proxy.i_seq, proxy.j_seq
        else:
            assert 0  # never goes here
        if (els[i] in ["H", "D"] and j in ss_i_seqs): sel_remove.append(i)
        if (els[j] in ["H", "D"] and i in ss_i_seqs): sel_remove.append(j)
    return model.select(~flex.bool(model.size(), sel_remove))
示例#2
0
def exclude_h_on_coordinated_S(model): # XXX if edits used it should be like in exclude_h_on_SS
  rm = model.get_restraints_manager().geometry
  els = model.get_hierarchy().atoms().extract_element()
  # Find possibly coordinated S
  exclusion_list = ["H","D","T","S","O","P","N","C","SE"]
  sel_s = []
  for proxy in rm.pair_proxies().nonbonded_proxies.simple:
    i,j = proxy.i_seqs
    if(els[i] == "S" and not els[j] in exclusion_list): sel_s.append(i)
    if(els[j] == "S" and not els[i] in exclusion_list): sel_s.append(j)
  # Find H attached to possibly coordinated S
  bond_proxies_simple, asu = rm.get_all_bond_proxies(
    sites_cart = model.get_sites_cart())
  sel_remove = flex.size_t()
  for proxy in bond_proxies_simple:
    i,j = proxy.i_seqs
    if(els[i] in ["H","D"] and j in sel_s): sel_remove.append(i)
    if(els[j] in ["H","D"] and i in sel_s): sel_remove.append(j)
  return model.select(~flex.bool(model.size(), sel_remove))
示例#3
0
def stats(model, prefix, no_ticks=True):
    # 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()
    #
    N = 10
    SS = get_ss_selections(hierarchy=model.get_hierarchy())
    HB_all = find(
        model=model.select(flex.bool(model.size(), True)),
        a_DHA_cutoff=90).get_params_as_arrays(replace_with_empty_threshold=N)
    HB_alpha = find(
        model=model.select(SS.both.h_sel),
        a_DHA_cutoff=90).get_params_as_arrays(replace_with_empty_threshold=N)
    HB_beta = find(
        model=model.select(SS.both.s_sel),
        a_DHA_cutoff=90).get_params_as_arrays(replace_with_empty_threshold=N)
    print(HB_all.d_HA.size())
    result_dict = {}
    result_dict["all"] = HB_all
    result_dict["alpha"] = HB_alpha
    result_dict["beta"] = HB_beta
    #  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], ["all", 5]]):
        key, i = it
        ax = plt.subplot(int("32%d" % i))
        if (no_ticks):
            #ax.set_xticks([])
            ax.set_yticks([])
        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)
        if (not no_ticks):
            plt.yticks([0.01, end1], ["0", end2],
                       visible=True,
                       rotation="horizontal")

        if (key == "alpha"): plt.ylim(0, end2 + 0.02)
        elif (key == "beta"): plt.ylim(0, end2 + 0.02)
        elif (key == "all"): plt.ylim(0, end2 + 0.02)
        else: assert 0
        #
        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], ["all", 6]]):
        key, i = it
        ax = plt.subplot(int("32%d" % i))
        if (j in [0, 1]):
            ax.tick_params(bottom=False)
            ax.set_xticklabels([])
        if (no_ticks):
            #ax.set_xticks([])
            ax.set_yticks([])
        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)
        if (not no_ticks):
            plt.yticks([0.01, end1], ["0", end2],
                       visible=True,
                       rotation="horizontal")

        if (key == "alpha"): plt.ylim(0, end2 + 0.02)
        elif (key == "beta"): plt.ylim(0, end2 + 0.02)
        elif (key == "all"): plt.ylim(0, end2 + 0.02)
        else: assert 0
        #
        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)
    if (no_ticks):
        plt.subplots_adjust(wspace=0.025, hspace=0.025)
    #fig.savefig("%s.png"%prefix, dpi=1000)
    fig.savefig("%s.pdf" % prefix)