Skip to content

Commit

Permalink
Merge pull request #49 from NDoering99/main
Browse files Browse the repository at this point in the history
make visualization easier to use
  • Loading branch information
talagayev authored Dec 28, 2023
2 parents c45a3eb + 0ef5a1b commit 0ed67de
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion openmmdl/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0+548.gc46c6f1.dirty"
__version__ = "1.0.0+557.gc45a3eb.dirty"
46 changes: 37 additions & 9 deletions openmmdl/openmmdl_analysis/visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -11,22 +11,50 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"filepath = '/your/file/path/Visualization' # add the filepath to the directory where openmmdl_analysis Visualization outputs are saved\n",
"ligname = 'UNK' # add the name of the ligand from the original PDB File"
"ligname = 'FMN' # add the name of the ligand from the original PDB File"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09acfdb0e59f46d481905cef43c231c0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"ThemeManager()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4b33c5fd6d6541ed8b9766bdbfe27e42",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NGLWidget(gui_style='ngl', layout=Layout(height='1000px', width='1000px'), max_frame=9999)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# change receptor_type, width and height as needed (preset to protein and 1000x1000)\n",
"view = visualization(filepath, ligname)\n",
"# change receptor_type, width and height as needed (preset to receptor_type='protein or nucleic' and 1000x1000)\n",
"view = visualization(ligname)\n",
"view.display(gui=True, style='ngl')"
]
},
Expand Down Expand Up @@ -54,7 +82,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.10.10"
},
"vscode": {
"interpreter": {
Expand Down
24 changes: 12 additions & 12 deletions openmmdl/openmmdl_analysis/visualization_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import nglview as nv
import subprocess
import os
import shutil

from openmmdl.openmmdl_analysis.barcode_generation import waterids_barcode_generator

Expand Down Expand Up @@ -136,22 +137,19 @@ def cloud_json_generation(df_all):
return clouds


def visualization(filepath, ligname, receptor_type='protein', height='1000px', width='1000px'):
def visualization(ligname, receptor_type='protein or nucleic', height='1000px', width='1000px'):
"""Generates visualization of the trajectory with the interacting waters and interaction clouds.
Args:
json_file_path (str): path to .json file containing the interaction clouds
pdb_file_path (str): path to pdb file (use interacting_waters.pdb for better visualization)
dcd_file_path (str): path to dcd file (use interacting_waters.dcd for better visualization)
interacting_waters_file_path (str): path to .pkl file containing the interacting water ids
receptor_type (str, optional): type of receptor. Defaults to 'protein'.
ligname (str): name of the ligand in the pdb file
receptor_type (str, optional): type of receptor. Defaults to 'protein or nucleic'.
height (str, optional): height of the visualization. Defaults to '1000px'.
width (str, optional): width of the visualization. Defaults to '1000px'.
Returns:
nglview widget: returns the nglview widget containing the visualization
"""
with open(f'{filepath}clouds.json') as f:
with open('clouds.json') as f:
data = json.load(f)

sphere_buffers = []
Expand All @@ -163,9 +161,9 @@ def visualization(filepath, ligname, receptor_type='protein', height='1000px', w
sphere_buffer["radius"] += [cloud["radius"]]
sphere_buffers.append(sphere_buffer)

pdb_structure = md.load(f'{filepath}interacting_waters.pdb')
dcd_trajectory = md.load(f'{filepath}interacting_waters.dcd', top=pdb_structure)
with open(f'{filepath}interacting_waters.pkl', 'rb') as f:
pdb_structure = md.load(f'interacting_waters.pdb')
dcd_trajectory = md.load(f'interacting_waters.dcd', top=pdb_structure)
with open(f'interacting_waters.pkl', 'rb') as f:
interacting_watersids = pickle.load(f)

view = nv.show_mdtraj(dcd_trajectory)
Expand All @@ -174,7 +172,7 @@ def visualization(filepath, ligname, receptor_type='protein', height='1000px', w

for water in interacting_watersids:
view.add_licorice(selection=f"water and {water}")
view.add_licorice(selection='ligand')
view.add_licorice(selection=ligname)

for sphere_buffer, name in zip(sphere_buffers, ['hydrophobic', 'acceptor', 'donor', 'waterbridge', 'negative_ionizable', 'positive_ionizable', 'pistacking', 'pication', 'halogen', 'metal']):
js = (
Expand All @@ -196,4 +194,6 @@ def visualization(filepath, ligname, receptor_type='protein', height='1000px', w
def run_visualization():
package_dir = os.path.dirname(__file__)
notebook_path = os.path.join(package_dir, 'visualization.ipynb')
subprocess.run(['jupyter', 'notebook', notebook_path])
current_dir = os.getcwd()
shutil.copyfile(notebook_path, f'{current_dir}/visualization.ipynb')
subprocess.run(['jupyter', 'notebook', 'visualization.ipynb'])

0 comments on commit 0ed67de

Please sign in to comment.