Provided by Christ Notes
Bible Search

September 19, 2006

More substructure searches

I have been using a customised version of the Lab Notebook from Macs In Chemistry as my labbook for several years now. I have however never really liked the substructure search in it. I don't want to first create a database and then search. When I'm looking for somehting I'm looking for it now... Besides, the fact that it uses ChemFinder that's still only available for Classic makes it even less attractive.

I have lately discovered the beauty of Open Babel and I figured that it's substructure search program obgrep should be possible to use to search in the Lab Notebook.

To make this possible, some AppleScripts are needed (in addition to Open Babel...). The first one can be downloaded here. Save it (control click on the link and choose save link as...) somewhere you like it (in theory you should only need to run it once). The other two should instead be entered into scripts in FileMaker. (I use FileMaker 5.5, I don't know if the following is working in different versions.)
Open the ScriptMaker found in the "Script"-menu. I think you should find a script in the resulting list that's called "Get_data" with an underscore (If you don't, pleas let me know and I will try to find the correct script for you...). Double click that script to edit it. Add a "Perform Applescript" action by double clicking in the list to the left. Make sure the newly added action ended up at the bottom of the script. Double click the line saying "Perform Applescript" to edit it. Paste the following code in the new window.

set basePath to cell "startup disk"
set smilesFile to basePath & ":Lab_Notebook:substructuresearch.smi"
alias smilesFile
on error --> file doesn't exist
open for access file smilesFile
close access file smilesFile
end try

set refnr to cell "Reference_Number" of current record
set reac1 to (cell "smilesreactant" of current record) & " " & refnr & "_react1\n"
if reac1 is equal to " " & refnr & "_react1\n" then set reac1 to ""
set reac2 to (cell "Reactant2_SMILES" of current record) & " " & refnr & "_react2\n"
if reac2 is equal to " " & refnr & "_react2\n" then set reac2 to ""
set prod to (cell "SMILES_String" of current record) & " " & refnr & "_prod\n"
if prod is equal to " " & refnr & "_prod\n" then set prod to ""

tell application "Finder"
set filelength to get eof file smilesFile
write reac1 to file smilesFile starting at (filelength + 1)
write reac2 to file smilesFile starting at (filelength + (length of reac1) + 1)
write prod to file smilesFile starting at (filelength + (length of reac1) + (length of reac2) + 1)
end tell

Press "OK" twice to return to the list of scripts. The Notebook will now save the structures to a separate (searchable) file when you press the "Get data" button. Note that if you dublicate a previous reaction you will need to press "Get data" or you won't find the new reaction when doing substructure searches.

Finally, you'll need to add the script that performs the actual search. Still in ScriptMaker, go to the Name field and enter SMART_search. Press the New button to ceate and edit this script. Add an AppleScript action as above and paste the following code into it.

show every record of database "LabNotebook"
set basePath to cell "startup disk"
set basePath to POSIX path of file (basePath & ":Lab_Notebook:substructuresearch.smi")
set the_SMART to ""
set dd to display dialog "Enter SMARTs (leave empty to cancel)" default answer the_SMART buttons {"Reactant", "Product", "All"} default button 3
set the_SMART to the text returned of dd
set the_Role to button returned of dd
if the_SMART is not equal to "" then
if the_Role is equal to "Reactant" then
set the_grep to "_react"
else if the_Role is equal to "Product" then
set the_grep to "_prod"
set the_grep to "_"
end if
set the_results to do shell script "/usr/local/bin/obgrep " & quoted form of the_SMART & " " & basePath & " | grep " & the_grep & " || echo ERROR" without altering line endings
set oldTextDelimiter to AppleScript's text item delimiters
if the_results is equal to "ERROR\n" then
display dialog "No matching structures found" with icon caution buttons {"OK"} default button 1
end if
set AppleScript's text item delimiters to "\n"
set the_results to every text item of the_results
set the_search to ""
repeat with i from 1 to the count of the_results
set AppleScript's text item delimiters to " "
set the_reference to the last text item of (item i of the_results)
set AppleScript's text item delimiters to "_"
set the_reference to every text item of the_reference
repeat with j from 1 to (the count of the_reference) - 1
set the_search to the_search & item j of the_reference
if j is not equal to ((the count of the_reference) - 1) then set the_search to the_search & "_"
end repeat
set the_search to the_search & return
end repeat
set cell "List_search" of current record to the_search
do script "Find_List"
set AppleScript's text item delimiters to oldTextDelimiter
end if

Press "OK" twice and then "Finished" to return to FileMaker. Now the scripts are created and you "only" need to connect the SMART_search to a button. Go to the Layout view by selecting it from the View menu. I changed the existing Substructure search button to point to the new script but you could also add a new button. If you choose to change the existing button, control click (or right click) on it to bring up the contextual menu. Select "Buttons" and change the script SSS for your new SMART_search. Press OK and go back to the Browse view.

Your Lab Notebook is now set up to use the substructure search. Before you can do any searches you should run the first script you downloaded to add all compounds to the searchable file. Run the script by double clicking it.

Now you're ready to try the first search. When you press the search-button you should see a dialog asking for a SMART string and three buttons to search for reactants, products, or both. The creation of SMART strings can be a bit tricky at first but for the most times it works with a simple SMILES string that can be created in for example ChemDraw. For more information on SMART strings, look at the tutorials at Daylight. Unfortunately, the SMART search in Open Babel has some problems when it comes to stereochemistry so it's best to leave that out of the SMART string. (Or remove it if you get too few results).

If you don't have Open Babel installed I recommend you install ChemSpotlight that comes with a compiled binary of Open Babel. If you choose to install Open Babel somewhere else than /usr/local/bin/ you need to change the SMART_search script to point at your location.

Happy searching!
Posted 17 years, 1 month ago on September 19, 2006
The trackback for this post is disabled

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title
Your Name:
Email Address:
Make Public?
Make Public?

Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.