<?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 rubyopenbabel</title>
    <link>http://depth-first.com/articles/tag/rubyopenbabel</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Open Babel 2.2.0</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.org"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right"&gt;&lt;/img&gt;&lt;/a&gt;&lt;a href="http://openbabel.org"&gt;Open Babel&lt;/a&gt; 2.2.0 has been &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=40728&amp;amp;package_id=32894"&gt;released&lt;/a&gt;. This version introduces a variety of new features and improvements. It also includes the &lt;a href="http://depth-first.com/articles/2007/04/09/painless-installation-of-ruby-open-babel"&gt;Ruby Open Babel&lt;/a&gt; interface that allows scripting through the popular &lt;a href="http://ruby-lang.org"&gt;Ruby language&lt;/a&gt;; Ruby Open Babel can be &lt;a href="http://depth-first.com/articles/2007/04/09/painless-installation-of-ruby-open-babel"&gt;installed both quickly and easily&lt;/a&gt;. Further details are available from the &lt;a href="http://openbabel.org/wiki/Open_Babel_2.2.0"&gt;release notes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Future articles will highlight some of the new Open Babel features using Ruby.&lt;/p&gt;</description>
      <pubDate>Fri, 04 Jul 2008 11:29:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c4a2fcb5-29a7-496c-b9f0-529b84997d04</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2008/07/04/open-babel-2-2-0</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>rubyopenbabel</category>
      <category>openbabel</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>Interconvert (Almost) Any SMILES and InChI with Ruby Open Babel</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.sf.net"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;SMILES and InChI are the two most widely-used &lt;a href="http://depth-first.com/articles/2007/03/14/eleven-qualities-of-the-perfect-line-notation-for-the-web"&gt;line notations&lt;/a&gt; in cheminformatics. Not surprisingly, there are many situations in which it's useful to interconvert the two. This article shows a simple method for doing so using &lt;a href="http://depth-first.com/articles/tag/rubyopenbabel"&gt;Ruby Open Babel&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Parsing InChIs&lt;/h4&gt;

&lt;p&gt;Version 1.01 of the IUPAC/NIST C InChI toolkit introduced the ability to parse InChIs. This capability has subsequently been incorporated into &lt;a href="http://openbabel.sf.net"&gt;Open Babel&lt;/a&gt;, and by extension, Ruby Open Babel. It's this capability that we'll take advantage of.&lt;/p&gt;

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

&lt;p&gt;The following library provides everything we need to convert between SMILES and InChI via 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;openbabel&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_inchi&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="attribute"&gt;@@to_inchi&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;smi&lt;/span&gt;&lt;span class="punct"&gt;',&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="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;def &lt;/span&gt;&lt;span class="method"&gt;smiles_to_inchi&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;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_inchi&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;smiles&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 SMILES &lt;span class="expr"&gt;#{smiles}&lt;/span&gt;.&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
    &lt;span class="attribute"&gt;@@to_inchi&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 the Library&lt;/h4&gt;

&lt;p&gt;After saving the above code to a file named &lt;strong&gt;inchi.rb&lt;/strong&gt;, we can interactively convert SMILES and InChIs:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'inchi'
=&gt; true
irb(main):002:0&gt; include InChI
=&gt; Object
irb(main):003:0&gt; smiles = inchi_to_smiles "InChI=1/C14H12/c1-3-7-13(8-4-1)11-12-14-9-5-2-6-10-14/h1-12H/b12-11-"
=&gt; "c1ccc(cc1)C(/[H])=C(/[H])c1ccccc1"
irb(main):004:0&gt; inchi = smiles_to_inchi smiles
=&gt; "InChI=1/C14H12/c1-3-7-13(8-4-1)11-12-14-9-5-2-6-10-14/h1-12H/b12-11-"
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;In the above test, the InChI for &lt;em&gt;cis&lt;/em&gt;-stilbene is converted into a SMILES string which is then converted back to InChI form with complete fidelity, including alkene geometry. Note that this would not have been possible using the approach that was &lt;a href="http://depth-first.com/articles/2006/09/19/decoding-inchis-with-rino"&gt;previously discussed&lt;/a&gt; in which molfiles were used as intermediate datastructures.&lt;/p&gt;

&lt;p&gt;What about chiral centers? Here the results are mixed. For example, when the round-trip conversion is applied to propranalol (&lt;a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=21138"&gt;PubChem&lt;/a&gt;, &lt;a href="http://60minutes.yahoo.com/segment/21/memory_drug"&gt;Video&lt;/a&gt;), the configuration of the stereocenter is &lt;em&gt;inverted&lt;/em&gt;.&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'inchi'
=&gt; true
irb(main):002:0&gt; include InChI
=&gt; Object
irb(main):003:0&gt; smiles = inchi_to_smiles "InChI=1/C16H21NO2/c1-12(2)17-10-14(18)11-19-16-9-5-7-13-6-3-4-8-15(13)16/h3-9,12,14,17-18H,10-11H2,1-2H3/t14-/m1/s1"
=&gt; "CC(C)NC[C@@H](COc1cccc2ccccc12)O"
irb(main):004:0&gt; inchi = smiles_to_inchi smiles
=&gt; "InChI=1/C16H21NO2/c1-12(2)17-10-14(18)11-19-16-9-5-7-13-6-3-4-8-15(13)16/h3-9,12,14,17-18H,10-11H2,1-2H3/t14-/m0/s1"
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;However, the same round-trip conversion of phenethanol works without inversion of stereochemistry:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'inchi'
=&gt; true
irb(main):002:0&gt; include InChI
=&gt; Object
irb(main):003:0&gt; smiles = inchi_to_smiles " InChI=1/C8H10O/c1-7(9)8-5-3-2-4-6-8/h2-7,9H,1H3/t7-/m0/s1"
=&gt; "C[C@@H](c1ccccc1)O"
irb(main):004:0&gt; inchi = smiles_to_inchi smiles
=&gt; "InChI=1/C8H10O/c1-7(9)8-5-3-2-4-6-8/h2-7,9H,1H3/t7-/m0/s1"
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The most likely explanation is that under certain conditions, Open Babel incorrectly interprets and/or writes stereo parities.&lt;/p&gt;

&lt;h4&gt;One More Gotcha&lt;/h4&gt;

&lt;p&gt;On my system (Linux Mandriva 2007.1), attempting to perform the round-trip test on glucose resulted (reproducibly) in a segfault:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'inchi'
=&gt; true
irb(main):002:0&gt; include InChI
=&gt; Object
irb(main):003:0&gt; smiles = inchi_to_smiles "InChI=1/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5-,6?/m1/s1"
=&gt; "C([C@H]1[C@H]([C@@H]([C@H](C(O)O1)O)O)O)O"
irb(main):004:0&gt; inchi = smiles_to_inchi smiles
./inchi.rb:20: [BUG] Segmentation fault
ruby 1.8.6 (2007-03-13) [i686-linux]

Aborted
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The same segfault was obtained when using the &lt;tt&gt;babel&lt;/tt&gt; command-line utility:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ babel -ismi -oinchi
C([C@H]1[C@H]([C@@H]([C@H](C(O)O1)O)O)O)O
[Return]
Segmentation fault
&lt;/pre&gt;
&lt;/div&gt;

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

&lt;p&gt;As you can see, Ruby Open Babel makes short work of interconverting SMILES and InChIs. Despite problems with stereochemical configuration and segfaults on reading certain SMILES strings, the approach outlined here offers a quick and economical way to interconvert a variety of SMILES and InChIs.&lt;/p&gt;</description>
      <pubDate>Mon, 25 Jun 2007 08:45:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:08b043b0-d9c9-4de9-bc51-c20b4f94c306</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/06/25/interconvert-almost-any-smiles-and-inchi-with-ruby-open-babel</link>
      <category>Tools</category>
      <category>inchi</category>
      <category>smiles</category>
      <category>rubyopenbabel</category>
    </item>
    <item>
      <title>Interactive Ruby Open Babel</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.sf.net"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;One of my favorite features of Ruby is the &lt;a href="http://tryruby.hobix.com/"&gt;Interactive Ruby&lt;/a&gt; (irb) shell. For those who haven't used it, irb lets you interactively create Ruby programs. Are you not exactly sure how to use that new library? Do you want to be able to "play" with an object to see how it works? Then irb is the perfect tool.&lt;/p&gt;

&lt;p&gt;One of the new features contained in &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=40728&amp;amp;package_id=32894&amp;amp;release_id=499413"&gt;Open Babel 2.1&lt;/a&gt; is a &lt;a href="http://depth-first.com/articles/2007/04/09/painless-installation-of-ruby-open-babel"&gt;Ruby interface&lt;/a&gt;. The power and convenience of irb makes it an excellent tool for exploring Open Babel. With some minor customizations, it can be even better.&lt;/p&gt;

&lt;h4&gt;Customizing irb&lt;/h4&gt;

&lt;p&gt;Your irb sessions can be customized by creating and editing the &lt;strong&gt;.irbrc&lt;/strong&gt; file located in your home directory. This file, containing standard Ruby, is loaded prior to the start of your irb session.&lt;/p&gt;

&lt;h4&gt;Tab Completion&lt;/h4&gt;

&lt;p&gt;Code completion is one of those things that, once you've used it, you wonder how you ever got by without. Although it tends not to be activated by default, irb fully supports code completion with the "Tab" key.&lt;/p&gt;

&lt;p&gt;To activate this feature, add the following line to your &lt;strong&gt;.irbrc&lt;/strong&gt; file:&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;irb/completion&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

As an example, let's say you'd like to use irb to understand how &lt;tt&gt;OpenBabel::OBMol&lt;/tt&gt; objects work. Entering the following code gets you there:

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'openbabel'
=&gt; true
irb(main):002:0&gt; mol=OpenBabel::OBMol.new
=&gt; #&amp;lt;OpenBabel::OBMol:0xb7cd30a4&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;What exactly can this OBMol do? Let's start with the "get" methods. Entering &lt;tt&gt;mol.get&lt;/tt&gt; followed by the Tab key gives the following:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
irb(main):003:0&gt; mol.get
mol.get_angle                    mol.get_gidvector
mol.get_atom                     mol.get_givector
mol.get_bond                     mol.get_gtdvector
mol.get_conformer                mol.get_internal_coord
mol.get_conformers               mol.get_mod
mol.get_coordinates              mol.get_mol_wt
mol.get_data                     mol.get_residue
mol.get_dimension                mol.get_spaced_formula
mol.get_energy                   mol.get_sssr
mol.get_exact_mass               mol.get_title
mol.get_first_atom               mol.get_torsion
mol.get_flags                    mol.get_total_charge
mol.get_formula                  mol.get_total_spin_multiplicity
irb(main):003:0&gt; mol.get_
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;If you were interested in molecular weight, you'd see the &lt;tt&gt;mol.get_mol_wt&lt;/tt&gt; method, which you could fully enter by typing &lt;tt&gt;mol.get_mol&lt;/tt&gt; followed by the Tab key.&lt;/p&gt;

&lt;p&gt;Tab completion also works with module names. What are the complete contents of the &lt;tt&gt;OpenBabel&lt;/tt&gt; module? Just type &lt;tt&gt;OpenBabel::&lt;/tt&gt; followed by the Tab key. There are over 400 possibilities, so you might want to narrow it down a bit. For example, &lt;tt&gt;OpenBabel::OBM&lt;/tt&gt; followed by the Tab key gives:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
irb(main):003:0&gt; OpenBabel::OBM
OpenBabel::OBMessageHandler  OpenBabel::OBMolAtomDFSIter  OpenBabel::OBMolRingIter
OpenBabel::OBMol             OpenBabel::OBMolAtomIter     OpenBabel::OBMolTorsionIter
OpenBabel::OBMolAngleIter    OpenBabel::OBMolBondIter
OpenBabel::OBMolAtomBFSIter  OpenBabel::OBMolPairIter
irb(main):003:0&gt; OpenBabel::OBM 
&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;Persistent Command History&lt;/h4&gt;

&lt;p&gt;Just like other shell environments, irb supports a command line history through the up and down arrows. Like Tab completion, it's one of those things you can't work without.&lt;/p&gt;

&lt;p&gt;As you use irb, you'll find yourself exiting and re-entering frequently. By default, irb doesn't support persistent command histories. This means your previous commands are lost every time you exit. What a pain.&lt;/p&gt;

&lt;p&gt;Luckily, it's easy to create a persistent command history. Fire up your text editor and make the following changes to &lt;strong&gt;.irbrc&lt;/strong&gt;:&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;irb/completion&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;irb/ext/save-history&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="constant"&gt;ARGV&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;concat&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;--readline&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;,&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;--prompt-mode&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;,&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;simple&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;]&lt;/span&gt;
&lt;span class="constant"&gt;IRB&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;conf&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:SAVE_HISTORY&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;100&lt;/span&gt;
&lt;span class="constant"&gt;IRB&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;conf&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:HISTORY_FILE&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;&lt;span class="expr"&gt;#{ENV['HOME']}&lt;/span&gt;/.irb-save-history&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;From now on, your last 100 irb commands will be just a single key away, regardless of how many sessions ago they were entered.&lt;/p&gt;

One caveat: if you compile Ruby from source, you may notice that the command history doesn't work. Instead, pressing the up-arrow displays "[[A".

I found the fix in &lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/5118"&gt;this list posting&lt;/a&gt;. In your Ruby source distribution directory, execute the following commands:

&lt;div class="console"&gt;
&lt;pre&gt;
$ cd ext/readline
$ ruby extconf.rb
$ make
$ sudo make install
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Why this extension doesn't compile by default is beyond me, but at least the solution is simple.&lt;/p&gt;

&lt;h4&gt;Other Customizations&lt;/h4&gt;

&lt;p&gt;You can customize irb in many other ways. For some ideas, see &lt;a href="http://www.rubycentral.com/book/irb.html"&gt;The Pickaxe Book&lt;/a&gt; and &lt;a href="http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks"&gt;RubyGarden&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Wed, 16 May 2007 10:07:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6ee27b96-125d-402b-afd0-9f4315d3b47e</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/05/16/interactive-ruby-open-babel</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>rubyopenbabel</category>
      <category>irb</category>
      <category>tabcompletion</category>
      <category>commandhistory</category>
    </item>
    <item>
      <title>Painless Installation of Ruby Open Babel</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.sf.net"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;&lt;a href="http://openbabel.sf.net"&gt;Open Babel&lt;/a&gt; 2.1.0 has just been &lt;a href="http://downloads.sourceforge.net/openbabel/openbabel-2.1.0.tar.gz?modtime=1175958364&amp;amp;big_mirror=0"&gt;released&lt;/a&gt;. Among its new features is a Ruby interface containing most of the functionality of the C++ library. Installation is quick and easy, as shown in this article.&lt;/p&gt;

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

&lt;p&gt;In addition to a working build system, you'll need &lt;a href="http://www.ruby-lang.org/en/"&gt;Ruby&lt;/a&gt; and the Ruby development libraries. Although any recent version should do, this tutorial was written with version 1.8.5.&lt;/p&gt;

&lt;h4&gt;Step 0: Compile and Install Open Babel&lt;/h4&gt;

&lt;p&gt;Given the right tools on your system, compiling and and installing Open Babel from source is trivial. &lt;a href="http://openbabel.sourceforge.net/wiki/Get_Open_Babel"&gt;This page&lt;/a&gt; gives instructions for doing so on Linux, Windows, and Mac OS X.&lt;/p&gt;

&lt;h4&gt;Step 1: Create the Wrapper's Makefile&lt;/h4&gt;

&lt;p&gt;After unpacking, compiling, and installing Open Babel, change into the &lt;strong&gt;scripts/ruby&lt;/strong&gt; directory of your source distribution. Next, run the &lt;strong&gt;extconf.rb&lt;/strong&gt; script:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ ruby extconf.rb
checking for main() in -lopenbabel... yes
creating Makefile
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you've probably guessed, the purpose of this script is to generate a Makefile specific to your platform. This script uses the standard Ruby library &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/mkmf/rdoc/index.html"&gt;mkmf&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Step 2: Compile the Wrapper&lt;/h4&gt;

&lt;p&gt;After creating a Makefile, we're ready to compile the C++ Ruby wrapper, contained in &lt;strong&gt;openbabel_ruby.cpp&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ make
g++ -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux-gnu -I. -I../../include  -fPIC -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -Wall  -fPIC   -c openbabel_ruby.cpp
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This output will be followed by other lines as the compiler builds the wrapper library.&lt;/p&gt;

&lt;h4&gt;Step 3: Install the Wrapper&lt;/h4&gt;

&lt;p&gt;After compiling the wrapper, we're ready to install it. You can probably guess that the next command will be (as root):&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
# make install
/usr/bin/install -c -m 0755 openbabel.so /usr/lib/ruby/site_ruby/1.8/x86_64-linux-gnu
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Your install directory is chosen by Ruby to be appropriate for your platform and Ruby version.&lt;/p&gt;

&lt;h4&gt;Hello, Benzene!&lt;/h4&gt;

&lt;p&gt;Congratulations, you've installed Ruby Open Babel! You can verify that your new library works with interactive Ruby (irb):&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'openbabel'
=&gt; true
irb(main):002:0&gt; c=OpenBabel::OBConversion.new
=&gt; #&amp;lt;OpenBabel::OBConversion:0x2acedbadd020&amp;gt;
irb(main):003:0&gt; c.set_in_format 'smi'
=&gt; true
irb(main):004:0&gt; benzene=OpenBabel::OBMol.new
=&gt; #&amp;lt;OpenBabel::OBMol:0x2acedbacfa10&amp;gt;
irb(main):005:0&gt; c.read_string benzene, 'c1ccccc1'
=&gt; true
irb(main):006:0&gt; benzene.num_atoms
=&gt; 6
&lt;/pre&gt;
&lt;/div&gt;</description>
      <pubDate>Mon, 09 Apr 2007 10:09:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a3e7148e-96de-416a-996f-a8c7d7289531</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/04/09/painless-installation-of-ruby-open-babel</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>rubyopenbabel</category>
      <category>obruby</category>
      <category>openbabel</category>
      <category>mkmf</category>
    </item>
    <item>
      <title>Creating Canonical SMILES with Ruby Open Babel</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.sf.net"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right" border="0"&gt;&lt;/a&gt;&lt;/img&gt;Unlike many data types, molecular structure representations are not normally unique. Each numbering system you choose for the atoms and bonds of a molecule gives rise to completely accurate, but degenerate molecular representations. This is one of the fundamental &lt;a href="http://depth-first.com/articles/2006/09/03/peculiarities-of-chemical-information"&gt;peculiarities of chemical information&lt;/a&gt; - and the focus of much research activity &lt;a href="http://depth-first.com/articles/2007/03/14/eleven-qualities-of-the-perfect-line-notation-for-the-web"&gt;over the last sixty or so years&lt;/a&gt;. One of the most widely-used approaches to this problem is canonicalization.&lt;/p&gt;

&lt;p&gt;This article discusses the &lt;a href="http://sourceforge.net/forum/forum.php?forum_id=629764"&gt;SMILES canonicalization capability&lt;/a&gt; in the upcoming Open Babel 2.1 release. Among several other enhancements, this release will also feature a brand new Ruby interface. By way of preview, this article will demonstrate just how convenient it has now become to generate canonical SMILES strings with Ruby.&lt;/p&gt;

&lt;p&gt;&lt;center&gt;&lt;img src="http://depth-first.com/demo/20070403/aminopterin.png"&gt;&lt;/img&gt;&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;Consider the putative rodenticide aminopterin, the structure of which is shown above. Regardless of whether it turns out to be the culprit in the &lt;a href="http://www.cbsnews.com/stories/2007/03/23/national/main2600615.shtml"&gt;recent pet food poisoning case&lt;/a&gt;, it's a relatively complex molecule. And with this complexity comes many possible representations. Here's one of just hundreds, if not thousands, of possible SMILES strings for this molecule:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
Nc3nc(N)c2nc(CNc1ccc(C(=O)N[C@@H](CCC(=O)O)C(=O)O)cc1)cnc2n3
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;If you were developing a database of molecules and needed to support exact structure searching, how would you do it? One way would be to convert a query molecule to a canonical SMILES string, and then simply look for that string in an index of your database's canonical SMILES. This is useful because it allows us to convert a chemistry-specific problem (exact structure search) into a generic computer science problem (text matching).&lt;/p&gt;

&lt;p&gt;We can create a simple Ruby library to convert any SMILES string into an Open Babel canonical SMILES string:&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;openbabel&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Can&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;
    &lt;span class="attribute"&gt;@conversion&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;@conversion&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;smi&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;can&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;convert&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;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;@conversion&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;read_string&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;smiles&lt;/span&gt;
    &lt;span class="attribute"&gt;@conversion&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;write_string&lt;/span&gt; &lt;span class="ident"&gt;mol&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;

Save this code as a file called &lt;strong&gt;can.rb&lt;/strong&gt; in your working directory. The library can then be used, for example, via interactive ruby (irb):

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'can'
=&gt; true
irb(main):002:0&gt; c=Can.new
=&gt; #&lt;Can:0x2ac6cc653228 @conversion=#&lt;OpenBabel::Conversion:0x2ac6cc6531d8&gt;&gt;
irb(main):003:0&gt; puts c.convert('Nc3nc(N)c2nc(CNc1ccc(C(=O)N[C@@H](CCC(=O)O)C(=O)O)cc1)cnc2n3')
OC(=O)CC[C@@H](NC(=O)c1ccc(NCc2cnc3nc(N)nc(N)c3n2)cc1)C(=O)O
=&gt; nil
irb(main):004:0&gt; puts c.convert('C1=CC(=CC=C1C(=O)N[C@@H](CCC(=O)O)C(=O)O)NCC2=CN=C3C(=N2)C(=NC(=N3)N)N')
OC(=O)CC[C@@H](NC(=O)c1ccc(NCc2cnc3nc(N)nc(N)c3n2)cc1)C(=O)O
=&gt; nil
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you can see, both SMILES strings for aminopterin were converted into the same canonical SMILES string.&lt;/p&gt;

&lt;p&gt;Unlike InChI, which uses a "standard" &lt;a href="http://depth-first.com/articles/2006/08/12/inchi-canonicalization-algorithm"&gt;canonicalization algorithm&lt;/a&gt;, SMILES canonicalization varies by software package. As a result, the SMILES canonicalization described here will be most useful &lt;em&gt;within&lt;/em&gt; a software package, but probably not &lt;em&gt;externally&lt;/em&gt; to it, at least initially.&lt;/p&gt;

&lt;p&gt;Ruby is still an upstart language in cheminformatics. But tools like &lt;a href="http://depth-first.com/articles/tag/rubycdk"&gt;Ruby CDK&lt;/a&gt; and Ruby Open Babel offer ample opportunities for learning what this remarkable language can do for the development of chemistry applications.&lt;/p&gt;</description>
      <pubDate>Tue, 03 Apr 2007 11:59:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:53ca2aed-221a-4d52-bbb9-324fedce78d8</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/04/03/creating-canonical-smiles-with-ruby-open-babel</link>
      <category>Tools</category>
      <category>openbabel</category>
      <category>ruby</category>
      <category>rubyopenbabel</category>
      <category>smiles</category>
      <category>canonicalization</category>
    </item>
  </channel>
</rss>
