A Python Script

At the end of the previous page on setting up and accessing a Sqlite datasets from a Jupyter notebook there was and example of using a ChEMBLID to return the SMILES string. It is very easy to convert this to a python script as shown below. 

After the imports, we first need to get the input, this is the first argument in the input command.

We then set up the connection to the base, note we need to include the full path to the database. Then construct the query and execute, parse the list returned to get the SMILES that the script returns

Save this as ChEMBLIDLookup.py and you can then access it using the Terminal command shown below. 

The real beauty though is this python script can be accessed from multiple source for example AppleScript

A ChemDraw Applescript to get structure

Open the Script Editor, it is probably in the Utilities folder within the Applications folder.

First create a dialog box and capture the response

Then check which button was pressed and get the text returned (the ChEMBLID). Next construct the Terminal command, using the full path to the python that you want to use and the location of the python script. Copy the returned SMILES string to the clipboard.

If you are not sure of the path to python type “which python” in a Terminal window.

Finally we bring ChemDraw to the front and and use the menu items scripting to paste as SMILES.

tell application “ChemDraw 22.0.0” activate

end tell

The full script is shown in the image below.

Save the script as GetChEMBLStructure in the ChemDraw scripts folder, the path to the folder is shown below (you might need to create it).

Next time you open ChemDraw you should see a Scripts dropdown menu in the top bar. Click on this and you should be able to choose the script.

This should open up a dialog box into which you can enter the ChEMBLID

Click on the Search button and you should find the structure in the ChemDraw document

Checking if a structure is in ChEMBL

In a similar manner we can write a python script that takes a InChiKey as input and returns the CHEMBLID.

Test the python script in the Terminal

Now use ChemDraw to generate the InChiKey and pass it to the python script. The first part of the script checks if the Copy menu item is enabled to check a structure is selected. Then we script the menu items to copy the INChiKey to the clipboard. As before we create the SQLite command and capture the response. We then run the command and check the response, if the ChEMBLID is found it is displayed if not there is an error and the dialog displays “Not Found”. Finally the ChEMBLID is copied to the clipboard so you can paste it into the ChemDraw document.

Save it in the Chemdraw scripts folder and when you start up chemdraw it should be visible in the dropdown menu. Draw a structure and select the script and you should see a dialog

Since the ChEMBL ID is copied to the clipboard you can paste it under the structure.

Last updated 12 April 2023

Related Posts

2 thoughts on “Other ways of using the exact search

Comments are closed.