The proto-Nucleic-Acid Builder (pNAB)
Functions | Variables
jupyter_widgets Namespace Reference

A file for displaying widgets in the Jupyter notebook. More...

Functions

def view_nglview (molecule, label=False)
 Display molecules using the NGLView viewer. More...
 
def fixed_bonds (num_bonds, num_atoms, param)
 Display widgets for determining indices of fixed bonds. More...
 
def path (file_path, param)
 Display backbone to Jupyter notebook given a file path. More...
 
def upload_backbone (f, param)
 Upload a backbone file to Jupyter notebook. More...
 
def backbone (param)
 Main backbone widget for use in Jupyter notebook. More...
 
def base_path (file_path, param, base_number)
 Display base to Jupyter notebook given a file path. More...
 
def upload_base (f, param, base_number)
 Upload a base file to Jupyter notebook. More...
 
def add_base (number_of_bases, param)
 Display widgets to upload the requested number of bases. More...
 
def bases (param)
 Bases widget for use in Jupyter notebook. More...
 
def helical_parameters (param)
 
def algorithm (chosen_algorithm, param)
 Display search parameters based on the chosen algorithm. More...
 
def runtime_parameters (param)
 Runtime parameter widget for use in Jupyter notebook. More...
 
def upload_input (param, f)
 Widget to upload an input file. More...
 
def display_options_widgets (param, input_file, uploaded=False)
 Display all widgets in Jupyter notebook given an input file. More...
 
def user_input_file (param)
 Display input file options. More...
 
def run (button)
 Function to run the code when the user finishes specifying all options. More...
 
def extract_options ()
 Extracts user options from the widgets. More...
 
def single_result (result, header, results, prefix)
 Interactive function to display a single result. More...
 
def show_results (results, header, prefix)
 Display results. More...
 
def builder ()
 The function called from the Jupyter notebook to display the widgets. More...
 

Variables

dictionary input_options = {}
 Stores the widgets corresponding to the user-defined options. More...
 

Detailed Description

A file for displaying widgets in the Jupyter notebook.

This file containts widgets for sepecifying options in the Jupyter notebook using the ipywidgets library (https://github.com/jupyter-widgets/ipywidgets). Using Jupyter notebook is not necessary for using the program, as the program can be run in as a python script. However, the widgets provide a graphical user interface for making input files, running the code, and displaying the results. The Jupyter notebook can be run locally or on the clouds using Binder (https://mybinder.org/v2/gh/alenaizan/pnab/master?filepath=binder).

The widgets have four main components: Backbone, Bases, Helical Parameters, and Runtime Parameters. The Bases section does not require the user input but displays some information about the available nucleobases in the library. The NGLView library is used for visualization

To run the widgets from a Jupyter notebook, simply execute the following:

import pnab
pnab.builder()

Function Documentation

◆ add_base()

def jupyter_widgets.add_base (   number_of_bases,
  param 
)

Display widgets to upload the requested number of bases.

Parameters
number_of_bases(int) The number of additional bases to define
param(dict) options._options_dict['Base'] and dictionaries for the other defined bases
See also
bases
upload_base
options._options_dict
view_nglview

◆ algorithm()

def jupyter_widgets.algorithm (   chosen_algorithm,
  param 
)

Display search parameters based on the chosen algorithm.

There are six search algorithms and each one has a set of input parameters. The search algorithms are:

  • Systematic Search: Requires specifying the dihedral angle step size, dihedral_step.
  • Monte Carlo Search: Requires specifying the number of steps, num_steps, and the Monte Carlo temperature, monte_carlo_temperature.
  • Weighted Monte Carlo Search: Also requires specifying the weighting temperature, weighting_temperature.
  • Random Search: Requires specifying the number of steps, num_steps.
  • Weighted Random Search: Also requires specifying the weighting temperature, weighting_temperature.
  • Genetic Algorithm Search: Requires specifying the number of generations, num_steps, the population size, population_size, the mutation_rate, mutation_rate, and the crossover rate, crossover_rate.
Parameters
chosen_algorithm(str) The chosen algorithm
param(dict) options._options_dict['RuntimeParameters']
Returns
None; jupyter_widgets.input_options is modified in place
See also
runtime_parameters
input_options
options._options_dict

◆ backbone()

def jupyter_widgets.backbone (   param)

Main backbone widget for use in Jupyter notebook.

This function displays the backbone widgets.

Parameters
param(dict) options._options_dict['Backbone']
Returns
None
See also
upload_backbone
options._options_dict
display_options_widgets

◆ base_path()

def jupyter_widgets.base_path (   file_path,
  param,
  base_number 
)

Display base to Jupyter notebook given a file path.

This function displays the options for the base. If the file_path does not exist, this function displays nothing.

Parameters
file_path(str) Path to a file containing the 3D structure of the base molecule
param(dict) options._options_dict['Base']
base_numberThe number of the new base
Returns
None; jupyter_widgets.input_options is modified in place
See also
upload_base
input_options
options._options_dict
view_nglview

◆ bases()

def jupyter_widgets.bases (   param)

Bases widget for use in Jupyter notebook.

This function displays information on the available nucleobases that are defined in the program. The bases are defined in "data/bases_library.yaml"

Returns
None
See also
display_options_widgets

◆ builder()

def jupyter_widgets.builder ( )

The function called from the Jupyter notebook to display the widgets.

Execute the following to display all the widgets in the notebook

import pnab
pnab.builder()
Returns
None

◆ display_options_widgets()

def jupyter_widgets.display_options_widgets (   param,
  input_file,
  uploaded = False 
)

Display all widgets in Jupyter notebook given an input file.

If input_file is provided, then it updates the default options in options._options_dict to display the user-defined options. If input_file is "Upload file", then an ipywidgets.FileUpload widget is displayed. This function also displays a widget for running the program after the user defines all the options.

Parameters
param(dict) options._options_dict
input_file(str) Input file
uploaded(bool) Whether a file is uploaded by the user or not
Returns
None
See also
backbone
bases
helical_parameters
runtime_parameters
upload_input
run
user_input_file
options._options_dict

◆ extract_options()

def jupyter_widgets.extract_options ( )

Extracts user options from the widgets.

This function extracts the values of all options specifed by the user. It access all the widgets in jupyter_widgets.input_options and extracts their values.

Returns
user_options A dictionary of the values of all the user-defined options
See also
run
input_options
options._options_dict

◆ fixed_bonds()

def jupyter_widgets.fixed_bonds (   num_bonds,
  num_atoms,
  param 
)

Display widgets for determining indices of fixed bonds.

This function is changed interactively bases on the number of fixed bonds requested by the user.

Parameters
num_bonds(int) number of fixed bonds; changed dynamically by the user
num_atoms(int) number of atoms in the backbone
param(dict) options._options_dict['Backbone']
Returns
None; jupyter_widgets.input_options is modified in place
See also
path
input_options
options._options_dict

◆ helical_parameters()

def jupyter_widgets.helical_parameters (   param)
Display widgets for specifying helical parameters. It also displays an image illustrating
the used helical parameters.

@param param (dict) @a options._options_dict['HelicalParameters']

@returns None; @a jupyter_widgets.input_options is modified in place

@sa input_options
@sa display_options_widgets 
@sa options._options_dict

◆ path()

def jupyter_widgets.path (   file_path,
  param 
)

Display backbone to Jupyter notebook given a file path.

This function displays the options for the backbone. If the file_path does not exist, this function displays nothing.

Parameters
file_path(str) Path to a file containing the 3D structure of a backbone molecule
param(dict) options._options_dict['Backbone']
Returns
None; jupyter_widgets.input_options is modified in place
See also
upload_backbone
input_options
options._options_dict
view_nglview

◆ run()

def jupyter_widgets.run (   button)

Function to run the code when the user finishes specifying all options.

It extracts the user-defined options and creates a pNAB.pNAB instance. Then, it run the code and display the results.

Parameters
button(variable) variable for using the widgets.Button.on_click method
See also
display_options_widgets
pNAB.pNAB
show_results

◆ runtime_parameters()

def jupyter_widgets.runtime_parameters (   param)

Runtime parameter widget for use in Jupyter notebook.

Displays widgets for specifying runtime parameters.

Parameters
param(dict) options._options_dict['RuntimeParameters']
Returns
None; jupyter_widgets.input_options is modified in place
See also
algorithm
input_options
display_options_widgets
options._options_dict

◆ show_results()

def jupyter_widgets.show_results (   results,
  header,
  prefix 
)

Display results.

A function to display all the accepted candidates using a dropdown list.

Parameters
results(np.ndarray) numpy array of results sorted by total energy
header(str) A comma separated string of the output properties of the conformer
prefix(dict) A dictionary of the prefix of the run and the associated helical configuration
Returns
None
See also
run
single_result

◆ single_result()

def jupyter_widgets.single_result (   result,
  header,
  results,
  prefix 
)

Interactive function to display a single result.

It displays one accepted conformer and prints its energies and other properties.

Parameters
result(int) index of the conformer in the results array
header(str) A comma separated string of the output properties of the conformer
results(np.ndarray) a numpy array of all the accepted conformers
prefix(dict) A dictionary of the prefix of the run and the associated helical configuration
Returns
None
See also
show_results

◆ upload_backbone()

def jupyter_widgets.upload_backbone (   f,
  param 
)

Upload a backbone file to Jupyter notebook.

This function is used to upload a backbone file and write it. If a file is already specified, then the backbone is displayed. If a file is uploaded, this function writes the file to the current working directory. Then, the function calls the jupyter_widgets.path function interactively with the backbone file path.

Parameters
f(ipywidgets.FileUpload) File upload widget
param(dict) options._options_dict['Backbone']
Returns
None
See also
path
backbone

◆ upload_base()

def jupyter_widgets.upload_base (   f,
  param,
  base_number 
)

Upload a base file to Jupyter notebook.

This function is used to upload a base file and write it. If a file is already specified, then the base is displayed. If a file is uploaded, this function writes the file to the current working directory. Then, the function calls the jupyter_widgets.base_path function interactively with the base file path.

Parameters
f(ipywidgets.FileUpload) File upload widget
param(dict) options._options_dict['Base'] for the appropriate base number
base_number(int) The number of the additional base
Returns
None
See also
base_path
add_base

◆ upload_input()

def jupyter_widgets.upload_input (   param,
  f 
)

Widget to upload an input file.

If a file is uploaded, it is written in the current working directory. Then, this function calls jupyter_widgets.display_options_widgets function with the newly written file.

Parameters
param(dict) options._options_dict
f(ipywidgets.FileUpload) file upload widget
Returns
None
See also
display_options_widgets

◆ user_input_file()

def jupyter_widgets.user_input_file (   param)

Display input file options.

Gives the user several input files that they can try, and the option that they upload their input file. Once an input file is chosen, all widgets are displayed with the user-defined options.

Parameters
param(dict) options._options_dict
Returns
None
See also
display_options_widgets

◆ view_nglview()

def jupyter_widgets.view_nglview (   molecule,
  label = False 
)

Display molecules using the NGLView viewer.

A function to view molecules using the NGLView project (https://github.com/arose/nglview). It is used to display the geometry of the backbone with atom index labels. It is also used to display accepted nucleic acid candidates generated after the search. For backbone molecules, the number of atoms in the backbone is computed here and returned to be used for bounding the displayed atomic indices in backbone widgets.

Parameters
molecule(str) Path to a file containing the 3D structure of the molecule
label(bool) Whether to display atom index labels
Returns
number of atoms in molecule if label is True, else None
Attention
If the molecules are not displayed correctly, you may need to execute
jupyter-nbextension enable nglview --py --sys-prefix
See also
jupyter_widgets.path
jupyter_widgets.single_result

Variable Documentation

◆ input_options

dictionary jupyter_widgets.input_options = {}

Stores the widgets corresponding to the user-defined options.

This dictionary has the same structure as the options._options_dict dictionary that has all the available options for the code. The widgets are added to this dictionary and the values of the widgets are extracted when the user runs the code

See also
options._options_dict
extract_options