Callbacksο
A collection of functions to easily create JavaScript callbacks.
- mols2grid.callbacks.external_link(url='https://leruli.com/search/{}/home', field='SMILES', url_encode=False, b64_encode=True) mols2grid.callbacks._JSCallback [source]ο
Opens an external link using
url
as a template string and the value in the correspondingfield
. 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
andb64_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 titlesubtitle (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 titlesubtitle (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}
syntaxstyle (str) β CSS style assigned to the popup window
- Returns
js_callback β JavaScript code that allows to display a popup window
- Return type
- 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 with3Dmol.js
- Parameters
title (str) β Title of the popup. Use
title='${data["Name"]}'
to use the value of the column βNameβ as a titlesubtitle (str) β Secondary title which works the same as title.
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 theurl
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.