Skip to content

Commit 180ae73

Browse files
committed
add pymol render example and notebook version
1 parent b5b7f88 commit 180ae73

File tree

2 files changed

+447
-3
lines changed

2 files changed

+447
-3
lines changed

templates/09_figure_output.ipynb

Lines changed: 397 additions & 0 deletions
Large diffs are not rendered by default.

templates/09_figure_output.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
# %%
12
from pathlib import Path
23

3-
from pyhdx.fileIO import csv_to_dataframe
4+
import pandas as pd
5+
import proplot as pplt
6+
from pymol import cmd
7+
48
from pyhdx.config import cfg
9+
from pyhdx.fileIO import csv_to_dataframe
510
from pyhdx.plot import (
11+
CMAP_NORM_DEFAULTS,
12+
ddG_scatter_figure,
613
dG_scatter_figure,
714
linear_bars_figure,
815
rainbowclouds_figure,
9-
ddG_scatter_figure,
1016
)
11-
import proplot as pplt
17+
from pyhdx.support import apply_cmap, color_pymol
1218

1319
# %%
1420
cwd = Path(__file__).parent
@@ -54,3 +60,44 @@
5460
# %%
5561
protein_states = plot_data.columns.get_level_values(0).unique()
5662
ddG_scatter_figure(plot_data, reference=protein_states[0])
63+
64+
# %%
65+
# Creating a colored structure
66+
cmd.load("https://files.rcsb.org/download/1QYN.pdb")
67+
cmd.set("antialias", 2)
68+
cmd.set("fog", 0)
69+
70+
# %%
71+
cmd.remove("resn HOH") # This removes only water molecules
72+
cmd.ipython_image()
73+
# %%
74+
# take dG values for SecB tetramer and reindex (pad with nan)
75+
# such that these regions are correctly colored as no coverage
76+
dG_values = plot_data[("SecB_tetramer", "dG")].reindex(pd.RangeIndex(1, 160))
77+
78+
# %%
79+
# create a pandas Series with hexadeicmal codes
80+
cmap, norm = CMAP_NORM_DEFAULTS["dG"]
81+
colors = apply_cmap(dG_values, cmap, norm)
82+
colors
83+
84+
# %%
85+
# apply the colors to the pymol structure
86+
color_pymol(colors, cmd)
87+
cmd.ipython_image()
88+
89+
# %%
90+
91+
# save the output
92+
cmd.png(
93+
"SecB_dG_render.png",
94+
width="10cm",
95+
dpi=300,
96+
ray=1,
97+
)
98+
99+
100+
# %%
101+
# rotate for a different view
102+
cmd.rotate("y", 90)
103+
cmd.ipython_image()

0 commit comments

Comments
 (0)