Macs in Chemistry

Insanely great science

Applescript Tutorial 7

In an earlier tutorial I showed how it was possible to create a substructure searchable chemical database using FileMaker and OpenBabel. In the subsequent tutorial I showed one way to render the chemical structures using ChemDraw. Judging by the number of downloads of the file a number of people have been looking at it. As you will have noticed embeding the structure into a container field for each record results in a much longer file size. In this case a 650 record database increases from approx 300K to 55MB, so for large databases this increase in size could be a major headache. One option is to have a global container field that you can insert the structure into as needed, and it is very easy to modify the existing scripts to do this.

However in this tutorial I thought it might be interesting to exploit one of the new features in FileMaker, the ability to add a "webview" to a record to display an html page into which is embeded a java applet or plugin that can be used to render the chemical structure. (This has only been tested with FileMaker 9). So whilst this is in the Applescripts tutorial section this particular tutorial actually only uses the FileMaker scripting language.

The database used in the previous tutorials can be down loaded here, it includes the structure field but I would leave it in place for the time being.

First we need a couple of fields that we can use to generate the HTML for the web page, we need to add the three global fields highlighted below.

chem_database_html

Into the chemdraw_html_header field paste the following text:-

<html><head> <title>1</title></head><body> <embed src="file:////Users/swain/Desktop/Chem_Database/HTML/temp.cdx" align="baseline" border="0"width="300" height="200" type="chemical/x-cdx"id=2 dataurl="data:chemical/smiles

Into the chemdraw_html_footer field paste the following text:-

" viewonly="true"> <noembed>Sorry, your browser does not support plugins.</noembed>
</body> </html>

We now need to insert the Web Viewer, set the view to "Layout Mode" then select the Web Viewer from the left hand tool palette and draw the web viewer as shown, then select "Object Info" from the View menu and name the web viewer "web_structure".

chem_database_load_webview

Next in the "Chem_Database" folder you downloaded create a folder called "HTML" this is where the html pages that you will be loading into the web viewer will reside. For this example we are going to use ChemDraw Plugin to render the structure. To do this we need to have a blank chemdraw file in the HTML folder, so open ChemDraw and save the blank document in to the HTML folder calling the file "temp.cdx".

If we now return to FileMaker we are ready to build the scripts that create the html page and then load it into the web viewer. The first script is "createchemdrawhtml", as shown below, create the required html by concatonating "chemdrawhtmlheader" & SMILES & "chemdrawhtmlfooter". This inserts the SMILES string of the current record into the html code. The second step "Export Field Contents" creates a file called "htmlpage.htm" and inserts the text from the contents of the field "theHTML".

create_html

All that remains now is to load this into the web viewer, the first step just performs the script to create the web page. I did it this way for ease of explanation it could have course all been in one script. The next step loads the web viewer, insert the name of the web viewer "web_structure" and select as the action "Go to URL", in the dialog box select "Custom Web Address" and in the "Web Address" box insert the path to the html page which should be something like.

"file://localhost/Users/YOUR USER NAME/Desktop/Chem_Database/HTML/html_page.htm"

Now save the script and you are ready to go

chem_database_load_webview

If you run the "createchemdrawhtml" script it should fill in the field "theHTML" and create a file in the HTML folder called "htmlpage.htm", if this works run the "loadwebpage" script, the first time it may take a few seconds to load, subsequent occasions should be much faster. As you can see in the image below I've actually added a button at the top called "structure" and linked this to the "loadwebpage" script. You can use the same strategy to render structures using a java applet and I'll show this in more detail in the next tutorial.

chem_database_final