Franz J. Vesely > MolSim Tutorial > Technical Matters  
 
 





 
< >
Vesely MolSim Tutorial



1.2 Technical Matters

  • What units?
  • What about boundaries?
  • What initial configuration?
  • How to adjust density and temperature?

Subsections

1.2.1 Units

To avoid the handling of small numbers, choose units appropriate to the model.

Lennard-Jones: Energy unit $E_{0}=\epsilon$; length $l_{0}=\sigma$. The pair energy is then

$ u_{LJ}^{*}=4\left[ r^{*-12}-r^{*-6}\right] $


where $u^{*} \equiv u/\epsilon$ and $r^{*} \equiv r/\sigma$.

As the third mechanical unit, choose the atomic mass $m_{0}=1 AMU= 1.6606 \cdot 10^{-27}kg$.

The time unit is now the combination $t_{0}=\sqrt{m_{0} \sigma^{2}/\epsilon}$.

Electrical charge: best measured in multiples of the electron charge, $q_{0}=1.602 \cdot 10^{-19} As$.

Number density: $\rho=N/V$ is a large number; therefore we reduce it by a suitable standard density, $\rho_{0}=1/\sigma^{3}$: $\rho^{*} \equiv N \sigma^{3}/V$.

Temperature: $T_{0}=\epsilon/k$

Hard spheres: no "natural" unit of energy; therefore choose self-consistent time unit $t_{0}=\sqrt{m_{0}d^{2}/kT}$.

For hard spheres of diameter $d_{0}=2 r_{0}$ the customary standard density is $\rho_{0}=\sqrt{2}/d_{0}^{3}$; thus: $\rho^{*}=N d_{0}^{3}/V\sqrt{2}$.


1.2.2 Periodic boundary conditions (PBC) and nearest image convention (NIC)

To avoid "wall effects" we surround the basic cell containing the $N$ particles by periodic images of itself.

Spin lattices: In each coordinate direction the last ("rightmost") spin in a row interacts also with a right neighbor, which is taken to be identical to the first (leftmost) spin in that row, and vice versa (see Figure).

Figure 1.1: Periodic boundary conditions on a spin lattice




Fluid: Apply the following rule:
For each particle $i$ store, instead of any coordinate $x_{i}$, the quantity

$(x_{i}+2L) \mbox{mod}L$

(with $L$ the side length of the cell). When a particle leaves the cell to the right, it is automatically replaced by a particle entering from the left, etc.


Nearest Image Convention: In computing pair vectors between two particles $i$ and $j$ one needs only differences of coordinate values. If this coordinate difference $\Delta x_{ij} \equiv x_{j}-x_{i}$ is larger than $L/2$, then the particle $j$ will not be regarded as an interaction partner of $i$; instead, its left periodic image with coordinate $x_{j}-L$ interacts with $i$.

The NIC rule may be implemented by a sequence of IF commands or by the more compact code line

$ \Delta x = \Delta x - L \cdot nint \left( \frac{\textstyle \Delta x}{\textstyle L}\right) $


where nint($a$) denotes the rounded value of $a$, i.e. the integer nearest to $a$. This formulation of NIC is also better suited for vectorising compilers.

1.2.3 Starting configuration

On an Ising lattice, draw $N$ spin values with equal probabilities for $+ 1$ and $-1$.

Molecules in disordered media: Overlaps must be avoided. $\Longrightarrow$ Place the molecules on a lattice, then "melt"this crystal before the actual simulation run: Thermalization.

Population number in a cubic cell with face-centered cubic arrangement: $4m^{3}$, with $m=1,2,\dots$. Therefore typical particle numbers in simulations are $N= 32, 108, 256, 500$ etc.

What about 2-dimensional systems?

When simulating two-dimensional systems, the setting up of periodic base cells and of initial configurations is an issue that takes some considering. Since 2D systems are important both in the teaching and in the application of simulation, some suggestions are compiled here.

A dense packing of discs is hexagonal. The most convenient periodic cell in two dimensions would be quadratic. Unfortunately, these are contradictory requirements.

There are two possible periodic cells compatible with a hexagonal structure: (a) rectangular; (b) rhombic.

  • Rectangular unit cell:
    Figure 1.2: 2D periodic cell: rectangle


    The unit cell then has $l_{y}=\sqrt{3} l_{x}$ and contains $N_{0}=2$ discs.

    Periodic boundary conditions are handled as usually, but with different base cell lengths along the axes: $L_{x}=m_{x} l_{x}$, $L_{y}=m_{y} l_{y}$ ($m_{x}$ may or may not be equal to $m_{y}$.)

    Nearest image convention: as usual, but again with different thresholds along the axes: $\pm L_{x}/2$ and $ \pm L_{y}/2$, respectively.

  • Rhombic unit cell:
    Figure 1.3: 2D periodic cell: rhombic


    The crystallographic unit is now a rhombus with $\alpha=60^{0}$ and $l_{y}=l_{x} \sqrt{3}/2$; it contains $N_{0}=1$ particle.

    Periodic boundary conditions are best handled in a non-orthogonal coordinate system. Let $\vec{r} \equiv \{x,y\}$ denote the cartesian coordinates, and $\vec{r}' \equiv \{x',y'\}$ the coordinates in the rhombic system. Then $\vec{r}' = A \cdot \vec{r}$ with

    $ A = \left( \begin{array}{cc}1&-\frac{1}{\sqrt{3}}\\0&\frac{2}{\sqrt{3}}\end{array} \right) \;\;\;\;\;\; B \equiv A^{-1} = \left( \begin{array}{cc}1&\frac{1}{2}\\0&\frac{\sqrt{3}}{2}\end{array} \right) $

    Specifically, when the new coordinates (after a time or MC step) are $x,y$, then
    • Compute
      $ \begin{eqnarray} x'&=&x-\frac{1}{\sqrt{3}} y \\ y'&=&\frac{2}{\sqrt{3}} y \end{eqnarray} $

    • Apply PBC as always, but in rhombic coordinates:
      $ \begin{eqnarray} x'&=&(x'+2L_{x})\;{\rm mod} L_{x} \\ y'&=&(y'+2L_{y})\;{\rm mod} L_{y} \end{eqnarray} $

    • Now transform back to Cartesius:
      $ \begin{eqnarray} x&=&x'+\frac{1}{2} y' \\ y&=&\frac{\sqrt{3}}{2} y' \end{eqnarray} $

    Nearest image convention:
    Is applied in cartesian coordinates, possibly with a potential cutoff at $L_{y}/2$:

    $ \begin{eqnarray} \Delta x &=& \Delta x-L_{x} \;{\rm ANINT}(\Delta x/L_{x}) \\ \Delta y &=& \Delta y-L_{y} \;{\rm ANINT}(\Delta y/L_{y}) \end{eqnarray} $

Reference Density in 2D: Let $d$ be a reference distance, which in the Lennard-Jones case is equal to $\left. \right.^{6}\!\!\sqrt{2} \sigma$, and for hard discs is identical to the disc diameter. The reference density is then

$ n_{0}=\frac{\textstyle 1}{\textstyle V_{0}}=\frac{\textstyle 2}{\textstyle d^{2}\sqrt{3}} $

Let $n^{*}$ be a desired reduced density, $n^{*} \equiv n/n_{0} = V_{0}/V=d^{2}/l_{x}^{2}$. Thus, $l_{x}$ must be chosen as $l_{x}=d/\sqrt{n^{*}}$.


Adjusting density and temperature:
Given $N$, the density is adjusted to a desired value by shrinking or expanding the volume: scale all coordinates by a suitable factor.

The temperature is a constant parameter in an MC simulation. In molecular dynamics it must be adjusted in the following manner. Since

$T=m \langle| v|^{2} \rangle/3k$

(with $k=1.3804 \cdot 10^{-23} J/deg$) or, in reduced units,

$ T^{*}=m^{*} \langle | v^{*}|^{2} \rangle/3$


we first take the average of $| v^{*}|^{2}$ over a number of MD steps to determine the actual temperature of the simulated system. Then we scale each velocity component according to

$ v_{i,x} \leftrightarrow v_{i,x} \sqrt{T^{*}_{desired}/T^{*}_{actual}} $

Since $T^{*}$ is a fluctuating quantity it can be adjusted only approximately.



EXERCISE:
Consider a pair of Lennard-Jones particles with $\epsilon=1.6537\cdot 10^{-21} J$ and $\sigma=3.405 \cdot 10^{-10} m$ (typical for Argon). Let the two molecules be situated at a distance of $3.2 \cdot10^{-10}m$ from each other.

- Calculate the potential energy of this arrangement.

- Do the same calculation using $\epsilon$ and $\sigma$ as units of energy and length, respectively. These parameters then vanish from the expression for the pair energy, and the calculation is done with quantities of order $1$.

- With the above units for energy and length, together with the atomic mass unit, compute the metric value of the self-consistent unit of time? Let one of the particles have a metric speed $v=500 m/s$, typical of the thermal velocities of atoms or small molecules. What is the value of $v$ in self-consistent units?

1.2.4 Neighbourhood tables

Approximately 95 pc. of the computing time in a simulation is expended for the calculation of the pair forces, torques, energies etc. For systems of more than $N=500$ particles the interaction is usually cut off at some pair distance smaller than half the box side length: $r_{co}<L/2$. Even the scanning of all particle pairs for the condition $r_{ij}^{2} < r_{co}^{2}$ may become costly for large systems.

Verlet suggested that in such cases the possible interaction partners of each particle $i$ are listed in an array, and only the particles in that list are considered. As the molecules diffuse around, the lists must be updated regularly by an occasional $N(N-1)/2$ scan. Here is the detailed procedure:

Figure 1.4: Verlet neighbour lists: $r_{out} \approx 1.1-1.2 r_{co}$. All particles $j$ within a distance $r_{out}$ of particle $i$ are entered in a list.


These lists of neighbours, $LIST(i)$, are stored in sequence, in one long array. For each $i$ a pointer $POINT(i)$ points to the start of the list of its neighbours:
Figure 1.5: Storage of Verlet lists


The first setup of the lists requires $N(N-1)$ operations; every 10-20 steps the lists must be updated, again at the same cost. However, in the time of diffusion between $r_{co}$ and $r_{out}$, for each particle $i$ only the possible partners with indices $j=LIST(POINT(i))$ to $j=LIST(POINT(i+1)-1)$ need be considered.

1.2.5 Linked lists

For even larger particle numbers the cell volume $L^{3}$ is divided into $M^{3}$ subcells with side lengths $l \equiv L/M \leq r_{co}$.


Figure 1.6: For a particle $i$ in the shaded subcell, eligible interaction partners $j$ can be only from the subcells marked with a dot


Figure 1.7: To avoid duplication of pair property calculations, only the marked cells should be scanned for partners of a particle in the shaded cell. (But respect periodic b.c.!)


The following description follows the discussion found in Hockney's book [HOCKNEY, EASTWOOD: COMPUTER SIMULATION USING PARTICLES. McGraw-Hill, New York 1981].

Define two pointer arrays defined as follows:
  • $hoc[k= 1 \dots M^{3}]$ (for "head of chain"); its $k$-element contains the largest particle number of all inhabitants of cell $k$.
  • $ll[i=1 \dots N]$ ( "linked list"); number of the next (i.e. lower) particle in the presently treated cell; when $ll[i]=0$ that cell is finished.
Procedure:
In a language-free (but Fortran-like) form, proceed as follows:
	do 100 k=1,ncell // where usually ncell=M^3
100	hoc(k)=0
	do 200 i=1,n
	  icell=1+int(x(i)/cl)  //where cl=l=L/M
	         +int(y(i)/cl)*M
		 +int(z(i)/cl)*M*M
	  ll(i)=hoc(icell)
	  hoc(icell)=i
200	continue


These few quick steps may be performed at each MD or MC step to update the linked-cell pointer arrays. When it comes to calculating interactions, these arrays provide the information about possible partner molecules.

For clarity, consider this example:

Figure 1.8: See text. Note that the cells are numbered from lower left (1) to upper right(9)


After nulling all arrays, the codelet does this:

i=1      icell=5     ll(1)=0     hoc(5)=1
i=2      icell=9     ll(2)=0     hoc(9)=2
i=3      icell=9     ll(3)=2     hoc(9)=3
i=4      icell=6     ll(4)=0     hoc(6)=4
i=5      icell=3     ll(5)=0     hoc(3)=5
i=6      icell=6     ll(6)=4     hoc(6)=6


Later, when it comes to scan the lists (force or energy calculation), we proceed thus:

For a particle (no. $1$) in cell $5$, we have to scan cells $3,(5),6,(8),9$ where the brackets denote those cells which in our example are empty of partners.
icell=3:     hoc(3)=5    --->   compute (1-5)     ll(5)=0
icell=6:     hoc(6)=6    --->   compute (1-6)     ll(6)=4
                         --->   compute (1-4)     ll(4)=0
icell=9:     hoc(9)=3    --->   compute (1-3)     ll(3)=2
                         --->   compute (1-2)     ll(2)=0



PROJECT MC/MD: As a first reusable module for a simulation program, write a code to set up a cubic box of side length $L$ inhabited by up to $N=4 m^{3}$ particles in a face-centered cubic arrangement. Use your favourite programming language and make the code flexible enough to allow for easy change of volume (i.e. density). Make sure that the lengths are measured in units of $\sigma_{LJ}$. For later reference, let us call this subroutine STARTCONF.

Advice: It is convenient to count the lower, left and front face of the cube as belonging to the basic cell, while the three other faces belong to the next periodic cells.

To test for correct arragement of the particles, compute the diagnostic

$ S_{0} \equiv \frac{\textstyle 1}{\textstyle 3}\sum_{i=1}^{N} \left[ \cos (4 m \pi x_{i}/L)+\cos (4 m \pi y_{i}/L)+ \cos (4 m \pi z_{i}/L) \right] $

which is sometimes called "melting factor". For a fcc configuration it should be equal to $N$ (why?).

By scaling all lengths, adjust the volume such that the reduced number density becomes $\rho^{*}=0.6$


PROJECT MD: Augment the subroutine STARTCONF by a procedure that assigns random velocities to the particles, making sure that the sum total of each velocity component is zero.


PROJECT MC/MD: The second subroutine will serve to compute the total potential energy in the system, assuming a Lennard-Jones interaction and applying the nearest image convention:

$ E_{pot}=\frac{\textstyle 1}{\textstyle 2}\sum_{i}\sum_{j \neq i} u_{LJ}(r_{ij}) = \sum_{i=1}^{N-1} \sum_{j=i+1}^{N} u_{LJ}(r_{ij}) $

Write such a subroutine and call it ENERGY. Use it to compute the energy in the system created by STARTCONF.


vesely may-06

< >