Calculate force on atoms given the energy of configuration, trajectory of simulation and position of atoms in each frame

Background

I am using a neural network to calculate the potential energy of atoms in a configuration and then adding energy of all atoms to compare it with the true energy of the configuration(label) to update the weights.

I am doing so for 10000 configurations of 100 atoms each for liquid Argon at 100K.

Note I don't have the actual energy of each atom and only the energy of the configuration.

Problem

I need to calculate the forces on each atom to see if the sum of forces for all the atoms is zero in X,Y,Z axis. In case it is not I want to find out how off is it from zero.

How do I calculate the force on atoms using their position and potential energy for a given trajectory. I know I need to do $\frac{dE}{dr}$ but what should be my E and r. Also since I don,t a formula for E(r), what should my $dE$ and $dr$ be respectively?

• I'm not sure this will be possible if you only know the energy of the configuration as a whole. Jul 23 '18 at 1:20
• I would agree with a cyclohexane. I would imagine there would be any number of possible forces on each atom that would be consistent with a particular total energy. Jul 23 '18 at 1:39
• In addition, I'm not sure checking the accuracy of the potential function by obtaining the force from the potential is valid. You could check for self-consistency that way, but accuracy suggests that you need some other method for so doing. Jul 23 '18 at 13:20
• @a-cyclohexane-molecule From what I do know about machine learning, he would have a potential function technically, the issue is that it is expressed in terms of the neural network (essentially a composition of a bunch of activator functions associated with given nodes). However, as I mentioned in my comment, I think its becoming more common for machine learning libraries to include derivatives wrt to the inputs, so even if he doesn't know the form of his potential, it should still be possible to obtain the derivatives. Jul 23 '18 at 15:17
• @porphyrin sorry for my conduct. you were just trying to help Jul 23 '18 at 15:20

tl,dr: Forces are equivalent to the negative of the gradient, use small, arbitrary $\mathrm{d}r$ for each atom

The problem, as you mention, with many neural network methods in chemistry at the moment, is that the $E = f(x,y,z)$ is a black box and thus analytical gradients (and thus forces) are often not available.

First, as you clearly know, $F = -\nabla E(x,y,z)$ so you need to solve $\frac{\mathrm{d}E}{\mathrm{d}r}$ for your neural network. (I indicate this for anyone reading who doesn't realize that the force will inherently be the negative of the gradient of the energy function.

So what you need is a finite difference method. This is, of course, a common problem (e.g., on Math Stack Exchange or Wikipedia):

$$\frac{\partial E}{\partial x} \approx \frac{f(x+\epsilon)-f(x)}{\epsilon}$$

Picking a good step $\epsilon$ is a bit tricky, but I'd probably pick something like 0.01 Å or 0.001 Å, as a start. In your case, it sounds like you want Cartesian gradients, so you'll take your $f(x,y,z)$ and perform the partial derivatives for all three axes (i.e., the initial point $(x,y,z)$ plus 3 extra energy evaluations per atom.

That is, you'd loop through each atom, move it a bit in the x, y, and z directions and evaluate the system to get the gradient/force on that atom. You'll, therefore, have $3N$ energy evaluations to get all the forces on all the atoms.

You can perform better (and more computationally expensive) finite difference methods if you choose.

• Since we are using a constant $\epsilon$ to calculate all forces, that means to calculate the total force i am just doing $f(x+n.\epsilon)-f(x)$ divided by $\epsilon$ and it's value doesn't really matter if the force on system is to be $0$. Isn't this faulty in a way? Jul 23 '18 at 22:34
• If you're sure that the forces are zero, then in principal $\epsilon$ doesn't matter. In practice, there are numerical issues that do matter, because forces are rarely exactly zero. Moreover, numerical accuracy issues often come into play. Jul 23 '18 at 23:48
• Could you possibly point me to a more reliable reference for this kind of technique? It feels a little too easy you see 😅 Jul 23 '18 at 23:57
• @fireball.1 - this is a simple implementation of numerical gradients. If you don't trust me, you can see the links to Math.SE and Wikipedia Jul 24 '18 at 0:01
• @fireball.1 numerical differentiation is a very common technique, particularly in this type of case where it would it be difficult or impossible to compute an analytical derivative. Jul 24 '18 at 0:30