<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; Organic Chemistry</title>
	<atom:link href="http://www.dimuthu.org/catagory/organic-chemistry/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Organic Chemistry &#8211; Reaction Simulator</title>
		<link>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 05:24:24 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Organic Chemistry]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[G.C.E. A/L]]></category>
		<category><![CDATA[Reaction Simulator]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=683</guid>
		<description><![CDATA[Organic Reaction Simulator It is a tool that simulates the organic reactions and automatically generate the IUPAC names for the organic compounds drawn by you. This covers most of the syllabus of the Organic Chemistry for G.C.E. A/L examination. Features Nice Canvas to draw your Organic compounds. Generates IUPAC names for the drawn component as [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Organic Reaction Simulator</strong></p>
<p>It is a tool that simulates the organic reactions and automatically generate the IUPAC names for the organic compounds drawn by you. This covers most of the syllabus of the Organic Chemistry for G.C.E. A/L examination.</p>
<p><strong>Features</strong></p>
<ul>
<li> Nice Canvas to draw your Organic compounds.</li>
<li>Generates IUPAC names for the drawn component as possible. (It generates IUPAC names for almost all the compounds which G.C.E A/L examination expect students to know)</li>
<li>You can simulate reaction for organic compounds with preferred inorganic/organic compounds and the selected conditions. (Currently supporting 168 reactions)</li>
<li>Extensibility of adding IUPAC naming rules without the need of recompiling the code.</li>
<li>Extensibility of adding custom reactions, again without compiling a single line of code.</li>
</ul>
<p>Here is a screen shot of the main panel when &#8216;Aldole reaction&#8217; is simulated for some simple reactants.</p>
<div id="attachment_690" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/aldole.jpg"><img class="size-full wp-image-690" title="Aldole Reaction - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/aldole.jpg" alt="Aldole Reaction - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Aldole Reaction - Reaction Simulator</p></div>
<p><strong>The Drawing Panel</strong></p>
<p>The &#8216;Reaction Simulator&#8217; app provides 2 views for the user. One is the main panel which shows and manages reactions which is shown in the above figure. The other view is the drawing panel. It will be not much different from your favorite drawing application.</p>
<div id="attachment_692" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/drawing_panel.jpg"><img class="size-full wp-image-692" title="Drawing Panel - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/drawing_panel.jpg" alt="Drawing Panel - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Drawing Panel - Reaction Simulator</p></div>
<p>Here you can select elements and bond types to draw your organic compound. Additionally It has tools to move or delete selected parts of your drawing.</p>
<p>The other thing you may have already noticed, you don&#8217;t need to complete all the bonds for a particular element. Rather if you keep one side of a single bond unconnected, it will be automatically connected to a &#8216;H&#8217;(Hydrogen) at the rendering, similarly for double bond the default connecting element would be &#8216;O&#8217;(Oxygen), and for triple bond it is &#8216;N&#8217; (Nytrogen). And you don&#8217;t even need to bother about connecting bonds with an element, as if you connected only one bond to &#8216;C&#8217; all the other 3 possible bonds will be considered as connected with &#8216;H&#8217;s.</p>
<p>Just check the drawing panel on your own and find its user friendliness. Now after you finish designing your compound, just press &#8220;RETURN&#8221;.</p>
<div id="attachment_694" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/iupac.jpg"><img class="size-full wp-image-694" title="IUPAC Name Generator - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/iupac.jpg" alt="IUPAC Name Generator - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">IUPAC Name Generator - Reaction Simulator</p></div>
<p>Yea it will nicely render our compound, and look at the bottom, it has generated the IUPAC name for the compound.</p>
<p><strong>The Main Panel</strong></p>
<p>This contain a canvas that you can add, edit and delete organic compounds (so you will be directed to the &#8216;Drawing Panel&#8217;), some sidebar panels to select Inorganic compounds and additional conditions requires for the reactions and a set of buttons to start reactions and manage the result set. At the end of the sidebar there is a &#8216;help&#8217; button that directed you to the user guide.</p>
<p><strong>Extending IUPAC Naming Rules</strong></p>
<p>If you go to the &#8220;Data/IUPAC/&#8221; directory (you can view svn from here, <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/IUPAC/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/IUPAC/</a>) you can find there are set of .txt files (infact xmls) that defines the IUPAC rules.</p>
<p>If you open one of them (we will take al.txt), it would be something like this</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;IUPAC</span> <span style="color: #000066;">basename</span>=<span style="color: #ff0000;">"al"</span> <span style="color: #000066;">subname</span>=<span style="color: #ff0000;">"oxo"</span> <span style="color: #000066;">level</span>=<span style="color: #ff0000;">"6"</span> <span style="color: #000066;">nonumber</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000066;">affectto</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"7"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/IUPAC<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>It is the naming rules for aldehyde compounds. (H-C=O). First it identify the the aldehyde by checking double bond to &#8216;O&#8217; (which is the element type &#8217;7&#8242;), and a single bond to &#8216;H&#8217; (which is the element type &#8217;1&#8242;). If the element group found, it will give the name &#8216;al&#8217; or &#8216;oxo&#8217; depending on whether it defines the main group of elements of the compound or not.</p>
<p>If you take a look at all these rules, you can have a good idea what each of these syntax mean. And may be you can add your own rules, if you find something missing or incorrect there.</p>
<p><strong>Extending the Reactions</strong></p>
<p>The reaction rules are stored in the &#8220;Data/Reactions/&#8221; directory ( <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/</a>).</p>
<p>I will take the first reaction we studied in the &#8216;Organic Chemistry&#8217; Class.</p>
<p>CH4 + Cl2 + hv  (dim light) &#8212;&#8212;&#8212;&#8212;&#8212;-&gt; CCl4 + H2</p>
<p>Here is the rule defining that reaction. (cl2hv.txt)</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reaction</span> <span style="color: #000066;">inorganics</span>=<span style="color: #ff0000;">"Cl2"</span> <span style="color: #000066;">conditions</span>=<span style="color: #ff0000;">"hv"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/check<span style="font-weight: bold; color: black;">&gt;</span></span></span>

	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"remain"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"remain"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
					<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"replace"</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">"Cl"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
					<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reaction<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>If you take a close look at, what it says is if there exist inorganic &#8216;Cl2&#8242; and condition &#8216;hv&#8217; (reactions inorganics=&#8221;Cl2&#8243; conditions=&#8221;hv&#8221;), check for a &#8216;H&#8217; (element type=&#8221;H&#8221;) elements that is connected to a &#8216;C&#8217; element (which is the root of the XML) through a single bond (bond type=&#8221;1&#8243;), then don&#8217;t replace the &#8216;C&#8217; (reordering activity=&#8221;remain&#8221;) and don&#8217;t replace the bond type (reordering activity=&#8221;remain&#8221;), just replace the &#8216;H&#8217; with &#8216;Cl&#8217; (reordering activity=&#8221;replace&#8221; to=&#8221;Cl&#8221;). It is so simple as that.</p>
<p>These rules are applied to all the C elements in reactants. Look at the following figure for this rule in application.</p>
<div id="attachment_698" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/cl2hv.jpg"><img class="size-full wp-image-698" title="Alkane + Cl2 Reaction - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/cl2hv.jpg" alt="Alkane + Cl2 Reaction - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Alkane + Cl2 Reaction - Reaction Simulator</p></div>
<p>These reaction rules can be as complex as you want. Specially when two or more reactants are involved in a reaction, rules defining that reaction will be little complex. Look at how aldole reaction (which is applied in the first figure of this post) is written in <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/aldole.txt">aldole.txt</a>.</p>
<p>There are all together 168 reactions currently defined in this way. If you found some reaction is missing, feel free to add a another rule file defining that reaction. And if you want to share that with others, just let me know <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , so I can integrate it in to the distribution.</p>
<p><strong>Download</strong></p>
<p>This software application is not yet in a official release. I just thought use this post to do a pre release of the &#8216;Reaction Simulator&#8217;. You can download the windows binary of the pre release version (343KB) from <a href="http://downloads.dimuthu.org/bins/chemistry/reaction_simulator_pre_release/reaction_simulator_pre_release.zip">http://downloads.dimuthu.org/bins/chemistry/reaction_simulator_pre_release/reaction_simulator_pre_release.zip</a></p>
<p><strong>Source Code</strong></p>
<p>SVN location for the source code of &#8216;Reaction Simulator&#8217; is <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/</a></p>
<p><strong>Known Limitations &#8211; Possible Improvements<br />
</strong></p>
<ul>
<li>Generation of IUPAC names and simulations of reactions are not supported for compounds which involves Benzene ring.</li>
<li>IUPAC names generation is not supported for cyclic compounds which are anyway not part of the G.C.E. A/L syllabus.</li>
<li>The set of elements, available in drawing compounds, set of inorganic compounds and conditions, available in reactions are fixed and cannot be extended without changing the code and recompiling.</li>
<li>You can&#8217;t start with an IUPAC name and derive the compound. Currently you always have to start with drawing the compound and then generate the IUPAC.</li>
<li>Only for windows!</li>
</ul>
<p><strong>Little Background</strong></p>
<p>4 years ago, When I was a level 2 student in the <a href="http://www.mrt.ac.lk/">University of Moratuwa</a>, I participated to a competition for making educational software tools organized by <a href="http://www.cse.mrt.ac.lk/">C.S.E</a> and <a href="http://www.nie.lk/">N.I.E (National Institute of Education)</a>. I submitted a software that teaches Organic Chemistry. It consisted of interactive tutorials targeting local G.C.E A/L exams with exercises and revisions in both Sinhala(My Mother tongue) and English languages(not in Unicode though). I got the second price for that.</p>
<p>After the award I decided to improve my software application by adding an &#8216;Organic Reaction Simulator&#8217;. In fact in the vacation of 2 weeks for the New Year, I could complete it.</p>
<p>Although the N.I.E supposed to distribute the applications submitted to the competition throughout the country, it didn&#8217;t happened. So I decided to publish at least the &#8216;Reaction Simulator&#8217; application which I actually didn&#8217;t submitted to the competition.</p>
<p><strong>Technologies Used</strong></p>
<p>This is completely written in C++. It hasn&#8217;t use MFC, because I thought MFC is too heavy for such a small application. I used a lightweight, small image library code taken with some custom changes from some windows game programming book.</p>
<p>This is using XML to load data about reactions and IUPAC names which I have described in details in the early part of the blog. It uses a small inbuilt xml parser (just one recursive function) to parse these xmls.</p>
<p>So it has no depenedencies to third party libraries, You can just chekcout the <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/">souce code from the svn</a>, open the visual studio project and compile it (press &#8216;F7&#8242;).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

