Skip to content

Commit 4bce9cf

Browse files
authored
Merge pull request #252 from Jhsmit/molstar_v2
Molstar v2
2 parents 9d86686 + e2f8ecb commit 4bce9cf

File tree

13 files changed

+745
-43
lines changed

13 files changed

+745
-43
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-latest, windows-latest]
11-
python-version: [3.7, 3.8, 3.9]
11+
python-version: [3.8, 3.9]
1212

1313
steps:
1414
- uses: actions/checkout@v2

dev/gui/dev_gui_secB.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pyhdx.web.apps import main_app
1818
from pyhdx.web.base import STATIC_DIR
1919
from pyhdx.web.utils import load_state, fix_multiindex_dtypes
20+
from pyhdx.config import cfg
2021

2122
sys._excepthook = sys.excepthook
2223

@@ -98,12 +99,12 @@ def init_dashboard():
9899
fit_control.patience = 100
99100
fit_control.learning_rate = 100
100101

101-
ngl = ctrl.views['protein']
102-
ngl._ngl.pdb_string = Path(test_dir / '1qyn.pdb').read_text()
103-
ctrl.views['protein'].object = pdb_string
102+
# ngl = ctrl.views['protein']
103+
# ngl._ngl.pdb_string = Path(test_dir / '1qyn.pdb').read_text()
104+
# ctrl.views['protein'].object = pdb_string
104105

105-
fit_result = load_fitresult(fitresult_dir)
106-
src.add(fit_result, 'fit_1')
106+
# fit_result = load_fitresult(fitresult_dir)
107+
# src.add(fit_result, 'fit_1')
107108

108109
diff = ctrl.control_panels['DifferentialControl']
109110
diff._action_add_comparison()
@@ -116,7 +117,7 @@ def init_dashboard():
116117

117118

118119
if __name__ == '__main__':
119-
pn.serve(tmpl, show=True, static_dirs={'pyhdx': STATIC_DIR})
120+
pn.serve(tmpl, show=True, static_dirs={'pyhdx': STATIC_DIR, 'assets': cfg.assets_dir})
120121

121122
elif __name__.startswith('bokeh_app'):
122123
tmpl.servable()

pyhdx/config.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
scheduler_address = 127.0.0.1:52123
33
n_workers = 10
44

5+
[server]
6+
assets_dir = ~/.pyhdx/assets
7+
58
[fitting]
69
dtype = float64
710
device = cpu

pyhdx/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def write_config(self, path=None):
104104
with open(pth, "w") as config_file:
105105
self._config.write(config_file)
106106

107+
@property
108+
def assets_dir(self):
109+
spec_path = self.get("server", "assets_dir")
110+
assets_dir = Path(spec_path.replace('~', str(home_dir)))
111+
112+
return assets_dir
113+
107114
@property
108115
def TORCH_DTYPE(self):
109116
dtype = self.get("fitting", "dtype")

pyhdx/web/apps/pyhdx_app.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,14 @@ modules:
530530
ddG: ddG_comparison_select
531531
views:
532532
protein: #NGL?
533-
type: ngl_colors
533+
type: pdbemolstar_colors
534534
sources:
535535
pdb: pdb
536536
color: protein_src
537+
hide_water: True
538+
hide_non_standard: True
539+
hide_heteroatoms: True
540+
hide_carbs: True
537541
opts: # opts are not applied directly but matched to color dataframe and then applied
538542
- rfu
539543
- drfu

pyhdx/web/apps/rfu_app.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,15 @@ modules:
209209
drfu: drfu_comparison_select
210210

211211
views:
212-
protein: #NGL?
213-
type: ngl_colors
212+
protein:
213+
type: pdbemolstar_colors
214214
sources:
215215
pdb: pdb
216216
color: protein_src
217+
hide_water: True
218+
hide_non_standard: True
219+
hide_heteroatoms: True
220+
hide_carbs: True
217221
opts: # opts are not applied directly but matched to color dataframe and then applied
218222
- rfu
219223
- drfu

pyhdx/web/controllers.py

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import itertools
22
import sys
3-
import urllib.request
3+
import uuid
44
import zipfile
55
from datetime import datetime
66
from io import StringIO, BytesIO
@@ -91,15 +91,8 @@ def _action_debug(self):
9191
print("break")
9292

9393
def _action_test(self):
94-
trs = self.transforms["peptide_select"]
95-
cache = trs._cache
96-
print(cache._cache.keys())
97-
print(cache)
98-
print(cache._store.keys())
99-
100-
for item in cache._store.keys():
101-
print(item)
102-
print(cache[item])
94+
pdbe_view = self.views['protein']
95+
pdbe_view.pdbe.test = not pdbe_view.pdbe.test
10396

10497
@property
10598
def _layout(self):
@@ -1837,26 +1830,53 @@ class ProteinControl(PyHDXControlPanel):
18371830
doc="Method of protein structure input",
18381831
objects=["RCSB PDB Download", "PDB File"],
18391832
)
1840-
file_binary = param.Parameter()
1833+
file_binary = param.Parameter(doc="Corresponds to file upload value")
18411834
pdb_id = param.String(doc="RCSB ID of protein to download")
18421835
load_structure = param.Action(lambda self: self._action_load_structure())
18431836

1837+
highlight_mode = param.Selector(
1838+
default="Single",
1839+
objects=["Single", "Range"]
1840+
)
1841+
1842+
highlight_range = param.Range(
1843+
default=(1,2),
1844+
step=1,
1845+
inclusive_bounds=[True, True],
1846+
)
1847+
highlight_value = param.Integer(
1848+
default=1
1849+
)
1850+
1851+
highlight = param.Action(lambda self: self._action_highlight())
1852+
1853+
clear_highlight = param.Action(lambda self: self._action_clear_highlight())
1854+
18441855
def __init__(self, parent, **params):
18451856
super(ProteinControl, self).__init__(
1846-
parent, _excluded=["file_binary"], **params
1857+
parent, _excluded=["file_binary", "highlight_range"], **params
18471858
)
1859+
self.n_term, self.c_term = 1, 2
1860+
self.src.param.watch(self._hdxm_added, 'hdxm_objects')
1861+
18481862
self.update_box()
18491863

18501864
@property
18511865
def _layout(self):
18521866
return [
18531867
("self", self.own_widget_names), # always use this instead of none?
1854-
("transforms.protein_src", None),
1868+
("transforms.protein_src", "value"),
1869+
('views.protein', 'visual_style'),
1870+
('views.protein', 'lighting'),
1871+
('views.protein', 'spin'),
1872+
('views.protein', 'reset'),
18551873
]
18561874

18571875
def make_dict(self):
18581876
return self.generate_widgets(
1859-
file_binary=pn.widgets.FileInput(multiple=False, accept=".pdb")
1877+
file_binary=pn.widgets.FileInput(multiple=False, accept=".pdb"),
1878+
highlight_range=pn.widgets.IntRangeSlider,
1879+
highlight_mode=pn.widgets.RadioButtonGroup,
18601880
)
18611881

18621882
@param.depends("input_mode", watch=True)
@@ -1868,11 +1888,37 @@ def _update_input_mode(self):
18681888

18691889
self.update_box()
18701890

1891+
@param.depends("highlight_mode", watch=True)
1892+
def _update_highlight_mode(self):
1893+
if self.highlight_mode == "Single":
1894+
self._excluded = ["highlight_range"]
1895+
elif self.highlight_mode == "Range":
1896+
self._excluded = ["highlight_value"]
1897+
1898+
self.update_box()
1899+
1900+
def _action_highlight(self):
1901+
data = {
1902+
'color': {'r': 200, 'g': 105, 'b': 180},
1903+
'focus': True,
1904+
}
1905+
1906+
if self.highlight_mode == "Single":
1907+
data["residue_number"] = self.highlight_value
1908+
elif self.highlight_mode == "Range":
1909+
data["start_residue_number"] = self.highlight_range[0]
1910+
data["end_residue_number"] = self.highlight_range[1]
1911+
1912+
self.views['protein'].pdbe.highlight([data])
1913+
1914+
def _action_clear_highlight(self):
1915+
self.views['protein'].pdbe.clear_highlight()
1916+
18711917
def _action_load_structure(self):
18721918
if self.input_mode == "PDB File":
18731919
pdb_string = self.file_binary.decode()
18741920
self.parent.sources["pdb"].add_from_string(
1875-
pdb_string, "unknown"
1921+
pdb_string, f"local_{uuid.uuid4()}"
18761922
) # todo parse and extract pdb id?
18771923

18781924
elif self.input_mode == "RCSB PDB Download":
@@ -1882,6 +1928,14 @@ def _action_load_structure(self):
18821928

18831929
self.parent.sources["pdb"].add_from_pdb(self.pdb_id)
18841930

1931+
def _hdxm_added(self, *events):
1932+
hdxm_object = next(reversed(self.src.hdxm_objects.values()))
1933+
self.n_term = min(self.n_term, hdxm_object.coverage.protein.n_term)
1934+
self.c_term = max(self.c_term, hdxm_object.coverage.protein.c_term)
1935+
1936+
self.param['highlight_value'].bounds = (self.n_term, self.c_term)
1937+
self.param['highlight_range'].bounds = (self.n_term, self.c_term)
1938+
18851939

18861940
class FileExportControl(PyHDXControlPanel):
18871941
"""

0 commit comments

Comments
 (0)