StructureViewer¶
-
class
visualife.widget.StructureViewer(div_id, **kwargs)¶ Bases:
objectRepresents a viewer for biological molecules.
It contains NGL viewer inside. It may display .pdb or .mol formats. See full documentation here http://nglviewer.org
The following example shows how to load a PDB file from a local directory:
It has been created by the following code:
from visualife.widget import StructureViewer panel3d_A = StructureViewer("show_3d_A",backgroundColor="white", width=200, height=200, menu_buttons={}) panel3d_A.add_model("1", "../_static/2q9f.pdb") panel3d_B = StructureViewer("show_3d_B",backgroundColor="white", width=200, height=200, menu_buttons={}) panel3d_B.add_model("1", "2gb1") pdb_txt = "ATOM 408 N LYS A 28 -2.867 6.554 -3.724 1.00 0.17 N" pdb_txt += "\n" + "ATOM 409 CA LYS A 28 -2.011 7.699 -3.277 1.00 0.21 C" pdb_txt += "\n" + "ATOM 410 C LYS A 28 -1.865 7.707 -1.749 1.00 0.19 C" pdb_txt += "\n" + "ATOM 411 O LYS A 28 -0.810 8.013 -1.230 1.00 0.23 O" panel3d_C = StructureViewer("show_3d_C",backgroundColor="white", width=200, height=200, menu_buttons={}) panel3d_C.add_model("1", pdb_txt) panel3d_C.as_sticks()
Methods Summary
add_model(model_id, URL, **kwargs)Adds a new structure to this viewer. add_style(model_id, style[, …])Modify a style used to display a structure add_to_menu(button_name, callback)Adds a button to the menu, binds a callback to the button_name as_cartoon([evt])Displays a molecule or its fragment as cartoon as_lines([evt])Displays a molecule or its fragment as lines as_spheres([evt])Displays a molecule or its fragment as spheres as_sticks([evt])Displays a molecule or its fragment as sticks center([evt])Centers the scene clear([evt])Clears the scene color_ss(model_id)Color given model by secondary structure hide_model(model_id)Hides a requested structure (i.e. remove_model(model_id)Removes a model from this widget and from the NGL viewer remove_style(model_id[, rep])Remove a style used to structure replace_bfactors(model_id, bf_values)Replaces B-factor values with given values show_distance(model_id, atom_pairs_list)Show distance between pair of atom in a given model show_model(model_id)Makes visible a requested structure (i.e. zoom_heteroatom(evt)Zooms to the heteroatoms group zoom_to(model_id, selection)Zooms to the active selection Methods Documentation
-
add_model(model_id, URL, **kwargs)¶ Adds a new structure to this viewer.
Parameters: - model_id –
stringID used to identify that molecule - URL –
string|File|Blobeither a URL or an object containing the file data:- a four character string is assumed to be a PDB code of a protein to be downloaded from the PDB website
- a string that contains multiple lines is assumed to be a PDB-formatted text
- other strings are recognized as local file names
- blob and file objects are handled by NGL instance directly
- kwargs – see below
Returns: Promise object of StructureComponent or a SurfaceComponent
- model_id –
-
add_style(model_id, style, representation_parameters={})¶ Modify a style used to display a structure
Parameters: - model_id –
stringID of a model to apply the style - style –
stringname of the representation to be set, e.g."cartoon"or"licorice" - representation_parameters – dictionary used to create a
NGL.StructureRepresentationTypeobject
Returns: None
- model_id –
Adds a button to the menu, binds a callback to the button_name
Parameters: - button_name –
stringname for button - callback – function or
stringto bind on click
- button_name –
-
as_cartoon(evt=None)¶ Displays a molecule or its fragment as cartoon
The method will be applied to residues (chains, atoms) that have been recently selected by
active_selection()method. By default the whole structure is selectedParameters: evt – event object; its not used by this method must must appear in the method definition so it can be used as a callback for an HTML event
-
as_lines(evt=None)¶ Displays a molecule or its fragment as lines
The method will be applied to residues (chains, atoms) that have been recently selected by
active_selection()method. By default the whole structure is selectedParameters: - evt – event object; its not used by this method must must appear in the method definition so it can be used as a callback for an HTML event
- kwargs – see below
Returns: None
-
as_spheres(evt=None)¶ Displays a molecule or its fragment as spheres
The method will be applied to residues (chains, atoms) that have been recently selected by
active_selection()method. By default the whole structure is selectedParameters: - evt – event object; its not used by this method must must appear in the method definition so it can be used as a callback for an HTML event
- kwargs – see below
Returns: None
-
as_sticks(evt=None)¶ Displays a molecule or its fragment as sticks
The method will be applied to residues (chains, atoms) that have been recently selected by
active_selection()method. By default the whole structure is selectedParameters: - evt – event object; its not used by this method must must appear in the method definition so it can be used as a callback for an HTML event
- kwargs – see below
Returns: None
-
center(evt=None)¶ Centers the scene
-
clear(evt=None)¶ Clears the scene
-
color_ss(model_id)¶ Color given model by secondary structure
Parameters: model_id – stringwith model id
-
hide_model(model_id)¶ Hides a requested structure (i.e. a model).
This method does not remove the structure, it just make it invisible. You can always show the structure again by calling
show()method. The structure must have been already added to this WidgetParameters: model_id – stringID of a model to showReturns: True if shown successfully, false if this called failed (e.g. when the requested structure has not been registered in this Widget)
-
remove_model(model_id)¶ Removes a model from this widget and from the NGL viewer
Parameters: model_id – stringID of a model to be removedReturns: True if the structure was actually removed
-
remove_style(model_id, rep=None)¶ Remove a style used to structure
Parameters: - model_id –
stringID of a model to apply the style - rep –
NGL.StructureRepresentationTypeobject
Returns: None
- model_id –
-
replace_bfactors(model_id, bf_values)¶ Replaces B-factor values with given values
Every atom of an i-th residue gets bf_values[i] :param model_id:
stringid that define a model to be affected :param bf_values:listlist of values to be used
-
show_distance(model_id, atom_pairs_list)¶ Show distance between pair of atom in a given model
Parameters: - model_id – id of model to mark the distances
- atom_pairs_list –
listof tuples of atom pairs eg. [(13,31),(5,43)]
-
show_model(model_id)¶ Makes visible a requested structure (i.e. a model).
The structure must have been already added to this Widget
Parameters: structure_id – stringID of a model to showReturns: True if shown successfully, false if this called failed (e.g. when the requested structure has not been registered in this Widget)
-
zoom_heteroatom(evt)¶ Zooms to the heteroatoms group
Parameters: - evt – event object; its not used by this method must must appear in the method definition so it can be used as a callback for an HTML event
- kwargs – see below
Returns: None
-
zoom_to(model_id, selection)¶ Zooms to the active selection
The method will zoom and center the view on residues (chains, atoms) that have been recently selected by
active_selection()method. By default the whole structure is selectedParameters: - evt – event object; its not used by this method must must appear in the method definition so it can be used as a callback for an HTML event
- kwargs – see below
Returns: None
-