Title: Seminar 1: Efficient Algorithms for Molecular Dynamics Simulation
1Seminar 1Efficient Algorithms for Molecular
Dynamics Simulation
2About the Project
- Part of TOMSK (Towards Molecular Structure
Kinetics) - Build an engine layer for particle simulations
3About Molecular Simulations
- Real molecules obey quantum laws but can
approximate with classical laws. - e.g. Newtons law forcemassacceleration
- Molecular Dynamics (MD) integrates equations of
motion of atoms each timestep. - Cannot predict precisely what will happen
generates statistical prediction.
4Chosen Interaction Model
- Lennard Jones Potential Pair Equation
- I will use this to simulateatoms in a stable
liquid. - NOTE Will be easy to overwrite/change
interaction model add statistical analysis
functions (e.g. calc Temperature).
5Simulating Liquids
- Can only simulate so many 1000s of particles.
- To simulate bulk liquidI will use Periodic
Bounding Condition (PBC) ? (boundaries wrap
around)
Surface particle has less neighbors
Range search on box with PBC
Microscopic droplet (finite particles)
PBC on 2D box
6N-body Problem
- N-body problem all (N) particles in a system
have pair-wise interaction. - Solutions
- Brute force approach compare all pairs ? O(N2)
- Better approach approximate distant forces
- Lead to many specific solutions.
Consider ALL
Approximate
7Chosen Solution
Single Range Query
- Chosen approach chose cutoff radius, and ignore
particles beyond this. - Involves moving self-spatial join query (many
range queries) ? has numerous applications - GIS, Computer graphics, etc.
Ignore
Cutoff radius (Rc)
Spatial join query
Symmetrical attractive/ repulsive forces
O--
NOTEDirection forces!
H
H
Permanent dipole
Argon atom (inert)
Water molecule
8Spatial Data Structure Fixed Grid
- Reviewed many types of structures.
- Fixed grid most effective for uniform particle
distribution. - Time to build (placeall pointsinto index)
O(N) - cell index atom coordinate / cellLen
- (along each dimension)
Fixed grid
NOTE cells per side (CPS)5
boxLen
Cutoff radius (rc)
cellLen
Cell List technique
9Scientific Process
- Using Visual C console application.
- Am using OO principles.
- Have read Effective C now reading More
Effective C. - Testing process
- Run a series of simulations in batch
- Output results to CSV including
- grid parameters,
- clock tics elapsed, ? primary focus
- distance calculates,
- more
- Analyze/graph CSV using Excel.
- Can be time consuming! ?
10Simulation Steps
- Set-up
- 1) Setup grid structure
- 2) Setup atoms in offset lattice
- 3) Assign random velocities.
- Iterate
- 1) Build grid (assign all atoms to cells).
- 2) Build neighbor list (for each atom in each
cell find neighbors). ? can take 95 of time - 3) Calculate force and move atoms ? implements
interaction model (can change). - 4) Wrap atoms back into cell boundaries.
- 5) Increment timestep.
11Finding Good Neighbours
Love thy neighbour -- the bible
Cell list approach Predetermine which cells are
within rc of each cell
Atom list approach For each atom check which
cells are within rc of atom
- NOTE Volume sphere 52 of its bounding cube
12Optimization Trick Half-sphere Query
Normal approach Search sphere
Faster approach Search upper hemi-sphere
i
NOTE will capture each neighbor twice (once from
each end)
j
i
j
13Smaller Optimization Tricks
- Early elimination if distancebetween atoms along
anydimension gt rc. - Dont calculate sqrt
- Lennard-Jones can be doneusing dist2
- NOTE if (dist2 lt cutoffRadius2)
? is in range - Determine optimal of cells per size.
- Is cell length cutoff radius optimal?
j
i
14Idea Using MBRs in cells
- For each cell, maintain a Minimum Bounding
Rectangle (MBR) around its atoms. - For any cell JUST tipped by rc, check atom is
inside rc of MBR before considering atoms
exhaustively.
This cell is just tipped
- NOTE can also beused inconjunction with sub
grid
MBR
15Improving Cache Hits through Spatial Locality
- Spatial locality principle objects close to
referred ones will probably be requested again in
the future. - Unsorted atoms ? means many cache misses.
4
5
2
3
6
1
16Space Filling Curves
- Space-filling curve A line passing through every
point in a space, in some order (according to
some algorithm). - Resort atom periodically (group by cells order
using curve). - Improves CPU performance gt50 in 2D moving point
query ? worth trying.
Z-ordering
Row-wise
Hilbert curve
Gray curve
17Verlet Neighbour List
- Choose a skin radius greater than rc.
- Build the verlet neighbor list using skin
radius - Next few iterations update list check which
neighbour pairs are inside rc. - Refinement only rebuild list when sum of 2 max
displacement (of any 2 atoms) gt skin thickness.
Skin/verlet radius (Rv)
5
Rl
6
7
6'
7'
1
Cut-off sphere
Rc
2
3
Skin
4
18Some Verlet Specific Ideas
- Dont check displacement each iteration check at
decreasing periods. - Dont update distances of atoms outside cut-off
sphere each iteration check more frequently as
it gets closer. - Determine optimal skin radius.
Skin/verlet radius (Rv)
5
Rl
6
7
6'
7'
1
Cut-off sphere
Rc
2
3
Skin
4
19Performance vs. Accuracy
- Some techniques that will improve performance,
but decrease accuracy - Dont always rebuild/update neighbor list when
necessary. - Increasing timestep
- Decreasing cutoff radius
- I can graph these by testing against a control.
small timestep
larger timestep
large rc
smaller rc
20Progress
- Basic grid is implemented
- Thesis started.
- Several graphs obtained.
- Added front end
- Uses MFC (Microsoft Foundation Class) using
OpenGL. - Demonstrates building on engine layer.
- Lets me see particles animate ( work out
problems) - Code messy
- Is still MUCH to implement test.
21Conclusion
- Molecular dynamics an (approximated)
simulation of real worldparticle behaviour. - Periodic Bounding Condition used for bulk
liquid - Best existing approach
- Verlet list, using cell list fixed grid to
build. - Ideas for improvement
- Minimal half cell list templates.
- MBRs inside cells.
- Space filling curves.
- Thesis may resemble a guide to implementing/optimi
zing moving spatial join queries. - Still much to be done.
22Thank YouAny Questions?
23(No Transcript)
24Revised Goal
EXTRA SLIDE
- Implement engine as efficient as possible.
- How it should work
- Pass in minimum parameters
- atoms, offset, max velocity box size(or load
atom data from file). - cutoff radius
- Engine should set remaining details to optimal.
Including - cells per side,
- verlet radius,
- subgrid? mbr? algorithm? etc.
25Idea Sub Grid
EXTRA SLIDE
- Sub grid adjacency list template guide break
each cell into (imaginary) sub-grid. - When considering an atom, check with sub-cell it
belongs to, that sub-cell will refine which
adjacent cells to search. - NOTE
- My primary focus is reducing time per
iterationbut main memory requirements ( setup
time) also important. - Choosing cell length equal to rc is typical.
But is it optimal? - No one method/metric is likely to be optimal in
ALL cases ? too many parameters.