<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Generating and Serving 2-D Molecular SVGs</title>
    <link>http://depth-first.com/articles/2006/09/09/generating-and-serving-2-d-molecular-svgs</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Generating and Serving 2-D Molecular SVGs</title>
      <description>&lt;p&gt;A &lt;a href="http://depth-first.com/articles/2006/09/07/rendering-molecules-with-svg-on-the-web"&gt;previous article&lt;/a&gt; showed some examples of 2-D molecular rendering using Scalable Vector Graphics (SVG) embedded in a web page. This article will outline some simple steps for generating these images and publishing them on the Web.&lt;/p&gt;

&lt;h4&gt;Prerequisites&lt;/h4&gt;

&lt;p&gt;This tutorial uses &lt;a href="http://depth-first.com/articles/2006/08/28/drawing-2-d-structures-with-structure-cdk"&gt;Structure-CDK&lt;/a&gt;, a &lt;a href="http://cdk.sf.net"&gt;CDK&lt;/a&gt; add-on library written in Java. You'll need to install Sun's JDK 1.4.2 or later (or an open source alternative). Although not required, &lt;a href="http://ant.apache.org/"&gt;Ant&lt;/a&gt; makes it easy to use Structure-CDK. You'll want to make sure that your browser is &lt;a href="http://depth-first.com/articles/2006/09/07/rendering-molecules-with-svg-on-the-web"&gt;SVG-enabled&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Creating a 2-D Molecular SVG File&lt;/h4&gt;

&lt;p&gt;&lt;center&gt;&lt;strong&gt;Methylenedioxymethamphetamine (MDMA)&lt;/strong&gt;&lt;/center&gt;
&lt;center&gt;
&lt;embed src="http://depth-first.com/demo/20060909/mdma.svg" TYPE="image/svg+xml" width=400" height="200" /&gt;
&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;An SVG image like the one shown above can be created with this sequence of steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download and unzip the &lt;a href="http://prdownloads.sourceforge.net/structure/structure-cdk-0.1.2.zip?download"&gt;current release&lt;/a&gt; of Structure-CDK.&lt;/li&gt;

&lt;li&gt;Move into the unzipped Structure-CDK directory and run the Structure Visual Testing Framework:&lt;br /&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ cd structure-cdk-0.1.2
$ ant vis
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;

&lt;li&gt;From the &lt;strong&gt;File&lt;/strong&gt; menu, choose &lt;strong&gt;Open...&lt;/strong&gt; and use the file dialog to open a molfile. The &lt;strong&gt;molfiles&lt;/strong&gt; directory contains some samples.&lt;/li&gt;

&lt;li&gt;Resize the image to taste and choose &lt;strong&gt;Save as SVG...&lt;/strong&gt; from the &lt;strong&gt;File&lt;/strong&gt; menu. This writes the SVG image to a directory and filename of your choice.&lt;/li&gt;

&lt;/ol&gt;

&lt;h4&gt;Viewing the SVG File&lt;/h4&gt;

&lt;p&gt;You now have several options for viewing the SVG file. One of the simplest is to open it with the &lt;a href="http://www.mozilla.com/firefox/"&gt;Firefox browser&lt;/a&gt;. Another option is to open it with the excellent, free SVG editor &lt;a href="http://www.inkscape.org/"&gt;Inkscape&lt;/a&gt;. From Inkscape, you can edit your image, apply any number of special effects from the mundane to the remarkable, and save the result to disk.&lt;/p&gt;

&lt;h4&gt;Deploying the SVG File on the Web&lt;/h4&gt;

&lt;p&gt;After uploading your SVG file to a blog or other site, you may have some additional configuration to do. Because the SVG MIME type is not configured by default on all servers, you may need to do so yourself.&lt;/p&gt;

&lt;p&gt;After uploading my first set of SVG files to my server, I tried to view them in Firefox. Instead of seeing the expected image in the browser window, I got a dialog asking if I wanted to open it with Inkscape or save it to disk.&lt;/p&gt;

&lt;p&gt;With the help of &lt;a href="http://www.mozilla.org/projects/svg/faq.html#choose-a-program"&gt;some documentation&lt;/a&gt;, I was able to track the problem down to my server, which was using the MIME type "image/svg-xml" instead of "image/svg+xml". The former is the obsolete SVG MIME type, which Firefox rejects. Internet Explorer equipped with Adobe's SVG plugin, on the other hand, accepts the obsolete MIME type, rendering SVG without presenting a dialog. &lt;a href="http://web-sniffer.net/"&gt;Web-Sniffer&lt;/a&gt;, which decodes header information from HTTP responses, may be useful for debugging your server's MIME type configuration.&lt;/p&gt;

&lt;p&gt;Having configured your server's SVG MIME type as "image/svg+xml", pointing your browser to your SVG file's URL will let you view it in its full, W3C-compliant glory.&lt;/p&gt;

&lt;h4&gt;Embedding the SVG File in HTML&lt;/h4&gt;

&lt;p&gt;There are a few options for embedding an SVG image in HTML. The most universally-applicable mechanism is the &lt;code&gt;&amp;lt;embed&amp;gt;&lt;/code&gt; tag:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;html&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;head&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;head&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;body&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="comment"&gt;&amp;lt;!-- document body --&amp;gt;&lt;/span&gt;

  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;embed&lt;/span&gt; &lt;span class="attribute"&gt;src&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;url-to-svg-file.svg&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;TYPE&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;image/svg+xml&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;400&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;400&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;body&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;head&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Embedding SVG into HTML carries some limitations. For example, you can't interact with the SVG DOM the way you can if the SVG is inlined, or placed directly into the HTML document itself. But that's a subject for another time.&lt;/p&gt;

&lt;p&gt;Creating and deploying 2-D molecular images as SVG documents is a straightforward process, provided that some details are taken care of. Future articles in this series will show how SVG's advanced features make it a compelling choice as a chemical informatics rendering platform.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: if your're viewing this article in a feed aggregator, the SVG images may have been stripped out. If so, please see the &lt;a href="http://depth-first.com/articles/2006/09/09/generating-and-serving-2-d-molecular-svgs"&gt;original article&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Sat, 09 Sep 2006 14:45:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:bff458bc-90f4-474f-8a46-b6e915aa34c5</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2006/09/09/generating-and-serving-2-d-molecular-svgs</link>
      <category>Graphics</category>
      <category>svg</category>
      <category>2d</category>
      <category>structurecdk</category>
      <category>web</category>
    </item>
  </channel>
</rss>
