<?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/java.xml" rel="self" type="application/atom+xml" /><link href="http://egonw.github.io/blog/" rel="alternate" type="text/html" /><updated>2026-11-19T06:09:00+00:00</updated><id>http://egonw.github.io/blog/feed/by_tag/java.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">CDK 1.2.x hits Debian Unstable</title><link href="http://egonw.github.io/blog/2011/04/22/cdk-12x-hits-debian-unstable.html" rel="alternate" type="text/html" title="CDK 1.2.x hits Debian Unstable" /><published>2011-04-22T00:00:00+00:00</published><updated>2011-04-22T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2011/04/22/cdk-12x-hits-debian-unstable</id><content type="html" xml:base="http://egonw.github.io/blog/2011/04/22/cdk-12x-hits-debian-unstable.html"><![CDATA[<p>Thanx to the work of <a href="https://launchpad.net/~onkarshinde">Onkar Shinde</a>, the
<a href="http://www.debian.org/">Debian</a> package for <a href="http://cdk.sf.net/">CDK</a> has been
updated from 1.0.2 (in <a href="http://wiki.debian.org/DebianSqueeze">Squeeze</a>) to 1.2.7
in <a href="http://wiki.debian.org/DebianUnstable">unstable</a>. The popularity content
shows some <a href="http://qa.debian.org/popcon.php?package=cdk">140 installations</a>:</p>

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

<p>BTW, <a href="http://packages.debian.org/search?keywords=jmol">Jmol</a> 12 is also available
as Debian package now!</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="debian" /><category term="java" /><category term="jmol" /><summary type="html"><![CDATA[Thanx to the work of Onkar Shinde, the Debian package for CDK has been updated from 1.0.2 (in Squeeze) to 1.2.7 in unstable. The popularity content shows some 140 installations:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/cdkPopCon.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/cdkPopCon.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">CDK 1.2.8: the changes, the authors, and the reviewers</title><link href="http://egonw.github.io/blog/2011/03/28/cdk-128-changes-authors-and-reviewers.html" rel="alternate" type="text/html" title="CDK 1.2.8: the changes, the authors, and the reviewers" /><published>2011-03-28T00:00:00+00:00</published><updated>2011-03-28T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2011/03/28/cdk-128-changes-authors-and-reviewers</id><content type="html" xml:base="http://egonw.github.io/blog/2011/03/28/cdk-128-changes-authors-and-reviewers.html"><![CDATA[<p><a href="https://sourceforge.net/projects/cdk/files/cdk/1.2.8/">CDK 1.2.8</a> is one more
bug fix release in the 1.2 series.</p>

<p><strong>The changes</strong><br />
The changes include another few new atom types and fixes of recognition of earlier
defined atom types, further widening the scope of chemistry recognized by the 1.2
series. It also has a few other minor fixes, as listed below.</p>

<ul>
  <li>fixed pdb_atomtypes.xml errors mentioned in https://sourceforge.net/mailarchive/message.php?msg_id=27206678,
including the nigly vdwRadius for GLN.CD <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=3ab7c25">3ab7c25</a></li>
  <li>whitespace-only: alignment of TYR-section <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=5b51e15">5b51e15</a></li>
  <li>Added two new authors <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=f72be81">f72be81</a></li>
  <li>Fixed a concurrency error, caused by the use of a static field which was not
supposed to be static, as the classes are instantiated just to allow customization
<a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=9f54afc">9f54afc</a></li>
  <li>Fixed the use of the proper Convertor <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=3ea9180">3ea9180</a></li>
  <li>Added the Co(3+) atom type (fixes #3093644) <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=c368c3d">c368c3d</a></li>
  <li>Added the unit test phosphine for bug #3190151 <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=851c1a6">851c1a6</a></li>
  <li>Added a unit test for a phosphor without explicit or implicit hydrogens <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=b35f3bf">b35f3bf</a></li>
  <li>Updated OrderQueryBond in SMARTS &amp; isomorphism matching so that we correctly
match when faced with aromatic bonds (rather than just looking at the bond
order) <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=commit;h=15f64ff">15f64ff</a></li>
</ul>

<p><strong>The authors</strong></p>

<pre>4  Egon Willighagen 
2  Jules Kerssemakers 
1  Julio Peironcely 
1  Rajarshi Guha 
</pre>

<p><strong>The reviewers</strong></p>

<pre>5  Rajarshi  Guha 
3  Egon Willighagen 
</pre>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="cheminf" /><category term="java" /><summary type="html"><![CDATA[CDK 1.2.8 is one more bug fix release in the 1.2 series.]]></summary></entry><entry><title type="html">Java Performance…</title><link href="http://egonw.github.io/blog/2011/03/08/java-performance.html" rel="alternate" type="text/html" title="Java Performance…" /><published>2011-03-08T00:00:00+00:00</published><updated>2011-03-08T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2011/03/08/java-performance</id><content type="html" xml:base="http://egonw.github.io/blog/2011/03/08/java-performance.html"><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Java_Virtual_Machine">Java virtual machines</a> are
weird things. They can optimize code on the fly, tuning how it runs the code,
depending on the data it processes. That is why it can be faster than C and
C++, or even faster then Fortran. Those are all pre-optimized based on the code,
not based on the workload. But, at the same time, performance is tricky, and
your best friend is a good profiler (like <a href="http://www.yourkit.com/">YourKit</a>,
which is free for Open Source use).</p>

<p>Reading about Java performance now and then is useful. It’s keep you aware of
the things that matter and that don’t. Via <a href="http://planeteclipse.org/planet/">Planet Eclipse</a>,
I read a couple of posts from the <a href="http://java-persistence-performance.blogspot.com/">Java Persistence Performance blog</a>.
And today <a href="http://java-persistence-performance.blogspot.com/2011/03/jvm-performance-part-iii-concurrent.html">I learned</a>
that the <a href="http://en.wikipedia.org/wiki/Just-in-time_compilation">JIT compiler</a>
can in fact remove the threading support in <a href="http://download.oracle.com/javase/6/docs/api/java/util/Hashtable.html">Hashtable</a>
when only one thread is used.</p>]]></content><author><name>Egon Willighagen</name></author><category term="java" /><summary type="html"><![CDATA[Java virtual machines are weird things. They can optimize code on the fly, tuning how it runs the code, depending on the data it processes. That is why it can be faster than C and C++, or even faster then Fortran. Those are all pre-optimized based on the code, not based on the workload. But, at the same time, performance is tricky, and your best friend is a good profiler (like YourKit, which is free for Open Source use).]]></summary></entry><entry><title type="html">Cleaner CDK Code #9: using the LoggingTool</title><link href="http://egonw.github.io/blog/2011/02/24/cleaner-cdk-code-9-using-loggingtool.html" rel="alternate" type="text/html" title="Cleaner CDK Code #9: using the LoggingTool" /><published>2011-02-24T00:10:00+00:00</published><updated>2011-02-24T00:10:00+00:00</updated><id>http://egonw.github.io/blog/2011/02/24/cleaner-cdk-code-9-using-loggingtool</id><content type="html" xml:base="http://egonw.github.io/blog/2011/02/24/cleaner-cdk-code-9-using-loggingtool.html"><![CDATA[<p>A trick I used from Miguel Howard (of <a href="http://www.jmol.org/">Jmol</a> fame) is
to not concatenate String until really needed. String concatenation will allocate
new Strings, and thus burden the garbage collector (yeah, you lucky Fortran
users who think twice before allocating memory :). Some time ago, he suggested
this trick for the logger. I think in Jmol, but the <a href="http://cdk.sf.net/">CDK</a>
inherited that idea.</p>

<h2 id="dont-concatenate-strings-when-calling-the-loggingtool">Don’t concatenate Strings when calling the LoggingTool</h2>

<p>Logging in the CDK can be turned off, and in production use, I often do. Therefore,
we can make it speed up by concatenating debug message String only when debugging
is turned on. The CDK <a href="http://pele.farmbio.uu.se/nightly/api/org/openscience/cdk/tools/ILoggingTool.html">LoggingTool</a>
can take care of this, so you should pass the Strings are individual parameters
to the logger call. Instead of:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">logger</span><span class="o">.</span><span class="na">debug</span><span class="o">(</span><span class="s">"the current atom is "</span> <span class="o">+</span> <span class="n">atom</span><span class="o">);</span>
</code></pre></div></div>

<p>you should write:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">logger</span><span class="o">.</span><span class="na">debug</span><span class="o">(</span><span class="s">"the current atom is "</span><span class="o">,</span> <span class="n">atom</span><span class="o">);</span>
</code></pre></div></div>

<p>And this works for any arbitrary number of Strings and objects, because the
logging tool debug method has this signature: <code class="language-plaintext highlighter-rouge">public void debug(Object object,
Object... objects)</code>. So, you can also just do:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">logger</span><span class="o">.</span><span class="na">debug</span><span class="o">(</span><span class="s">"The "</span><span class="o">,</span> <span class="n">i</span><span class="o">,</span> <span class="s">"th object is connected to the "</span><span class="o">,</span> <span class="n">j</span><span class="o">,</span> <span class="s">"th"</span><span class="o">);</span>
</code></pre></div></div>

<p>Actually, looking at the <code class="language-plaintext highlighter-rouge">debug()</code> method’s signature, I am not sure why we still
have the first Object separately… mmm.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="cheminf" /><category term="java" /><summary type="html"><![CDATA[A trick I used from Miguel Howard (of Jmol fame) is to not concatenate String until really needed. String concatenation will allocate new Strings, and thus burden the garbage collector (yeah, you lucky Fortran users who think twice before allocating memory :). Some time ago, he suggested this trick for the logger. I think in Jmol, but the CDK inherited that idea.]]></summary></entry><entry><title type="html">Groovy Cheminformatics…</title><link href="http://egonw.github.io/blog/2011/02/06/groovy-cheminformatics.html" rel="alternate" type="text/html" title="Groovy Cheminformatics…" /><published>2011-02-06T00:00:00+00:00</published><updated>2011-02-06T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2011/02/06/groovy-cheminformatics</id><content type="html" xml:base="http://egonw.github.io/blog/2011/02/06/groovy-cheminformatics.html"><![CDATA[<p><strong>Update</strong>: the <a href="https://chem-bla-ics.linkedchemistry.info/2012/01/15/groovy-cheminformatics-4th-edition.html">fourth edition <i class="fa-solid fa-recycle fa-xs"></i></a> is out.</p>

<p>Some project are never finished. Neither is this one, but it is never too late to change how things work, so, taking advantage of
publishing-on-demand, here I introduce the release-soon, release-often equivalent of cheminformatics books, my
<a href="http://www.lulu.com/product/paperback/groovy-cheminformatics-with-the-chemistry-development-kit/14745007">Groovy Cheminformatics with the Chemistry Development Kit</a>
book:</p>

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

<p>With a serious discount for just being the first edition (1.3.8-0), but still counting at 72 pages with 75 code examples, this edition
marks a personal milestone (and probably not much more than that). There remains much to do, but I promised a release by tomorrow, so
here it is. Next releases will contain more code examples, more functionality descriptions, and more literature reviewing where such
code is used in science. The plan is to make new editions with each new <a href="http://cdk.sf.net/">CDK</a> release, as well as new editions
when I added a new chapter, section, or just paragraph. But, there will not be a Nightly build service anytime soon.</p>

<p>The current table of content is as follows:</p>

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

<p>Now, the book content is <strong><em>not</em></strong> open content. However, it contains nothing that is not available in other means. It’s just the
compilation that makes this book interesting, as well as that I put effort in ensuring the code examples remain working.
For that, I ask a minor financial contribution.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="java" /><category term="cheminf" /><category term="cdkbook" /><summary type="html"><![CDATA[Update: the fourth edition is out.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://egonw.github.io/blog/blog/assets/images/cdkBookLulu.png" /><media:content medium="image" url="http://egonw.github.io/blog/blog/assets/images/cdkBookLulu.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Adding a new dictionary to Oscar</title><link href="http://egonw.github.io/blog/2010/11/29/adding-new-dictionary-to-oscar.html" rel="alternate" type="text/html" title="Adding a new dictionary to Oscar" /><published>2010-11-29T00:00:00+00:00</published><updated>2010-11-29T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2010/11/29/adding-new-dictionary-to-oscar</id><content type="html" xml:base="http://egonw.github.io/blog/2010/11/29/adding-new-dictionary-to-oscar.html"><![CDATA[<p>Say, you have your own dictionary of chemical compounds. For example, like your company’s list of yet-unpublished
<a href="http://chembl.blogspot.com/2010/08/research-code-to-company-name-mapping.html">internal research codes</a>. Still,
you want to index your local <a href="http://en.wikipedia.org/wiki/LISTSERV">listserv</a> to make it easier for your
employees to search for particular chemistry you are working on and perhaps related to something done at
other company sites. This is what Oscar is for.</p>

<p>But, it will need to understand things like <a href="http://chembl.blogspot.com/p/research-code-stems.html">UK-92,480</a>.
This is made possible with the Oscar4 refactorings we are currently working on. You only need to
<a href="https://chem-bla-ics.linkedchemistry.info/2010/10/28/oscar4-java-api-chemical-name.html">register a dedicated dictionary <i class="fa-solid fa-recycle fa-xs"></i></a>.
Oscar4 has a default dictionary which corresponds to the dictionary used by Oscar3, and a dictionary based on
<a href="http://www.ebi.ac.uk/chebi/">ChEBI</a> (an old version) (see <a href="http://bitbucket.org/wwmm/oscar4/src/247b8deef001/oscar4-chemnamedict/src/main/java/uk/ac/cam/ch/wwmm/oscar/chemnamedict/core/">this folder</a>
in the source code repository).</p>

<p>Adding a new dictionary is very straightforward: you just implement the <a href="http://bitbucket.org/wwmm/oscar4/src/247b8deef001/oscar4-chemnamedict/src/main/java/uk/ac/cam/ch/wwmm/oscar/chemnamedict/IChemNameDict.java">IChemNameDict</a>
interface. This is, for example, what the OPSIN dictionary looks like:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="nc">OpsinDictionary</span>
<span class="kd">implements</span> <span class="nc">IChemNameDict</span><span class="o">,</span> <span class="nc">IInChIProvider</span> <span class="o">{</span>

  <span class="kd">private</span> <span class="no">URI</span> <span class="n">uri</span><span class="o">;</span>

  <span class="kd">public</span> <span class="nf">OpsinDictionary</span><span class="o">()</span> <span class="kd">throws</span> <span class="nc">URISyntaxException</span> <span class="o">{</span>
    <span class="k">this</span><span class="o">.</span><span class="na">uri</span> <span class="o">=</span> <span class="k">new</span> <span class="no">URI</span><span class="o">(</span>
      <span class="s">"http://wwmm.cam.ac.uk/oscar/dictionariy/opsin/"</span>
    <span class="o">);</span>
  <span class="o">}</span>

  <span class="c1">// the URI is somewhat like a namespace</span>
  <span class="kd">public</span> <span class="no">URI</span> <span class="nf">getURI</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="n">uri</span><span class="o">;</span>
  <span class="o">}</span>

  <span class="c1">// there are no stop words defined in this</span>
  <span class="c1">// dictionary</span>
  <span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">hasStopWord</span><span class="o">(</span><span class="nc">String</span> <span class="n">queryWord</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
  <span class="o">}</span>

  <span class="c1">// see hasStopWord()</span>
  <span class="kd">public</span> <span class="nc">Set</span> <span class="nf">getStopWords</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nc">Collections</span><span class="o">.</span><span class="na">emptySet</span><span class="o">();</span>
  <span class="o">}</span>

  <span class="c1">// it has the name in the dictionary if the name</span>
  <span class="c1">// can be converted into an InChI</span>
  <span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">hasName</span><span class="o">(</span><span class="nc">String</span> <span class="n">queryName</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nf">getInChI</span><span class="o">(</span><span class="n">queryName</span><span class="o">).</span><span class="na">size</span><span class="o">()</span> <span class="o">!=</span> <span class="mi">0</span><span class="o">;</span>
  <span class="o">}</span>

  <span class="c1">// this dictionary can return InChIs for names</span>
  <span class="c1">// so, it implements the IInChIProvider interface</span>
  <span class="kd">public</span> <span class="nc">Set</span> <span class="nf">getInChI</span><span class="o">(</span><span class="nc">String</span> <span class="n">queryName</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">try</span> <span class="o">{</span>
      <span class="nc">NameToStructure</span> <span class="n">nameToStructure</span> <span class="o">=</span>
        <span class="nc">NameToStructure</span><span class="o">.</span><span class="na">getInstance</span><span class="o">();</span>
      <span class="nc">OpsinResult</span> <span class="n">result</span> <span class="o">=</span> <span class="n">nameToStructure</span>
        <span class="o">.</span><span class="na">parseChemicalName</span><span class="o">(</span>
          <span class="n">queryName</span><span class="o">,</span> <span class="kc">false</span>
        <span class="o">);</span>
      <span class="k">if</span> <span class="o">(</span><span class="n">result</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()</span>
          <span class="o">==</span> <span class="no">OPSIN_RESULT_STATUS</span><span class="o">.</span><span class="na">SUCCESS</span><span class="o">)</span> <span class="o">{</span>
        <span class="nc">Set</span> <span class="n">inchis</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">HashSet</span><span class="o">();</span>
        <span class="nc">String</span> <span class="n">inchi</span> <span class="o">=</span> <span class="nc">NameToInchi</span>
          <span class="o">.</span><span class="na">convertResultToInChI</span><span class="o">(</span>
            <span class="n">result</span><span class="o">,</span> <span class="kc">false</span>
          <span class="o">);</span>
        <span class="n">inchis</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">inchi</span><span class="o">);</span>
        <span class="k">return</span> <span class="n">inchis</span><span class="o">;</span>
      <span class="o">}</span>
    <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="nc">NameToStructureException</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
      <span class="n">e</span><span class="o">.</span><span class="na">printStackTrace</span><span class="o">();</span>   
    <span class="o">}</span>
    <span class="k">return</span> <span class="nc">Collections</span><span class="o">.</span><span class="na">emptySet</span><span class="o">();</span>
  <span class="o">}</span>

  <span class="kd">public</span> <span class="nc">String</span> <span class="nf">getInChIforShortestSMILES</span><span class="o">(</span>
    <span class="nc">String</span> <span class="n">queryName</span><span class="o">)</span>
  <span class="o">{</span>
    <span class="nc">Set</span> <span class="n">inchis</span> <span class="o">=</span> <span class="n">getInChI</span><span class="o">(</span><span class="n">queryName</span><span class="o">);</span>
    <span class="k">if</span> <span class="o">(</span><span class="n">inchis</span><span class="o">.</span><span class="na">size</span><span class="o">()</span> <span class="o">==</span> <span class="mi">0</span><span class="o">)</span> <span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
    <span class="k">return</span> <span class="n">inchis</span><span class="o">.</span><span class="na">iterator</span><span class="o">().</span><span class="na">next</span><span class="o">();</span>
  <span class="o">}</span>

  <span class="c1">// since names are converted on the fly, we do</span>
  <span class="c1">// not enumerate them</span>
  <span class="kd">public</span> <span class="nc">Set</span> <span class="nf">getNames</span><span class="o">(</span><span class="nc">String</span> <span class="n">inchi</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nc">Collections</span><span class="o">.</span><span class="na">emptySet</span><span class="o">();</span>
  <span class="o">}</span>
  <span class="kd">public</span> <span class="nc">Set</span> <span class="nf">getNames</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nc">Collections</span><span class="o">.</span><span class="na">emptySet</span><span class="o">();</span>
  <span class="o">}</span>
  <span class="kd">public</span> <span class="nc">Set</span> <span class="nf">getOrphanNames</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nc">Collections</span><span class="o">.</span><span class="na">emptySet</span><span class="o">();</span>
  <span class="o">}</span>
  <span class="kd">public</span> <span class="nc">Set</span> <span class="nf">getChemRecords</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nc">Collections</span><span class="o">.</span><span class="na">emptySet</span><span class="o">();</span>
  <span class="o">}</span>
  <span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">hasOntologyIdentifier</span><span class="o">(</span>
    <span class="nc">String</span> <span class="n">identifier</span><span class="o">)</span>
  <span class="o">{</span>
    <span class="c1">// this ontology does not use ontology</span>
    <span class="c1">// identifiers</span>
    <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
  <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>Now, you can implement the interface in various ways. You can even have the implementation hook into a SQL database
with JDBC, or use something else fancy. The dictionary will be used at various steps of the Oscar4 text analysis
workflow.</p>

<p>Mind you, the refactoring is not over yet, and the details may change here and there.</p>

<p>Your comments are most welcome!</p>]]></content><author><name>Egon Willighagen</name></author><category term="oscar" /><category term="java" /><summary type="html"><![CDATA[Say, you have your own dictionary of chemical compounds. For example, like your company’s list of yet-unpublished internal research codes. Still, you want to index your local listserv to make it easier for your employees to search for particular chemistry you are working on and perhaps related to something done at other company sites. This is what Oscar is for.]]></summary></entry><entry><title type="html">Oscar4 Java API: chemical name dictionaries</title><link href="http://egonw.github.io/blog/2010/10/28/oscar4-java-api-chemical-name.html" rel="alternate" type="text/html" title="Oscar4 Java API: chemical name dictionaries" /><published>2010-10-28T00:00:00+00:00</published><updated>2010-10-28T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2010/10/28/oscar4-java-api-chemical-name</id><content type="html" xml:base="http://egonw.github.io/blog/2010/10/28/oscar4-java-api-chemical-name.html"><![CDATA[<p>Besides getting Oscar used by <a href="http://www.ebi.ac.uk/chebi/">ChEBI</a> (hopefully <a href="https://chem-bla-ics.linkedchemistry.info/2010/10/21/oscar-text-mining-in-taverna.html">via Taverna <i class="fa-solid fa-recycle fa-xs"></i></a>),
my main task in <a href="https://chem-bla-ics.linkedchemistry.info/2010/10/15/working-on-oscar-for-three-months.html">my three month Oscar project <i class="fa-solid fa-recycle fa-xs"></i></a>
is to refactor things to make it more modular, and remove some features no longer needed (e.g. an automatically created workspace environment).
Clearly, I need to define a lot of <a href="https://chem-bla-ics.linkedchemistry.info/2010/10/26/multiple-unit-test-inheritance-with.html">new unit tests <i class="fa-solid fa-recycle fa-xs"></i></a>
to ensure my assumptions on how to code works are valid.</p>

<p>So, what are the API requirements set out? These include (but are not limited to):</p>

<ul>
  <li>have reasonable defaults</li>
  <li>being able to add custom dictionaries</li>
  <li>easily change the chemical entity recogniser</li>
  <li>plugin text normalization (see <a href="https://blogs.ch.cam.ac.uk/pmr/2010/10/24/the-absolute-minimum-every-scientist-with-data-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/">Peter’s post on UNICODE <i class="fa-solid fa-recycle fa-xs"></i></a>)</li>
</ul>

<p>This week I worked on the dictionary refactoring, and talked with Lezan about the <a href="http://www-ucc.ch.cam.ac.uk/products/software/chemicaltagger">ChemicalTagger</a>
and trying to get this based on the newer Oscar code (I think we’ll be able to finish that today). So, I cleaned up
some code I did in the first week, and introduced <a href="https://bitbucket.org/wwmm/oscar4/src/bf79fd11045c/oscar4-api/src/main/java/uk/ac/cam/ch/wwmm/oscar/Oscar.java">a Oscar class</a>
providing a Java API to the Oscar functionality.</p>

<p>So, to get started with Oscar in your application, you only need to do:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">Oscar</span> <span class="n">oscar</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">Oscar</span><span class="o">(</span>
  <span class="k">this</span><span class="o">.</span><span class="na">getClass</span><span class="o">().</span><span class="na">getClassLoader</span><span class="o">()</span>
<span class="o">);</span>
<span class="n">oscar</span><span class="o">.</span><span class="na">loadDefaultDictionaries</span><span class="o">();</span>
<span class="nc">Map</span><span class="o">&lt;</span><span class="nc">NamedEntity</span><span class="o">,</span><span class="nc">String</span><span class="o">&gt;</span> <span class="n">structures</span> <span class="o">=</span>
  <span class="n">oscar</span><span class="o">.</span><span class="na">getNamedEntities</span><span class="o">(</span>
    <span class="s">"Ingredients: acetic acid, water."</span>
  <span class="o">);</span>
</code></pre></div></div>

<p>The ClassLoader is needed because the Oscar class will not generally know how to load custom classes.</p>

<p>You can add additional dictionaries, by implementing the <a href="https://bitbucket.org/wwmm/oscar4/src/tip/oscar4-chemnamedict/src/main/java/uk/ac/cam/ch/wwmm/oscar/chemnamedict/IChemNameDict.java">IChemNameDict</a>
interface and one or more of <a href="https://bitbucket.org/wwmm/oscar4/src/tip/oscar4-chemnamedict/src/main/java/uk/ac/cam/ch/wwmm/oscar/chemnamedict/IInChIProvider.java">IInChIProvider</a>,
<a href="https://bitbucket.org/wwmm/oscar4/src/tip/oscar4-chemnamedict/src/main/java/uk/ac/cam/ch/wwmm/oscar/chemnamedict/ISMILESProvider.java">ISMILESProvider</a>,
and <a href="https://bitbucket.org/wwmm/oscar4/src/tip/oscar4-chemnamedict/src/main/java/uk/ac/cam/ch/wwmm/oscar/chemnamedict/ICMLProvider.java">ICMLProvider</a>.
For example, adding the OPSIN dictionary would extend the above code to:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">Oscar</span> <span class="n">oscar</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">Oscar</span><span class="o">(</span>
  <span class="k">this</span><span class="o">.</span><span class="na">getClass</span><span class="o">().</span><span class="na">getClassLoader</span><span class="o">()</span>
<span class="o">);</span>
<span class="n">oscar</span><span class="o">.</span><span class="na">loadDefaultDictionaries</span><span class="o">();</span>
<span class="n">oscar</span><span class="o">.</span><span class="na">getChemNameDict</span><span class="o">().</span><span class="na">register</span><span class="o">(</span>
  <span class="k">new</span> <span class="nf">OpsinDictionary</span><span class="o">()</span>
<span class="o">);</span>
<span class="nc">Map</span><span class="o">&lt;</span><span class="nc">NamedEntity</span><span class="o">,</span><span class="nc">String</span><span class="o">&gt;</span> <span class="n">structures</span> <span class="o">=</span>
  <span class="n">oscar</span><span class="o">.</span><span class="na">getNamedEntities</span><span class="o">(</span>
    <span class="s">"Ingredients: acetic acid, water."</span>
  <span class="o">);</span>
</code></pre></div></div>

<p>And, I think the <code class="language-plaintext highlighter-rouge">oscar.getChemNameDict()</code> method will be renamed to something like <code class="language-plaintext highlighter-rouge">oscar.getDictionaryRegistry()</code> really soon.</p>]]></content><author><name>Egon Willighagen</name></author><category term="oscar" /><category term="java" /><category term="chebi" /><category term="inchikey:XLYOFNOQVPJJNP-UHFFFAOYSA-N" /><category term="inchikey:QTBSBXVTEAMEQO-UHFFFAOYSA-N" /><summary type="html"><![CDATA[Besides getting Oscar used by ChEBI (hopefully via Taverna ), my main task in my three month Oscar project is to refactor things to make it more modular, and remove some features no longer needed (e.g. an automatically created workspace environment). Clearly, I need to define a lot of new unit tests to ensure my assumptions on how to code works are valid.]]></summary></entry><entry><title type="html">CDK 1.2 to 1.4 API changes #1: creating objects with an IChemObjectBuilder</title><link href="http://egonw.github.io/blog/2010/10/27/cdk-12-to-14-api-changes-1-creating.html" rel="alternate" type="text/html" title="CDK 1.2 to 1.4 API changes #1: creating objects with an IChemObjectBuilder" /><published>2010-10-27T00:00:00+00:00</published><updated>2010-10-27T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2010/10/27/cdk-12-to-14-api-changes-1-creating</id><content type="html" xml:base="http://egonw.github.io/blog/2010/10/27/cdk-12-to-14-api-changes-1-creating.html"><![CDATA[<p>Later this year (planned) a new stable branch of the CDK library will be released.
Time to look at some API changes, to ease migration. In this first post of the
series, I will show how the IChemObjectBuilder functionality has changed.</p>

<p><strong>CDK 1.2 code</strong></p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">IChemObjectBuilder</span> <span class="n">builder</span> <span class="o">=</span>
  <span class="nc">DefaultChemObjectBuilder</span><span class="o">.</span><span class="na">getInstance</span><span class="o">();</span>
<span class="nc">IMolecule</span> <span class="n">molecule</span> <span class="o">=</span> <span class="n">builder</span><span class="o">.</span><span class="na">newMolecule</span><span class="o">();</span>
<span class="n">molecule</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span><span class="n">builder</span><span class="o">.</span><span class="na">newAtom</span><span class="o">(</span><span class="s">"C"</span><span class="o">));</span>
</code></pre></div></div>

<p><strong>CDK 1.4 code</strong></p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">IChemObjectBuilder</span> <span class="n">builder</span> <span class="o">=</span>
  <span class="nc">DefaultChemObjectBuilder</span><span class="o">.</span><span class="na">getInstance</span><span class="o">();</span>
<span class="nc">IMolecule</span> <span class="n">molecule</span> <span class="o">=</span> <span class="n">builder</span><span class="o">.</span><span class="na">newInstance</span><span class="o">(</span>
  <span class="nc">IMolecule</span><span class="o">.</span><span class="na">class</span>
<span class="o">);</span>
<span class="n">molecule</span><span class="o">.</span><span class="na">addAtom</span><span class="o">(</span>
  <span class="n">builder</span><span class="o">.</span><span class="na">newInstance</span><span class="o">(</span><span class="nc">IAtom</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="s">"C"</span><span class="o">)</span>
<span class="o">);</span>
</code></pre></div></div>

<p>Now, please note that the <em>builder.newInstance()</em> method may actually return
null. This is not the case for the <a href="https://cdk.github.io/cdk/latest/docs/api/org/openscience/cdk/DefaultChemObjectBuilder.html">DefaultChemObjectBuilder <i class="fa-solid fa-recycle fa-xs"></i></a>,
or the <a href="https://cdk.github.io/cdk/latest/docs/api/org/openscience/cdk/nonotify/NoNotificationChemObjectBuilder.html">NoNotifiationChemObjectBuilder <i class="fa-solid fa-recycle fa-xs"></i></a>,
but future releases may have dedicated builders that do have such functionality.
However, these builder would not supposed to be used for building molecules
anyway.</p>

<p>The general patterns of <em>newInstance()</em> calls is that the first argument is
the interface for which you want an instance. All further parameters are passed
as parameters for the object’s constructor. The builder maps the input to appropriate
class constructors. To know what parameters you can pass when instantiating
an IAtom with the DefaultChemObjectBuilder, you would look at the constructor
of <a href="https://cdk.github.io/cdk/latest/docs/api/org/openscience/cdk/Atom.html">Atom <i class="fa-solid fa-recycle fa-xs"></i></a>.
Therefore, we can also call:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">IAtom</span> <span class="n">atom</span> <span class="o">=</span> <span class="n">builder</span><span class="o">.</span><span class="na">newInstance</span><span class="o">(</span>
  <span class="nc">IAtom</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="s">"C"</span><span class="o">,</span> <span class="k">new</span> <span class="nc">Point2d</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="o">)</span>
<span class="o">);</span>
</code></pre></div></div>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="cheminf" /><category term="java" /><summary type="html"><![CDATA[Later this year (planned) a new stable branch of the CDK library will be released. Time to look at some API changes, to ease migration. In this first post of the series, I will show how the IChemObjectBuilder functionality has changed.]]></summary></entry><entry><title type="html">CDK 1.2 to 1.4 API changes #2: implicit hydrogens</title><link href="http://egonw.github.io/blog/2010/10/27/cdk-12-to-14-api-changes-2-implicit.html" rel="alternate" type="text/html" title="CDK 1.2 to 1.4 API changes #2: implicit hydrogens" /><published>2010-10-27T00:00:00+00:00</published><updated>2010-10-27T00:00:00+00:00</updated><id>http://egonw.github.io/blog/2010/10/27/cdk-12-to-14-api-changes-2-implicit</id><content type="html" xml:base="http://egonw.github.io/blog/2010/10/27/cdk-12-to-14-api-changes-2-implicit.html"><![CDATA[<p>A second API change lies deep in the <a href="https://cdk.github.io/cdk/latest/docs/api/org/openscience/cdk/interfaces/IAtom.html">IAtom <i class="fa-solid fa-recycle fa-xs"></i></a>
interface. To reflect more accurately the meaning of the method, the <em>IAtomType.getHydrogenCount()</em>
has been renamed to <em>IAtomType.getImplicitHydrogenCount()</em>, and likewise the
setter methods.</p>

<p><strong>CDK 1.2 code</strong></p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">carbon</span><span class="o">.</span><span class="na">setHydrogenCount</span><span class="o">(</span><span class="mi">4</span><span class="o">);</span>
</code></pre></div></div>

<p><strong>CDK 1.4 code</strong></p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">carbon</span><span class="o">.</span><span class="na">setImplicitHydrogenCount</span><span class="o">(</span><span class="mi">4</span><span class="o">);</span>
</code></pre></div></div>

<p>Yeah, that’s a simple one. Just to make clear, in both versions the count reflected
the number of implicit hydrogens. The <em>getHydrogenCount()</em> suggested, however,
to return the number of all hydrogens attached to that atom, that is, the sum
of implicit and explicit hydrogens.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="cheminf" /><category term="java" /><summary type="html"><![CDATA[A second API change lies deep in the IAtom interface. To reflect more accurately the meaning of the method, the IAtomType.getHydrogenCount() has been renamed to IAtomType.getImplicitHydrogenCount(), and likewise the setter methods.]]></summary></entry><entry><title type="html">Multiple unit test inheritance with JExample</title><link href="http://egonw.github.io/blog/2010/10/26/multiple-unit-test-inheritance-with.html" rel="alternate" type="text/html" title="Multiple unit test inheritance with JExample" /><published>2010-10-26T00:10:00+00:00</published><updated>2010-10-26T00:10:00+00:00</updated><id>http://egonw.github.io/blog/2010/10/26/multiple-unit-test-inheritance-with</id><content type="html" xml:base="http://egonw.github.io/blog/2010/10/26/multiple-unit-test-inheritance-with.html"><![CDATA[<p>Two months ago I wrote about <a href="http://scg.unibe.ch/research/jexample">JExample</a> (see
<a href="https://chem-bla-ics.linkedchemistry.info/2010/08/14/specifying-unit-test-dependencies-with.html">Specifying unit test dependencies with JExample <i class="fa-solid fa-recycle fa-xs"></i></a>).
At the time, my examples did not include multiple unit test inheritance, but was informed later by @jexample
that is possible. I just got time to try it in the <a href="https://chem-bla-ics.linkedchemistry.info/2010/10/15/working-on-oscar-for-three-months.html">Oscar <i class="fa-solid fa-recycle fa-xs"></i></a>
project:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@Test</span> <span class="kd">public</span> <span class="nc">Oscar</span> <span class="nf">testConstructor</span><span class="o">()</span>
<span class="kd">throws</span> <span class="nc">URISyntaxException</span>
<span class="o">{</span>
  <span class="nc">Oscar</span> <span class="n">oscar</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">Oscar</span><span class="o">();</span>
  <span class="nc">Assert</span><span class="o">.</span><span class="na">assertNotNull</span><span class="o">(</span><span class="n">oscar</span><span class="o">);</span>
  <span class="k">return</span> <span class="n">oscar</span><span class="o">;</span>
<span class="o">}</span>

<span class="nd">@Given</span><span class="o">(</span><span class="s">"#testConstructor"</span><span class="o">)</span>
<span class="kd">public</span> <span class="nc">String</span> <span class="nf">testNormalize</span><span class="o">(</span><span class="nc">Oscar</span> <span class="n">oscar</span><span class="o">)</span>
<span class="kd">throws</span> <span class="nc">URISyntaxException</span>
<span class="o">{</span>
  <span class="nc">String</span> <span class="n">input</span> <span class="o">=</span> <span class="n">oscar</span><span class="o">.</span><span class="na">normalize</span><span class="o">(</span>
    <span class="s">"This is a simple input string with benzene."</span>
  <span class="o">);</span>
  <span class="nc">Assert</span><span class="o">.</span><span class="na">assertNotNull</span><span class="o">(</span><span class="n">input</span><span class="o">);</span>
  <span class="k">return</span> <span class="n">input</span><span class="o">;</span>
<span class="o">}</span>

<span class="nd">@Given</span><span class="o">(</span><span class="s">"#testConstructor,#testNormalize"</span><span class="o">)</span>
<span class="kd">public</span> <span class="nc">List</span> <span class="nf">testTokenize</span><span class="o">(</span>
  <span class="nc">Oscar</span> <span class="n">oscar</span><span class="o">,</span> <span class="nc">String</span> <span class="n">input</span><span class="o">)</span> <span class="kd">throws</span> <span class="nc">Exception</span>
<span class="o">{</span>
  <span class="nc">List</span> <span class="n">tokens</span> <span class="o">=</span> <span class="n">oscar</span><span class="o">.</span><span class="na">tokenize</span><span class="o">(</span><span class="n">input</span><span class="o">);</span>
  <span class="nc">Assert</span><span class="o">.</span><span class="na">assertNotNull</span><span class="o">(</span><span class="n">tokens</span><span class="o">);</span>
  <span class="nc">Assert</span><span class="o">.</span><span class="na">assertNotSame</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">tokens</span><span class="o">.</span><span class="na">size</span><span class="o">());</span>
  <span class="k">return</span> <span class="n">tokens</span><span class="o">;</span>
<span class="o">}</span>

<span class="nd">@Given</span><span class="o">(</span><span class="s">"#testConstructor,#testTokenize"</span><span class="o">)</span>
<span class="kd">public</span> <span class="nc">List</span> <span class="nf">testRecognizeNamedEntities</span><span class="o">(</span>
  <span class="nc">Oscar</span> <span class="n">oscar</span><span class="o">,</span> <span class="nc">List</span> <span class="n">tokens</span><span class="o">)</span>
<span class="kd">throws</span> <span class="nc">Exception</span>
<span class="o">{</span>
  <span class="nc">List</span> <span class="n">entities</span> <span class="o">=</span>
    <span class="n">oscar</span><span class="o">.</span><span class="na">recognizeNamedEntities</span><span class="o">(</span><span class="n">tokens</span><span class="o">);</span>
  <span class="nc">Assert</span><span class="o">.</span><span class="na">assertNotNull</span><span class="o">(</span><span class="n">entities</span><span class="o">);</span>
  <span class="nc">Assert</span><span class="o">.</span><span class="na">assertEquals</span><span class="o">(</span><span class="mi">1</span><span class="o">,</span> <span class="n">entities</span><span class="o">.</span><span class="na">size</span><span class="o">());</span>
  <span class="k">return</span> <span class="n">entities</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></div></div>

<p>The pattern here is that each test method returns one variable, so that any method depending on two
other unit test will have two parameters. The order is defined by the order in which they are given
by the <em>@Given</em> clause.</p>]]></content><author><name>Egon Willighagen</name></author><category term="java" /><category term="junit" /><summary type="html"><![CDATA[Two months ago I wrote about JExample (see Specifying unit test dependencies with JExample ). At the time, my examples did not include multiple unit test inheritance, but was informed later by @jexample that is possible. I just got time to try it in the Oscar project:]]></summary></entry></feed>