def create_user_res(serial_list, all_atoms, chain_selected, used_atoms,
    user_res_names):
    """Creates a customized BioPython Residue object corresponding to a user specified residue.

    Parameters
    ----------
    serial_list: list of int
        List of atom serial numbers included in residue
    all_atoms: list of :class:`Bio.PDB.Atom.Atom`
        All atoms in protein on selected chains
    chain_selected: list of str
        Chains included in analysis
    used_atoms: list of :class:`Bio.PDB.Atom.Atom`
        Atoms already included in analysis
    user_res_names: list of str
        User residue names already included in the analysis.

    Returns
    -------
    user_res: :class:`Bio.PDB.Residue.Residue`
        Customized residue object corresponding to the atoms in serial_list

    """
    source_res = []
    atm_list = []
    for atm in all_atoms:
        if atm.serial_number in serial_list:
            if atm.serial_number in used_atoms:
                message = 'Invalid atom serial number range. Atom ' + str(atm
                    .serial_number
                    ) + ' is already included in another residue.'
                raise ValueError(message)
            if atm.parent.parent.id not in chain_selected:
                message = 'Invalid atom serial number range. Atom ' + str(atm
                    .serial_number) + ' is in chain ' + str(atm.parent.
                    parent.id) + '.'
                raise ValueError(message)
            atm.get_full_id()
            if not source_res:
                source_res = atm.parent
            atm.get_full_id()
            atm_copy = atm.copy()
            atm_list.append(atm_copy)
    source_res.get_full_id()
    user_res = source_res.copy()
    for atm in list(source_res.get_atoms()):
        user_res.detach_child(atm.id)
    for atm in atm_list:
        user_res.add(atm)
    k = 1
    name = 'CUST'
    name += '-'
    while name + str(k) in user_res_names:
        k += 1
    user_res_names.append(name + str(k))
    user_res.resname = name + str(k)
    user_res.node_label = user_res.resname
    return user_res
