11import itertools
22import sys
3- import urllib . request
3+ import uuid
44import zipfile
55from datetime import datetime
66from 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
18861940class FileExportControl (PyHDXControlPanel ):
18871941 """
0 commit comments