Nanome Plugin API¶
The Nanome Plugin System is a Python-based API that allows users to connect 3rd party tools into the Nanome Virtual Reality Software Tool for Collaborative Molecular Modeling.
Table of Contents¶
Architecture¶
The overall architecture of this plugin system is designed to enable plugin creators to iterate fast and efficiently when developing, improving, or debugging a plugin for Nanome.
If you have any feedback or question, don’t hesitate to contact us or to directly contribute to our Github
Development iterations¶
As a result of this flexible architecture, no need to restart Nanome if your plugin crashes, or if you need to improve it:
- Stop your plugin. All sessions connected to it will be disconnected.
- Modify the python script
- Restart it
- Reconnect to it in Nanome. Using the 2D mode of Nanome might be useful in order to reconnect and test faster without having to wear your VR headset everytime.
How it works¶
Here is a simple way to represent the Plugin System architecture:
+---------------------------------+ +-------------------------------------------------+
| +-----------+ | | |
| |Nanome User| | | |
| |"Alice" +<------------>+ |
|Room +-----------+ | | |
|"Alice's Room" +-----------+ | | |
| |Nanome User| | | |
| |"Bob" | | | NTS |
| +-----------+ | | |
+---------------------------------+ | - Session A: "Alice's Room" (Alice is presenter)|
+---------------------------------+ | - Session B: "Dan's Room" (Carol is presenter) |
| +-----------+ | | |
| |Nanome User| | | - Plugin A: Docking Plugin |
| |"Carol" +<------------>+ |
|Room +-----------+ | | |
|"Dan's Room" +-----------+ | | |
| |Nanome User| | | |
| |"Dan" | | | |
| +-----------+ | | |
+---------------------------------+ +---------------------^---------------------------+
|
+-------------------------------------+
| | |
| +------v-------+ |
| |Docking Plugin| |
| +^------------^+ |
| | | |
| +---------v-+ +v----------+ |
| |Sub-process| |Sub-process| |
| |(Session A)| |(Session B)| |
| +-----------+ +-----------+ |
+-------------------------------------+
- NTS (the plugin server) is aware of which plugins and sessions are connected to it, and who is the presenter of each session.
- A session asks to connect to a plugin
- NTS transfers the request to the target plugin
- The plugin creates a subprocess on its computer, and instantiates its plugin class
- The subprocess replies to its main process, which transfers the reply to NTS, which transfers the reply to the room presenter
- Connection is established until the presenter requests a disconnection or the plugin is stopped.
NB: A plugin cannot talk to a Nanome session/user before being connected to it. NB2: Communications are encrypted from Nanome to NTS and from NTS to Plugins
Basics¶
Plugin description¶
The parameters of nanome.Plugin define how your plugin will appear in the list:
plugin = nanome.Plugin(name, description, category, has_advanced)
- category will define in which category the plugin will be when Nanome User clicks on the plugin filter dropdown. This is currently unsupported.
- has_advanced defines if an “Advanced Settings” button should be displayed when user selects the plugin in Nanome
Or, if using the one-line plugin setup:
nanome.Plugin.setup(name, description, category, has_advanced, plugin_class, host, port, key_file)
Entry points¶
Overriding these functions in your plugin will give you several entry points:
def start(self):
"""
| Called when user "Activates" the plugin
"""
pass
def update(self):
"""
| Called when when instance updates (multiple times per second)
"""
pass
def on_run(self):
"""
| Called when user presses "Run"
"""
pass
def on_stop(self):
"""
| Called when user disconnects or plugin crashes
"""
pass
def on_advanced_settings(self):
"""
| Called when user presses "Advanced Settings"
"""
pass
def on_complex_added(self):
"""
| Called whenever a complex is added to the workspace.
"""
pass
def on_complex_removed(self):
"""
| Called whenever a complex is removed from the workspace.
"""
pass
def on_presenter_change(self):
"""
| Called when room's presenter changes.
"""
pass
def on_advanced_settings(self):
"""
| Called when user presses "Advanced Settings"
"""
pass
def on_complex_added(self):
"""
| Called whenever a complex is added to the workspace.
"""
pass
def on_complex_removed(self):
"""
| Called whenever a complex is removed from the workspace.
"""
pass
def on_presenter_change(self):
"""
| Called when room's presenter changes.
"""
pass
Workspace API¶
Request entire workspace in deep mode¶
def on_run(self):
self.request_workspace(self.on_workspace_received)
def on_workspace_received(self, workspace):
pass
Request a list of specific complexes in deep mode¶
def on_run(self):
self.request_complexes([1, 6, 5], self.on_complexes_received) # Requests complexes with ID 1, 6 and 5
def on_complexes_received(self, complex_list):
pass
Request all complexes in the workspace in shallow mode¶
def on_run(self):
self.request_complex_list(self.on_complex_list_received)
def on_complex_list_received(self, complex_list):
pass
Update workspace to match exactly¶
def on_workspace_received(self, workspace):
# ...
# Do something with workspace
# ...
self.update_workspace(workspace)
Add to workspace¶
def on_run(self):
# ...
# Create new complexes
# ...
self.add_to_workspace([new_complex1, new_complex2])
Update specific structures¶
In shallow mode:
def on_complex_list_received(self, complex_list):
# ...
# Do something with shallow structures, i.e. move them, rename them
# ...
self.update_structures_shallow([complex, atom, residue])
In deep mode:
def on_workspace_received(self, complex_list):
# ...
# Do something with deep structures, i.e. move them, rename them
# ...
self.update_structures_deep([complex])
Structure¶
Deep / Shallow¶
Nanome has two molecular structure transmission mode: Deep and Shallow. Their goal is to make data transmission faster by requesting only the data needed.
- Deep mode will request/send the structure and its entire content. E.g. a molecule in deep mode will contain its name and any other property it might have + all its chains, residues, atoms and bonds
- Shallow mode will request/send only the structure itself. E.g. a molecule in shallow mode will only contain its name and any other property it might have
Whether a command requests one mode or the other is described in this documentation.
Structure hierarchy¶
Molecular structures are organized like so:
- Workspace
- —-Complex
- ——– Molecule
- ————– Chain
- ——————– Residue
- ————————– Atom
- ————————– Bond
A complex is a group of molecules and has a position and rotation. In Nanome, the user can switch between the molecules of a complex using the frame slider, in the information menu.
Index¶
Each molecular structure has an index available as a base property.
This index is a unique identifier for structures uploaded to Nanome. However, if a structure hasn’t been added to Nanome’s workspace yet, its index will be -1
To access this index:
if my_structure.index == -1:
Logs.message("This structure hasn't been uploaded to Nanome")
User Interface API¶
API¶
The UI API can be used to create a Menu from scratch or to interact with any menu or UI element generator by the Plugin Menu Creator.
UI elements are organized like so:
- Menu - Contains its size, title, enabled state, etc.
- —- Root - Main Layout Node
- ———- Layout Node - Contains positioning information, orientation, etc.
- —————- Content - Button/Slider/Text Input/etc.
- —————- Children Layout Nodes - A layout node can contain other Layout Nodes
- ———————- etc.
A menu hierarchy is created by placing LayoutNode
under each other, and changing their orientations and sizes.
Currently available UI elements are:
Following is an example of manual UI creation:
import nanome
from nanome.util import Logs
import sys
import time
# Config
NAME = "UI Plugin"
DESCRIPTION = "A simple plugin demonstrating how plugin system can be used to extend Nanome capabilities"
CATEGORY = "File Import"
HAS_ADVANCED_OPTIONS = False
# Plugin
def menu_closed_callback(menu):
Logs.message("Menu closed: " + menu.title + " " + str(menu.enabled))
def menu_opened_callback(menu):
Logs.message("Menu opened: " + menu.title + " " + str(menu.enabled))
def slider_changed_callback(slider):
Logs.message("slider changed: " + str(slider.current_value))
def dropdown_callback(dropdown, item):
Logs.message("dropdown item selected: " + str(item.name))
def slider_released_callback(slider):
Logs.message("slider released: " + str(slider.current_value))
def text_changed_callback(textInput):
Logs.message("text input changed: " + str(textInput.input_text))
def text_submitted_callback(textInput):
Logs.message("text input submitted: " + str(textInput.input_text))
class UIPlugin(nanome.PluginInstance):
def create_callbacks(self):
def spawn_menu_callback(button):
Logs.message("button pressed: " + button.text.value.idle)
self.update_content(button)
self.spawn_sub_menu()
self.spawn_menu_callback = spawn_menu_callback
def hover_callback(button, hovered):
Logs.message("button hover: " + button.text.value.idle, hovered)
self.hover_callback = hover_callback
def select_button_callback(button):
button.selected = not button.selected
Logs.message("Prefab button pressed: " + button.text.value.idle + " " + str(button._content_id))
self.update_content(button)
self.select_button_callback = select_button_callback
def loading_bar_callback(button):
Logs.message("button pressed: " + button.text.value.idle)
self.loadingBar.percentage += .1
self.loadingBar.title = "TITLE"
self.loadingBar.description = "DESCRIPTION " + str(self.loadingBar.percentage)
self.update_content(self.loadingBar)
self.loading_bar_callback = loading_bar_callback
def start(self):
self.integration.import_file = self.import_file
Logs.message("Start UI Plugin")
self.create_callbacks()
def import_file(self, request):
self.on_run()
def on_run(self):
Logs.message("Run UI Plugin")
menu = self.rebuild_menu()
self.update_menu(menu)
def rebuild_menu(self):
self.menu = nanome.ui.Menu()
menu = self.menu
menu.title = "Example UI Plugin"
menu.width = 1.0
menu.height = 1.0
menu.register_closed_callback(menu_closed_callback)
self.tab1 = self.create_tab1()
self.tab2 = self.create_tab2()
self.tab2.enabled = False
self.tab_buttons = self.create_tab_buttons()
menu.root.add_child(self.tab_buttons)
self.tabs = menu.root.create_child_node()
self.tabs.add_child(self.tab1)
self.tabs.add_child(self.tab2)
return menu
def spawn_sub_menu(self):
menu = nanome.api.ui.Menu(self.menu_index, "Menu " + str(self.menu_index))
menu.register_closed_callback(menu_closed_callback)
menu.width = 0.5
menu.height = 0.5
if self.previous_menu != None:
ln = self.previous_menu.root.create_child_node()
ln.add_new_label(str(self.menu_index - 1))
self.update_menu(self.previous_menu)
root = menu.root
button_node = root.create_child_node("button_node")
button = button_node.add_new_button("button")
button.register_pressed_callback(self.select_button_callback)
self.update_menu(menu)
self.menu_index += 1
self.previous_menu = menu
def create_tab1(self):
self.menu_index = 1
self.previous_menu = None
content = nanome.ui.LayoutNode()
ln_contentBase = nanome.ui.LayoutNode()
ln_label = nanome.ui.LayoutNode()
ln_button = nanome.ui.LayoutNode()
ln_slider = nanome.ui.LayoutNode()
ln_textInput = nanome.ui.LayoutNode()
ln_list = nanome.ui.LayoutNode()
content.forward_dist = .02
content.layer = 1
ln_label.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_label.padding = (0.01, 0.01, 0.01, 0.01)
ln_label.forward_dist = .001
label = nanome.ui.Label()
label.text_value = "Press the button..."
label.text_color = nanome.util.Color.White()
Logs.message("Added Label")
ln_button.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_button.padding = (0.01, 0.01, 0.01, 0.01)
ln_button.forward_dist = .001
#super styled button
button = nanome.ui.Button()
button.name = "OpenSubMenu"
b_t = button.text
b_t.active = True
b_t.value.set_all("Spawn menu")
b_t.auto_size = False
b_t.size = .6
b_t.underlined = True
b_t.ellipsis = True
b_t.color.idle = nanome.util.Color.Red()
b_t.color.highlighted = nanome.util.Color.Blue()
b_t.bold.set_all(False)
b_t.padding_left = .5
b_t.vertical_align = nanome.util.enums.VertAlignOptions.Middle
b_t.horizontal_align = nanome.util.enums.HorizAlignOptions.Left
b_m = button.mesh
b_m.active = True
b_m.color.idle = nanome.util.Color.Blue()
b_m.color.highlighted = nanome.util.Color.Red()
b_o = button.outline
b_o.active = True
b_o.color.idle = nanome.util.Color.Red()
b_o.color.highlighted = nanome.util.Color.Blue()
b_t = button.tooltip
b_t.title = "spawn a submenu"
b_t.content = "it is useless"
b_t.positioning_target = nanome.util.enums.ToolTipPositioning.center
button.register_pressed_callback(self.spawn_menu_callback)
button.register_hover_callback(self.hover_callback)
Logs.message("Added button")
ln_slider.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_slider.padding = (0.01, 0.01, 0.01, 0.01)
ln_slider.forward_dist = .001
slider = nanome.ui.Slider()
slider.register_changed_callback(slider_changed_callback)
slider.register_released_callback(slider_released_callback)
Logs.message("Added slider")
ln_textInput.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_textInput.padding = (0.01, 0.01, 0.01, 0.01)
ln_textInput.forward_dist = .001
textInput = nanome.ui.TextInput()
textInput.max_length = 30
textInput.register_changed_callback(text_changed_callback)
textInput.register_submitted_callback(text_submitted_callback)
textInput.number = True
textInput.text_color = nanome.util.Color.Blue()
textInput.placeholder_text_color = nanome.util.Color.Red()
textInput.background_color = nanome.util.Color.Grey()
textInput.text_horizontal_align = nanome.ui.TextInput.HorizAlignOptions.Right
textInput.padding_right = .2
textInput.text_size = .6
Logs.message("Added text input")
ln_list.sizing_type = nanome.ui.LayoutNode.SizingTypes.ratio
ln_list.sizing_value = 0.5
ln_list.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_list.padding = (0.01, 0.01, 0.01, 0.01)
ln_list.forward_dist = .03
prefab = nanome.ui.LayoutNode()
prefab.layout_orientation = nanome.ui.LayoutNode.LayoutTypes.vertical
child1 = nanome.ui.LayoutNode()
child1.sizing_type = nanome.ui.LayoutNode.SizingTypes.ratio
child1.sizing_value = .3
child1.name = "label"
child1.forward_dist = .01
child2 = nanome.ui.LayoutNode()
child2.name = "button"
child2.forward_dist =.01
prefab.add_child(child1)
prefab.add_child(child2)
prefabLabel = nanome.ui.Label()
prefabLabel.text_value = "Molecule Label"
prefabButton = nanome.ui.Button()
prefabButton.text.active = True
prefabButton.text.value.set_all("Molecule Button")
prefabButton.disable_on_press = True
prefabButton.register_pressed_callback(self.select_button_callback)
child1.set_content(prefabLabel)
child2.set_content(prefabButton)
list_content = []
for i in range(0, 10):
clone = prefab.clone()
list_content.append(clone)
list = nanome.ui.UIList()
list.display_columns = 1
list.display_rows = 1
list.total_columns = 1
list.items = list_content
Logs.message("Added list")
content.add_child(ln_contentBase)
ln_contentBase.add_child(ln_label)
ln_contentBase.add_child(ln_button)
ln_contentBase.add_child(ln_slider)
ln_contentBase.add_child(ln_textInput)
ln_contentBase.add_child(ln_list)
ln_label.set_content(label)
ln_button.set_content(button)
ln_slider.set_content(slider)
ln_textInput.set_content(textInput)
ln_list.set_content(list)
return content
def create_tab2(self):
content = nanome.ui.LayoutNode()
ln_contentBase = nanome.ui.LayoutNode()
ln_label = nanome.ui.LayoutNode()
ln_button = nanome.ui.LayoutNode()
ln_dropdown = nanome.ui.LayoutNode()
ln_textInput = nanome.ui.LayoutNode()
content.forward_dist = .02
content.layer = 1
ln_label.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_label.padding = (0.01, 0.01, 0.01, 0.01)
ln_label.forward_dist = .001
label = nanome.ui.Label()
label.text_value = "Press the button..."
label.text_color = nanome.util.Color.White()
Logs.message("Added Label")
ln_button.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_button.padding = (0.01, 0.01, 0.01, 0.01)
ln_button.forward_dist = .001
button = ln_button.add_new_toggle_switch("Toggle Switch")
button.text.size = .5
button.text.auto_size = False
button.register_pressed_callback(self.loading_bar_callback)
button.register_hover_callback(self.hover_callback)
Logs.message("Added button")
ln_dropdown.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_dropdown.padding = (0.01, 0.01, 0.01, 0.01)
ln_dropdown.forward_dist = .004
dropdown = nanome.ui.Dropdown()
dropdown.items = [nanome.ui.DropdownItem(name) for name in ["option1", "option2", "option3", "option4", "option5", "option6"]]
dropdown.register_item_clicked_callback(dropdown_callback)
Logs.message("Added dropdown")
ln_textInput.padding_type = nanome.ui.LayoutNode.PaddingTypes.ratio
ln_textInput.padding = (0.01, 0.01, 0.01, 0.01)
ln_textInput.forward_dist = .001
textInput = nanome.ui.TextInput()
textInput.max_length = 30
textInput.register_changed_callback(text_changed_callback)
textInput.register_submitted_callback(text_submitted_callback)
textInput.password = True
textInput.input_text = "hello"
Logs.message("Added text input")
prefab = nanome.ui.LayoutNode()
prefab.layout_orientation = nanome.ui.LayoutNode.LayoutTypes.vertical
child1 = nanome.ui.LayoutNode()
child1.sizing_type = nanome.ui.LayoutNode.SizingTypes.ratio
child1.sizing_value = .3
child1.name = "label"
child1.forward_dist = .01
child2 = nanome.ui.LayoutNode()
child2.name = "button"
child2.forward_dist =.01
prefab.add_child(child1)
prefab.add_child(child2)
prefabLabel = nanome.ui.Label()
prefabLabel.text_value = "Molecule Label"
prefabButton = nanome.ui.Button()
prefabButton.text.active = True
prefabButton.text.value.set_all("Molecule Button")
prefabButton.register_pressed_callback(self.select_button_callback)
child1.set_content(prefabLabel)
child2.set_content(prefabButton)
ln_loading_bar = nanome.ui.LayoutNode(name="LoadingBar")
ln_loading_bar.forward_dist = .003
self.loadingBar = ln_loading_bar.add_new_loading_bar()
content.add_child(ln_contentBase)
ln_contentBase.add_child(ln_label)
ln_contentBase.add_child(ln_button)
ln_contentBase.add_child(ln_dropdown)
ln_contentBase.add_child(ln_textInput)
ln_contentBase.add_child(ln_loading_bar)
ln_label.set_content(label)
ln_button.set_content(button)
ln_dropdown.set_content(dropdown)
ln_textInput.set_content(textInput)
return content
def create_tab_buttons(self):
LN = nanome.ui.LayoutNode
ln = LN()
ln.layout_orientation = nanome.util.enums.LayoutTypes.horizontal
ln._sizing_type = nanome.util.enums.SizingTypes.fixed
ln._sizing_value = .1
def tab1_callback(button):
self.tab_button1.selected = True
self.tab_button2.selected = False
self.tab1.enabled = True
self.tab2.enabled = False
self.update_node(self.tabs)
self.update_content(self.tab_button1, self.tab_button2)
def tab2_callback(button):
self.tab_button2.selected = True
self.tab_button1.selected = False
self.tab2.enabled = True
self.tab1.enabled = False
self.update_node(self.tabs)
self.update_content([self.tab_button2, self.tab_button1])
tab_button_node1 = ln.create_child_node("tab1")
self.tab_button1 = tab_button_node1.add_new_button("tab1")
self.tab_button1.register_pressed_callback(tab1_callback)
tab_button_node2 = ln.create_child_node("tab2")
self.tab_button2 = tab_button_node2.add_new_button("tab2")
self.tab_button2.register_pressed_callback(tab2_callback)
return ln
def __init__(self):
pass
permissions = [nanome.util.enums.Permissions.local_files_access]
integrations = [nanome.util.enums.Integrations.minimization, nanome.util.enums.Integrations.structure_prep]
nanome.Plugin.setup(NAME, DESCRIPTION, CATEGORY, HAS_ADVANCED_OPTIONS, UIPlugin, permissions=permissions, integrations=integrations)
Z-fighting problem¶
A known problem, called z-fighting, is the following:

If you look closely, you will see that the text intersects with its background. This happens when two objects are exactly on the same plan.
To fix this issue, try to set the forward_dist
of your foreground element (here, the text)
Files API¶
Here is a simple example of File API usage, requesting directory and files, and writing files on Nanome machine.
import nanome
class FilesAPITest(nanome.PluginInstance):
def on_run(self):
self.request_directory(".", self.on_directory_received) # Request all content of "." directory (where Nanome is installed)
def on_directory_received(self, result):
if result.error_code != nanome.util.DirectoryErrorCode.no_error: # If API couldn't access directory, display error
nanome.util.Logs.error("Directory request error:", str(result.error_code))
return
# For each entry in directory, display name and if directory
for entry in result.entry_array:
nanome.util.Logs.debug(entry.name, "Is Directory?", entry.is_directory)
self.request_files(["./api_bad_test.txt", "api_test.txt"], self.on_files_received) # Read two files
def on_files_received(self, file_list):
# For each file we read, display if error, and file content
for file in file_list:
nanome.util.Logs.debug("Error?", str(nanome.util.FileErrorCode(file.error_code)), "Content:", file.data)
# Prepare to write file "api_test.txt", with content "AAAA"
file = nanome.util.FileSaveData()
file.path = "./api_test.txt"
file.write_text("AAAA")
self.save_files([file], self.on_save_files_result) # Write file
def on_save_files_result(self, result_list):
# Check for writing errors
for result in result_list:
nanome.util.Logs.debug("Saving", result.path, "Error?", str(nanome.util.FileErrorCode(result.error_code)))
if __name__ == "__main__":
plugin = nanome.Plugin("Example File API", "Test File API by reading current directory, reading api_test.txt and api_bad_test.txt and modifying api_test.txt", "Examples", False)
plugin.set_plugin_class(FilesAPITest)
plugin.run()
Notifications API¶
Send a Notification of each type to the user¶
def on_run(self):
self.send_notification(nanome.util.enums.NotificationTypes.error, "There was an error")
self.send_notification(nanome.util.enums.NotificationTypes.message, "This is a message for the user")
self.send_notification(nanome.util.enums.NotificationTypes.success, "Something good might have happened)
self.send_notification(nanome.util.enums.NotificationTypes.warning, "Something bad might have happened")
Class reference¶
When importing nanome, the “api” module is flattened, meaning that plugin_instance can be referred to as “nanome.plugin_instance” or “nanome.api.plugin_instance”
nanome¶
nanome package¶
Subpackages¶
-
class
Shape
(shape_type)[source]¶ Bases:
nanome._internal._shapes._shape._Shape
Base class of a shape. Used in self.create_shape(shape_type) in plugins.Parameters: shape_type ( ShapeType
) – Enumerator representing the shape_type to create-
anchors
¶ - Anchors of the shape
Parameters: value (list of Anchor
) – Anchors of the shape
-
color
¶ - Color of the shape
Parameters: value ( Color
) – Color of the shape
-
index
¶ - Index of the shape
-
-
class
Stream
(network, id, data_type, direction)[source]¶ Bases:
object
Class allowing a update or read properties of a lot of structuresCreated by callingcreate_writing_stream()
orcreate_reading_stream()
When created, a stream is linked to a number of structures. Each call toupdate()
will update all these structures-
DataType
¶ alias of
nanome.util.enums.StreamDataType
-
Direction
¶ alias of
nanome.util.enums.StreamDirection
-
Type
¶ alias of
nanome.util.enums.StreamType
-
set_on_interrupt_callback
(callback)[source]¶ - Sets the function to call if the stream gets interrupted (crash)
-
-
class
ComplexIO
(base_object=None)[source]¶ Bases:
nanome._internal._addon._Addon
-
class
MMCIFSaveOptions
¶ Bases:
object
Options for saving MMCIF files.Includes options for writing:- hydrogens- only selected atoms
-
class
PDBSaveOptions
¶ Bases:
object
Options for saving PDB files.Includes options for writing:- hydrogens- TER records- bonds- heterogen bonds- only selected atoms
-
class
SDFSaveOptions
¶ Bases:
object
Options for saving SDF files.Includes options for writing:- all bonds- heterogen bonds
-
from_mmcif
(**kwargs)[source]¶ - Loads the complex from a .cif file
Returns: The complex read from the file
Return type: Complex
Parameters: kwargs – See below
Keyword Arguments:
-
from_pdb
(**kwargs)[source]¶ - Loads the complex from a .pdb file
Returns: The complex read from the file
Return type: Complex
Parameters: kwargs – See below
Keyword Arguments:
-
from_sdf
(**kwargs)[source]¶ - Loads the complex from a .sdf file
Returns: The complex read from the file
Return type: Complex
Parameters: kwargs – See below
Keyword Arguments:
-
to_mmcif
(path, options=None)[source]¶ - Saves the complex into a .cif file
Parameters: - path (str) – Path to the file
- options (
MMCIFSaveOptions
) – Save options
-
to_pdb
(path, options=None)[source]¶ - Saves the complex into a .pdb file
Parameters: - path (str) – Path to the file
- options (
PDBSaveOptions
) – Save options
-
to_sdf
(path, options=None)[source]¶ - Saves the complex into a .sdf file
Parameters: - path (str) – Path to the file
- options (
SDFSaveOptions
) – Save options
-
class
-
class
Atom
[source]¶ Bases:
nanome._internal._structure._atom._Atom
,nanome.api.structure.base.Base
Represents an Atom-
class
AtomRenderingMode
¶ Bases:
enum.IntEnum
Shape types an atom can be rendered as.To be used with atom.atom_mode-
Adaptive
= 6¶
-
BFactor
= 5¶
-
BallStick
= 0¶
-
Point
= 4¶
-
Stick
= 1¶
-
VanDerWaals
= 3¶
-
Wire
= 2¶
-
-
class
Rendering
(parent)[source]¶ Bases:
object
-
atom_color
¶
-
atom_mode
¶
-
atom_rendering
¶
-
label_text
¶
-
labeled
¶
-
selected
¶
-
surface_color
¶
-
surface_opacity
¶
-
surface_rendering
¶
-
-
acceptor
¶
-
atom_color
¶ - Color of the atom
Type: Color
-
atom_mode
¶ - Represents how the atom should be shown, such as ball and point or wired.
Type: AtomRenderingMode
-
bfactor
¶
-
bonds
¶ - Bonds that the atom is part of
-
chain
¶ - Chain that the atom is part of
-
complex
¶ - Complex that the atom is part of
-
conformer_count
¶
-
current_conformer
¶
-
donor
¶
-
formal_charge
¶
-
in_conformer
¶
-
molecular
¶
-
molecule
¶ - Molecule that the atom is part of
-
occupancy
¶
-
partial_charge
¶
-
position
¶ - Position of the atom
Type: Vector3
-
positions
¶
-
rendering
¶
-
residue
¶ - Residue that the atom is part of
-
serial
¶
-
surface_color
¶ - Color of the atom surface
Type: Color
-
class
-
class
Bond
[source]¶ Bases:
nanome._internal._structure._bond._Bond
,nanome.api.structure.base.Base
Represents a Bond between two atoms-
class
Kind
¶ Bases:
enum.IntEnum
Bond types.To be used with bond.kind and elements of bond.kinds-
Aromatic
= 4¶
-
CovalentDouble
= 2¶
-
CovalentSingle
= 1¶
-
CovalentTriple
= 3¶
-
Unknown
= 0¶
-
-
atom1
¶ First atom linked by this bond
Type: Atom
-
atom2
¶ Second atom linked by this bond
Type: Atom
-
chain
¶ - Chain that the bond is part of
-
complex
¶ - Complex that the bond is part of
-
conformer_count
¶
-
current_conformer
¶
-
in_conformer
¶
-
kinds
¶
-
molecular
¶
-
molecule
¶ - Molecule that the bond is part of
-
residue
¶ - Residue that the bond is part of
-
class
-
class
Chain
[source]¶ Bases:
nanome._internal._structure._chain._Chain
,nanome.api.structure.base.Base
Represents a Chain. Contains residues. Molecules contains chains.-
add_residue
(residue)[source]¶ - Add a residue to this chain
Parameters: residue ( Residue
) – Residue to add to the chain
-
atoms
¶ - The list of atoms that this chain’s residues contain
-
bonds
¶ - The list of bonds within this chain
-
complex
¶ - Complex that this chain is in
-
molecular
¶
-
molecule
¶ - Molecule that this chain is in
-
remove_residue
(residue)[source]¶ - Remove a residue from this chain
Parameters: residue ( Residue
) – Residue to remove from the chain
-
residues
¶ - The list of residues that this chain contains
-
-
class
Complex
[source]¶ Bases:
nanome._internal._structure._complex._Complex
,nanome.api.structure.base.Base
Represents a Complex that contains molecules.-
class
Rendering
(parent)[source]¶ Bases:
object
-
box_label
¶
-
boxed
¶
-
computing
¶
-
current_frame
¶
-
locked
¶
-
visible
¶
-
-
add_molecule
(molecule)[source]¶ - Add a molecule to this complex
Parameters: molecule ( Molecule
) – Molecule to add to the chain
-
atoms
¶ - The list of atoms within this complex
-
bonds
¶ - The list of bonds within this complex
-
chains
¶ - The list of chains within this complex
-
computing
¶
-
index_tag
¶
-
io
= <nanome.api.structure.io.complex_io.ComplexIO object>¶
-
molecular
¶
-
molecules
¶ - The list of molecules within this complex
-
position
¶ - Position of the complex
Type: Vector3
-
remove_molecule
(molecule)[source]¶ - Remove a molecule from this complex
Parameters: molecule ( Molecule
) – Molecule to remove from the chain
-
rendering
¶
-
residues
¶ - The list of residues within this complex
-
rotation
¶ - Rotation of the complex
Type: Quaternion
-
split_tag
¶
-
transform
¶
-
class
-
class
Molecule
[source]¶ Bases:
nanome._internal._structure._molecule._Molecule
,nanome.api.structure.base.Base
Represents a molecule. Contains chains.-
add_chain
(chain)[source]¶ - Add a chain to this molecule
Parameters: chain ( Chain
) – Chain to add to the molecule
-
associateds
¶
-
atoms
¶ - The atoms of this complex
Type: generator
<Atom
>
-
bonds
¶ - The bonds of this complex
Type: generator
<Bond
>
-
chains
¶ - The chains of this complex
Type: generator
<Chain
>
-
complex
¶ - Complex that the molecule belongs to
-
conformer_count
¶
-
current_conformer
¶
-
molecular
¶
-
names
¶
-
remove_chain
(chain)[source]¶ - Remove a chain from this molecule
Parameters: chain ( Chain
) – Chain to remove from the molecule
-
residues
¶ - The residues of this complex
Type: generator
<Residue
>
-
-
class
Residue
[source]¶ Bases:
nanome._internal._structure._residue._Residue
,nanome.api.structure.base.Base
Represents a Residue. Contains atoms. Chains contain residues.-
class
Rendering
(parent)[source]¶ Bases:
object
-
label_text
¶
-
labeled
¶
-
ribbon_color
¶
-
ribbon_mode
¶
-
ribbon_size
¶
-
ribboned
¶
-
-
class
RibbonMode
¶ Bases:
enum.IntEnum
Ribbon display modes.To be used with structure.Residue().ribbon_mode-
AdaptiveTube
= 1¶
-
Coil
= 2¶
-
SecondaryStructure
= 0¶
-
-
class
SecondaryStructure
¶ Bases:
enum.IntEnum
Secondary structure types.To be used with structure.Residue().secondary_structure-
Coil
= 1¶
-
Helix
= 3¶
-
Sheet
= 2¶
-
Unknown
= 0¶
-
-
add_atom
(atom)[source]¶ - Add an atom to this residue
Parameters: atom ( Atom
) – Atom to add to the residue
-
add_bond
(bond)[source]¶ - Add a bond to this residue
Parameters: bond ( Bond
) – Bond to add to the residue
-
atoms
¶ - The list of atoms within this complex
-
bonds
¶ - The list of bonds within this complex
-
chain
¶ - Chain that the residue is part of
-
complex
¶ - Complex that the residue is part of
-
molecular
¶
-
molecule
¶ - Molecule that the residue is part of
-
remove_atom
(atom)[source]¶ - Remove an atom from this residue
Parameters: atom ( Atom
) – Atom to remove from the residue
-
remove_bond
(bond)[source]¶ - Remove a bond from this residue
Parameters: bond ( Bond
) – Bond to remove from the residue
-
rendering
¶
-
ribbon_color
¶ - Color of the ribbon residue
Type: Color
-
ribbon_mode
¶ - Represents how the residue ribbon should be shown
Type: RibbonMode
-
ribbon_size
¶
-
ribboned
¶
-
secondary_structure
¶ - The secondary structure of the residue
Type: SecondaryStructure
-
serial
¶
-
type
¶
-
class
-
class
Workspace
[source]¶ Bases:
nanome._internal._structure._workspace._Workspace
Workspace that contains all the complexes shown in Nanome.-
add_complex
(complex)[source]¶ - Add complex to the workspace
Parameters: complex ( Complex
) – Complex to add to the workspace
-
client
= <nanome.api.structure.client.workspace_client.WorkspaceClient object>¶
-
complexes
¶ - The list of complexes within the workspace
Type: list of Complex
-
position
¶ - Position of the workspace
Type: Vector3
-
remove_complex
(complex)[source]¶ - Remove complex from the workspace
Parameters: complex ( Complex
) – Complex to remove from the workspace
-
rotation
¶ - Rotation of the workspace
Type: Quaternion
-
scale
¶ - Scale of the workspace
Type: Vector3
-
transform
¶
-
-
class
LayoutNodeIO
(base_object=None)[source]¶ Bases:
nanome._internal._addon._Addon
A class for json serialization and parsing of LayoutNode objects.Parameters: base_object ( LayoutNode
) – The LayoutNode to serialize
Bases:
nanome._internal._ui._button._Button
,nanome.api.ui.ui_base.UIBase
Represents a clickable button on a menuBases:
nanome._internal._ui._button._ButtonIcon
- Whether or not the icon is visible
Type: bool
- The color of the image by button state.
Type: MultiStateVariable
- The position of the iconA position of (1, 1, 1) represents right, top, front,whereas (0, 0, 0) represents the middle.
Type: tuple
<float
,float
,float
>
- The ratio of height to height + width for the icon.A size of 0.5 represents equal width and height
Type: float
- The rotation of the icon about each axis.A position of (90, 90, 90) represents a quarter rotationabout each of the X, Y and Z axes, whereas (0, 0, 0) represents no rotation.
Type: tuple
<float
,float
,float
>
- The sharpness of the icon image (between 0 and 1)
Type: float
- The size of the icon imageA size of 1 represents the full size.
Type: float
- The file paths to the icon image by button state.
Type: MultiStateVariable
Bases:
nanome._internal._ui._button._ButtonMesh
- Whether or not the mesh is visible
Type: bool
- The color of the mesh by button state
Type: MultiStateVariable
- Whether or not the mesh is visible by button state
Type: MultiStateVariable
Bases:
nanome._internal._ui._button._ButtonOutline
- Whether or not the outline is visible
Type: bool
- The line thickness of the outline by button state
Type: MultiStateVariable
Bases:
nanome._internal._ui._button._ButtonSwitch
- Whether or not the button is visible
Type: bool
- The color for the button when it is off
Type: Color
- The color for the button when it is on
Type: Color
Bases:
nanome._internal._ui._button._ButtonText
- Whether or not the button text is visible
Type: bool
- Whether or not to automatically scale the font size of the textbased on the size of the button
Type: bool
- Whether or not the text is bold by button state
Type: MultiStateVariable
- The color of the text by button state
Type: MultiStateVariable
- Whether or not to use an ellipsis if there is too much text to display
Type: bool
- The horizontal alignment of the text
Type: HorizAlignOptions
- The space between lines of text
Type: float
- The maximum font size the text will displayThis is the upper bound for auto sizing.
Type: float
- The minimum font size the text will displayThis is the lower bound for auto sizing.
Type: float
- The padding below the text
Type: float
- The padding to the left of the text
Type: float
- The padding to the right of the text
Type: float
- The padding above the text
Type: float
- The font size of the text displayed
Type: float
- Whether or not the button text is underlined.
Type: bool
- The text displayed by button state
Type: MultiStateVariable
- The vertical alignment of the text
Type: VertAlignOptions
Bases:
nanome._internal._ui._button._ButtonTooltip
- The main textual content of the tooltip
Type: str
- Determines which part of the tooltip is closest to the button (target)Refers to the tooltip
Type: ToolTipPositioning
- Determines which side of the button the tooltip (origin) will appear onRefers to the tooltip’s button
Type: ToolTipPositioning
- The title of the tooltip
Type: str
Bases:
enum.IntEnum
Horizontal alignment modes for text.To be used with ui.Label().text_horizontal_align and ui.Button().horizontal_align
Bases:
nanome._internal._ui._button._MultiStateVariable
- Represents the highlighted state where the element is being hovered
Type: Any
- Represents the idle state where the element is not being hovered and is not selected
Type: Any
- Represents the highlighted state where the element has been selected
Type: Any
- Represents the selected, highlighted state where the element has been selected and is being hovered over
Type: Any
- Sets the value for every state
- Sets the value for each state
- Represents the unusable state where the element cannot be interacted with
Type: Any
Bases:
enum.IntEnum
Vertical alignment modes for text.To be used with ui.Label().text_vertical_align and ui.Button().vertical_align
- Whether or not to disable the button after it has been pressed once.
Type: bool
- The name of the button
Type: str
- Registers a function to be called when the button is hovered over
Parameters: func (method ( Button
) -> None) – called when a button is hovered over
- Registers a function to be called when the button is pressed/clicked
Parameters: func (method ( Button
) -> None) – called when a button is pressed
- Whether or not the button is selectedCorresponds to a potentially visually distinct UI state
Type: bool
- Whether or not to toggle the selected state of the button when it is pressed.
Type: bool
- Whether or not the button is unusableCorresponds to a potentially visually distinct UI state
Type: bool
-
class
Dropdown
[source]¶ Bases:
nanome._internal._ui._dropdown._Dropdown
,nanome.api.ui.ui_base.UIBase
Represents a dropdown menu-
max_displayed_items
¶ - The maximum number of items to display at a timeIf there are more items in the dropdown than this value,a scrollbar will be appear on the dropdown.
Type: int
-
-
class
DropdownItem
(name='item')[source]¶ Bases:
nanome._internal._ui._dropdown_item._DropdownItem
Represents a dropdown item in a dropdown menu-
close_on_selected
¶ - Whether or not this item will close the Dropdown after being selectedSetting this value to false can allows for multiple items to be selected.
Type: bool
-
-
class
Image
(file_path='')[source]¶ Bases:
nanome._internal._ui._image._Image
,nanome.api.ui.ui_base.UIBase
Represents an image in a menu-
class
ScalingOptions
¶ Bases:
enum.IntEnum
Ways for an image to scale.To be used with ui.Image().scaling_option-
fill
= 1¶
-
fit
= 2¶
-
stretch
= 0¶
-
-
color
¶ - The color of the image
Type: Color
-
file_path
¶ - The file path to the image.Setting this and calling update_content will change the image.
Type: str
-
register_held_callback
(func)[source]¶ - Registers a function to be called rapidly while the image is being pressed
Parameters: func (method ( Image
,int
,int
) -> None) – called while the image is being pressed
-
register_pressed_callback
(func)[source]¶ - Registers a function to be called when the image is pressed
Parameters: func (method ( Image
,int
,int
) -> None) – called the image is pressed
-
register_released_callback
(func)[source]¶ - Registers a function to be called when the image is released
Parameters: func (method ( Image
,int
,int
) -> None) – called the image is released
-
scaling_option
¶ - Determines how the image scales.
Type: ScalingOptions
-
class
-
class
Label
(text=None)[source]¶ Bases:
nanome._internal._ui._label._Label
,nanome.api.ui.ui_base.UIBase
Represents a label that cannot be interacted with in a menu-
class
HorizAlignOptions
¶ Bases:
enum.IntEnum
Horizontal alignment modes for text.To be used with ui.Label().text_horizontal_align and ui.Button().horizontal_align-
Left
= 0¶
-
Middle
= 1¶
-
Right
= 2¶
-
-
class
VertAlignOptions
¶ Bases:
enum.IntEnum
Vertical alignment modes for text.To be used with ui.Label().text_vertical_align and ui.Button().vertical_align-
Bottom
= 2¶
-
Middle
= 1¶
-
Top
= 0¶
-
-
text_color
¶ - The color of the text on this label
Type: Color
-
text_horizontal_align
¶ - The horizontal alignment of the text
Type: HorizAlignOptions
-
text_max_size
¶ - The maximum font size the text will displayThis is the upper bound for auto sizing.
Type: float
-
text_min_size
¶ - The minimum font size the text will displayThis is the lower bound for auto sizing.
Type: float
-
text_vertical_align
¶ - The vertical alignment of the text
Type: VertAlignOptions
-
class
-
class
LayoutNode
(name='node')[source]¶ Bases:
nanome._internal._ui._layout_node._LayoutNode
Class for hierarchical UI objects representing part of a Nanome menu.Layout nodes are used to create menus, by defining where one UI element should be placed relative to another.One LayoutNode can contain one interactive UI element as well as any number of child Layout Nodes.Parameters: name ( str
) – Name of the node, used to identify it and find it later-
class
LayoutTypes
¶ Bases:
enum.IntEnum
Orientation modes for Layout Nodes.To be used with ui.LayoutNode().layout_orientation-
horizontal
= 1¶
-
vertical
= 0¶
-
-
class
PaddingTypes
¶ Bases:
enum.IntEnum
UI padding types.To be used with ui.LayoutNode().padding_type-
fixed
= 0¶
-
ratio
= 1¶
-
-
class
SizingTypes
¶ Bases:
enum.IntEnum
Ways in which a Layout Node can be sized within a UI layout.To be used with ui.LayoutNode().sizing_type-
expand
= 0¶
-
fixed
= 1¶
-
ratio
= 2¶
-
-
enabled
¶ - Defines if layout node is visible.If disabled, it will not influence the menu layout.
Type: bool
-
find_node
(name, recursively=True)[source]¶ - Checks child nodes for a node of the matching name.If “recursively” is True, this also checks all descending nodes.
Parameters: name (str) – Name of the node to find. Returns: LayoutNode with matching name Return type: LayoutNode
-
io
= <nanome.api.ui.io.layout_node_io.LayoutNodeIO object>¶
-
layer
¶ - The node layer. A node on layer 0 and another on layer 1 will be on different layouts, possibly overlapping
Type: int
-
layout_orientation
¶ - Defines if children node should be arranged vertically or horizontally
Type: LayoutOrientation
-
padding
¶
-
padding_type
¶ - The padding type of the LayoutNode.
Type: PaddingTypes
-
parent
¶
-
sizing_type
¶ - Defines how the node size in the layout should be calculated
Type: SizingTypes
-
sizing_value
¶ - Size of the node in its layout.Behavior is different depending of
sizing_type
Type: float
-
class
-
class
LoadingBar
[source]¶ Bases:
nanome._internal._ui._loading_bar._LoadingBar
,nanome.api.ui.ui_base.UIBase
Represents a loading bar that can display a percentage
-
class
Mesh
[source]¶ Bases:
nanome._internal._ui._mesh._Mesh
,nanome.api.ui.ui_base.UIBase
Represents a flat rectangular mesh with a solid color.-
mesh_color
¶ - The color of the mesh
Type: Color
-
-
class
Slider
(min_val=None, max_val=None, current_val=None)[source]¶ Bases:
nanome._internal._ui._slider._Slider
,nanome.api.ui.ui_base.UIBase
Represents a slider that has a set range of values
-
class
TextInput
[source]¶ Bases:
nanome._internal._ui._text_input._TextInput
,nanome.api.ui.ui_base.UIBase
Represents a text input, where the user can input text-
class
HorizAlignOptions
¶ Bases:
enum.IntEnum
Horizontal alignment modes for text.To be used with ui.Label().text_horizontal_align and ui.Button().horizontal_align-
Left
= 0¶
-
Middle
= 1¶
-
Right
= 2¶
-
-
background_color
¶ - The color of the background of this text input
Type: Color
-
number
¶ - Whether or not the input represents a number.Will display the number keyboard if set to true.
Type: bool
-
password
¶ - Whether or not the input represents a password.i.e. will display 123 as *** if true.
Type: bool
-
placeholder_text_color
¶ - Color of the placeholder text
Type: Color
-
register_changed_callback
(func)[source]¶ - Registers a function to be called whenever the text input is changed.The function must take a text input as its only parameter.
Parameters: func – The function that will be called when the text input is changed.
-
register_submitted_callback
(func)[source]¶ - Registers a function to be called whenever the user submits a text input.The function must take a text input as its only parameter.
Parameters: func – The function that will be called when the user submits a text input.
-
text_color
¶ - The color of the input text
Type: Color
-
text_horizontal_align
¶ - The horizontal alignment of the input and placeholder text
Type: HorizAlignOptions
-
class
-
class
UIList
[source]¶ Bases:
nanome._internal._ui._ui_list._UIList
,nanome.api.ui.ui_base.UIBase
A class representing a list of UI elements.
-
class
Files
(plugin_instance)[source]¶ Bases:
nanome._internal._files._Files
Class to navigate through files and directories on the machine running Nanome using unix-like filesystem methods.-
get
(source, dest, callback=None)[source]¶ - Gets file source from the Nanome session’s machine and writes to dest of the plugin machine.
Parameters:
-
mv
(source, dest, callback=None)[source]¶ - Rename source to dest, or move source into directory dest/
Parameters:
-
put
(source, dest, callback=None)[source]¶ - Send the file source on the plugin machine to be placed at dest on the Nanome session’s machine.
Parameters:
-
pwd
(callback=None)[source]¶ - Print the absolute path of the current working directory
Parameters: callback (method ( FileError
, str) -> None) – function that will be called with the full working directory path
-
-
class
Plugin
(name, description, tags=[], has_advanced=False, permissions=[], integrations=[])[source]¶ Bases:
nanome._internal._plugin._Plugin
Core class of any Plugin.Manages network, callbacks and APIsParameters: -
post_run
¶ - Function to call when the plugin is about to exitUseful when using autoreload
-
pre_run
¶ - Function to call before the plugin runs and tries to connect to NTSUseful when using autoreload
-
run
(host='config', port='config', key='config')[source]¶ - Starts the plugin by connecting to the server specified.If arguments (-a, -p) are given when starting plugin, host/port will be ignored.Function will return only when plugin exits.
Parameters:
-
static
set_custom_data
(*args)[source]¶ - Store arbitrary data to send to plugin instances
Parameters: args (Anything serializable) – Variable length argument list
-
-
class
AsyncPluginInstance
[source]¶ Bases:
nanome.api.plugin_instance.PluginInstance
Base class of any asynchronous plugin.Constructor should never be called by the user as it is network-instantiated when a session connects.All methods available to PluginInstance are available to AsyncPluginInstance.Decorating these methods with @async_callback will allow them to use the async keyword in their definition-
is_async
= True¶
-
-
class
PluginInstance
[source]¶ Bases:
nanome._internal._plugin_instance._PluginInstance
Base class of any plugin.Constructor should never be called by the user as it is network-instantiated when a session connects.Start, update, and all methods starting by “on” can be overridden by user, in order to get requests results-
add_bonds
(complex_list, callback=None, fast_mode=None)[source]¶ - Calculate bondsRequires openbabel to be installed
Parameters: - complex_list (list of
Complex
) – List of complexes to add bonds to - callback – Callable[[List[Complex]], None]
- complex_list (list of
-
add_dssp
(complex_list, callback=None)[source]¶ - Use DSSP to calculate secondary structures
Parameters: - complex_list (list of
Complex
) – List of complexes to add ribbons to - callback – Callable[[List[Complex]], None]
- complex_list (list of
-
add_to_workspace
(complex_list, callback=None)[source]¶ - Add a list of complexes to the current workspace
Parameters: complex_list (list of Complex
) – List of Complexes to add
-
apply_color_scheme
(color_scheme, target, only_carbons)[source]¶ Applies a color scheme to selected atoms.
Parameters: - color_scheme (
ColorScheme
) – the color scheme to use on atoms - target (
ColorSchemeTarget
) – whether you want to color the atom, the surface, or the ribbon - only_carbons (bool) – whether you want to only color carbons, or all atoms.
- color_scheme (
-
center_on_structures
(structures, callback=None)[source]¶ - Repositions the workspace such that the provided structure(s) will be in thecenter of the world.
Parameters: - structures (list of
Base
) – Molecular structure(s) to update. - callback – Callable[[], None]
- structures (list of
-
create_reading_stream
(indices_list, stream_type, callback=None)[source]¶ - Create a stream allowing the plugin to continuously receive properties of many objects
Parameters: - indices_list (list of
int
) – List of indices of all objects that should be in the stream - stream_type (list of
Type
) – Type of stream to create - callable – Callable[[Stream, StreamCreationError], None]
- indices_list (list of
-
create_writing_stream
(indices_list, stream_type, callback=None)[source]¶ - Create a stream allowing the plugin to continuously update properties of many objects
Parameters: - indices_list (list of
int
) – List of indices of all objects that should be in the stream - stream_type (list of
Type
) – Type of stream to create - callback – Callable[[Stream, StreamCreationError], None]
- indices_list (list of
-
custom_data
¶ Get custom data set with Plugin.set_custom_data
Type: tuple of objects or None if no data has been set
-
is_async
= False¶
-
open_url
(url)[source]¶ - Opens a URL alongside the Nanome session in the default web browser.
Parameters: url (str) – url to open
-
plugin_files_path
¶
-
request_complex_list
(callback=None)[source]¶ - Request the list of all complexes in the workspace, in shallow mode
kwarg callback: Callable[[List[Complex]], None]
-
request_complexes
(id_list, callback=None)[source]¶ - Requests a list of complexes by their indicesComplexes returned contains the full structure (atom/bond/residue/chain/molecule)
Parameters: id_list (list of int
) – List of indicesCallback: Callable[[List[Complex]], None]
-
request_controller_transforms
(callback=None)[source]¶ - Requests presenter controller info (head position, head rotation, left controller position, left controller rotation, right controller position, right controller rotation)
param callback: Callable[[Vector3, Quaternion, Vector3, Quaternion, Vector3, Quaternion], None]
-
request_export
(format, callback=None, entities=None)[source]¶ Request a file export using Nanome exporters Can request either molecule or workspace export, for entities in Nanome workspace or directly sent by the plugin (without begin uploaded to workspace)
Parameters: - format (
ExportFormats
) – File format to export - entities (list of or unique object of type
Workspace
orComplex
, or None, or list of or uniqueint
) – Entities to export (complexes to send, or indices if referencing complexes in workspace, or a workspace, or nothing if exporting Nanome workspace) - callback – Callable[[Union[str, bytes]], None]
- format (
- Requests spatial information of the plugin menu (position, rotation, scale)
Parameters: index (int) – Index of the menu you wish to read callback: Callable[[Vector3, Quaternion, Vector3], None]
-
request_presenter_info
(callback=None)[source]¶ - Requests presenter account info (unique ID, name, email)
callback: Callable[[PresenterInfo], None]
-
request_workspace
(callback=None)[source]¶ - Request the entire workspace, in deep mode
callback: Callable[[Workspace], None]
-
save_files
(file_list, callback=None)[source]¶ - Save files on the machine running Nanome, and returns result
Parameters: - file_list (list of
FileSaveData
) – List of files to save with their content - callable – Callable[[List[FileSaveData]], None]
- file_list (list of
-
send_files_to_load
(files_list, callback=None)[source]¶ - Send file(s) to Nanome to load directly using Nanome’s importers.Can send just a list of paths, or a list of tuples containing (path, name)
Parameters: files_list (list of or unique object of type str
or (str
,str
)) – List of files to load
-
send_notification
(type, message)[source]¶ - Send a notification to the user
Parameters: - type – Type of notification to send.
- message (str) – Text to display to the user.
- Update the position, scale, and rotation of the menu
Parameters: - index (int) – Index of the menu you wish to update
- position (
vector3
) – New position of the menu - rotation (
quaternion
) – New rotation of the menu - scale (
vector3
) – New scale of the menu
- Set text and/or usable state of the buttons on the plugin connection menu in Nanome
Parameters:
-
update_content
(*content)[source]¶ - Update specific UI elements (button, slider, list…)
Parameters: content ( UIBase
or multipleUIBase
or a list ofUIBase
) – UI elements to update
- Update the menu in Nanome
Parameters: menu ( Menu
) – Menu to update
-
update_node
(*nodes)[source]¶ - Updates layout nodes and their children
Parameters: nodes ( LayoutNode
or multipleLayoutNode
or a list ofLayoutNode
) – Layout nodes to update
-
update_structures_deep
(structures, callback=None)[source]¶ - Update the specific molecular structures in the scene to match the structures in parameter.Will also update descendent structures and can be used to remove descendent structures.
Parameters: structures (list of Base
) – List of molecular structures to update.callback: Callable[[], None]
-
update_structures_shallow
(structures)[source]¶ - Update the specific molecular structures in the scene to match the structures in parameterOnly updates the structure’s data, will not update children or other descendents.
Parameters: structures (list of Base
) – List of molecular structures to update.
-
-
class
Room
[source]¶ Bases:
nanome._internal._room._Room
Represents a room in Nanome
-
class
Color
(r=0, g=0, b=0, a=255, whole_num=None)[source]¶ Bases:
object
Represents a 32-bit color with red, green, blue and alpha channels (8 bits each).Parameters: -
classmethod
from_int
(value)[source]¶ - Set color from int after initializing.
Parameters: value ( int
) – Int value of the color
-
set_color_int
(num)[source]¶ - Assigns the color an integer value representingthe red component bitshifted 24 bits, bitwise ORed withthe green component bitshifted 16 bits, bitwise ORed withthe blue component bitshifted 8 bits, ORed withthe alpha component, or more simply:r << 24 | g << 16 | b << 8 | aOR0xRRGGBBAA
Parameters: num ( int
) – Number to set the color to
-
classmethod
-
class
MMCIFSaveOptions
[source]¶ Bases:
object
Options for saving MMCIF files.Includes options for writing:- hydrogens- only selected atoms
-
fetch
(key)[source]¶ - Fetch a configuration entry from your nanome configuration.Built-in keys are:host - your NTS server addressport - your NTS server portkey - your NTS key file or stringplugin_files_path - where your plugins will store files
Parameters: key ( str
) – The key of the config value to fetch
-
safe_cast
¶ classmethod(function) -> method
Convert a function to be a class method.
A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
- class C:
@classmethod def f(cls, arg1, arg2, …):
…
It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.
Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.
-
class
AtomRenderingMode
[source]¶ Bases:
enum.IntEnum
Shape types an atom can be rendered as.To be used with atom.atom_mode-
Adaptive
= 6¶
-
BFactor
= 5¶
-
BallStick
= 0¶
-
Point
= 4¶
-
Stick
= 1¶
-
VanDerWaals
= 3¶
-
Wire
= 2¶
-
-
class
ColorScheme
[source]¶ Bases:
enum.IntEnum
Color schemes for all structure representations.To be used with plugin_instance.apply_color_scheme-
BFactor
= 3¶
-
Chain
= 6¶
-
Chothia
= 14¶
-
DonorAcceptor
= 7¶
-
Element
= 4¶
-
Hydrophobicity
= 11¶
-
IMGT
= 12¶
-
Kabat
= 13¶
-
Monochrome
= 9¶
-
Occupancy
= 2¶
-
Rainbow
= 5¶
-
Residue
= 1¶
-
SecondaryStructure
= 8¶
-
YRBHydrophobicity
= 10¶
-
-
class
ColorSchemeTarget
[source]¶ Bases:
enum.IntEnum
Structure representations.To be used with plugin_instance.apply_color_scheme-
All
= 3¶
-
AtomBond
= 0¶
-
Ribbon
= 1¶
-
Surface
= 2¶
-
-
class
ExportFormats
[source]¶ Bases:
enum.IntEnum
File export formats.To be used with plugin_instance.request_export-
MMCIF
= 3¶
-
Nanome
= 0¶
-
PDB
= 1¶
-
SDF
= 2¶
-
SMILES
= 4¶
-
-
class
HorizAlignOptions
[source]¶ Bases:
enum.IntEnum
Horizontal alignment modes for text.To be used with ui.Label().text_horizontal_align and ui.Button().horizontal_align-
Left
= 0¶
-
Middle
= 1¶
-
Right
= 2¶
-
-
class
Integrations
[source]¶ Bases:
nanome.util.enums._CommandEnum
An enumeration.
-
calculate_esp
= 2¶
-
export_file
= 4¶
-
export_locations
= 5¶
-
generate_molecule_image
= 6¶
-
hydrogens
= 0¶
-
import_file
= 7¶
-
minimization
= 3¶
-
structure_prep
= 1¶
-
-
class
Kind
[source]¶ Bases:
enum.IntEnum
Bond types.To be used with bond.kind and elements of bond.kinds-
Aromatic
= 4¶
-
CovalentDouble
= 2¶
-
CovalentSingle
= 1¶
-
CovalentTriple
= 3¶
-
Unknown
= 0¶
-
-
class
LayoutTypes
[source]¶ Bases:
enum.IntEnum
Orientation modes for Layout Nodes.To be used with ui.LayoutNode().layout_orientation-
horizontal
= 1¶
-
vertical
= 0¶
-
-
class
LoadFileErrorCode
[source]¶ Bases:
enum.IntEnum
Errors when loading files into Nanome.Accessible via the first parameter of the ‘done’ callback for plugin_instance.send_files_to_load-
loading_failed
= 1¶
-
no_error
= 0¶
-
-
class
NotificationTypes
[source]¶ Bases:
enum.IntEnum
Types of user notifications.Each value exists as a method on nanome.util.Logs-
error
= 3¶
-
message
= 0¶
-
success
= 1¶
-
warning
= 2¶
-
-
class
PaddingTypes
[source]¶ Bases:
enum.IntEnum
UI padding types.To be used with ui.LayoutNode().padding_type-
fixed
= 0¶
-
ratio
= 1¶
-
-
class
Permissions
[source]¶ Bases:
nanome.util.enums._CommandEnum
An enumeration.
-
local_files_access
= 0¶
-
-
class
PluginListButtonType
[source]¶ Bases:
enum.IntEnum
Buttons on the plugin list, modifiable by the plugin itself.To be used with plugin_instance.set_plugin_list_button-
advanced_settings
= 1¶
-
run
= 0¶
-
-
class
RibbonMode
[source]¶ Bases:
enum.IntEnum
Ribbon display modes.To be used with structure.Residue().ribbon_mode-
AdaptiveTube
= 1¶
-
Coil
= 2¶
-
SecondaryStructure
= 0¶
-
-
class
ScalingOptions
[source]¶ Bases:
enum.IntEnum
Ways for an image to scale.To be used with ui.Image().scaling_option-
fill
= 1¶
-
fit
= 2¶
-
stretch
= 0¶
-
-
class
SecondaryStructure
[source]¶ Bases:
enum.IntEnum
Secondary structure types.To be used with structure.Residue().secondary_structure-
Coil
= 1¶
-
Helix
= 3¶
-
Sheet
= 2¶
-
Unknown
= 0¶
-
-
class
ShapeAnchorType
[source]¶ Bases:
enum.IntEnum
Object type to anchor a Shape to.To be used with shapes.Shape().anchors-
Atom
= 2¶
-
Complex
= 1¶
-
Workspace
= 0¶
-
-
class
ShapeType
[source]¶ Bases:
enum.IntEnum
Types of shapes that can be created within Nanome.Used internally-
Label
= 2¶
-
Line
= 1¶
-
Sphere
= 0¶
-
-
class
SizingTypes
[source]¶ Bases:
enum.IntEnum
Ways in which a Layout Node can be sized within a UI layout.To be used with ui.LayoutNode().sizing_type-
expand
= 0¶
-
fixed
= 1¶
-
ratio
= 2¶
-
-
class
SkyBoxes
[source]¶ Bases:
enum.IntEnum
Preset skyboxes to show in a Nanome roomTo be used with plugin_instance.room.set_skybox-
Black
= 3¶
-
BlueSkyAndClouds
= 0¶
-
BlueSkyAndGround
= 2¶
-
Graydient
= 5¶
-
Sunset
= 1¶
-
Unknown
= -1¶
-
White
= 4¶
-
-
class
StreamDataType
[source]¶ Bases:
enum.IntEnum
Stream datatypes.Used internally-
byte
= 1¶
-
float
= 0¶
-
string
= 2¶
-
-
class
StreamDirection
[source]¶ Bases:
enum.IntEnum
Stream directions (reading and writing).Used internally-
reading
= 1¶
-
writing
= 0¶
-
-
class
StreamType
[source]¶ Bases:
enum.IntEnum
Object attributes and sets of attributes that can be streamed to Nanome.To be used with plugin_instance.create_writing_stream and plugin_instance.create_reading_stream-
color
= 1¶
-
complex_position_rotation
= 4¶
-
label
= 3¶
-
position
= 0¶
-
scale
= 2¶
-
shape_color
= 6¶
-
shape_position
= 5¶
-
sphere_shape_radius
= 7¶
-
-
class
ToolTipPositioning
[source]¶ Bases:
enum.IntEnum
Ways in which a tooltip can appear on top of its Layout Node.To be used with ui.Button().tooltip.positioning_target-
bottom
= 5¶
-
bottom_left
= 4¶
-
bottom_right
= 6¶
-
center
= 8¶
-
left
= 3¶
-
right
= 7¶
-
top
= 1¶
-
top_left
= 2¶
-
top_right
= 0¶
-
-
class
VertAlignOptions
[source]¶ Bases:
enum.IntEnum
Vertical alignment modes for text.To be used with ui.Label().text_vertical_align and ui.Button().vertical_align-
Bottom
= 2¶
-
Middle
= 1¶
-
Top
= 0¶
-
-
class
VolumeType
[source]¶ Bases:
enum.IntEnum
Volume types visible within a complex.To be used with _internal._volumetric._VolumeData()._type-
cryo_em
= 3¶
-
default
= 0¶
-
density
= 1¶
-
density_diff
= 2¶
-
electrostatic
= 4¶
-
-
class
DirectoryErrorCode
[source]¶ Bases:
enum.IntEnum
Deprecated.-
folder_unreachable
= 1¶
-
no_error
= 0¶
-
-
class
FileError
[source]¶ Bases:
enum.IntEnum
File errors encounterable after performing a file operation on the Nanome host machine.Accessible via the first parameter of the ‘done’ callback for all methods on plugin_instance.files-
invalid_path
= 1¶
-
io_error
= 2¶
-
no_error
= 0¶
-
security_error
= 3¶
-
-
class
FileErrorCode
[source]¶ Bases:
enum.IntEnum
Deprecated.-
file_unreachable
= 1¶
-
missing_permission
= 3¶
-
no_error
= 0¶
-
path_too_long
= 2¶
-
-
class
FileMeta
[source]¶ Bases:
object
Represents file metadata from a Nanome host machine.Accessible via the second parameter of the ‘done’ callback for plugin_instance.files.ls
-
class
LoadInfoDone
[source]¶ Bases:
object
Represents the a file operation on the Nanome host machine.Accessible via the first parameter of the ‘done’ callback for all methods on plugin_instance.files-
ErrorCode
¶ alias of
nanome.util.enums.LoadFileErrorCode
-
-
class
Logs
[source]¶ Bases:
object
Allows for easy message logging without buffer issues.Possible log types are Debug, Warning, and Error.-
classmethod
debug
(*args)[source]¶ - Prints a debug messagePrints only if plugin started in verbose mode (with -v argument)
Parameters: args (Anything printable) – Variable length argument list
-
classmethod
error
(*args)[source]¶ - Prints an error
Parameters: args (Anything printable) – Variable length argument list
-
classmethod
-
class
Octree
(world_size=5000, max_per_node=8)[source]¶ Bases:
object
Tree containing inserted objects and their positions.Commonly used to get neighboring objects.-
add
(data, position)[source]¶ - Add a data node to the octree.
Parameters: - data (
object
) – Data node to add to the octree - position – Position of this data node
- data (
-
get_near
(pos, radius, max_result_nb=None)[source]¶ - Get nodes within the octree neighboring a position.
Parameters:
-
get_near_append
(pos, radius, out_list, max_result_nb=None)[source]¶ - Functions like get_near, but with an externally controlled list.
Parameters:
-
-
class
Quaternion
(x=0, y=0, z=0, w=1)[source]¶ Bases:
object
A vector that holds 4 values. Used for rotation.-
EPS
= 1e-06¶
-
dot
(other)[source]¶ - Returns the dot between this and another Quaternion
Parameters: other ( Quaternion
) – Quaternion to dot product withReturns: A float value representing the dot product. Return type: float
-
classmethod
from_matrix
(matrix)[source]¶ Creates a Quaternion from a 4x4 affine transformation matrix.
Parameters: matrix ( list
<list
<float
>>) – A 4x4 affine transformation matrixReturns: A Quaternion representing a rotation. Return type: Quaternion
-
get_conjugate
()[source]¶ - Returns the conjugate of this Quaternion.
Returns: A new Quaternion that is the conjugate of this Quaternion. Return type: Quaternion
-
-
class
StreamCreationError
[source]¶ Bases:
enum.IntEnum
Errors possible during stream creation.-
AtomNotFound
= 1¶
-
NoError
= 0¶
-
UnsupportedStream
= 2¶
-
-
class
StreamInterruptReason
[source]¶ Bases:
enum.IntEnum
Reasons for stream interruption.-
Crashed
= 1¶
-
StreamNotFound
= 0¶
-
-
class
StringBuilder
[source]¶ Bases:
object
A class to build strings from lists of strings. This class is used internally.-
append
(s)[source]¶ - Converts an object to a string and appends it to this StringBuilder’s list of strings.
Parameters: s – The object to be appended as a string.
-
-
class
Vector3
(x=0, y=0, z=0)[source]¶ Bases:
object
A vector that holds 3 values. Used for position and scale.-
classmethod
distance
(v1, v2)[source]¶ - Returns the distance between two vectors.
Parameters: - v1 (
Vector3
) – The first vector - v2 (
Vector3
) – The second vector
- v1 (
-
equals
(other)[source]¶ - Returns True if the components of this vector are the same as another’s.
Parameters: other ( Vector3
) – The other Vector3Returns: Whether or not this vector is component-equal to ‘other’ Return type: bool
-
classmethod
Overview
The Nanome Plugin API provides a way to interface and integrate external software with Nanome’s molecular modeling VR software. Through this API, users can link up external computational such as molecular dynamics, docking software, and link custom databases. The extended functionality includes the ability to create new windows inside of the virtual environment and is easily customizable through a drag and drop user interface.
Plugins can be designed and ran from different operating systems - Windows, Linux, and Mac depending on the requirements needed from each plugin.
- Some examples of plugins that our customers love are:
- Docking
- Chemical Interactions
- Electrostatic Potential Map generation
- Chemical Properties
- Custom Database Integrations
- Loading PDFs and PowerPoints
- Running custom molecular dynamics
- All of our public plugins are available on our Github <https://github.com/nanome-ai> (prefixed with “plugin-“).
The primary requirements for running plugins are the Nanome Virtual Reality Software and access to the Nanome Plugin Server (NTS). The Nanome Plugin Server acts as a relay to forward plugin information and processes data coming into and going out of the Nanome virtual environment.
- The Nanome Virtual Reality Software can be acquired directly from Nanome or in any of the VR stores here:
- Oculus Store: https://www.oculus.com/experiences/rift/1873145426039242
- Viveport: https://www.viveport.com/apps/0a467f78-2ed2-43eb-ada8-9d677d5acf54
- Steam: https://store.steampowered.com/app/493430/Nanome/
- Direct Download: https://nanome.ai/setup
- SideQuest: https://xpan.cc/a-333
Using Plugins¶
Please contact sales@nanome.ai to enable your account to use Plugins.
In order to use a plugin
Make sure you are fully connected to your Nanome plugin server. After the Nanome team has configured your account to use Plugins and has provided the target server location and port (NTS DNS and Port, e.g. organization.nanome.ai 8888), log into Nanome, create a room, and click on the purple “Stacks” button to the left of the Entry list. You should see an empty list or a list of plugins. If you see “Not connected to NTS”, please contact support@nanome.ai or your dedicated Account Manager.
Editing the Config File
First, you want to locate the Config file (nanome-config.ini) of the Nanome Application in the builds folder. If you downloaded Nanome through the Oculus store, it will be available here:
C:\Program Files\Oculus\Software\Software\nanome-nanome\Build
Open the nanome-config.ini file in a text editor and scroll down to the section named ‘ Nanome plugin server config’ and change to the following:
Plugin-server-addr = 127.0.0.1
Plugin-server-port = 8888
Now, we want to check to make sure that the Plugin Server is connected. Go ahead and launch Nanome, then log in using your credentials. Create a room and Start in 2D and click on the Plugins Icon on the bottom of the Entry Menu.
You should see that the NTS is connected and there are no current running plugins. If it says that “No NTS is connected”, that means it is unable to see the Plugin server and it is entered incorrectly on the Config file or in the Admin settings for home.nanome.ai. It could also be blocked by firewall.
Let’s go ahead and run a basic plugin to make sure it is working.
Installing your first plugin: Basic Plugin
Example Plugin
First, download the RemoveHydrogen.py basic plugin here:
This is a simple plugin example to remove all of the selected hydrogens in the workspace:
import nanome
from nanome.util import Logs
# Config
NAME = "Remove Hydrogens"
DESCRIPTION = "Remove hydrogens in all selected atoms"
CATEGORY = "Simple Actions"
HAS_ADVANCED_OPTIONS = False
# Plugin
class RemoveHydrogens(nanome.PluginInstance):
# When user clicks on "Activate"
def start(self):
Logs.message("Connected to a new session!") # Displays a message in the console
@staticmethod
def _should_be_removed(atom):
if atom.selected == False:
return False
if atom.symbol != 'H':
return False
return True
# When user clicks on "Run"
def on_run(self):
self.request_workspace(self.on_workspace_received) # Request the entire workspace, in "deep" mode
# When we receive the entire workspace from Nanome
def on_workspace_received(self, workspace):
for complex in workspace.complexes:
count = 0
for residue in complex.residues:
# First, find all atoms to remove
atoms_to_remove = []
for atom in residue.atoms:
# If this atom is an H and is selected, delete it
if RemoveHydrogens._should_be_removed(atom):
atoms_to_remove.append(atom)
# Then, remove these atoms
for atom in atoms_to_remove:
residue.remove_atom(atom)
count += len(atoms_to_remove)
Logs.debug(count, "hydrogens removed from", complex.molecular.name) # Displays a message in the console only if plugin started in verbose mode
self.update_workspace(workspace) # Update Nanome workspace, in "deep" mode
# Setup plugin information, register RemoveHydrogens as the class to instantiate, and connect to the server
nanome.Plugin.setup(NAME, DESCRIPTION, CATEGORY, HAS_ADVANCED_OPTIONS, RemoveHydrogens)
Development¶
In order to prepare your development environment and create your own first plugins, follow this link:
Installation¶
In order to install the Nanome Plugin API, you need a supported version of Python. Then, use python’s package manager, pip, to install nanome:
$ pip install nanome
Or, to upgrade your current installation:
$ pip install nanome --upgrade
Server¶
A Nanome Transport Server (NTS) is required to run your plugins and connect them to Nanome. A public server will be available in the near future. If you need a NTS, please contact us.
Running Your First Plugin¶
Starting a plugin is fairly easy. If you copy-pasted the example plugin on the home page, in a file named “RemoveHydrogens.py”, you can start your plugin like this:
$ python RemoveHydrogens.py
Or on Linux (python 3 is still preferred when available):
$ python3 RemoveHydrogens.py
To choose the IP address and the port of your server, you have two options:
Short term, testing: Using arguments
$ python RemoveHydrogens.py -a 123.456.789.0 -p 4567
Long term, for production: Changing the script (call to plugin.run, last line of the example script above)
plugin.run('123.456.789.0', 4567)
Arguments¶
When starting a plugin, a few optional arguments are available:
- -h: Displays available arguments
- -a [IP]: Specifies NTS address
- -p [PORT]: Specifies NTS port
- -k [FILE]: Specifies a key file to use (if NTS is protected by key)
- -v: Enables verbose mode, to display
debug()
messages - -r: Enables Live Reload
On the VR Side¶
In order to connect Nanome (VR) to your server, make sure that its configuration file (nanome-config.ini, located in its installation directory) contains the following:
plugin-server-addr = 127.0.0.1 # Use the correct address for your server plugin-server-port = 8888 # Use the correct port for your server
Our Plugins¶
We have a growing list of plugins available on our Github (all repositories starting with “plugin-“)
In order to install them, you have 2 possibilities: Use pip or manually download them from github.
This is the easiest way. For instance, to install and run URLLoader, simply use:
$ pip install nanome-loaders
$ nanome-url-loader -a address_of_your_nts
And it will be up and running Please refer to each individual repository README for more information about our plugins