def ligand_neighbor_selection(lig, radius, pose, include_ligand=False):
    rad = float(radius)
    not_ligand = NotResidueSelector()
    not_ligand.set_residue_selector(lig)

    lig_distant_neighbors = InterGroupInterfaceByVectorSelector()
    lig_distant_neighbors.group1_selector(lig)
    lig_distant_neighbors.group2_selector(not_ligand)
    lig_distant_neighbors.cb_dist_cut(2.0 * rad)
    lig_distant_neighbors.nearby_atom_cut(rad)

    lig_contacts = pr.rosetta.core.select.residue_selector.CloseContactResidueSelector(
    )
    lig_contacts.central_residue_group_selector(lig)
    lig_contacts.threshold(rad)

    lig_neighbors = OrResidueSelector()
    lig_neighbors.add_residue_selector(lig_distant_neighbors)
    lig_neighbors.add_residue_selector(lig_contacts)

    if include_ligand:
        selection = AndResidueSelector()
        selection.add_residue_selector(not_ligand)
    else:
        selection = OrResidueSelector()
        selection.add_residue_selector(lig)

    selection.add_residue_selector(lig_neighbors)
    return get_residues_from_subset(selection.apply(pose))
def selector_to_vector(residue_selector, pose):
    residue_vector = []
    resids = get_residues_from_subset(residue_selector.apply(pose))
    for res_int in resids:
        res = pose.pdb_info().pose2pdb(res_int).split()
        residue_vector.append(''.join(res))
    return residue_vector
def selector_to_list(pose, selector):
    """
    Produces a list of residues from a pose that are identified 
    by a given selector
    """
    # Make selection
    selection = selector.apply(pose)

    # Convert to a vector of selected residues
    selected_vector = get_residues_from_subset(selection)

    # Convert vector to a list
    selected_list = list(selected_vector)

    return selected_list
Example #4
0
def _pose_to_residue_chain_tuples(pose, residue_selector, logger=_logger):
    """
    Given a Pose object and ResidueSelector object, return a tuple of lists containing
    PDB residue numbers and chain IDs for the selection.
    """

    pdb_numbering = list(zip(get_res_num_from_pdb_info(pose), get_chains_from_pdb_info(pose)))
    residues_from_subset = list(get_residues_from_subset(residue_selector.apply(pose)))
    residue_chain_tuples = [pdb_numbering[i - 1] for i in residues_from_subset]
    
    if len(residue_chain_tuples) == 0:
        logger.info("ResidueSelector {0} is empty and did not select any residues!".format(residue_selector))
        return [], []
    else:
        return map(list, zip(*residue_chain_tuples))
def apply_dihedral_constraint(atom_str_list, residue_index, pose, \
            cst_degrees='0,180', cst_stdev='5.0'):
    atoms = []  #pr.rosetta.utility.vector1_core_id_AtomID()
    index = get_residues_from_subset(residue_index.apply(pose))
    print(index)
    for atomstr in atom_str_list:
        new_atom = pr.rosetta.core.id.NamedAtomID(atomstr, int(index.back()))
        atoms.append(
            pr.rosetta.core.pose.named_atom_id_to_atom_id(new_atom, pose))
    ambiguous = pr.rosetta.core.scoring.constraints.AmbiguousConstraint()
    for degree_skip in [float(x) for x in cst_degrees.split(',')]:
        dihedral_func = pr.rosetta.core.scoring.func.CircularHarmonicFunc( \
                np.radians(degree_skip), np.radians(float(cst_stdev)))
        dihedral_cst = pr.rosetta.core.scoring.constraints.DihedralConstraint(\
                atoms[0], atoms[1], atoms[2], atoms[3], dihedral_func)
        ambiguous.add_individual_constraint(dihedral_cst)
    pose.add_constraint(ambiguous)
    # Print to a configuration file the initial conditions of the simulation:
    #  Line 1 : Number of docks, decoys and steps
    #  Line 2 : Initial total score of the pose
    #  Line 3 : Initial conformation file name
    with open("init.conf", "w") as conf:
        conf.write("%d %d %d\n" % (len(dg.points), args.n_decoys, args.n_steps))
        conf.write("%f\n" % (score_function(pose)))
        conf.write("%s\n" % (args.input_file))
    
    # Orient the grid. In this case, the grid's X [1, 0, 0] axis should match
    # the orientation of the length of the ligand (this is the DE vector, where
    # D and E are the alpha carbon atoms of the first and last residues on the
    # ligand), therefore locking 2 of the 3 rotation degrees of freedom of the
    # grid. The third rotation degree of freedom will be left at the original
    # state (matching the natural axis). 
    lig_res = get_residues_from_subset(ChainSelector("C").apply(pose))
    D = np.array(pose.residue(list(lig_res)[0]).atom(2).xyz())
    E = np.array((pose.residue(list(lig_res)[len(lig_res) - 1]).atom(2).xyz()))
    de_normal = (E - D) / np.linalg.norm(D - E)
    dg.orient(np.array([1, 0, 0]), de_normal)

    # Ex. Print the current docking grid starting points in PDB format.
    dg.as_pdb("grid.pdb")

    # Looping over the number of points in the docking grid, move the Chain B   
    # of the target protein to the new positions and run the simultaneous
    # position and design optimization protocol on each one, asynchronously.
    p = Pose()
    for point_id in range(len(dg.points)):
        # Create a copy of the original position of the Chain B of the target
        # protien.
def selector_to_list(pose, selector):
    """
    Produces a list of residues from a pose identified by a given selector
    """

    return list(get_residues_from_subset(selector.apply(pose)))
Example #8
0
def main(args):

    if args.ligand_type == 'ligand':
        init_args = ' '.join(['-extra_res_fa', args.ligand_name])
        lig_name = args.ligand_name.split('/')[-1].strip('.params')
    else:
        init_args = ''

    pr.init(init_args)
    sf = pr.get_fa_scorefxn()
    sf.add_weights_from_file('ref2015')

    pose = pr.pose_from_pdb(args.input_pdb)
    sf(pose)

    print_notice("Scaffold protein Loaded Successfully!")
    print_notice("Scaffold protein has" + str(pose.total_residue()) +
                 "residues.")

    if args.symmetric_file:
        sfsm = SetupForSymmetryMover(args.symmetric_file)
        sfsm.apply(pose)

    #Importing list of residues if the ligand is a protein
    if args.ligand_type == 'protein':
        ligres = ResidueIndexSelector(args.residue_set)
    #Targeting the ligand if the ligand isn't protein
    elif args.ligand_type == 'ligand':
        ligres = ResidueNameSelector()
        ligres.set_residue_name3(lig_name)

    print_notice("Ligand found at resnum: " + \
            str(get_residues_from_subset(ligres.apply(pose))) )

    #Setting the proteins not in the ligand
    not_ligand = NotResidueSelector()
    not_ligand.set_residue_selector(ligres)

    #Setting the protein considered part of the ligand
    ligand_distant_contacts = InterGroupInterfaceByVectorSelector()
    ligand_distant_contacts.group1_selector(ligres)
    ligand_distant_contacts.group2_selector(not_ligand)
    ligand_distant_contacts.cb_dist_cut(2.5 * float(args.radius))
    ligand_distant_contacts.nearby_atom_cut(float(args.radius))

    #Test set: ClosecontactResidueSelector
    close_contacts = pr.rosetta.core.select.residue_selector.CloseContactResidueSelector(
    )
    close_contacts.central_residue_group_selector(ligres)
    close_contacts.threshold(float(args.radius))

    all_contacts = OrResidueSelector()
    all_contacts.add_residue_selector(close_contacts)
    all_contacts.add_residue_selector(ligand_distant_contacts)

    non_lig_residues = AndResidueSelector()
    non_lig_residues.add_residue_selector(all_contacts)
    non_lig_residues.add_residue_selector(not_ligand)

    #Collecting the residues from the subset
    neighbor_residues = get_residues_from_subset(non_lig_residues.apply(pose))
    pdb_residues = []
    for residue in neighbor_residues:
        print(pose.pdb_info().pose2pdb(residue))
        resid = pose.pdb_info().pose2pdb(residue).split()
        pdb_residues.append(''.join(resid))

    print_notice("Ligand found, neighbor residues are: " +
                 ', '.join([x for x in pdb_residues]))
    print_notice("Ligand found, total neighbor residues is " +
                 str(len(pdb_residues)))

    #Removing residues in the REMARKS section
    remove_set = []
    f = open(args.input_pdb, 'r')
    for line in f.readlines():
        if 'REMARK' in line:
            items = [x for x in line.split(' ') if x != '']
            residue_set = [int(items[6]), int(items[11])]
            for resi in residue_set:
                if resi not in remove_set:
                    remove_set.append(resi)

    residue_final_set = []
    for resi in pdb_residues:
        idx = int(resi[0:-1])
        if idx not in remove_set:
            residue_final_set.append(resi)
    #Final list for the designable residues
    residue_final_set.append('0')
    print_notice("Neighbor residues cleaned \n \n Residues are: " +\
            ', '.join([x for x in residue_final_set]))

    if args.out_file:
        out_name = args.out_file
    else:
        out_name = args.input_pdb.strip('.pdb') + '_lig.pos'

    f = open(out_name, "w")
    for x in residue_final_set:
        f.write(x + '\n')
    f.close
    print("emd182::Wrote ligand position residues of pdb file " +
          args.input_pdb + " to filename: " + out_name)
Example #9
0
def selector_to_vector(residue_selector, pose):
    rosetta_vector = pr.rosetta.utility.vector1_unsigned_long()
    for res_int in [int(x) for x in \
                get_residues_from_subset(residue_selector.apply(pose)) ]:
        rosetta_vector.append(res_int)
    return rosetta_vector
Example #10
0
def residue_pairs(
    self,
    primary_residue_selector=TrueResidueSelector(),
    secondary_residue_selector=TrueResidueSelector(),
    neighborhood_distance_maximum=None,
    sequence_distance_minimum=None,
):
    """Iterate the permutations of residue pairs from two selections which are
    within a cartesian and/or outside a sequence distance cutoff.

    The method uses the PrimarySequenceNeighborhoodSelector and
    NeighborhoodResidueSelector under the hood. Note that all _permutations_ of
    residues are yielded, not _combinations_. If you prefer combinations simply
    check `if residue_pair[0].sequence_position() > residue_pair[1].sequence_position():`.

    primary_residue_selector - ResidueSelector
    secondary_residue_selector - ResidueSelector
    neighborhood_distance - float
    sequence_distance - int

    return - iterator(tuple(Residue, Residue))
    """
    primary_residue_selection = primary_residue_selector.apply(self)
    primary_residue_indices = get_residues_from_subset(primary_residue_selection)

    for primary_residue_index in primary_residue_indices:
        temp_secondary_residue_selector = secondary_residue_selector

        primary_residue_index_selector = ResidueIndexSelector(primary_residue_index)
        temp_secondary_residue_selector = AndResidueSelector(
            temp_secondary_residue_selector,
            NotResidueSelector(primary_residue_index_selector),
        )

        if (
            neighborhood_distance_maximum
        ):  # Select residues within cartesian neighborhood distance
            neighborhood_residue_selector = NeighborhoodResidueSelector(
                primary_residue_index_selector, neighborhood_distance_maximum, False
            )
            temp_secondary_residue_selector = AndResidueSelector(
                temp_secondary_residue_selector, neighborhood_residue_selector
            )

        if (
            sequence_distance_minimum
        ):  # Select residues outside sequence neighborhood distance
            sequence_residue_selector = PrimarySequenceNeighborhoodSelector(
                sequence_distance_minimum,
                sequence_distance_minimum,
                primary_residue_index_selector,
            )
            temp_secondary_residue_selector = AndResidueSelector(
                temp_secondary_residue_selector,
                NotResidueSelector(sequence_residue_selector),
            )

        secondary_residue_selection = temp_secondary_residue_selector.apply(self)
        secondary_residue_indices = get_residues_from_subset(
            secondary_residue_selection
        )

        for secondary_residue_index in secondary_residue_indices:
            yield tuple(
                [
                    self.residues[primary_residue_index],
                    self.residues[secondary_residue_index],
                ]
            )