Callbacks

A collection of functions to easily create JavaScript callbacks.

Opens an external link using url as a template string and the value in the corresponding field. The value can be URL-encoded or base64-encoded if needed.

Parameters
  • url (str) – Template string used to generate the URL that will be opened.

  • field (str) – Field name used to generate the URL that will be opened. The value can be encoded (see below).

  • url_encode (bool) – Encode the value fetched from the specified field to replace characters that are not allowed in a URL e.g., spaces become %20.

  • b64_encode (bool) – Base64-encode the value fetched from the field.

:raises ValueError : Both url_encode and b64_encode have been specified.:

mols2grid.callbacks.info(title='SMILES', subtitle=None, img_size=(400, 300), style='') mols2grid.callbacks._JSCallback[source]

Displays a bigger image of the molecule, alongside some useful descriptors: molecular weight, number of Hydrogen bond donors and acceptors, TPSA, Crippen ClogP and InChIKey.

Parameters
  • title (str) – Title of the popup. Use title='${data["Name"]}' to use the value of the column β€œName” as a title

  • subtitle (str) – Secondary title which works the same as title.

  • img_size (tuple) – Width and height of the molecule depiction.

  • style (str) – CSS style applied to the modal window.

mols2grid.callbacks.make_popup_callback(title=None, subtitle=None, svg=None, html='', js='', style='')[source]

Creates a JavaScript callback that displays a popup window

Parameters
  • title (str) – Title of the popup. Use title='${data["Name"]}' to use the value of the column β€œName” as a title

  • subtitle (str) – Secondary title which works the same as title.

  • svg (str) – SVG depiction of the molecule

  • html (str) – Content of the popup window

  • js (str) – JavaScript code executed before making the content of the popup window. This allows you to create variables and reuse them later in the html content of the popup, using the ${my_variable} syntax

  • style (str) – CSS style assigned to the popup window

Returns

js_callback – JavaScript code that allows to display a popup window

Return type

str

mols2grid.callbacks.show_3d(title='SMILES', subtitle=None, query=['pubchem', 'cactus'], height='100%', style='width:100%;height:100%') mols2grid.callbacks._JSCallback[source]

Queries the API(s) listed in query using the SMILES of the structure, to fetch the 3D structure and display it with 3Dmol.js

Parameters
  • title (str) – Title of the popup. Use title='${data["Name"]}' to use the value of the column β€œName” as a title

  • subtitle (str) – Secondary title which works the same as title.

  • query (list or dict) –

    List of APIs used to fetch the 3D structure from (by order of priority). To use a custom API, use a dict with the following format:

    {
        "url": "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/{}/SDF?record_type=3d",
        "format": "sdf",
        "field": "SMILES",
        "encode": True,
    }
    

    In this example, the value in the SMILES field will be URI-encoded and replace the curly-braces in the url strings to create the URL to fetch the 3D structure from in the SDF format.

  • height (str) – Height of the 3Dmol.js viewer in the modal.

  • style (str) – CSS style applied to the modal window.