frag_pele/Analysis/sidecahins_analyser.py
def compute_atom_distances(pdb_target, res_file, output_report, chain="L"):
    """
    This function calculate atom-atom distances for ligand and residue atoms. The residue number and atom names
    (for both, ligand and residue) must be specified in a file ('res_file').
    :param pdb_target: input PDB file path
    :param res_file: file with instructions. This file must have n rows with three format: RESNUM LATOMNAME/SLIGAND
    ATOMNAMES/SRESIDUE. If you want to calculate a distance using a center of mass write [ATOM1,ATOM2,ATOMN]

    :param output_report:
    :param chain:
    :return:
    """
    # Load PDB files
    target = pdb2prody(pdb_target)
    ligand = target.select("chain {}".format(chain))
    print(ligand.getNames())
    # Reading instructions from file
    list_of_instructions = read_selecteds_from_file(res_file)
    # Select the input atoms
    report = []
    for line in list_of_instructions:
        resnum, atom_name_ref, atom_name_tar = line.split()
        # If the user wants to select more than one atom he has to put them in a string with this format: [atom1,atomN...]
        if "[" in atom_name_ref or "]" in atom_name_ref:
            print("Multiple atom selection for the ligand")
            atom_string_with_comas = atom_name_ref.strip("[").strip("]")
            atom_list = atom_string_with_comas.split(",")
            atom_string = ' '.join(atom_list)
            atom_ref_selected = ligand.select("name {}".format(atom_string))
            print("Selected atoms: {}".format(atom_ref_selected.getNames()))
        else:
            print("Single atom selection for the ligand")
            atom_ref_selected = ligand.select("name {}".format(atom_name_ref))
            print("Selected atom: {}".format(atom_ref_selected.getNames()))

        if "[" in atom_name_tar or "]" in atom_name_tar:
            print("Multiple atom selection for the system")
            atom_string_with_comas = atom_name_tar.strip("[").strip("]")
            atom_list = atom_string_with_comas.split(",")
            atom_string = ' '.join(atom_list)
            atom_tar_selected = select_atom_given_name_type_and_num(target, resnum, atom_string)
            print("Selected atoms: {}".format(atom_tar_selected.getNames()))
        else:
            print("Single atom selection for the system")
            atom_tar_selected = select_atom_given_name_type_and_num(target, resnum, atom_name_tar)
            print("Selected atom: {}".format(atom_tar_selected.getNames()))
        try:
            number_of_selected_atoms_ref = len(atom_ref_selected.getNames())
        except AttributeError:
            exit("None atoms where selected. Please, check if the selected atoms exists in the ligand in {}".format(pdb_target))
        try:
            number_of_selected_atoms_tar = len(atom_tar_selected.getNames())
        except AttributeError:
            exit("None atoms where selected. Please, check if the selected atoms exists in the residue {} in {}".format(resnum, pdb_target))
        # Now there are four possibilities: len 1 in target and ref, len > 1 in one of both and len >1 in both.
        # If the len is more than 1 we will use the center of mass as a point to compute the distance.
        if number_of_selected_atoms_ref <= 1 and number_of_selected_atoms_tar <= 1:
            distance = prody.calcDistance(atom_tar_selected, atom_ref_selected)
        elif number_of_selected_atoms_ref <= 1 and number_of_selected_atoms_tar > 1:
            center_tar = prody.calcCenter(atom_tar_selected)
            atom_coords = atom_ref_selected.getCoords()[0]
            distance = np.linalg.norm(center_tar - atom_coords)
        elif number_of_selected_atoms_ref > 1 and number_of_selected_atoms_tar <= 1:
            center_ref = prody.calcCenter(atom_ref_selected)
            atom_coords = atom_tar_selected.getCoords()[0]
            distance = np.linalg.norm(atom_coords - center_ref)
        else:
            center_tar = prody.calcCenter(atom_tar_selected)
            center_ref = prody.calcCenter(atom_ref_selected)
            distance = np.linalg.norm(center_tar-center_ref)
        report_line = "{:4} {:10} {:10} {:6.3f}\n".format(resnum, ''.join(atom_ref_selected.getNames()),
                                                          ''.join(atom_tar_selected.getNames()), distance)
        report.append(report_line)

    report_final = ''.join(report)

    if output_report:
        with open(output_report, "w") as report_file:
            report_file.write(report_final)
    print(report_final)
    return report_final

    This function calculate atom-atom distances for ligand and residue atoms. The residue number and atom names
    (for both, ligand and residue) must be specified in a file ('res_file').
    :param pdb_target: input PDB file path
    :param res_file: file with instructions. This file must have n rows with three format: RESNUM LATOMNAME/SLIGAND
    ATOMNAMES/SRESIDUE. If you want to calculate a distance using a center of mass write [ATOM1,ATOM2,ATOMN]

    :param output_report:
    :param chain:
    :return:
    
This function calculate atom-atom distances for ligand and residue atoms. The residue number and atom names
(for both, ligand and residue) must be specified in a file ('res_file').
This function calculate atom - atom distances for ligand and residue atoms . The residue number and atom names ( for both ligand and residue ) must be specified in a file ( ' res_file ' ) .
def compute_atom_distances(pdb_target, res_file, output_report, chain="L"):
    target = pdb2prody(pdb_target)
    ligand = target.select("chain {}".format(chain))
    print(ligand.getNames())
    list_of_instructions = read_selecteds_from_file(res_file)
    report = []
    for line in list_of_instructions:
        resnum, atom_name_ref, atom_name_tar = line.split()
        if "[" in atom_name_ref or "]" in atom_name_ref:
            print("Multiple atom selection for the ligand")
            atom_string_with_comas = atom_name_ref.strip("[").strip("]")
            atom_list = atom_string_with_comas.split(",")
            atom_string = ' '.join(atom_list)
            atom_ref_selected = ligand.select("name {}".format(atom_string))
            print("Selected atoms: {}".format(atom_ref_selected.getNames()))
        else:
            print("Single atom selection for the ligand")
            atom_ref_selected = ligand.select("name {}".format(atom_name_ref))
            print("Selected atom: {}".format(atom_ref_selected.getNames()))
        if "[" in atom_name_tar or "]" in atom_name_tar:
            print("Multiple atom selection for the system")
            atom_string_with_comas = atom_name_tar.strip("[").strip("]")
            atom_list = atom_string_with_comas.split(",")
            atom_string = ' '.join(atom_list)
            atom_tar_selected = select_atom_given_name_type_and_num(target, resnum, atom_string)
            print("Selected atoms: {}".format(atom_tar_selected.getNames()))
        else:
            print("Single atom selection for the system")
            atom_tar_selected = select_atom_given_name_type_and_num(target, resnum, atom_name_tar)
            print("Selected atom: {}".format(atom_tar_selected.getNames()))
        try:
            number_of_selected_atoms_ref = len(atom_ref_selected.getNames())
        except AttributeError:
            exit("None atoms where selected. Please, check if the selected atoms exists in the ligand in {}".format(pdb_target))
        try:
            number_of_selected_atoms_tar = len(atom_tar_selected.getNames())
        except AttributeError:
            exit("None atoms where selected. Please, check if the selected atoms exists in the residue {} in {}".format(resnum, pdb_target))
        if number_of_selected_atoms_ref <= 1 and number_of_selected_atoms_tar <= 1:
            distance = prody.calcDistance(atom_tar_selected, atom_ref_selected)
        elif number_of_selected_atoms_ref <= 1 and number_of_selected_atoms_tar > 1:
            center_tar = prody.calcCenter(atom_tar_selected)
            atom_coords = atom_ref_selected.getCoords()[0]
            distance = np.linalg.norm(center_tar - atom_coords)
        elif number_of_selected_atoms_ref > 1 and number_of_selected_atoms_tar <= 1:
            center_ref = prody.calcCenter(atom_ref_selected)
            atom_coords = atom_tar_selected.getCoords()[0]
            distance = np.linalg.norm(atom_coords - center_ref)
        else:
            center_tar = prody.calcCenter(atom_tar_selected)
            center_ref = prody.calcCenter(atom_ref_selected)
            distance = np.linalg.norm(center_tar-center_ref)
        report_line = "{:4} {:10} {:10} {:6.3f}\n".format(resnum, ''.join(atom_ref_selected.getNames()),
                                                          ''.join(atom_tar_selected.getNames()), distance)
        report.append(report_line)
    report_final = ''.join(report)
    if output_report:
        with open(output_report, "w") as report_file:
            report_file.write(report_final)
    print(report_final)
    return report_final
def compute_atom_distances ( pdb_target , res_file , output_report , chain = "L" ) : target = pdb2prody ( pdb_target ) ligand = target . select ( "chain {}" . format ( chain ) ) print ( ligand . getNames ( ) ) list_of_instructions = read_selecteds_from_file ( res_file ) report = [ ] for line in list_of_instructions : resnum , atom_name_ref , atom_name_tar = line . split ( ) if "[" in atom_name_ref or "]" in atom_name_ref : print ( "Multiple atom selection for the ligand" ) atom_string_with_comas = atom_name_ref . strip ( "[" ) . strip ( "]" ) atom_list = atom_string_with_comas . split ( "," ) atom_string = ' ' . join ( atom_list ) atom_ref_selected = ligand . select ( "name {}" . format ( atom_string ) ) print ( "Selected atoms: {}" . format ( atom_ref_selected . getNames ( ) ) ) else : print ( "Single atom selection for the ligand" ) atom_ref_selected = ligand . select ( "name {}" . format ( atom_name_ref ) ) print ( "Selected atom: {}" . format ( atom_ref_selected . getNames ( ) ) ) if "[" in atom_name_tar or "]" in atom_name_tar : print ( "Multiple atom selection for the system" ) atom_string_with_comas = atom_name_tar . strip ( "[" ) . strip ( "]" ) atom_list = atom_string_with_comas . split ( "," ) atom_string = ' ' . join ( atom_list ) atom_tar_selected = select_atom_given_name_type_and_num ( target , resnum , atom_string ) print ( "Selected atoms: {}" . format ( atom_tar_selected . getNames ( ) ) ) else : print ( "Single atom selection for the system" ) atom_tar_selected = select_atom_given_name_type_and_num ( target , resnum , atom_name_tar ) print ( "Selected atom: {}" . format ( atom_tar_selected . getNames ( ) ) ) try : number_of_selected_atoms_ref = len ( atom_ref_selected . getNames ( ) ) except AttributeError : exit ( "None atoms where selected. Please, check if the selected atoms exists in the ligand in {}" . format ( pdb_target ) ) try : number_of_selected_atoms_tar = len ( atom_tar_selected . getNames ( ) ) except AttributeError : exit ( "None atoms where selected. Please, check if the selected atoms exists in the residue {} in {}" . format ( resnum , pdb_target ) ) if number_of_selected_atoms_ref <= 1 and number_of_selected_atoms_tar <= 1 : distance = prody . calcDistance ( atom_tar_selected , atom_ref_selected ) elif number_of_selected_atoms_ref <= 1 and number_of_selected_atoms_tar > 1 : center_tar = prody . calcCenter ( atom_tar_selected ) atom_coords = atom_ref_selected . getCoords ( ) [ 0 ] distance = np . linalg . norm ( center_tar - atom_coords ) elif number_of_selected_atoms_ref > 1 and number_of_selected_atoms_tar <= 1 : center_ref = prody . calcCenter ( atom_ref_selected ) atom_coords = atom_tar_selected . getCoords ( ) [ 0 ] distance = np . linalg . norm ( atom_coords - center_ref ) else : center_tar = prody . calcCenter ( atom_tar_selected ) center_ref = prody . calcCenter ( atom_ref_selected ) distance = np . linalg . norm ( center_tar - center_ref ) report_line = "{:4} {:10} {:10} {:6.3f}\n" . format ( resnum , '' . join ( atom_ref_selected . getNames ( ) ) , '' . join ( atom_tar_selected . getNames ( ) ) , distance ) report . append ( report_line ) report_final = '' . join ( report ) if output_report : with open ( output_report , "w" ) as report_file : report_file . write ( report_final ) print ( report_final ) return report_final
This function calculate atom-atom distances for ligand and residue atoms.
This function calculate atom - atom distances for ligand and residue atoms .
"""
    This function calculate atom-atom distances for ligand and residue atoms. The residue number and atom names
    (for both, ligand and residue) must be specified in a file ('res_file').
    :param pdb_target: input PDB file path
    :param res_file: file with instructions. This file must have n rows with three format: RESNUM LATOMNAME/SLIGAND
    ATOMNAMES/SRESIDUE. If you want to calculate a distance using a center of mass write [ATOM1,ATOM2,ATOMN]

    :param output_report:
    :param chain:
    :return:
    """ # Load PDB files # Reading instructions from file # Select the input atoms # If the user wants to select more than one atom he has to put them in a string with this format: [atom1,atomN...] # Now there are four possibilities: len 1 in target and ref, len > 1 in one of both and len >1 in both. # If the len is more than 1 we will use the center of mass as a point to compute the distance.
None
pdb_target
input PDB file path
input PDB file path
res_file
file with instructions. This file must have n rows with three format: RESNUM LATOMNAME/SLIGAND
ATOMNAMES/SRESIDUE. If you want to calculate a distance using a center of mass write [ATOM1,ATOM2,ATOMN]
file with instructions . This file must have n rows with three format : RESNUM LATOMNAME / SLIGAND ATOMNAMES / SRESIDUE . If you want to calculate a distance using a center of mass write [ ATOM1 ATOM2 ATOMN ]
output_report
None
chain
None