frag_pele/Growing/AddingFragHelpers/pdb_joiner.py
def extract_and_change_atomnames(molecule, selected_resname, core_resname, rename=False):
    """
    Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following
    the next pattern: G1, G2, G3...
    :param molecule: ProDy molecule.
    :param selected_resname: Residue name whose atoms you would like to rename.
    :return: ProDy molecule with atoms renamed and dictionary {"original atom name" : "new atom name"}
    """
    assert selected_resname != core_resname, "core and fragment residue name must be different"
    fragment = molecule.select("resname {}".format(selected_resname))
    core = molecule.select("resname {}".format(core_resname))
    core_atom_names = [atom.getName() for atom in core]
    fragment_atom_names = [atom.getName() for atom in fragment]
    names_dictionary = {}
    for n, atom_name in enumerate(fragment_atom_names):
        if rename:
            names_dictionary[atom_name] = "G{}".format(n)
        else:
            # If the atomname is repited
            if atom_name in core_atom_names:
                initial_atom_name = atom_name
                while atom_name in core_atom_names:
                    atom_name_digit = re.findall('\d+', atom_name)[0]
                    new_atom_name_digit = int(atom_name_digit) + 1
                    atom_name = atom_name.replace(atom_name_digit, str(new_atom_name_digit))
                final_atom_name = atom_name
                core_atom_names.append(final_atom_name)
                names_dictionary[initial_atom_name] = final_atom_name
            else:
                names_dictionary[atom_name] = atom_name
    for atom in molecule:
        if atom.getResname() == selected_resname:
            if atom.getName() in names_dictionary:
                atom.setName(names_dictionary[atom.getName()])
    return molecule, names_dictionary

    Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following
    the next pattern: G1, G2, G3...
    :param molecule: ProDy molecule.
    :param selected_resname: Residue name whose atoms you would like to rename.
    :return: ProDy molecule with atoms renamed and dictionary {"original atom name" : "new atom name"}
    
Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following
the next pattern: G1, G2, G3
Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following the next pattern : G1 G2 G3
def extract_and_change_atomnames(molecule, selected_resname, core_resname, rename=False):
    assert selected_resname != core_resname, "core and fragment residue name must be different"
    fragment = molecule.select("resname {}".format(selected_resname))
    core = molecule.select("resname {}".format(core_resname))
    core_atom_names = [atom.getName() for atom in core]
    fragment_atom_names = [atom.getName() for atom in fragment]
    names_dictionary = {}
    for n, atom_name in enumerate(fragment_atom_names):
        if rename:
            names_dictionary[atom_name] = "G{}".format(n)
        else:
            if atom_name in core_atom_names:
                initial_atom_name = atom_name
                while atom_name in core_atom_names:
                    atom_name_digit = re.findall('\d+', atom_name)[0]
                    new_atom_name_digit = int(atom_name_digit) + 1
                    atom_name = atom_name.replace(atom_name_digit, str(new_atom_name_digit))
                final_atom_name = atom_name
                core_atom_names.append(final_atom_name)
                names_dictionary[initial_atom_name] = final_atom_name
            else:
                names_dictionary[atom_name] = atom_name
    for atom in molecule:
        if atom.getResname() == selected_resname:
            if atom.getName() in names_dictionary:
                atom.setName(names_dictionary[atom.getName()])
    return molecule, names_dictionary
def extract_and_change_atomnames ( molecule , selected_resname , core_resname , rename = False ) : assert selected_resname != core_resname , "core and fragment residue name must be different" fragment = molecule . select ( "resname {}" . format ( selected_resname ) ) core = molecule . select ( "resname {}" . format ( core_resname ) ) core_atom_names = [ atom . getName ( ) for atom in core ] fragment_atom_names = [ atom . getName ( ) for atom in fragment ] names_dictionary = { } for n , atom_name in enumerate ( fragment_atom_names ) : if rename : names_dictionary [ atom_name ] = "G{}" . format ( n ) else : if atom_name in core_atom_names : initial_atom_name = atom_name while atom_name in core_atom_names : atom_name_digit = re . findall ( '\d+' , atom_name ) [ 0 ] new_atom_name_digit = int ( atom_name_digit ) + 1 atom_name = atom_name . replace ( atom_name_digit , str ( new_atom_name_digit ) ) final_atom_name = atom_name core_atom_names . append ( final_atom_name ) names_dictionary [ initial_atom_name ] = final_atom_name else : names_dictionary [ atom_name ] = atom_name for atom in molecule : if atom . getResname ( ) == selected_resname : if atom . getName ( ) in names_dictionary : atom . setName ( names_dictionary [ atom . getName ( ) ] ) return molecule , names_dictionary
Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following
the next pattern: G1, G2, G3...
Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following the next pattern : G1 G2 G3 ...
"""
    Given a ProDy molecule and a Resname this function will rename the PDB atom names for the selected residue following
    the next pattern: G1, G2, G3...
    :param molecule: ProDy molecule.
    :param selected_resname: Residue name whose atoms you would like to rename.
    :return: ProDy molecule with atoms renamed and dictionary {"original atom name" : "new atom name"}
    """ # If the atomname is repited
ProDy molecule with atoms renamed and dictionary {"original atom name" : "new atom name"}
ProDy molecule with atoms renamed and dictionary { " original atom name " : " new atom name " }
molecule
None
selected_resname
Residue name whose atoms you would like to rename.
Residue name whose atoms you would like to rename .
core_resname
rename