<jupyter_start><jupyter_text>RMSD visualizationThis notebooks aims to identify a set of docking poses that can be used to visualize different RMSD ranges.<jupyter_code>from pathlib import Path

from openeye import oechem
import pandas as pd
from pymol import cmd

from kinoml.databases.pdb import smiles_from_pdb, download_pdb_structure
from kinoml.modeling.OEModeling import read_molecules, select_chain, remove_non_protein, write_molecules
CACHE_DIR = Path("../data/.cache")
fred_results = pd.read_csv("../data/fred_results.csv", index_col=0)
fred_results = fred_results[~fred_results["rmsd"].isna()]
fred_results = fred_results.sort_values("rmsd")<jupyter_output><empty_output><jupyter_text>Select example<jupyter_code>good_poses_pdb_ids = set(fred_results[
    fred_results["rmsd"] < 2
]["ligand_pdb_id"])
worst_poses_pdb_ids = set(fred_results[
    fred_results["rmsd"] > 30
]["ligand_pdb_id"])
print("Structures with good and bad poses:")
print([x for x in good_poses_pdb_ids if x in worst_poses_pdb_ids])
print(fred_results[fred_results["ligand_pdb_id"] == "5zan"]["rmsd"].to_list())
# find representative docking poses for several RMSD ranges
pdb_id, expo_id  = "5zan", "9A6"
result_selection = fred_results[fred_results["ligand_pdb_id"] == pdb_id]
representative_poses = []
rmsds = []
for lower_bound in [0, 2, 4, 8, 16, 30]:
    range_poses = result_selection[
        (result_selection["rmsd"] >= lower_bound) &
        (result_selection["rmsd"] < lower_bound + 2) 
    ]
    if len(range_poses) > 0:
        rmsds.append(range_poses.rmsd[0])
        representative_poses.append(range_poses.index[0])
print(representative_poses)
print(rmsds)
# merge pose with protein and save
docking_pose_paths = list(Path("../data/fred").glob("*.sdf"))
for representative_pose in representative_poses:
    protein_pdb_id = representative_pose.split("_")[5]
    protein_chain_id = representative_pose.split("_")[6][5]
    protein_structure_path = download_pdb_structure(protein_pdb_id, CACHE_DIR)
    protein_structure = read_molecules(protein_structure_path)[0]
    protein_structure = select_chain(protein_structure, protein_chain_id)
    protein_structure = remove_non_protein(protein_structure, remove_water=True)
    docking_pose_path = [
        docking_pose_path for docking_pose_path 
        in docking_pose_paths 
        if protein_pdb_id in docking_pose_path.name and "5zan" in docking_pose_path.name
    ][0]
    docking_pose = read_molecules(docking_pose_path)[0]
    oechem.OEAddMols(protein_structure, docking_pose)
    write_molecules([protein_structure], f"../data/fred/{protein_pdb_id}_{expo_id}.pdb")<jupyter_output><empty_output><jupyter_text>PyMol visualization<jupyter_code># load reference structure, docking pose and align
cmd.fetch(pdb_id)
for representative_pose in representative_poses:
    protein_pdb_id = representative_pose.split("_")[5]
    cmd.load(f"../data/fred/{protein_pdb_id}_{expo_id}.pdb", f"{protein_pdb_id}")
    cmd.align(f"{protein_pdb_id}", pdb_id)
# representation of reference structure
cmd.show_as("cartoon", f"{pdb_id}")
cmd.show_as("licorice", f"{pdb_id} and resname {expo_id}")
cmd.color("white", pdb_id)
# color
color_dict = {
    "3nrm": "green", "5one": "cyan", "5ew9": "magenta", "4ceg": "salmon", 
    "4dea": "slate", "4c3p": "orange",
}
for docking_pose, color in color_dict.items():
    cmd.color(color, docking_pose)
cmd.color("atomic", "not element C")
# docking pose representation
for docking_pose in color_dict.keys():
    cmd.hide("cartoon", docking_pose)
    cmd.hide("licorice", docking_pose)
    cmd.show_as("lines", f"{docking_pose} and resname UNL")
cmd.set("line_width", 3)
cmd.hide("lines", "hydro")
# general visualization settings
cmd.bg_colour("white")
cmd.remove("solvent")
cmd.set("ambient", 0.4)
cmd.set("antialias", 1)
cmd.set("ortho", 1)
cmd.set("ray_trace_mode", 1)
cmd.set("cartoon_fancy_helices", 1)
cmd.set("cartoon_highlight_color", "grey30")
# save pymol session
cmd.save("../pics/rmsd_visualization.pse")
# pic for binding pocket focus
cmd.set_view((
    -0.641249239,    0.734733999,   -0.221281186,
    -0.678720772,   -0.677629352,   -0.283111989,
    -0.357958853,   -0.031358212,    0.933209717,
     0.000077804,    0.000069283, -165.494964600,
   -14.712101936,   31.087493896,   -7.455860615,
   141.041702271,  189.951400757,   20.000000000
))
cmd.ray(4000, 4000)
cmd.png("../pics/rmsd_visualization.png")
# pic for ligand focus
cmd.set("cartoon_transparency", 0.8)
cmd.set_view((
    -0.653953254,   -0.321630001,   -0.684761167,
    -0.669361591,   -0.175815970,    0.721829236,
    -0.352553338,    0.930398583,   -0.100310877,
     0.000077804,    0.000069283,  -79.589012146,
   -14.712101936,   31.087493896,   -7.455860615,
    55.135738373,  104.045455933,   20.000000000
))
cmd.ray(4000, 2000)
cmd.png("../pics/rmsd_visualization2.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13557929334428923, 'fraction_numerical': 0.09038619556285948, 'mean_word_length': 5.226342710997442, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '380459', 'license': 'MIT', 'n_tokens_mistral': 2150, 'n_tokens_neox': 1847, 'n_words': 324, 'path': 'notebooks/14_RMSD_visualization.ipynb', 'repo_name': 'openkinome/kinase-docking-benchmark', 'size': '4868'}