This simple script allows you to copy a chemical name to the clipboard and then use the Chemical Identifier Resolver service to get the corresponding SMILES and then paste it into ChemDraw.
This service works as a resolver for different chemical structure identifiers and allows one to convert a given structure identifier into another representation or structure identifier. It can help you identify and find the chemical structure if you have an identifier such as an InChIKey. You can either use the resolver web form above or use the following simple URL API scheme:
The format for the query is very simple
https://cactus.nci.nih.gov/chemical/structure/”structure identifier”/”representation”
Example: Chemical name to Standard InChIKey:
https://cactus.nci.nih.gov/chemical/structure/aspirin/stdinchikey
Chemical names are resolved by a database lookup into a full structure representation. The service has currently approx. 68 million chemical names available linked to approx. 16 million unique structure records. The set of available names includes trivial names, synonyms, systematic names, registry numbers, etc.
The AppleScript is shown below, the first part creates a dialog box populated by the clipboard contents, you can also type in the query string. The next part url encodes the query string to make sure it does not contain characters the would not be allowed in a URL.
Then we use curl to retrieve the data, and finally ChemDraw to display the results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
set the clipboard to «class ktxt» of ((the clipboard as text) as record) set the_clip to the clipboard --Comment out if not needed --display dialog the_clip display dialog "Input Name" default answer the_clip buttons {"Cancel", "Get Structure"} default button 2 copy the result as list to {button_pressed, text_returned} --Need to encode text to sure URL is OK set the_encode_text to encode_text(text_returned, true, false) --set theURL to "http://cactus.nci.nih.gov/chemical/structure/name/smiles" --display dialog the_encode_text set theURL to "http://cactus.nci.nih.gov/chemical/structure/" & the_encode_text & "/smiles" set the_SMILES to (do shell script "curl -L " & theURL) --display dialog the_SMILES set the clipboard to the_SMILES tell application "ChemDraw 20.0" activate --if enabled of menu item "Paste" then do menu item "SMILES" of menu "Paste Special" of menu "Edit" if enabled of command "pasteAsSMILES" then do command "pasteAsSMILES" end tell on encode_text(this_text, encode_URL_A, encode_URL_B) set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789" set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*" set the URL_B_chars to ".-_:" set the acceptable_characters to the standard_characters if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars set the encoded_text to "" repeat with this_char in this_text if this_char is in the acceptable_characters then set the encoded_text to (the encoded_text & this_char) else set the encoded_text to (the encoded_text & encode_char(this_char)) as string end if end repeat return the encoded_text end encode_text on encode_char(this_char) set the ASCII_num to (the ASCII number this_char) set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"} set x to item ((ASCII_num div 16) + 1) of the hex_list set y to item ((ASCII_num mod 16) + 1) of the hex_list return ("%" & x & y) as string end encode_char |
The script can be downloaded from here
Last updated 29 October 2023