Ncs rotamer differences.py

From CCP4 wiki
Jump to navigation Jump to search
def compare_ncs_rotamer(imol, chain_A, chain_B):
    n_residues = chain_n_residues(chain_A, imol)
    mismatched_rotamers = []

    for serial_number in range(n_residues):
        res_name_A = resname_from_serial_number(imol, chain_A, serial_number)
        res_no_A   = seqnum_from_serial_number(imol, chain_A, serial_number)
        ins_code_A = insertion_code_from_serial_number(imol, chain_A, serial_number)
        res_name_B = resname_from_serial_number(imol, chain_B, serial_number)
        res_no_B   = seqnum_from_serial_number(imol, chain_B, serial_number)
        ins_code_B = insertion_code_from_serial_number(imol, chain_B, serial_number)
        if not (res_no_A == res_no_B):
            print "sequence number for %i does not match" %res_no_A
        else:
            if not (res_name_A == res_name_B):
                print "residue names for %s do not match" %res_name_A
            else:
                rot_name_A = get_rotamer_name(imol, chain_A, res_no_A, ins_code_A)
                rot_name_B = get_rotamer_name(imol, chain_B, res_no_B, ins_code_B)
                if not (rot_name_A == rot_name_B):
                    mismatched_rotamers.append([imol, chain_A, res_no_A,
                                                ins_code_A, rot_name_A,
                                                "-" if rot_name_A == "" else rot_name_A,
                                                "-" if rot_name_B == "" else rot_name_B])

    dialog_box_of_buttons("Mismatched Rotamers",
                          [300, 300],
                          map(lambda rotamer:
                              [" " + rotamer[1] + " " +             # label
                               str(rotamer[2]) + rotamer[3] + " " +
                               rotamer[4] +                         # res_name
                               ":  " + rotamer[5] +
                               " vs. " + rotamer[6],
                               lambda func:
                               (set_go_to_atom_molecule(imol),
                                set_go_to_atom_chain_residue_atom_name(rotamer[1], rotamer[2], " CA "))
                               ],
                              mismatched_rotamers),
                          "  Close  ")

And you would use it something like this:

imol = read_pdb("test.pdb")
compare_ncs_rotamer(imol, "A", "B")