# Physics:Pairs

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

# Two-Body Problems

This page explains the numerical simulation of two-body problems suitable for a first numerical simulation.

The coordinates of two point particles can be represented by two vectors, $\vec x_1 \in \mathbb R^3$ and $\vec x_2 \in \mathbb R^3$. They have corresponding masses and velocities ($m_i,\vec v_i$).

Because the interaction between the particles is invariant to translations, the energy of interaction can only depend on the difference between coordinates, $\vec r = \vec x_2 - \vec x_1$. Even better, since the interaction should be invariant to rotation, the potential energy should really only depend on the length of $\vec r$, which we denote $r = |\vec r|$. You must memorize the formula for computing the magnitude of a vector,

$|\vec r|^2 = \sum_i \vec r_i^2 = r_x^2 + r_y^2 + r_z^2$.

## Common Energy Functions

### Harmonic Oscillator

The most common energy function is undoubtedly the potential energy of the harmonic oscillator,

$U(r) = \frac{k}{2} (r - r_0)^2$.

It has two parameters, k, and $r_0$. Because of its commonly usage to represents the energy of a bond between atoms, $r_0$ is sometimes referred to as the bond length, and k as the bond stretch constant.

### Lennard-Jones

The second most common pair-energy function is arguably the Lennard-Jones form,

$U(r) = 4 \epsilon\left( \left(\frac{\sigma}{r}\right)^{12} - \left(\frac{\sigma}{r}\right)^6 \right)$.

This form is used to represent a pair of atoms that are not bonded. It also has two parameters. $\epsilon$ is the well-depth' and $\sigma$ is the distance where the energy crosses from positive to negative. There is an alternate way to write this energy by re-defining $R = \sigma 2^{1/6}$ and re-factoring the 4 inside the parentheses.

### Other Forms

There are many other forms that try to represent the actual physical interaction energy between pairs of atoms more realistically than the primitive approximations above. You should look these up on your own

For the FENE potential (and the others as well) an excellent reference is the Gromacs User Manual and high-level summaries of these functions are also present in the LAMMPS Documentation.

## Derivatives of the Energy

According to Newton's law, we must compute the force as,

$\vec F = -\vec \nabla U$, where $U$ is the potential energy function.

In component form, $\vec \nabla_i = \frac{\partial}{\partial x_i}$ is the derivative with respect to the $i^\mathrm{th}$ component.

To find the derivative of $U(r)$ with respect to $\vec x_i$, the chain rule has to be used at least twice. The first one is easy, and can be summarized in vector form,

$\vec \nabla_{x_2} = -\vec \nabla_{x_2} = \nabla_r$

In English, $\vec x_2$ increases as much as $\vec r$ does, and $x_1$ decreases as much as $\vec r$ increases.

The second part is harder, since it requires going from $\vec r$ dependence to $\vec r$ dependence.

It is written in vector form as,

$\vec \nabla_r U(r) = \frac{\vec r}{r} \frac{dU(r)}{dr}$

# Example Implemenentation

This example shows the steps needed to run a 2-particle simulation in outline form. It is not complete, since the functions are not yet implemented.

<source lang="python"> from numpy import * import pylab as plt

1. Understand system.

def plot_atoms(x):

   # Make a plot of all atoms.
#plt.plot([x0, x1], [x0, x1], 'o')
plt.plot([x[0,0]], [x[0,1]], 'o')
plt.plot([x[1,0]], [x[1,1]], 'o')
# cruft
plt.gca().set_xlim([0,10])
plt.gca().set_ylim([0,10])

   plt.show()


def mag(r):

   return sqrt(r*r+r*r+r*r)


1. Use physics.

def calc_energy(x):

   # coords -> distance vectors
r = x - x

   # distance vectors -> lengths
print(mag(r))
print(r)
# lengths -> energies


def main():

   # Define starting locations
# x has 2 indices:
#  index 0 - atom number
#  index 1 - x,y, or z
x = array([ [5,5,-1],
[7,8,0] ])
plot_atoms(x)
calc_energy(x)
`

main() </source>