Entwickler Tagebuch

Table of contents

What did I want to programm

I wanted to create an app that could help me. Since I have chemistry in school I decided to create an app

that would automate some boring and tedious tasks.

The first tasks that came to my mind were reaction balancing and calculating entrophy, enthalpy and gibbs free energy.

Reaction balancer

You almost always encounter an chemical reaction in chemistry. Like

C + O2CO

Now the problem is, that one the left side are two O but on the right side is only one O.

So we have to arrange the equation. This is pretty easy, we just add a 2 before the CO.

C + O2 → 2 CO

But now we have 2 C on the right side, but one on the left, so we also add a 2 before the C.

Now the equation is balanced:
2 C + O2 → 2 CO ( 2 C and 2 O on the left side and 2 C and 2 O on the right side)

Balancing is relatively easy, but it's still work, error-prone and you often don't have much time.

Theoretical background

Our equation can also be written as x1 C + x2 O2 → x3 CO
An equation is balanced if we have the same number of atoms on every side of the equation, i.e. the following equations must be true:
x1 (C) - x3 (C) = 0
and
2 x2 (O) - x3 (O) = 0

If we use Gaussian elimination we would get the solution that x1 = 2, x2 = 1 and x3 = 2

A group in an equation are the parts that are separetad by an +.
E.g. C, O2 and CO are groups of the equation.
A group also has an repetition count, O2 would have the repetion count 2.

Pseudocode:

get all groups of the left reaction
get all distinct elements of the group

get all groups of the right reation
get all distinct elements of the group

if distinctElementL is in distinctElementR{
add equation xgroupL.position* (count of elementL) - xgroupR.position * (count of elementR)= 0
}

apply Gaussian elimination


Unfortunately I didn't have enough time to implement this feature :(

Drawing given molecules

It's also good to know how a given chemical formula will look.
So I searched for a java library that could draw chemical molecules.
I found Jmol which looked really nice.

But ...
it uses java.awt for drawing so I was out of luck and it would have been impossible to replace java.awt with android specific draw apis.
Jmol has/had an android app, but I were unable to find the source of the nor did I find the app, only a wiki page about the app.

So unfortunately no drawings of molecules :(

Calculating entrophy, enthalpy and Gibbs free energy

Enthalpy is defined as H, it's unit is KJoule/mol. If we a equation given a know the enthalpy of formation (this means that the molecule is formed of the pure elements)
for all molecules, we can calculate the reaction enthalpy like this:
(Hess's law)

ΔHR = ΔHfProducts - ΔHfEducts

Entrophy is defined as S, it's unit is Joule/Kelvin.
And we can calculate it like this:
(Hess's law)

ΔSR = SRProducts - SREducts

Gibbs free energy is defined as G, it's unit is KJoule/mol
It can be calculated using the Gibbs–Helmholtz equation:
ΔG = <H - T*<S (T in Kelvin)
If ΔG >0 the reaction is endergonic, if ΔG <0 the reaction is exergonic.
Endergonic means that the reaction won't happen, exergonic means that the reaction can possible happen.

Theoretical background

Entrophy is a measure for the disorder of a system.

Enthalpy more or less describes how much energy is released in a chemical reaction.

The Gibbs free energy says if a reaction can occur or not.

This heavily relied on balanced equations, so it wasn't implemented.

What did I actually programm

So, I didn't anything and I thought about something that would also be valueable for me.
And in my opinion a nice periodic table with pictures and everything would be helpful, so I decided to implement the periodic table.

Periodic table

I think that everyone knows the periodic table, it basically shows the mass, the phase, the group and the series.
But I wanted more, like melting point, boiling point, common ions and electron negativity.

Implementation

The elements were presented in a ListView were the symbol, the atomic number and the element name were shown.
If you clicked one item, you were shown a new fragment with a RecyclerView inside. I used github.com/bignerdranch/expandable-recycler-view to group the different properties and to make it less messy.
If I found a image, you would also see a nice parallax effect with the toolbar :)

Where I got the data

If found the data on StackOverflow Chemistry. It was in the .csv format which could be easily converted to sql.
That's also what I did, I converted it to sql, added the phase information, because it wasn't included and I threw it into sqlite.
Everything worked very nice so far.

My app looked pretty good but I wanted to add decided to polish the app a little bit.
So I added a collapsing toolbar, As desribed here .

About the used images

I first searched wikipedia and found very much pictures, but very much licensed under CC BY-SA 3.0 DE under I wasn't sure if I can use the pictures with the Apache 2.0 License.
So I only used pictures where I was sure that I won't be sued :D
There were very beautiful pictures like this (Crystals of Gallium)


(CC BY-SA 3.0, Author is en.wikipedia.org/wiki/User:Foobar )
and this (Tantalum single crystal with a high purity)

(CC BY-SA 3.0, Author is https://commons.wikimedia.org/wiki/User:Alchemist-hp )

What do I think about Kotlin

Kotlin is a nice new language, although I have never used it before the contest.
I really like extension methods, because it allows to add methods without overriding classes which is really nice.
I don't really know why I should use properties, but I'm sure that there is a reasion for this decision.

Another nice feature is that you don't have to (always) type the type of a variable.
Kotlin natively suppports singletons, but I wasn't sure how to transform a Java singleton to a Kotlin singleton, but I guess that I was just to stupid^^
I'm also a huge fan of when(), I really like it and have used it often. What I don't understand is: Why doesn't Kotlin have static methods/properties.

To sum up, I think that Kotlin has some really nice features and I have to try kotlinjs :)

Why did I participate

I already participated in the RoboVM PR Contest, so you might think 'why does he participate if he already won something' ?
If you know that you can win something, you (atleast I am) are more motivated to do sth. Being able to win IntelliJ Ultimate which I could never afford, sounded really nice.
I would never have learned Kotlin because I didn't even know that Kotlin existed :)

I apologize for my probably horrible English...

This post is licensed under CC BY-NC-SA 3.0