<?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: Tag rubycdk</title>
    <link>http://depth-first.com/articles/tag/rubycdk</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Ruby CDK for Newbies</title>
      <description>&lt;p&gt;&lt;img src="http://depth-first.com/demo/20071004/newbies.png" align="right"&gt;&lt;/img&gt;Scripting languages and cheminformatics can be a highly-effective combination. With their relaxed syntax, compilation-free execution, and interactive testing environments, scripting languages offer fast development iteration cycles. And scripting languages' support for manipulating libraries written in other languages can be key in today's heterogeneous cheminformatics software environment.&lt;/p&gt;

&lt;p&gt;Although there are many &lt;a href="http://depth-first.com/articles/2006/11/14/eleven-free-cheminformatics-scripting-environments"&gt;cheminformatics scripting environments&lt;/a&gt; to choose from, Ruby offers some important advantages. Number one on the list is the wildly-popular &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt; Web development framework. Others worth mentioning include &lt;a href="http://tryruby.hobix.com/"&gt;interactive ruby&lt;/a&gt; (irb), the &lt;a href="http://www.rubygems.org/"&gt;RubyGems&lt;/a&gt; package manager, the &lt;a href="http://martinfowler.com/articles/rake.html"&gt;Rake&lt;/a&gt; build system, the &lt;a href="http://jruby.org"&gt;JRuby&lt;/a&gt; Ruby implementation, &lt;a href="http://rubyforge.org"&gt;RubyForge&lt;/a&gt;, and a host of other productivity-boosters.&lt;/p&gt;

&lt;p&gt;A major focus of Depth-First over the last few months has been &lt;a href="http://depth-first.com/articles/tag/rubycdk"&gt;Ruby CDK&lt;/a&gt;. This library consists of a thin Ruby wrapper around the open source &lt;a href="http://cdk.sf.net"&gt;Chemistry Development Kit&lt;/a&gt; (CDK), &lt;a href="http://depth-first.com/articles/2006/08/28/drawing-2-d-structures-with-structure-cdk"&gt;Structure-CDK&lt;/a&gt;, an open source 2D rendering toolkit, and &lt;a href="http://depth-first.com/articles/tag/opsin"&gt;OPSIN&lt;/a&gt;, an open source chemical nomenclature parser. A recent comment on Depth-First by &lt;a href="http://chem-bla-ics.blogspot.com/"&gt;Egon Willighagen&lt;/a&gt;, one of CDK's creators, got me thinking about centralizing this documentation. The following collection of links is a step in that direction.&lt;/p&gt;

&lt;h4&gt;Overview and Installation&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/10/30/agile-chemical-informatics-development-with-cdk-and-ruby-rcdk-0-3-0"&gt;Agile Chemical Informatics Development with CDK and Ruby CDK 0.3.0&lt;/a&gt; Installation of Ruby CDK on Linux.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/10/12/running-ruby-java-bridge-on-windows"&gt;Running Ruby Java Bridge on Windows&lt;/a&gt; Special installation instructions for Ruby CDK on Windows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Ruby CDK in Its Environment&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/10/17/from-iupac-nomenclature-to-2-d-structures-with-opsin"&gt;From IUPAC Nomenclature to 2D Structures with OPSIN&lt;/a&gt; OPSIN converts IUPAC nomenclature into molecular representations and is now part of Ruby CDK.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/11/14/eleven-free-cheminformatics-scripting-environments"&gt;Eleven Free Cheminformatics Scripting Environments&lt;/a&gt; So many choices, so little time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/10/24/metaprogramming-with-ruby-mapping-java-packages-onto-ruby-modules"&gt;Metaprogramming with Ruby : mapping Java Packages Onto Ruby Modules&lt;/a&gt; Behind the scenes look at a trick used in Ruby CDK.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Using Ruby CDK&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/11/21/build-a-rails-cheminformatics-application-in-thirty-minutes"&gt;Build a Rails Cheminformatics Application in Thirty Minutes&lt;/a&gt; First article in a series on building a SMILES Depict application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/11/27/anatomy-of-a-cheminformatics-web-application-beautifying-depict"&gt;Anatomy of a Cheminformatics Web Application: Beautifying Depict&lt;/a&gt; Second article in the series - cleaning up the Depict user interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/12/04/anatomy-of-a-cheminformatics-web-application-ajaxifying-depict"&gt;Anatomy of a Cheminformatics Web Application: Ajaxifying Depict&lt;/a&gt; Third article in the series - use Ajax to automatically update the Depict drawing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/11/13/cheminformatics-for-the-web-convert-sd-files-to-html-with-ruby-cdk"&gt;Cheminformatics for the Web: Convert SD Files to HTML with Ruby CDK&lt;/a&gt; SD Files are both everywhere and useless by themselves to chemists - why not convert them into HTML and post them to the Web?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/11/15/diversity-oriented-chemical-informatics"&gt;Diversity-Oriented Chemical Informatics&lt;/a&gt; CDK is chock-full of nifty little tidbits, like the ability to enumerate all molecules of a given empirical formula.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/11/22/scripting-molecular-fingerprints-with-ruby-cdk"&gt;Scripting Molecular Fingerprints with Ruby CDK&lt;/a&gt; To borrow a phrase from a cheminformatics master: "It's just that easy."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/12/11/hacking-molbank-creating-a-graphical-table-of-contents"&gt;Hacking Molbank: Creating a Graphical Table of Contents&lt;/a&gt; The intersection of Open Access, Open Source, and rapid application development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/12/18/anatomy-of-a-cheminformatics-web-application-structure-cleanup-in-java-molecular-editor"&gt;Anatomy of a Cheminformatics Web Application: Structure Cleanup in Java Molecular Editor&lt;/a&gt; The structure editor &lt;em&gt;can&lt;/em&gt; be lean, mean, and still highly functional - just offload resource-hungry features to the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2007/03/13/from-iupac-name-to-molecular-formula-with-ruby-cdk"&gt;From IUPAC Name to Molecular Formula with Ruby CDK&lt;/a&gt; &lt;a href="http://wwmm.ch.cam.ac.uk/blogs/corbett/"&gt;Peter Corbett's&lt;/a&gt; awesome OPSIN Library plays nice with Ruby CDK.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2007/09/06/from-inchi-to-image-with-ruby-open-babel-and-ruby-cdk"&gt;From InChI to Image with Ruby Open Babel and Ruby CDK&lt;/a&gt; InChIs are not easy to interpret - fortunately, this little library will do it for you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2007/09/19/easily-calculate-tpsa-descriptors-from-smiles-strings-using-ruby-cdk"&gt;Easily Calculate TPSA Descriptors from SMILES Strings Using Ruby CDK&lt;/a&gt; It just works.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2007/09/20/ruby-cdk-one-liners-create-a-molfile-with-2d-atom-coordinates-from-arbitrary-smiles-strings"&gt;Ruby CDK One-Liners: Create a Molfile with 2D Atom Coordinates from Arbitrary SMILES Strings&lt;/a&gt; Extremely short library for solving a very common cheminformatics problem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://depth-first.com/articles/2006/12/05/source-code-documentation-in-ruby-rdoc-for-ruby-cdk"&gt;Source Code Documentation in Ruby: RDoc for Ruby CDK&lt;/a&gt; When all else fails, read the documentation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Image Generation Credit: &lt;a href="http://txt2pic.com/"&gt;txt2pic.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 04 Oct 2007 10:01:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e2e8719d-5cef-4a64-813a-bf49cd1aa41f</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/10/04/ruby-cdk-for-newbies</link>
      <category>Tools</category>
      <category>rubycdk</category>
      <category>rcdk</category>
      <category>newbies</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Ruby CDK One-Liners: Create a Molfile With 2D Atom Coordinates From Arbitrary SMILES Strings</title>
      <description>&lt;p&gt;&lt;a href="http://ruby-lang.org"&gt;&lt;img src="http://depth-first.com/files/ruby_logo_new.gif" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;A very common operation in cheminformatics is the interconversion of molfiles and SMILES strings. Usually, converting from SMILES gives a molfile in which all atoms have coordinates of (0,0,0). Sometimes you just need more than that. The following &lt;a href="http://depth-first.com/articles/tag/rcdk"&gt;Ruby CDK&lt;/a&gt; code will accept an arbitrary SMILES string and return a molfile with fully-assigned 2D atom coordinates:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk/util&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;RCDK&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Util&lt;/span&gt;

&lt;span class="constant"&gt;XY&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;coordinate_molfile&lt;/span&gt; &lt;span class="constant"&gt;Lang&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;smiles_to_molfile&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;c1ccccc1&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Looking at it this way, those four lines of require/include statements seem pretty darn verbose.&lt;/p&gt;</description>
      <pubDate>Thu, 20 Sep 2007 14:18:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:8c347f16-8a0c-4d35-a02c-a2560fdc5f79</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/09/20/ruby-cdk-one-liners-create-a-molfile-with-2d-atom-coordinates-from-arbitrary-smiles-strings</link>
      <category>Tools</category>
      <category>rubycdk</category>
      <category>rcdk</category>
      <category>smiles</category>
      <category>molfile</category>
      <category>interconversion</category>
      <category>sdg</category>
      <category>coordinates</category>
    </item>
    <item>
      <title>Easily Calculate TPSA Descriptors from SMILES Strings Using Ruby CDK</title>
      <description>&lt;p&gt;&lt;a href="http://ruby-lang.org"&gt;&lt;img src="http://depth-first.com/files/ruby_logo_new.gif" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;A D-F reader wrote in to ask how to calculate Topological Polar Surface Area (TPSA) using &lt;a href="http://depth-first.com/articles/tag/rcdk"&gt;Ruby CDK&lt;/a&gt;. TPSA is one of the most widely-used descriptors for predicting membrane permeability and from it other important ADME properties. This article shows how to calculate TPSA with Ruby using Ruby CDK.&lt;/p&gt;

&lt;h4&gt;The Library&lt;/h4&gt;

&lt;p&gt;Our library consists of nothing more than a few method calls to manipulate the underlying &lt;a href="http://cdk.sf.net"&gt;CDK&lt;/a&gt; library. The &lt;tt&gt;tpsa_for&lt;/tt&gt; method accepts any SMILES string and returns the calculated TPSA:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require_gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk/util&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="ident"&gt;jrequire&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;org.openscience.cdk.qsar.descriptors.molecular.TPSADescriptor&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;TPSA&lt;/span&gt;
  &lt;span class="attribute"&gt;@@calc&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Org&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Openscience&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Cdk&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Qsar&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Descriptors&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Molecular&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TPSADescriptor&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;tpsa_for&lt;/span&gt; &lt;span class="ident"&gt;smiles&lt;/span&gt;
    &lt;span class="ident"&gt;mol&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;RCDK&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Util&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Lang&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;read_smiles&lt;/span&gt; &lt;span class="ident"&gt;smiles&lt;/span&gt;

    &lt;span class="attribute"&gt;@@calc&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;calculate&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;mol&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;getValue&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;doubleValue&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;An Interactive Test&lt;/h4&gt;

&lt;p&gt;Saving the library to a file called &lt;strong&gt;tpsa.rb&lt;/strong&gt; lets us test it through interactive Ruby (irb):&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'tpsa'
./tpsa.rb:2:Warning: require_gem is obsolete.  Use gem instead.
/usr/local/lib/ruby/gems/1.8/gems/rcdk-0.3.0/lib/rcdk/java.rb:26:Warning: require_gem is obsolete.  Use gem instead.
=&gt; true
irb(main):002:0&gt; include TPSA
=&gt; Object
irb(main):003:0&gt; tpsa_for 'COCCc1ccc(OCC(O)CNC(C)C)cc1' # metoprolol
=&gt; 50.72
irb(main):004:0&gt; tpsa_for 'O=C3Nc1ccc(Cl)cc1C(c2ccccc2)=NC3O' # oxazepam
=&gt; 61.69
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The results we obtain for metoprolol and oxazepam are 50.72 and 61.69, respectively. These values compare well with those reported by Ertl et al. in the &lt;a href="http://dx.doi.org/10.1021/jm000942e"&gt;definitive paper on TPSA&lt;/a&gt; (50.7 and 61.7, respectively).&lt;/p&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

&lt;p&gt;It doesn't take much Ruby to command a wide range of cheminformatics functionality - in this case TPSA calculations. But the fun doesn't stop there. The CDK, and by extension Ruby CDK, offer access to a &lt;a href="http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/api/org/openscience/cdk/qsar/descriptors/molecular/package-frame.html"&gt;wide array of descriptor calculations&lt;/a&gt;, each of which follow the same basic pattern outlined here. All of it can be prototyped, debugged, and deployed through one of the most flexible programming languages currently available.&lt;/p&gt;</description>
      <pubDate>Wed, 19 Sep 2007 09:27:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:f9b7229e-0e55-4299-a5ce-4d035a424398</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/09/19/easily-calculate-tpsa-descriptors-from-smiles-strings-using-ruby-cdk</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>rcdk</category>
      <category>rubycdk</category>
      <category>tpsa</category>
      <category>descriptor</category>
      <category>rjb</category>
    </item>
    <item>
      <title>From InChI to Image with Ruby Open Babel and Ruby CDK</title>
      <description>&lt;p&gt;&lt;a href="http://ruby-lang.org"&gt;&lt;img src="http://depth-first.com/files/ruby_logo_new.gif" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;Like SMILES, InChI is a line notation that can be used to encode and store chemical information relatively efficiently. Although there are a number of scenarios where this strategy is used, what many of them have in common is the need to eventually convert an InChI into a human-readable form. In most cases, this form will be a 2D chemical structure. This article will show how a small Ruby library can convert InChI strings into color PNG images with the help of &lt;a href="http://depth-first.com/articles/tag/rubyopenbabel"&gt;Ruby Open Babel&lt;/a&gt; and &lt;a href="http://depth-first.com/articles/tag/rcdk"&gt;Ruby CDK&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;The Library&lt;/h4&gt;

&lt;p&gt;Our library accepts an InChI as input and produces a scaled PNG image as output. It re-uses part of a &lt;a href="http://depth-first.com/articles/2007/06/25/interconvert-almost-any-smiles-and-inchi-with-ruby-open-babel"&gt;previously-discussed&lt;/a&gt; library for the interconversion of SMILES and InChI.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;openbabel&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require_gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk/util&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;InChI&lt;/span&gt;
  &lt;span class="attribute"&gt;@@to_smiles&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;OpenBabel&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;OBConversion&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="attribute"&gt;@@to_smiles&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;set_in_and_out_formats&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;inchi&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;smi&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;inchi_to_png&lt;/span&gt; &lt;span class="ident"&gt;inchi&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;path_to_png&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;height&lt;/span&gt;
    &lt;span class="ident"&gt;smiles&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;inchi_to_smiles&lt;/span&gt; &lt;span class="ident"&gt;inchi&lt;/span&gt;

    &lt;span class="constant"&gt;RCDK&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Util&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Image&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;smiles_to_png&lt;/span&gt; &lt;span class="ident"&gt;smiles&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;path_to_png&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;height&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;private&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;inchi_to_smiles&lt;/span&gt; &lt;span class="ident"&gt;inchi&lt;/span&gt;
      &lt;span class="ident"&gt;mol&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;OpenBabel&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;OBMol&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;

      &lt;span class="attribute"&gt;@@to_smiles&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;read_string&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;mol&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;inchi&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;or&lt;/span&gt; &lt;span class="keyword"&gt;raise&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;Can't parse InChI: &lt;span class="expr"&gt;#{inchi}&lt;/span&gt;.&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
      &lt;span class="attribute"&gt;@@to_smiles&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;write_string&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;mol&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;strip&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Testing&lt;/h4&gt;

Our library can be tested by saving it to a file called &lt;strong&gt;inchi.rb&lt;/strong&gt; and using interactive Ruby (the warning can safely be ignored for now):

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'inchi'
./inchi.rb:3:Warning: require_gem is obsolete.  Use gem instead.
/usr/local/lib/ruby/gems/1.8/gems/rcdk-0.3.0/lib/rcdk/java.rb:26:Warning: require_gem is obsolete.  Use gem instead.
i=&gt; true
irb(main):002:0&gt; include InChI
=&gt; Object
irb(main):003:0&gt; inchi='InChI=1/C23H27FN4O2/c1-15-18(23(29)28-10-3-2-4-21(28)25-15)9-13-27-11-7-16(8-12-27)22-19-6-5-17(24)14-20(19)30-26-22/h5-6,14,16H,2-4,7-13H2,1H3' #risperidone
=&gt; "InChI=1/C23H27FN4O2/c1-15-18(23(29)28-10-3-2-4-21(28)25-15)9-13-27-11-7-16(8-12-27)22-19-6-5-17(24)14-20(19)30-26-22/h5-6,14,16H,2-4,7-13H2,1H3"
irb(main):004:0&gt; inchi_to_png inchi, 'risperidone.png', 300, 300
=&gt; nil
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This code produces the following image:&lt;/p&gt;

&lt;p&gt;&lt;center&gt;&lt;a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=5073"&gt;&lt;img src="http://depth-first.com/demo/20070906/risperidone.png"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;Our library can also be used on more complicated molecules, for example Brevetoxin:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'inchi'
./inchi.rb:3:Warning: require_gem is obsolete.  Use gem instead.
/usr/local/lib/ruby/gems/1.8/gems/rcdk-0.3.0/lib/rcdk/java.rb:26:Warning: require_gem is obsolete.  Use gem instead.
=&gt; true
irb(main):002:0&gt; include InChI
=&gt; Object
irb(main):003:0&gt; inchi='InChI=1/C49H70O13/c1-26-17-36-39(22-45(52)58-36)57-44-21-38-40(62-48(44,4)23-26)18-28(3)46-35(55-38)11-7-6-10-31-32(59-46)12-8-14-34-33(54-31)13-9-15-43-49(5,61-34)24-42-37(56-43)20-41-47(60-42)30(51)19-29(53-41)16-27(2)25-50/h6-8,14,25-26,28-44,46-47,51H,2,9-13,15-24H2,1,3-5H3/b7-6-,14-8-' #brevetoxin a
=&gt; "InChI=1/C49H70O13/c1-26-17-36-39(22-45(52)58-36)57-44-21-38-40(62-48(44,4)23-26)18-28(3)46-35(55-38)11-7-6-10-31-32(59-46)12-8-14-34-33(54-31)13-9-15-43-49(5,61-34)24-42-37(56-43)20-41-47(60-42)30(51)19-29(53-41)16-27(2)25-50/h6-8,14,25-26,28-44,46-47,51H,2,9-13,15-24H2,1,3-5H3/b7-6-,14-8-"
irb(main):004:0&gt; inchi_to_png inchi, 'brevetoxin.png', 300, 200
=&gt; nil
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This produces the following image:&lt;/p&gt;

&lt;p&gt;&lt;center&gt;&lt;a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=6437089"&gt;&lt;img src="http://depth-first.com/demo/20070906/brevetoxin.png"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/center&gt;&lt;/p&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

&lt;p&gt;While our library could certainly be improved, it solves what otherwise would be a very difficult problem conveniently. Areas for further work include error handling and improving the appearance of the images (the latter is the aim of &lt;a href="http://depth-first.com/articles/tag/firefly"&gt;Firefly&lt;/a&gt;). Despite the fact that three programming languages are used (Ruby, C++, and Java), this complexity is neatly encapsulated behind a simple Ruby interface.&lt;/p&gt;</description>
      <pubDate>Thu, 06 Sep 2007 08:25:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:242847bf-aa4f-474d-979f-7b73ed072a28</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/09/06/from-inchi-to-image-with-ruby-open-babel-and-ruby-cdk</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>rubycdk</category>
      <category>rcdk</category>
      <category>rubyopenbabel</category>
      <category>depict</category>
      <category>inchi</category>
      <category>sdg</category>
    </item>
    <item>
      <title>Structure Diagram Generation</title>
      <description>&lt;p&gt;&lt;img src="http://depth-first.com/demo/20070411/difficult.png" align="right"&gt;&lt;/img&gt;Given a molecule with no 2D coordinates, how would you render a human-readable view? This problem arises in many situations, but most commonly in the context of interpreting &lt;a href="http://depth-first.com/articles/tag/linenotation"&gt;line notations&lt;/a&gt; such as IUPAC nomenclature, SMILES, or InChI. Whatever the solution you come up with, you'll come face-to-face with the structure diagram generation (SDG) problem.&lt;/p&gt;

&lt;p&gt;Generating 2D molecular coordinates is a fundamental (and remarkably difficult) problem in cheminformatics. Discussions in the primary literature &lt;a href="http://dx.doi.org/10.1021/ci60011a015"&gt;date back&lt;/a&gt; to at least the 1970s with Chemical Abstract Service's pioneering large-scale efforts. A &lt;a href="http://dx.doi.org/10.1021/ci050550m"&gt;recent article&lt;/a&gt; from Chemical Computing Group (CCG) described the design and implementation of an advanced SDG system. To my knowledge, the only open source implementation of an SDG system is found in the &lt;a href="http://wiki.cubic.uni-koeln.de/cdknews/index.php/CDKNews/article/view/5"&gt;Chemistry Development Kit&lt;/a&gt;, and by extension &lt;a href="http://depth-first.com/articles/tag/rubycdk"&gt;Ruby CDK&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The SDG problem plays an important role in the &lt;a href="http://depth-first.com/articles/2007/03/30/the-aesthetics-of-chemical-structure-diagrams"&gt;aesthetics of chemical structure diagrams&lt;/a&gt;, as mentioned by two readers. To render a molecule aesthetically, 2D coordinates must minimize confusing atom overlaps, unconventional orientations, and unusual bond angles.&lt;/p&gt;

&lt;p&gt;The role of SDG in cheminformatics can only continue to increase in importance, especially as more and more structures are automatically generated through mining the primary literature, the Internet, &lt;a href="http://wwmm.ch.cam.ac.uk/blogs/murrayrust/?p=28"&gt;old PDFs&lt;/a&gt;, and other sources. With all of these new computer-generated structures will come the need to make them readily understandable to a chemist through SDG.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Apr 2007 10:20:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:9212c666-5a2f-414a-82c3-2a63ea07d845</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/04/11/structure-diagram-generation</link>
      <category>Tools</category>
      <category>sdg</category>
      <category>rubycdk</category>
      <category>aesthetics</category>
      <category>2d</category>
      <category>smiles</category>
      <category>inchi</category>
    </item>
    <item>
      <title>From IUPAC Name to Molecular Formula with Ruby CDK</title>
      <description>&lt;p&gt;&lt;img src="http://depth-first.com/files/ruby_logo_new.gif" align="right"&gt;&lt;/a&gt;Recently, a question was raised on the &lt;a href="http://tech.groups.yahoo.com/group/chemoinf/"&gt;Yahoo cheminf group list&lt;/a&gt; regarding the conversion of IUPAC names into molecular formulas. This can be done quickly with Ruby CDK, as this article will show.&lt;/p&gt;

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

&lt;p&gt;This tutorial requires &lt;a href="http://depth-first.com/articles/2006/10/30/agile-chemical-informatics-development-with-cdk-and-ruby-rcdk-0-3-0"&gt;Ruby CDK&lt;/a&gt;, which in turn requires &lt;a href="http://rjb.rubyforge.org/"&gt;Ruby Java Bridge&lt;/a&gt; (RJB). A recent Depth-First article described the minimal system configuration required to run &lt;a href="http://depth-first.com/articles/2006/08/26/scripting-java-libraries-with-ruby-java-bridge"&gt;RJB on Linux&lt;/a&gt;. Another article showed how to install &lt;a href="http://depth-first.com/articles/2006/10/12/running-ruby-java-bridge-on-windows"&gt;RJB on Windows&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;A Small Library&lt;/h4&gt;

&lt;p&gt;The following library will convert IUPAC nomenclature into molecular formulas with Ruby:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require_gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rcdk/util&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;Formulator&lt;/span&gt;
  &lt;span class="attribute"&gt;@@hydrogen_adder&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Rjb&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="ident"&gt;import&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;org.openscience.cdk.tools.HydrogenAdder&lt;/span&gt;&lt;span class="punct"&gt;').&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;get_formula&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;iupac_name&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;mol&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;RCDK&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Util&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Lang&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;read_iupac&lt;/span&gt; &lt;span class="ident"&gt;iupac_name&lt;/span&gt;
    &lt;span class="attribute"&gt;@@hydrogen_adder&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;addExplicitHydrogensToSatisfyValency&lt;/span&gt; &lt;span class="ident"&gt;mol&lt;/span&gt;
    &lt;span class="ident"&gt;analyzer&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Rjb&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="ident"&gt;import&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;org.openscience.cdk.tools.MFAnalyser&lt;/span&gt;&lt;span class="punct"&gt;').&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;mol&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

    &lt;span class="ident"&gt;analyzer&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;getMolecularFormula&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Save this code as a file named &lt;strong&gt;formulator.rb&lt;/strong&gt; in your working directory.&lt;/p&gt;

&lt;h4&gt;Testing the Library&lt;/h4&gt;

&lt;p&gt;The Formulator library can be tested with the following code:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;formulator&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;Formulator&lt;/span&gt;

&lt;span class="ident"&gt;get_formula&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;benzene&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; &amp;quot;C6H6&amp;quot;&lt;/span&gt;
&lt;span class="ident"&gt;get_formula&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;4-(3,4-dichlorophenyl)-N-methyl-1,2,3,4-tetrahydronaphthalen-1-amine&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; &amp;quot;C17H17NCl2&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Limitations&lt;/h4&gt;

&lt;p&gt;You may run across classes of structures that are not recognized by Ruby CDK. This is due to limitations of the underlying &lt;a href="http://depth-first.com/articles/tag/opsin"&gt;OPSIN library&lt;/a&gt;. For example, OPSIN does not yet recognize fused heterocycle names such as 'imidazo[2,1-b][1,3]thiazole'.&lt;/p&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

&lt;p&gt;Ruby CDK makes short work of converting IUPAC names into molecular formulas. This is just one example of the kind of conversion that's possible. For example, &lt;a href="http://depth-first.com/articles/2006/10/30/agile-chemical-informatics-development-with-cdk-and-ruby-rcdk-0-3-0"&gt;a recent article&lt;/a&gt; discussed the conversion of IUPAC names to color 2-D structures.&lt;/p&gt;

&lt;p&gt;Due to Ruby's position as both a highly functional scripting language and as the foundation for the popular Web application framework &lt;a href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt;, a variety of IUPAC nomenclature translation applications are just a few lines of code away.&lt;/p&gt;</description>
      <pubDate>Tue, 13 Mar 2007 10:25:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6529cee0-0821-45b1-865a-267a3254d85a</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/03/13/from-iupac-name-to-molecular-formula-with-ruby-cdk</link>
      <category>Tools</category>
      <category>rubycdk</category>
      <category>rcdk</category>
      <category>iupac</category>
      <category>formula</category>
    </item>
  </channel>
</rss>
