{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "chem-bla-ics",
  "description": "Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.",
  "home_page_url": "https://chem-bla-ics.linkedchemistry.info/",
  "feed_url": "https://chem-bla-ics.linkedchemistry.info/2010/06/10/cdk-jchempaint-6-rendering-atom-numbers.json",
  "icon": "https://chem-bla-ics.linkedchemistry.info/assets/images/chem-bla-ics_logo.png",
  "language": "en",
  "authors": [
    {
      "name": "Egon Willighagen",
      "url": "https://orcid.org/0000-0001-7542-0286",
      "_orcid": "0000-0001-7542-0286"
    }
  ],
  "items": [

    {
      "id": "https://doi.org/10.59350/5cfpy-kym94",
      "url": "https://chem-bla-ics.linkedchemistry.info/2010/06/10/cdk-jchempaint-6-rendering-atom-numbers.html",
      "title": "CDK-JChemPaint #6: rendering atom numbers",
      "content_html": "<p>I have made a few new <a href=\"http://cdk.sf.net/\">CDK</a>-JChemPaint patches in the past two days, the latest being\n<a href=\"https://sourceforge.net/projects/cdk/files/CDK-JChemPaint/15/\">patch 15</a>. With the help from\n<a href=\"http://gilleain.blogspot.com/\">Gilleain</a>, all rendering parameters are now using the new API, as explained\n<a href=\"https://chem-bla-ics.linkedchemistry.info/2010/04/05/cdk-jchempaint-3-rendering-parameters.html\">earlier <i class=\"fa-solid fa-recycle fa-xs\"></i></a> in\n<a href=\"http://chem-bla-ics.blogspot.com/search?q=%22cdk-jchempaint+%23%22\">this series</a>.</p>\n\n<p>Additionally, the API to work with rendering parameters is now much simpler. The previous posts did not\nreally explain how to tune parameters, so here goes. One important thing to realize, is that a rendering\nparameter can only be changed if the generator that defines it has been registered. To see what parameters\nbelongs to what generator, for which you can use the script discussed in\n<a href=\"https://chem-bla-ics.linkedchemistry.info/2010/04/05/cdk-jchempaint-3-rendering-parameters.html\">post #3 <i class=\"fa-solid fa-recycle fa-xs\"></i></a>.</p>\n\n<h2 id=\"atom-numbers\">Atom Numbers</h2>\n\n<p>In some situations you like to draw atom numbers. This can be done by replacing the BasicAtomGenerator by an\nAtomNumberGenerator in the script given in <a href=\"https://chem-bla-ics.linkedchemistry.info/2010/04/05/cdk-jchempaint-1-rendering-molecules.html\">post #1 <i class=\"fa-solid fa-recycle fa-xs\"></i></a>:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">List</span> <span class=\"n\">generators</span> <span class=\"o\">=</span> <span class=\"k\">new</span> <span class=\"nc\">ArrayList</span><span class=\"o\">();</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicSceneGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicBondGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">AtomNumberGenerator</span><span class=\"o\">());</span>\n</code></pre></div></div>\n\n<p>This would result in an image like this:</p>\n\n<p><img src=\"/assets/images/triazole.atomno.png\" alt=\"\" /></p>\n\n<p>Now, we also might want to give those numbers a color, to make them stand out a bit. Orange, perhaps :)\nThis is where rendering parameters come in. To the code from\n<a href=\"https://chem-bla-ics.linkedchemistry.info/2010/04/05/cdk-jchempaint-1-rendering-molecules.html\">post #1 <i class=\"fa-solid fa-recycle fa-xs\"></i></a>,\nafter the instantiation of the renderer, we add:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"c1\">// tune parameters</span>\n<span class=\"n\">model</span> <span class=\"o\">=</span> <span class=\"n\">renderer</span><span class=\"o\">.</span><span class=\"na\">getRenderer2DModel</span><span class=\"o\">();</span>\n<span class=\"n\">model</span><span class=\"o\">.</span><span class=\"na\">set</span><span class=\"o\">(</span>\n  <span class=\"nc\">AtomNumberGenerator</span><span class=\"o\">.</span><span class=\"na\">AtomNumberTextColor</span><span class=\"o\">.</span><span class=\"na\">class</span><span class=\"o\">,</span>\n  <span class=\"nc\">Color</span><span class=\"o\">.</span><span class=\"na\">orange</span>\n<span class=\"o\">);</span>\n</code></pre></div></div>\n\n<p>The output then looks like:</p>\n\n<p><img src=\"/assets/images/triazole.atomno_2.png\" alt=\"\" /></p>\n\n<h2 id=\"atom-numbers-and-symbols\">Atom Numbers and Symbols</h2>\n\n<p>But you can also render both element symbols and numbers. Then, clearly, you just add both generators:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">List</span> <span class=\"n\">generators</span> <span class=\"o\">=</span> <span class=\"k\">new</span> <span class=\"nc\">ArrayList</span><span class=\"o\">();</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicSceneGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicAtomGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicBondGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">AtomNumberGenerator</span><span class=\"o\">());</span>\n</code></pre></div></div>\n\n<p>But, in order to have the label and the symbol not overlap, we define an offset (Thanx to\n<a href=\"http://github.com/s-wolf\">Sebastian</a>, of <a href=\"http://www.biomedcentral.com/1471-2105/11/148/abstract\">MetFrag</a>\nfame, for the feature request!):</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"n\">model</span><span class=\"o\">.</span><span class=\"na\">set</span><span class=\"o\">(</span>\n  <span class=\"nc\">AtomNumberGenerator</span><span class=\"o\">.</span><span class=\"na\">Offset</span><span class=\"o\">.</span><span class=\"na\">class</span><span class=\"o\">,</span>\n  <span class=\"k\">new</span> <span class=\"n\">javax</span><span class=\"o\">.</span><span class=\"na\">vecmath</span><span class=\"o\">.</span><span class=\"na\">Vector2d</span><span class=\"o\">(</span><span class=\"mi\">10</span><span class=\"o\">,</span><span class=\"mi\">10</span><span class=\"o\">)</span>\n<span class=\"o\">);</span>\n</code></pre></div></div>\n\n<p>Then it gets to look like:</p>\n\n<p><img src=\"/assets/images/triazole.atomno_3.png\" alt=\"\" /></p>\n\n<p>This last full example will be available from GitHub shortly.</p>\n\n<p><strong>Update</strong> Steffen asked in the comments if it is possible to just color the atoms by element type. CDK-JChemPaint\npatch 15 does not allow that, but adding that feature is easy enough, and the patch will be part of the next\nrelease. Use this configuration:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicSceneGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">BasicBondGenerator</span><span class=\"o\">());</span>\n<span class=\"n\">generators</span><span class=\"o\">.</span><span class=\"na\">add</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">AtomNumberGenerator</span><span class=\"o\">());</span>\n</code></pre></div></div>\n\n<p>And these parameter settings:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"n\">model</span> <span class=\"o\">=</span> <span class=\"n\">renderer</span><span class=\"o\">.</span><span class=\"na\">getRenderer2DModel</span><span class=\"o\">();</span>\n<span class=\"n\">model</span><span class=\"o\">.</span><span class=\"na\">set</span><span class=\"o\">(</span>\n  <span class=\"nc\">AtomNumberGenerator</span><span class=\"o\">.</span><span class=\"na\">ColorByType</span><span class=\"o\">.</span><span class=\"na\">class</span><span class=\"o\">,</span>\n  <span class=\"kc\">true</span>\n<span class=\"o\">);</span>\n</code></pre></div></div>\n\n<p>This give you for <a href=\"http://en.wikipedia.org/wiki/Triazole\">triazole</a>:</p>\n\n<p><img src=\"/assets/images/triazole.atomno_4.png\" alt=\"\" /></p>",
      "summary": "I have made a few new CDK-JChemPaint patches in the past two days, the latest being patch 15. With the help from Gilleain, all rendering parameters are now using the new API, as explained earlier in this series.",
      "image": "https://chem-bla-ics.linkedchemistry.info/assets/images/triazole.atomno_2.png",
      "date_published": "2010-06-10T00:00:00+00:00",
      "date_modified": "2026-07-17T00:00:00+00:00",
      "tags": ["cdk","chemistry"],
      
      
      
      
      
      
        "authors": [ { "name": "Egon Willighagen", "url": "https://orcid.org/0000-0001-7542-0286" } ]
      
    }

  ]
}
