def _find_branch(pt, targets, branches):
    """Determines which branch a pathway belongs to and returns that branch.

    A ShortestPath belongs to a branch if the first surface exposed residue it reaches during the
    pathway is the target of that particular branch.

    Parameters
    ----------
    pt: ShortestPath
        ShortestPath object
    targets: list of str
        List of surface exposed residues
    branches: list of pyemapBranch objects
        List of branches already found

    Returns
    -------
    cur_branch: Branch
        Branch object that pt belongs to

    """
    res = pt.path[0]
    count = 0
    while res not in targets:
        count += 1
        res = pt.path[count]
    count = 0
    cur_branch = branches[0]
    while not res == cur_branch.target:
        count += 1
        cur_branch = branches[count]
    return cur_branch