In chemistry, the most common way of representing molecules is to use Cartesian coordinates.
The problem of Cartesian coordinates is that if one rotates or translates a molecule, the coordinates change. However, properties like the total energy of the molecule, the dipole moment or the atomisation energy remain unchanged.
Therefore, if you want to learn the properties of a molecule with a neural network, you want to represent the molecular structure in a way that doesn’t change when you rotate or translate the molecule.
By doing this, you make the training process more efficient because the neural network doesn’t need to learn that many different Cartesian coordinates represent the same structure.
This is where Atom Centred Symmetry Functions (ACSF) come in handy. They are a way of representing a molecular structure which remains the same when the molecule is rotated or translated.
Understanding how they work
Note: in this post I will use the functional form of ACSF that was used by Parkhill et all. in this paper.
ACSF generally include two and three-body terms. For example, the two body term is usually written in papers as:
This can be quite confusing, so let’s break it down. The sum is over atoms , which are the neighbours of atom of a particular atom type. and are parameters that are picked by the user. is the distance between atom and . The last term is a cut off function which depends on the distance between the atoms and on a cut-off distance .
If you are worried about the sum over neighbours of a particular atom type, rest assured. We shall go through it with examples.
Let’s say that we have a toy-system with 5 particles, of 3 different types.
The snippet below shows the coordinates of all the particles and their type. Blue particles are of ‘type 0‘, pink particles are of ‘type 1‘ and green particles are of ‘type 2‘.
If we want to calculate the two-body term for particle 0, we construct it as follows. We make a vector where for each element the sum is over particles of type . This can be shown with an image:
For the sum is over blue particles, for it is over pink particles and for it is over green particles. With some pseudo code:
For this particular toy system, if we choose , and , this gives [0.01198774, 0.33275008, 0.22066655].
To make this extra clear, let’s calculate the two-body term also for particle 1. Again, we make a vector where for each element the sum is over particles of type .
As you can see, now has two terms in the sum. This is because particle 1 (in pink) is close to two blue particles. However, it doesn’t have any pink neighbours, so remains zero. Using the same parameters as for , this gives [0.66550016, 0.0, 0.66550016] .
This process is then repeated for each particle in the system, so you end up with 5 vectors of length 3.
There is one final step that needs to be done to have the complete two-body term. Remember the parameter ? Usually you don’t use only one value of , but many. You need to repeat the calculations we have done above, but with a different value of , for example . Then, you concatenate the new vector of length 3 to the one obtained with .
For example, for particle 0, if we used we would obtain [0.24078022, 0.9045085, 1.37344827]. So then the full body term would be:
[0.01198774, 0.33275008, 0.22066655, 0.24078022, 0.9045085, 1.37344827]
With an image:
One minor point to note is that it doesn’t matter in which order you concatenate the vectors. You could calculate all the terms for particle 0 interacting with a blue particle with different values of , then have a vector with all the interactions with pink particles with the different values of and finally all the interactions with green particles. This again is more easily shown with an image:
If you have made it this far, well done! The most complicated part is now over. The principle is the same for the three body term, except that there are more parameters and we look at 2 neighbours at a time!
The three body term is expressed as:
The parameters that need to be picked by the user are: , , and . Remember how in the two body term the parameter took multiple values? Here both and take multiple values. The only other variable that hasn’t been introduced yet is , which is the angle between particles , and .
Now, let’s construct the three body term for particle zero. The sum in is over pairs of neighbour types. The possible pairs of neighbour types are:
[00, 11, 22, 01, 02, 12]
where the order of the pairs doesn’t matter – i.e. 01 = 10. So, the first part of the three body term for particle 0 can be visualised as follows:
And expressed with pseudo code:
The first two terms are zero because there are no two other blue particles or two pink particles near particle 0. The third term captures the interaction of particle 0 with particle 2 and particle 4 which are both green.
Now, this process has to be repeated with different values of and . For example, if we chose to use and , then, we would end up with four vectors of length 6 to be concatenated. This can be shown with an image:
And then repeat this process for every particle!
Once all the 2 and 3-body terms are obtained for each particle, they are also concatenated. In this way, you have 1 vector for each particle.
If you are interested in an implementation that is easy to understand, I have made one in Numpy that you can find here. This implementation is very slow, so don’t use it if you have many values of the parameters or many molecules. If you want a faster implementation, you can have a look at this one. It is implemented in TensorFlow, so it is harder to read, but it is much faster.
That implementation is part of the python package QML (Quantum Machine Learning), which can be used to generate a variety of descriptors and then use them for either Kernel Ridge Regression or Neural Networks.