COM3190/6116 Assignment 2019: Simulating Chemistry
Dr. Ramsay G. Taylor April 5, 2019
Introduction
Although Process Algebra like CCS and CSP were created to model software and computer systems, they have also been used to model chemical [1] and bio- chemical [2] systems. This assignment is going to take some inspiration from that work and build a chemical simulator in Erlang.
You will be representing different molecules as Erlang processes, and the pro- cess evolution will model the chemical changes. As a simple example, you hope- fully recall enough Organic Chemistry to discuss the combustion of Methanol in Oxygen. Methanol has the chemical formula CH3OH. It burns (or combusts) in oxygen by decomposing into its constituent parts and combining with the O2 to form water (H2O) and carbon dioxide (CO2). In some circumstances you can get incomplete combustion that leaves behind soot (which is just carbon, C) or carbon monoxide (CO).
Ultimately, this process starts with Methanol and Oxygen molecules and, through a sequence of exchanges and evolutions, converts those molecules into Water and Carbon Dioxide, assuming there is enough Oxygen present. We shall model the molecules as processes, and their exchanges as communications. Figure 1 shows an example of the possible communications and evolutions of the molecules and some of their intermediary molecules.
It should be apparent that there are various possible interactions and evo- lutions involving the different molecules that might occur in the system. For example, if an O2 molecule can receive a carbon atom from somewhere it can evolve to CO2. Meanwhile, it could be convinced to release an oxygen atom
perhaps to an H2 molecule that can then become H2O. We can see that
H2|O2 H2O|O its a reasonable evolution in this CCS model.
We are only going to model the atom transfers, not any of the energy gain
or release, so we dont care how hot it gets!
1
CH3OH = CH2OH = CHOH =
CH3 = CH2 = CH =
CHOH = COH =
H3OH = H2OH = HOH =
H3 =
H2 =
H =h.0
O2 = c.CO2+o.O
c.H3OH + h.CH2OH + oh.CH3 c.H2OH + h.CHOH + oh.CH2 c.HOH + h.COH + oh.CH
c.H3 + h.CH2 c.H2 + h.CH c.H + h.C
c.HOH + oh.CH + h.COH c.OH + oh.C
h.H2OH + oh.H3 h.HOH+oh.H2 h.OH + oh.H
h.H2 h.H
O =
OH =
H =
C = o.CO CO = o.CO2
h.OH + o.0
h.H2O + o.H + h.O oh.H2 O
Figure 1: The combustion of Methanol as a CCS model.
Tasks
Task 1 (30%): The CCS model in Figure 1 includes some molecules that are somewhat unrealistic, like HOH, which is clearly going to be just H2O, since they will tend to form stable molecules if they can. There are several other states that arent stable like H2OH. An accepted set of intermediates is listed in the literature [3] (yes, I did look this up!) as CH3, CH4, HCO, CH3O, and CH2OH. You should rewrite the CCS model to only use those intermediate states. You can do this by making some of the transitions lead to parallel compositions, so rather than CH3 = c.H3 you might have something more stable like c.(H2|H) (i.e. a molecule of H2 and one H ion). You can keep the various definitions for O2, O, C, CO, and OH if these are helpful. The various Hn molecules should be simplified to just H or H2 and you can then use parallel composition so: H3 = H2|H. The only stable definitions should be H2O and CO2, everything else that you define should have further evolutions specified.
Task 2 (70%): You should build an Erlang system to simulate these reac- tions. The Erlang system should be based on the CCS model in Figure 1, with the modifications made in Task 1, so your system should consist of separate Erlang processes to model different molecules and to use message passing to simulate reactions. In the Erlang system you will need to take account of the
2
fact that Erlang communication requires a PID to direct messages to, and it doesnt enforce synchronisation. You will want to design some system to nego- tiate possible reactions and then execute them, but you should ensure that your system is composed of many small processes rather than being a single large process. The system should also display some information about its progress to the terminal. The system should be able to detect when it has reached a stable state (e.g. all H2O and CO2 molecules, or it has run out of Oxygen (O2). It should then print out its composition, so how many H2O molecules, how many CO2 etc. Your system should be configurable to allow different numbers of Methanol and Oxygen molecules to be included at the start so you can experi- ment with different combustion conditions. To make using your system sensible, you must export a function called react that takes two arguments: a number of Methanol molecules and a number of Oxygen molecules to start the system with.
Assessment
Your submission should be done via MOLE. You should submit at least two files:
1. A PDF containing your response to Task 1 (i.e. the CCS definition), and a brief summary describing the design of your Erlang system for Task 2 this should describe the processes that are spawned in the system, how their communication is handled, and how their evolutions match the CCS model.
2. One or more Erlang source files containing the code for your system for Task 2. This should be clearly laid out and commented as well as being functional. Some evidence that you have tested the code is expected preferably eunit tests.
References
[1] G. Berry and G. Boudol. The chemical abstract machine. Theoretical Com- puter Science, 96(1):217 248, 1992.
[2] M. Calder and J. Hillston. Process algebra modelling styles for biomolecular processes. Transactions on Computational Systems Biology XI, pages 125, 2009.
[3] E. Fernandez-Tarrazo, M. Sanchez-Sanz, A. L. Sanchez, and F. A. Williams. A multipurpose reduced chemical-kinetic mechanism for methanol combus- tion. Combustion Theory and Modelling, 20(4):613631, 2016.
3
Reviews
There are no reviews yet.