<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="http://egonw.github.io/blog/feed/by_tag/pubchem.xml" rel="self" type="application/atom+xml" /><link href="http://egonw.github.io/blog/" rel="alternate" type="text/html" /><updated>2026-11-30T04:27:36+00:00</updated><id>http://egonw.github.io/blog/feed/by_tag/pubchem.xml</id><title type="html">chem-bla-ics</title><subtitle>Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.</subtitle><author><name>Egon Willighagen</name></author><entry><title type="html">How many hydrogen-bond acceptor groups does triazole have?</title><link href="http://egonw.github.io/blog/2010/12/10/how-many-hydrogen-bond-acceptor-groups.html" rel="alternate" type="text/html" title="How many hydrogen-bond acceptor groups does triazole have?" /><published>2010-12-10T00:00:00+00:00</published><updated>2010-12-10T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2010/12/10/how-many-hydrogen-bond-acceptor-groups</id><content type="html" xml:base="http://egonw.github.io/blog/2010/12/10/how-many-hydrogen-bond-acceptor-groups.html"><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Andrew_S.I.D._Lang">Andrew</a> asked me about the
H-bond donor capabilities of <a href="http://en.wikipedia.org/wiki/1,2,4-Triazole">1,2,4-triazole</a>:</p>

<p><img src="/blog/assets/images/1,2,4-triazole.png" alt="" /></p>

<p>Apparently, the way he uses the <a href="http://cdk.sf.net">CDK</a> library, it returns
<a href="https://sourceforge.net/tracker/index.php?func=detail&amp;aid=3133610&amp;group_id=20024&amp;atid=120024">zero H-bond donor groups</a>,
as is visible in <a href="http://showme.physics.drexel.edu/onsc/models/AbrahamDescriptorsModel001.php?commonname=1,2,4-triazole">his application</a>
down the bottom of the page. When start from the PubChem entry, it correctly
detects on H-bond donor group, so it seems to have to do with implicit hydrogens
(not uncommon). Debugging will continue later, when I am done analyzing the
<a href="http://www.beilstein-journals.org/bjoc/">Beilstein Journal of Organic Chemistry</a>
literature with <a href="oscar3-chem.sf.net">Oscar</a>.</p>

<p>But, I do like to put this question out in the open: how many <em>H-bond acceptor</em>
groups does this triazole have? The CDK calculates 3 groups, while <a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=9257&amp;loc=ec_rcs">PubChem
counts 2</a>.
<a href="http://www.chemspider.com/RecordView.aspx?rid=16b4a40c-0eaf-45ed-bbf3-10baed079a9b">ChemSpider thinks 3</a>
too.</p>

<p>Intuitively, I would agree with the CDK and ChemSpider: the nitrogen which acts
as the single H-bond donor still have a free electron pair. What do you think?
Is <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a> wrong, or is the CDK and <a href="http://chemspider.com">ChemSpider</a>
wrong? Can this special nitrogen be both a donor and acceptor at the same time?
I think so. However, I do not know how I can easily search <a href="http://wwmm.ch.cam.ac.uk/crystaleye/">CrystalEye</a>
for this. Bonus points for answering the <a href="http://blueobelisk.shapado.com/questions/how-can-i-searched-crystaleye-for-particular-packing-types">Blue Obelisk eXchange question</a>.</p>]]></content><author><name>Egon Willighagen</name></author><category term="beilstein" /><category term="cdk" /><category term="cheminf" /><category term="chemistry" /><category term="chemspider" /><category term="pubchem" /><category term="inchikey:NSPMIYGKQJPBQR-UHFFFAOYSA-N" /><summary type="html"><![CDATA[Andrew asked me about the H-bond donor capabilities of 1,2,4-triazole:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/1,2,4-triazole.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/1,2,4-triazole.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Using PubChem to create CDK unit tests</title><link href="http://egonw.github.io/blog/2010/09/26/using-pubchem-to-create-cdk-unit-tests.html" rel="alternate" type="text/html" title="Using PubChem to create CDK unit tests" /><published>2010-09-26T00:00:00+00:00</published><updated>2010-09-26T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2010/09/26/using-pubchem-to-create-cdk-unit-tests</id><content type="html" xml:base="http://egonw.github.io/blog/2010/09/26/using-pubchem-to-create-cdk-unit-tests.html"><![CDATA[<p>In 2008 I posted about <a href="https://chem-bla-ics.blogspot.com/2008/05/wicked-chemistry-and-unit-testing.html">Wicked chemistry and unit testing</a>
and was using <a href="https://en.wikipedia.org/wiki/BeanShell">BeanShell</a> at the time
to convert a structure on <a href="https://pubchem.ncbi.nlm.nih.gov/">PubChem</a> into <a href="http://cdk.sf.net">CDK</a>
source code. But since I rather use <a href="https://en.wikipedia.org/wiki/Groovy_%28programming_language%29">Groovy</a>
now, I have updated the code. I used <a href="https://chem-bla-ics.blogspot.com/2010/09/cdk-137-changes-authors-and-reviewers.html">CDK 1.3.6</a>
and the PubChem XML format now:</p>

<pre>import org.openscience.cdk.Molecule;
import org.openscience.cdk.io.*;

if (args.length == 0 || args[0] == null) {
  System.out.println("Syntax: pc2ut.groovy [CID]\n");
  System.exit(0);
}

String cid = args[0];
String urlString =
  "http://pubchem.ncbi.nlm.nih.gov/summary/" +
  "summary.cgi?disopt=SaveXML&amp;cid=" + cid;

URL url = new URL(urlString);

PCCompoundXMLReader reader =
  new PCCompoundXMLReader(url.openStream());
Molecule mol = reader.read(new Molecule());

StringWriter stringWriter = new StringWriter();
CDKSourceCodeWriter writer =
  new CDKSourceCodeWriter(stringWriter);
writer.write(mol);
writer.close();

System.out.print(stringWriter.toString());
</pre>

<p><strong>Update</strong> An observant reader would have noticed that the output of the current
CDKSourceCodeWriter is actually producing code that does not compile. The CDK
API has changed, but the created output was not updated accordingly. Apparently,
no one is actually using this class, or those who have were not interested in
that piece of functionality to file a bug report.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="pubchem" /><category term="mcprinciples" /><summary type="html"><![CDATA[In 2008 I posted about Wicked chemistry and unit testing and was using BeanShell at the time to convert a structure on PubChem into CDK source code. But since I rather use Groovy now, I have updated the code. I used CDK 1.3.6 and the PubChem XML format now:]]></summary></entry><entry><title type="html">Searching PubChem from within Bioclipse</title><link href="http://egonw.github.io/blog/2009/08/07/searching-pubchem-from-within-bioclipse.html" rel="alternate" type="text/html" title="Searching PubChem from within Bioclipse" /><published>2009-08-07T00:00:00+00:00</published><updated>2009-08-07T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2009/08/07/searching-pubchem-from-within-bioclipse</id><content type="html" xml:base="http://egonw.github.io/blog/2009/08/07/searching-pubchem-from-within-bioclipse.html"><![CDATA[<p>For the application note which we are about to submit, I was working on improving the <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a>
<a href="http://www.bioclipse.net/">Bioclipse</a> API a bit, resulting in new <code class="language-plaintext highlighter-rouge">download</code> methods:</p>

<script src="https://gist.github.com/163281.js"></script>

<p>The search allows using <a href="http://pubchem.ncbi.nlm.nih.gov/help.html#PubChem_index">PubChem Filters</a> which provides
many simple means to restrict the search results. For example, we can search molecules and restrict on the molecular
weight:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">lists</span> <span class="o">=</span> <span class="nx">pubchem</span><span class="p">.</span><span class="nf">download</span><span class="p">(</span><span class="nx">pubchem</span><span class="p">.</span><span class="nf">search</span><span class="p">(</span><span class="dl">"</span><span class="s2">malaria 300:500[MW]</span><span class="dl">"</span><span class="p">))</span>
</code></pre></div></div>

<p>Other filters you can use in pubchem.search (provided by PubChem itself), includes (with examples):</p>

<ul>
  <li><strong>[el]</strong>: <code class="language-plaintext highlighter-rouge">pubchem.search("Au[el]")</code></li>
  <li><strong>[inchi]</strong>: <code class="language-plaintext highlighter-rouge">pubchem.search("\"InChI=1S/CH4/h1H4\"[inchi]")</code></li>
  <li><strong>[inchikey]</strong>: <code class="language-plaintext highlighter-rouge">pubchem.search("VNWKTOKETHGBQD-UHFFFAOYSA-N[inchikey]")</code></li>
  <li><strong>[mimass]</strong>: <code class="language-plaintext highlighter-rouge">pubchem.search("375.9785:375.9786[mimass]")</code></li>
</ul>

<p>And many, many more… see the linked Filters page.</p>

<p>Now, you surely want to look at the hits, for which we use the molecular table editor:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">list</span> <span class="o">=</span> <span class="nx">pubchem</span><span class="p">.</span><span class="nf">download</span><span class="p">(</span><span class="nx">pubchem</span><span class="p">.</span><span class="nf">search</span><span class="p">(</span><span class="dl">"</span><span class="s2">375.9785:375.9786[mimass]</span><span class="dl">"</span><span class="p">))</span>
<span class="nx">cdk</span><span class="p">.</span><span class="nf">saveSDFile</span><span class="p">(</span><span class="dl">"</span><span class="s2">/Virtual/hits.sdf</span><span class="dl">"</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span>
<span class="nx">ui</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="dl">"</span><span class="s2">/Virtual/hits.sdf</span><span class="dl">"</span><span class="p">)</span>
</code></pre></div></div>

<p>Resulting in:</p>

<p><img src="/blog/assets/images/pubchemSearchResults.png" alt="" /></p>]]></content><author><name>Egon Willighagen</name></author><category term="bioclipse" /><category term="pubchem" /><category term="inchikey:VNWKTOKETHGBQD-UHFFFAOYSA-N" /><summary type="html"><![CDATA[For the application note which we are about to submit, I was working on improving the PubChem Bioclipse API a bit, resulting in new download methods:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/pubchemSearchResults.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/pubchemSearchResults.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">PubChem-CDK</title><link href="http://egonw.github.io/blog/2009/05/11/pubchem-cdk.html" rel="alternate" type="text/html" title="PubChem-CDK" /><published>2009-05-11T00:00:00+00:00</published><updated>2009-05-11T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2009/05/11/pubchem-cdk</id><content type="html" xml:base="http://egonw.github.io/blog/2009/05/11/pubchem-cdk.html"><![CDATA[<p><a href="http://pele.farmbio.uu.se/pubchem/">PubChem-CDK</a> is a project that runs <a href="http://cdk.sf.net/">CDK</a> code on the <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a> data.
As we speak, a groovy script reads about 100 PubChem Compounds XML entries per second into the database. Mind you, not the SDF they distribute which uses a
custom extension to overcome the limits of the real MDL SDF format.</p>

<p>Right now, it has run the atom type perception algorithm on about 1M compounds, and has a pretty good coverage of the <em>organic chemistry</em> domain. I will
analyze the <a href="http://pele.farmbio.uu.se/pubchem/atomtyping/">results</a> statistically soon, but will likely use this data first to add some missing atom types
to CDK 1.2.x. BTW, did you know only <strong><em>three</em></strong> <a href="http://pele.farmbio.uu.se/pubchem/atomtyping/?element=C">carbon atoms failed</a>?
A C<sup>4-</sup> (CID:<a href="http://pele.farmbio.uu.se/pubchem/?cid=156031">156031</a>), a C<sup>3+</sup> (CID:<a href="http://pele.farmbio.uu.se/pubchem/?cid=161072">161072</a>),
and a C<sup>2+</sup> (CID:<a href="http://pele.farmbio.uu.se/pubchem/?cid=161073">161073</a>). Would your cheminformatics library know what their properties are?</p>

<p>It is really nice way of browsing PubChem, BTW. For example, did you know there are several boron compounds which have a substructure [N+]-[B+]-[N+]? Yes,
three positive charges, <em>next</em> to each other? For example (CID:<a href="http://pele.farmbio.uu.se/pubchem/?cid=3612285">3612285</a>):</p>

<p><img src="/blog/assets/images/CID3612285.png" alt="" /></p>

<p>Well, neither did I. How was it synthesised? What are the spectral properties? How do they stabilise it? What magic counter ion? PubChem, unfortunately,
does not have links to primary literature, and there is no free source for that available. A failure in chemistry. The source points to
<a href="http://cdb.ics.uci.edu/index.htm">ChemDB</a>, but the <a href="http://cdb.ics.uci.edu/cgibin/ChemicalDetailWeb.psp?chemical_id=5257702">entry in that database</a> does
not shed light on this either.</p>

<p>Anyway, more on this later. Much more, as I plan to run many CDK algorithms on this code.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="pubchem" /><category term="inchikey:QBHDGWNWWIEZOM-UHFFFAOYSA-N" /><summary type="html"><![CDATA[PubChem-CDK is a project that runs CDK code on the PubChem data. As we speak, a groovy script reads about 100 PubChem Compounds XML entries per second into the database. Mind you, not the SDF they distribute which uses a custom extension to overcome the limits of the real MDL SDF format.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/CID3612285.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/CID3612285.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Downloading Domoic Acid from PubChem</title><link href="http://egonw.github.io/blog/2009/04/17/downloading-domoic-acid-from-pubchem.html" rel="alternate" type="text/html" title="Downloading Domoic Acid from PubChem" /><published>2009-04-17T00:10:00+00:00</published><updated>2009-04-17T00:10:00+00:00</updated><id>http://egonw.github.io/blog/2009/04/17/downloading-domoic-acid-from-pubchem</id><content type="html" xml:base="http://egonw.github.io/blog/2009/04/17/downloading-domoic-acid-from-pubchem.html"><![CDATA[<p>The identity of <a href="http://en.wikipedia.org/wiki/Domoic_acid">domoic acid</a> has been under discussion (see
<a href="http://www.chemspider.com/blog/the-plot-thickens-on-domoic-acid.html">here</a>, <a href="http://www.chemspider.com/blog/where-does-ce-news-source-its-chemical-structures.html">here</a>
and <a href="http://www.chemspider.com/blog/providing-some-structured-support-with-chemspiders-wikipedia-services.html">here</a>).
(And I very much like the <a href="http://www.chemspider.com/">ChemSpider</a> service to make it easy to
<a href="http://www.chemspider.com/blog/providing-some-structured-support-with-chemspiders-wikipedia-services.html">copy data from ChemSpider into WikiPedia ChemBoxes</a>;
cheers!)</p>

<p>Now, my practical in next weeks <a href="https://apps.sourceforge.net/mediawiki/cdk/index.php?title=CDK_Workshop_2009">CDK Workshop will</a> use
<a href="http://groovy.codehaus.org/">Groovy</a> (please install it on your laptop!), and am hacking up example scripts for the course material,
and came up with this script to download the structure of <a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=5282253">domoic acid</a>
from <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a> (CID:5282253):</p>

<script src="https://gist.github.com/97067.js"></script>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="pubchem" /><category term="chemspider" /><category term="wikipedia" /><category term="inchikey:VZFRNCSOCOPNDB-AOKDLOFSSA-N" /><summary type="html"><![CDATA[The identity of domoic acid has been under discussion (see here, here and here). (And I very much like the ChemSpider service to make it easy to copy data from ChemSpider into WikiPedia ChemBoxes; cheers!)]]></summary></entry><entry><title type="html">Rednael, CDK Git for Rajarshi’s patches, PubChem SDF</title><link href="http://egonw.github.io/blog/2009/04/13/rednael-cdk-git-for-rajarshis-patches.html" rel="alternate" type="text/html" title="Rednael, CDK Git for Rajarshi’s patches, PubChem SDF" /><published>2009-04-13T00:00:00+00:00</published><updated>2009-04-13T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2009/04/13/rednael-cdk-git-for-rajarshis-patches</id><content type="html" xml:base="http://egonw.github.io/blog/2009/04/13/rednael-cdk-git-for-rajarshis-patches.html"><![CDATA[<p>Short blog item about some <a href="http://cdk.git.sourceforge.net/">CDK Git</a> updates. Could not get sleep, so might as well spend that time on
<a href="http://cdk.sf.net/">CDK</a> hacking, not? Reason why I actually could not catch sleep was the news that <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a>
SD files are not regular MDL SD files, but use custom extensions, for example, for dative bonds (see
<a href="ftp://ftp.ncbi.nlm.nih.gov/pubchem/specifications/pubchem_sdtags.pdf">this PDF</a>). This <em>surely</em> explains the weird things I have seen,
but, unfortunately, the big SDF button on PubChem does not warn about that. Anyway, thanx for Wolfgang for informing about that
customization!</p>

<p>So, instead I hacked a bit on the CDK, which was about time. Last two weeks have been really busy with finding a new house (which we did),
and writing two big grant applications (about done). Finally time for cleaning up my TOREPLY list on Gmail. I picked the request of
<a href="http://blog.rguha.net/">Rajarshi</a> to put online some of his patches, which are now available from
<a href="http://pele.farmbio.uu.se/git/rajarshi.git/">pele.farmbio.uu.se/git/rajarshi.git</a>, where you will
<a href="https://sourceforge.net/tracker/?func=browse&amp;group_id=20024&amp;atid=320024">find four of his patches ready for review</a>:
<em>fp2d</em>, <em>pcore</em>, <em>pubchemfp</em> and <em>cleanpt</em>. These are <strong>really</strong> interesting patches!</p>

<p>That brings me to the last thing for today: <a href="http://github.com/egonw/rednael/tree/master">Rednael</a>.
<a href="http://en.wikipedia.org/wiki/Zarah_Leander">Leander</a> (a nickname already reserved, so reverse used) is an
<a href="http://en.wikipedia.org/wiki/Internet_Relay_Chat">IRC</a> bot for the #cdk channel which reports us of commits to our main Git repository.
Back in the old SVN days (time goes so fast :), we had the <a href="http://cia.vc/">CIA</a> (Langley?) use there equipment to monitor SVN commit,
and <a href="http://cia.vc/stats/project/cdk">report those online</a> and on IRC, but Git is too advanced for them, apparently. So, I wrote
my own little bot to do it (see earlier link to GitHub). It can monitor multiple channels and report about multiple RSS feeds per
channel. Thus, it is actually not restricted to Git commits alone.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="git" /><category term="pubchem" /><summary type="html"><![CDATA[Short blog item about some CDK Git updates. Could not get sleep, so might as well spend that time on CDK hacking, not? Reason why I actually could not catch sleep was the news that PubChem SD files are not regular MDL SD files, but use custom extensions, for example, for dative bonds (see this PDF). This surely explains the weird things I have seen, but, unfortunately, the big SDF button on PubChem does not warn about that. Anyway, thanx for Wolfgang for informing about that customization!]]></summary></entry><entry><title type="html">Bioclipse2 Scripting #2: searching PubChem</title><link href="http://egonw.github.io/blog/2009/02/21/bioclipse2-scripting-2-searching.html" rel="alternate" type="text/html" title="Bioclipse2 Scripting #2: searching PubChem" /><published>2009-02-21T00:00:00+00:00</published><updated>2009-02-21T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2009/02/21/bioclipse2-scripting-2-searching</id><content type="html" xml:base="http://egonw.github.io/blog/2009/02/21/bioclipse2-scripting-2-searching.html"><![CDATA[<p>This week I have been porting the PubChem plugin for <a href="http://www.bioclipse.net/">Bioclipse</a> 1.2 to the new manager-based architecture. While still working on the Wizards,
you can run the following JavaScript in Bioclipse2 from SVN and from the next beta (*):</p>

<script src="https://gist.github.com/67462.js"></script>

<p>*) There was some confusion on the <em>two</em> beta Bioclipse2 releases so far. Some people expected a release without any bugs left. That release is what we planned to call a
<em>Release Candidate</em>. We agree that the first two betas at least turned out to be more alpha than we actually hoped, and we thank everyone who has given these releases a
go. Those who tried several development releases of Bioclipse2 saw a lot of ongoing development, and we are fixing
<a href="http://bugs.bioclipse.net/">any bug reported</a> on these releases. So, do not hesitate in reporting bugs!</p>

<p>Earlier in this series:</p>

<ul>
  <li><a href="http://chem-bla-ics.blogspot.com/2008/10/bioclipse2-scripting-1-from-smiles-to.html">Bioclipse2 Scripting #1: from SMILES to a UFF optimized structure in Jmol</a></li>
  <li><a href="http://chem-bla-ics.blogspot.com/2008/11/next-generation-asynchronous.html">Next generation asynchronous webservices #2</a></li>
  <li><a href="http://chem-bla-ics.blogspot.com/2008/11/scripting-jchempaint.html">Scripting JChemPaint</a></li>
  <li><a href="http://chem-bla-ics.blogspot.com/2009/02/bioclipse-for-cdk-developers-1.html">Bioclipse for CDK Developers #1</a></li>
</ul>]]></content><author><name>Egon Willighagen</name></author><category term="bioclipse" /><category term="pubchem" /><category term="javascript" /><summary type="html"><![CDATA[This week I have been porting the PubChem plugin for Bioclipse 1.2 to the new manager-based architecture. While still working on the Wizards, you can run the following JavaScript in Bioclipse2 from SVN and from the next beta (*):]]></summary></entry><entry><title type="html">Editing and Validation of PubChem XML documents</title><link href="http://egonw.github.io/blog/2009/01/15/editing-and-validation-of-pubchem-xml.html" rel="alternate" type="text/html" title="Editing and Validation of PubChem XML documents" /><published>2009-01-15T00:00:00+00:00</published><updated>2009-01-15T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2009/01/15/editing-and-validation-of-pubchem-xml</id><content type="html" xml:base="http://egonw.github.io/blog/2009/01/15/editing-and-validation-of-pubchem-xml.html"><![CDATA[<p>With the general framework set up for <a href="http://chem-bla-ics.blogspot.com/2008/12/editing-and-validation-of-cml-documents.html">editing and validation of CML documents</a>,
it was fairly easy to support the <a href="ftp://ftp.ncbi.nlm.nih.gov/pubchem/specifications/pubchem.xsd">PubChem XML file format schema too</a>.</p>

<p>With the upcoming Bioclipse2 beta (scheduled next Friday), all you need to install on top of the Bioclipse2 core is the new XML feature.</p>]]></content><author><name>Egon Willighagen</name></author><category term="pubchem" /><category term="xml" /><category term="bioclipse" /><summary type="html"><![CDATA[With the general framework set up for editing and validation of CML documents, it was fairly easy to support the PubChem XML file format schema too.]]></summary></entry><entry><title type="html">Wicked chemistry and unit testing</title><link href="http://egonw.github.io/blog/2008/05/03/wicked-chemistry-and-unit-testing.html" rel="alternate" type="text/html" title="Wicked chemistry and unit testing" /><published>2008-05-03T00:00:00+00:00</published><updated>2008-05-03T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2008/05/03/wicked-chemistry-and-unit-testing</id><content type="html" xml:base="http://egonw.github.io/blog/2008/05/03/wicked-chemistry-and-unit-testing.html"><![CDATA[<p>After a discussion on starting development releases for <a href="http://cdk.sf.net/">CDK</a> on <a href="https://lists.sourceforge.net/lists/listinfo/cdk-devel">cdk-devel</a>,
the discussion continued on the state of the <a href="http://chem-bla-ics.blogspot.com/2007/07/atom-typing-in-cdk.html">CDK atom typer</a>.
<a href="http://dtp.nci.nih.gov/branches/itb/itb_index.html">Dan</a> and <a href="http://cheminfo.informatics.indiana.edu/~rguha/">Rajarshi</a>
have done tests in the past against <a href="http://pubchem.ncbi.nlm.nih.gov/">PubChem</a> and its DTP/NCI subset. Rajarshi made his
analysis part of <a href="http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/">CDK Nightly</a>,
and provides but <a href="http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/">a summary</a>
(which seems broken: zero fails) and a <a href="http://cheminfo.informatics.indiana.edu/~rguha/tmp/dtp-atype-report.txt">detailed list</a>.</p>

<p>Dan, do I understand correctly that those <em>Structure Evaluation:No Comparision - Unparameterized Atom - S.</em> lines in the
<strong>Depositor-Supplied Comments</strong> section on PubChem are based on CDK trunk? That would be a great honor! Anyways…</p>

<p>The amount of atom types we use to describe the chemistry we observe is overwhelming (even without charged or radical atoms).
And, most atom type lists are quite limited in what they represent. However, having an explicit list allows the computer to
decide if it can do reasonable calculations on a structure. <strong>Always filter your data to screen for unrecognized atom types,
before heading of to, for example, QSAR calculations!</strong></p>

<p>Now, many fails are because of the incomplete CDK atom type list (e.g. Au in <a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?sid=413374">SID:413374</a>),
or because the atom typer code has a bug (e.g. <a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?sid=403517">SID:403517</a>).
And these screenings against PubChem provide a nice priority list. However, others are either because the used SDF format
cannot represent the chemistry (e.g. <a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?sid=420394">SID:420394</a>), or the
entry is a plain wrong (e.g. <a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?sid=301178">SID:301178</a>). The latter
two types of fails, I am annotating using <a href="http://del.icio.us/egonw/pubchem+check-valency">del.icio.us/egonw/pubchem+check-valency</a>
for others to comment on (just tag the same page using <a href="http://del.icio.us/">del.ici.us</a>, and I’ll see the comments show up.</p>

<h2 id="unit-testing">Unit testing</h2>

<p>For the first two types of fails, basically three things need to be done:</p>

<ul>
  <li>add the atom type to <a href="http://cdk.svn.sourceforge.net/viewvc/*checkout*/cdk/cdk/trunk/src/main/org/openscience/cdk/config/data/cdk_atomtypes.xml?content-type=text%2Fxml">the ontology</a></li>
  <li>write a unit test for <a href="http://cdk.svn.sourceforge.net/viewvc/cdk/cdk/trunk/src/test/org/openscience/cdk/atomtype/CDKAtomTypeMatcherTest.java?view=log">CDKAtomTypeMatcherTest</a></li>
  <li>add perception code to <a href="http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/api/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.html">CDKAtomTypeMatcher</a></li>
</ul>

<p>Because we cannot use <a href="http://www.opensmiles.org/">SMILES</a> or file readers for writing these tests (than we can confounding
of error sources), we have to hard code the chemical structure, which may be a bit cumbersome.</p>

<p>Unless you use the <a href="http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/api/org/openscience/cdk/io/CDKSourceCodeWriter.html">CDKSourceCodeWriter</a>!
This <a href="http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/api/org/openscience/cdk/io/IChemObjectWriter.html">IChemObjectWriter</a>
creates CDK source code, staring with a IMolecule. Now, because our bug reports are derived from fails against the PubChem
screening, we can simply use this <a href="http://www.beanshell.org/">BeanShell</a> code to download a structure from
PubChem and convert it to CDK source code:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="err">#</span><span class="o">!/</span><span class="n">usr</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">bsh</span>

<span class="kn">import</span> <span class="nn">org.openscience.cdk.Molecule</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.openscience.cdk.io.MDLV2000Reader</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.openscience.cdk.io.CDKSourceCodeWriter</span><span class="o">;</span>

<span class="k">if</span> <span class="o">(</span><span class="n">bsh</span><span class="o">.</span><span class="na">args</span><span class="o">.</span><span class="na">length</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">||</span> <span class="n">bsh</span><span class="o">.</span><span class="na">args</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
  <span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Syntax: pubchem2unittest.bsh [CID]\n"</span><span class="o">);</span>
  <span class="nc">System</span><span class="o">.</span><span class="na">exit</span><span class="o">(</span><span class="mi">0</span><span class="o">);</span>
<span class="o">}</span>

<span class="nc">String</span> <span class="n">cid</span> <span class="o">=</span> <span class="n">bsh</span><span class="o">.</span><span class="na">args</span><span class="o">[</span><span class="mi">0</span><span class="o">];</span>
<span class="nc">String</span> <span class="n">urlString</span> <span class="o">=</span> <span class="s">"http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?disopt=SaveSDF&amp;cid="</span> <span class="o">+</span> <span class="n">cid</span><span class="o">;</span>

<span class="no">URL</span> <span class="n">url</span> <span class="o">=</span> <span class="k">new</span> <span class="no">URL</span><span class="o">(</span><span class="n">urlString</span><span class="o">);</span>

<span class="nc">MDLV2000Reader</span> <span class="n">reader</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">MDLV2000Reader</span><span class="o">(</span><span class="n">url</span><span class="o">.</span><span class="na">openStream</span><span class="o">());</span>
<span class="nc">Molecule</span> <span class="n">mol</span> <span class="o">=</span> <span class="n">reader</span><span class="o">.</span><span class="na">read</span><span class="o">(</span><span class="k">new</span> <span class="nc">Molecule</span><span class="o">());</span>

<span class="nc">StringWriter</span> <span class="n">stringWriter</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">StringWriter</span><span class="o">();</span>
<span class="nc">CDKSourceCodeWriter</span> <span class="n">writer</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">CDKSourceCodeWriter</span><span class="o">(</span><span class="n">stringWriter</span><span class="o">);</span>
<span class="n">writer</span><span class="o">.</span><span class="na">write</span><span class="o">(</span><span class="n">mol</span><span class="o">);</span>
<span class="n">writer</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>

<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">print</span><span class="o">(</span><span class="n">stringWriter</span><span class="o">.</span><span class="na">toString</span><span class="o">());</span>
</code></pre></div></div>

<p>For example, I am currently debugging a sulphur atom type perception problem, for which the simplest
substructure looks like (<a href="https://chem-bla-ics.blogspot.com/2008/05/wicked-chemistry-and-unit-testing.html">sid=12279910</a>,
<code class="language-plaintext highlighter-rouge">InChI=1/C2H7NS/c1-4(2)3/h3H,1-2H3)</code>:</p>

<p><img src="/blog/assets/images/sid12279910.png" alt="" /></p>

<p>I can convert this PubChem entry to CDK source code with:</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>bsh <span class="nt">-classpath</span> dist/jar/cdk-svn-20080221.jar tools/pubchem2unittest.bsh 12279910
</code></pre></div></div>

<p>Resulting in this output which I can copy/paste into my unit test:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">IMolecule</span> <span class="n">mol</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">Molecule</span><span class="o">();</span>
<span class="nc">IAtom</span> <span class="n">a1</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"S"</span><span class="o">);</span>
<span class="n">a1</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">2.866</span><span class="o">,</span> <span class="mf">0.25</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a1</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a2</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"N"</span><span class="o">);</span>
<span class="n">a2</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">3.7321</span><span class="o">,</span> <span class="mf">0.75</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a2</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a3</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"C"</span><span class="o">);</span>
<span class="n">a3</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">2.0</span><span class="o">,</span> <span class="mf">0.75</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a3</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a4</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"C"</span><span class="o">);</span>
<span class="n">a4</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">2.866</span><span class="o">,</span> <span class="o">-</span><span class="mf">0.75</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a4</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a5</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a5</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">2.31</span><span class="o">,</span> <span class="mf">1.2869</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a5</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a6</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a6</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">1.4631</span><span class="o">,</span> <span class="mf">1.06</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a6</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a7</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a7</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">1.69</span><span class="o">,</span> <span class="mf">0.2131</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a7</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a8</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a8</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">2.246</span><span class="o">,</span> <span class="o">-</span><span class="mf">0.75</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a8</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a9</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a9</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">2.866</span><span class="o">,</span> <span class="o">-</span><span class="mf">1.37</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a9</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a10</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a10</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">3.486</span><span class="o">,</span> <span class="o">-</span><span class="mf">0.75</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a10</span><span class="o">);</span>
<span class="nc">IAtom</span> <span class="n">a11</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"H"</span><span class="o">);</span>
<span class="n">a11</span><span class="o">.</span><span class="na">setPoint2d</span><span class="o">(</span><span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mf">4.269</span><span class="o">,</span> <span class="mf">0.44</span><span class="o">));</span>  <span class="n">mol</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">a11</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b1</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a1</span><span class="o">,</span> <span class="n">a2</span><span class="o">,</span> <span class="no">DOUBLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b1</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b2</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a1</span><span class="o">,</span> <span class="n">a3</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b2</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b3</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a1</span><span class="o">,</span> <span class="n">a4</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b3</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b4</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a2</span><span class="o">,</span> <span class="n">a11</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b4</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b5</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a3</span><span class="o">,</span> <span class="n">a5</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b5</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b6</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a3</span><span class="o">,</span> <span class="n">a6</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b6</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b7</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a3</span><span class="o">,</span> <span class="n">a7</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b7</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b8</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a4</span><span class="o">,</span> <span class="n">a8</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b8</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b9</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a4</span><span class="o">,</span> <span class="n">a9</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b9</span><span class="o">);</span>
<span class="nc">IBond</span> <span class="n">b10</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="na">getBuilder</span><span class="o">().</span><span class="na">newBond</span><span class="o">(</span><span class="n">a4</span><span class="o">,</span> <span class="n">a10</span><span class="o">,</span> <span class="no">SINGLE</span><span class="o">);</span>
<span class="n">mol</span><span class="o">.</span><span class="na">addBond</span><span class="o">(</span><span class="n">b10</span><span class="o">);</span>
</code></pre></div></div>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="pubchem" /><summary type="html"><![CDATA[After a discussion on starting development releases for CDK on cdk-devel, the discussion continued on the state of the CDK atom typer. Dan and Rajarshi have done tests in the past against PubChem and its DTP/NCI subset. Rajarshi made his analysis part of CDK Nightly, and provides but a summary (which seems broken: zero fails) and a detailed list.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/sid12279910.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/sid12279910.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Chemical RDFa with Operator in the Firefox toolbar</title><link href="http://egonw.github.io/blog/2007/06/27/chemical-rdfa-with-operator-in-firefox.html" rel="alternate" type="text/html" title="Chemical RDFa with Operator in the Firefox toolbar" /><published>2007-06-27T00:10:00+00:00</published><updated>2007-06-27T00:10:00+00:00</updated><id>http://egonw.github.io/blog/2007/06/27/chemical-rdfa-with-operator-in-firefox</id><content type="html" xml:base="http://egonw.github.io/blog/2007/06/27/chemical-rdfa-with-operator-in-firefox.html"><![CDATA[<p>December last year <a href="http://chem-bla-ics.blogspot.com/2006/12/including-smiles-cml-and-inchi-in.html">I proposed the use of microformats and RDFa</a>
for simple semantic markup of molecular information. I linked that with the <a href="http://chem-bla-ics.blogspot.com/2006/02/hacking-inchi-support-into.html">InChI extension for the Postgenomic.com software</a>
for <a href="http://cb.openmolecules.net/">Chemical blogspace</a> and wrote these tools to work with the markup:</p>

<ul>
  <li><a href="http://chem-bla-ics.blogspot.com/2006/12/smiles-cas-and-inchi-in-blogs.html">wrote a Greasemonkey script to automatically link to webservices</a>,</li>
  <li><a href="http://chem-bla-ics.blogspot.com/2007/01/chemistry-in-html-javascript-from.html">explained how that script can be used on the server</a>, and</li>
  <li><a href="http://chem-bla-ics.blogspot.com/2007/05/cb-comments-for-inchis.html">adapted a Greasemonkey script to show blog items related to molecules</a>.</li>
</ul>

<p>All using the new semantic markup.</p>

<p>Of the two, I think RDFa has the best future. Then I <a href="http://chem-bla-ics.blogspot.com/2007/05/added-my-hcard-to-my-blog.html">discovered Operator</a>,
written by <a href="http://www.kaply.com/weblog/">Mike</a>. While the Greasemonkey scripts already allow me to link to, for example, PubChem and eMolecules,
the <a href="https://addons.mozilla.org/en-US/firefox/addon/4106">Operator Firefox Addon</a> allowed me to open vCards incorporated in HTML pages directly
to my address book client. Thus, I could open chemistry directly in <a href="http://bioclipse.net/">Bioclipse</a> too!</p>

<p>That was the idea, at least. I contacted Mike, and he asked me to wait until the first 0.8 releases, which he
<a href="http://www.kaply.com/weblog/2007/06/04/operator-08a-is-available/">announced earlier this month</a>.
This version allows user scripts to be written, which define how RDFa should be handled. And with his patience and help, this was the result:</p>

<p><img src="/blog/assets/images/pubchemRDFa.png" alt="" /></p>

<p>The HTML is almost <a href="http://chem-bla-ics.blogspot.com/2006/12/smiles-cas-and-inchi-in-blogs.html">as explained before</a>, and looks like:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html</span> <span class="na">xmlns=</span><span class="s">"http://www.w3.org/2002/06/xhtml2/"</span><span class="nt">&gt;</span>

<span class="nt">&lt;h1&gt;</span>Chemical RDFa with Operator<span class="nt">&lt;/h1&gt;</span>

<span class="nt">&lt;div</span> <span class="na">about=</span><span class="s">"#chem_123"</span> <span class="na">xmlns:chem=</span><span class="s">"http://www.blueobelisk.org/chemistryblogs/"</span><span class="nt">&gt;</span>
  Methane has the following identifier: <span class="nt">&lt;span</span> <span class="na">property=</span><span class="s">"chem:inchi"</span><span class="nt">&gt;</span>InChI=1/CH4/h1H4<span class="nt">&lt;/span&gt;</span>
<span class="nt">&lt;/div&gt;</span>

<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>It is important here to wrap the statement in a <code class="language-plaintext highlighter-rouge">&lt;div&gt;</code> element and to add the <code class="language-plaintext highlighter-rouge">@about</code> attribute to it, defining the Subject. Moreover,
you need to use the <code class="language-plaintext highlighter-rouge">@property</code> attributes instead of <code class="language-plaintext highlighter-rouge">@class</code>. The content of this attribute defined the Predicate, and the content of the
<code class="language-plaintext highlighter-rouge">&lt;span&gt;</code> element is the Object, completing the RDF triple.</p>

<p>Operator detects these RDFa statements from the HTML, and creates a new menu item <em>Search in Pubchem</em> using this piece of code:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">pubchem_inchi</span> <span class="o">=</span> <span class="p">{</span>
  <span class="na">description</span><span class="p">:</span> <span class="dl">"</span><span class="s2">Search in PubChem</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">short</span><span class="p">:</span> <span class="dl">"</span><span class="s2">PubChem</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">scope</span><span class="p">:</span> <span class="p">{</span>
    <span class="na">semantic</span><span class="p">:</span> <span class="p">{</span>
      <span class="dl">"</span><span class="s2">RDFa</span><span class="dl">"</span> <span class="p">:</span>  <span class="p">{</span>
        <span class="na">property</span> <span class="p">:</span> <span class="dl">"</span><span class="s2">http://www.blueobelisk.org/chemistryblogs/inchi</span><span class="dl">"</span><span class="p">,</span>
        <span class="na">defaultNS</span> <span class="p">:</span> <span class="dl">"</span><span class="s2">http://www.blueobelisk.org/chemistryblogs/</span><span class="dl">"</span>
      <span class="p">}</span>
    <span class="p">}</span>
  <span class="p">},</span>
  <span class="na">doAction</span><span class="p">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">semanticObject</span><span class="p">,</span> <span class="nx">semanticObjectType</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if </span><span class="p">(</span><span class="nx">semanticObjectType</span> <span class="o">==</span> <span class="dl">"</span><span class="s2">RDFa</span><span class="dl">"</span><span class="p">)</span> <span class="p">{</span>
      <span class="k">return</span> <span class="dl">"</span><span class="s2">http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?CMD=search&amp;DB=pccompound&amp;term=%22</span><span class="dl">"</span> <span class="o">+</span> <span class="nx">semanticObject</span><span class="p">.</span><span class="nx">inchi</span> <span class="o">+</span> <span class="dl">"</span><span class="s2">%22[InChI]</span><span class="dl">"</span><span class="p">;</span>
    <span class="p">}</span>
  <span class="p">}</span>
<span class="p">};</span>

<span class="nx">SemanticActions</span><span class="p">.</span><span class="nf">add</span><span class="p">(</span><span class="dl">"</span><span class="s2">pubchem_inchi</span><span class="dl">"</span><span class="p">,</span> <span class="nx">pubchem_inchi</span><span class="p">);</span>
</code></pre></div></div>

<p>You can reproduce this by installing Operator 0.8a in Firefox, saving the script to a file in your home directory, and
reading it via the Operator “Options” dialog. Make sure to also set the <em>Display Style</em> in the <em>General</em> tab of the dialog to
<em>Data formats</em>. Only then will the RDFa magic kick in.</p>

<p>Adding support for eMolecules, ChemSpider and whatever else we like is easy now. What I still need to explore (or ask Mike),
is how I can trigger the <em>Open With/Save As</em> dialog of Firefox.</p>]]></content><author><name>Egon Willighagen</name></author><category term="pubchem" /><category term="rdf" /><category term="userscript" /><category term="inchi" /><category term="rdfa" /><summary type="html"><![CDATA[December last year I proposed the use of microformats and RDFa for simple semantic markup of molecular information. I linked that with the InChI extension for the Postgenomic.com software for Chemical blogspace and wrote these tools to work with the markup:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/pubchemRDFa.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/pubchemRDFa.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>