## The Notebook.

A bunch of possibly interesting things.

# Changes to ChemSi

Recently I chose to rewrite ChemSi in its entirety to clean up the code base and add some new features. Now, instead of only having a text based front end which limits the usability (so you can't have cyclic reactions, etc) and simultaneously makes it harder to maintain (I had wanted to use electron energies instead of electro negativities) I chose to write it in an object orientated manner. This enables it to be used as a Python module, as opposed to a program.

Using

import chemi

the module will be loaded, and commands can be used within it. For example;

import chemi

q = chemi.periodic_table["Na"].out(1)
print q["name"]
print q['shells']['3s0']
print q
s = chemi.Reaction(300)
q = chemi.Reaction(300)
s.reactants.append(chemi.Compound("NaBr", 0, 0, []))
s.reactants.append(chemi.Compound("NaBr", 0, 0, []))
s.reactants.append(chemi.Compound("Cl2", 0, 0, []))
s.predict()
print(chemi.output(s.return_reactants()) + " -> " + chemi.output(s.return_products()))
q.reactants = s.products
q.reactants[2] = chemi.Compound("F2", 0, 0, [])
q.predict()
print(chemi.output(q.return_reactants()) + " -> " + chemi.output(q.return_products()))



Will give the following output;

ben@Nitrate:~/Development/ChemSi\$ python test.py
Sodium
{'energy': -1.5, 'number': 1}
{'molar': 23.0, 'electronegativity': 0.9, 'name': u'Sodium', 'shells': {'2p1': {'energy': -166.7, 'number': 2}, '2p0': {'energy': -166.7, 'number': 2}, '2p-1': {'energy': -166.7, 'number': 2}, '3s0': {'energy': -1.5, 'number': 1}, '1s0': {'energy': -1646.3, 'number': 2}, '2s0': {'energy': -275.5, 'number': 2}}, 'an': 11, 'small': u'Na'}
Cl2 + 2NaBr -> Br2 + 2NaCl
F2 + 2NaCl -> 2NaF + Cl2



Here I have done something which would've been impossible in a previous version of ChemSi. I have first of all used the new periodic table definition to return some information about sodium - the name, the 3s0 shell energy (kJmol^-1, approximated using the Rydberg equation) and then a general print out of it. I then go on to add some Sodium Bromide to reaction s, and some chlorine. I then get it to use my algorithm to predict the reaction products, before printing out the reaction;

Which it predicts correctly. I then move the products into reaction q, but replace the bromine with fluorine. I then predict them together, and I get;

These predictions are typically more accurate than the old model - for example;

In the previous ChemSi code this would've given AlBr and FeBr2 - which isn't accurate. So, in some respects it is getting better. On the other hand, because the algorithm I am using to fill the shell energies has faults with transition metals and elements with a 4s or higher orbital (it fills them going up in n,l,m ie 1s, 2s, 2p, 3s, 3p, 3d, 4s as opposed to the actual energies) it means that the above demonstration with NaI will not work accurately - the Chlorine is calculated to be higher and so is not substituted. Regardless, the new prediction engine seems to work better - fixes will be released in the coming weeks to fix these issues.

The code is already up on GitHub and along side it you will find a new class definitions file which explains each of the new classes.