Applescript Tutorial 6
Rendering the chemical structures
In the previous tutorial we built the FileMaker database, imported the structures as SMILES strings and then built the substructure searching script. Whilst SMILES strings are a brilliant way to store chemical structures in a database in a very compact form, they leave a little to be desired when it comes to actually working out what structure the SMILES encodes.
To add a depiction of the structure we first add a container field to the database, this will hold the rendered structure.
We now need to generate the structures, whilst it would be possible to draw all the structures by hand by using a mixture of FileMaker scripting and Applescript with ChemDraw it is possible to automate the structure generation. First we need to build the FileMaker scripts, within FileMaker open ScriptMaker from the Scripts menu and create a new script called "ChemdrawfromSMILES" as shown in the image below. The first step checks we are in Browse mode and then at the first record. We then loop through each of the records, first copying the SMILES string and then using Applescript to get ChemDraw to generate the structure.
When you add the "Perform Applescript" FileMaker script step a window will open onto which you can paste the following Applescript. First using the "Paste Special" menu to convert the SMILES to a rendered structure, then selecting it and copying it to the clipboard.
tell application "CS Chemdraw Ultra"<br> activate if enabled of menu item "Paste" then do menu item "SMILES" of menu "Paste Special" of menu "Edit" if enabled of menu item "Select All" then<br> do menu item "Select All"<br> end if do menu item "Cut" end tell tell window "SMILES_Database" of application "Filemaker Pro"<br> activate do script "Paste_CD" end tell
The Paste_CD script now pastes the contents of the clipboard into the container field.
If you now run the "ChemdrawfromSMILES" script it should loop through all the records in the current found set, use ChemDraw to generate the structure and copy it into the Structure container field.