abhilash_report
TRANSCRIPT
The Institute Of Mathematical Sciences
Summer Research Project Report - 2014
Molecular Dynamics Simulations ofPolymers
Author:Abhilash SahooIISER - Kolkata
Special thanks to:Abhiram ReddyNISER - Bhubaneswar
Supervisor:Dr. Vani Vemparala
IMSc - Chennai
July 1, 2014
Contents
1 Introduction 3
2 Interatomic Potentials 32.1 The Lennard-Jones Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 Derivation Of Lennard-Jones’ Force . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 The Coulomb potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Harmonic bond potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.4 Dihedral potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Ensembles 5
4 Maxwell-Boltzman Distributions 6
5 Box-Mueller algorithm 6
6 Initial Conditions (Setting up the system) 7
7 Time Evolution Of The System 87.1 Velocity-Verlet algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87.2 Leapfrog algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
8 Calculation Of Pressure 9
9 Periodic Boundry Conditions 99.1 Minimum Image Convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
10 LAMMPS: Large-scale Atomic/Molecular Massively Parallel Simulator 10
11 Visual Molecular Dynamics (VMD) 10
12 Systems 1012.1 1000-particle 3D-LJ system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1012.2 30-monomer chain neutral polymer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1112.3 30-monomer chain charged polymer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
13 Conclusion 16
Appendices 18
A Calculation Of L-J Forces (With Cutoff) 18
B Calculation Of raial distribution function, g(r) 20
C Calculation of end-end distance 23
D Calculation Of radius of gyration 25
E Program to create chain of polymer 27
F Program to create solvent 29
G Adding solvent to polymer chain and creating the complete LAMMPS input file 31
References 37
1
Abstract
Molecular dynamics is an extremely popular mode of computational simulations. In this reportthe basics of molecular dynamics simulations and certain computational tricks that are essential forthis has been illustrated. This report also visits some simple systems under the influence of commoninteractions like Lennard-Jones interactions and long range columb interactions. The results, withtheir physical relavance has been presented in this report.
2
1 Introduction
Computer modelling generally involves numeric solutions to various equations and aims at reachingbeyond experiments and theoretical predictions. Simulations are often the most favoured methods forstudying complex syestems and macroscopic changes resulting from the changes associated with themicroscopic parameters. They are often used as tools to predict experimental outcomes. There arebasically two techniques by which molecular simulations are carried out.
1. Monte-Carlo Simulations: (This employs ensemble averages.)
〈A〉 =
∫AP (E)∫P (E)
(1)
Where A = any quantity that is being averaged over; P(E) = The probability density. The P(E)depends on the ensemble we consider.
2. Molecular Dynamics simulations: (This employs time averages.)
〈A〉 =
∫ τ
0
A(t)dt (2)
Ergodic priniciple states the equivalence of the two methods as time goes to infinity.
Usage of a particular method for simulation is problem and system specific. Each method has its own setof advantages. Molecular dynamics primarily studies the time evolution of the system and then emplopysstatistical techniques in order to calculate macroscopical properties of the system.
The molecular dynamics simulations consists of certain generic steps:
1. Setting up initial positions and initial velocities of the particles.
2. Calculate forces on particles from inter-atomic potentials.
3. Choose an appropriate “dt” keeping in mind the system we are considering.
4. Time evolve the system using “time evolution” algorithms like velocity verlet, Leap frog etc.
5. Repeat the procedure as long as needed
2 Interatomic Potentials
We considered several types of interatomic potentials during the course of our project.
1. Lennard-Jones’ potential, VLJ
2. Electrostatic interaction, Vcol
3. Harmonic interaction, Vh
4. Bond-angle potential, Vangle
The net potential is given byVnet = VLJ + Vcol + Vh + Vangle (3)
2.1 The Lennard-Jones Potential
Lennard-jones potential basically determines the interaction potentials between two neutral entities. Itconsists of a repulsive as well as an attractive part. mathematically it is given by
V (r) = 4ε((σ
r)12 − (
σ
r)6) (4)
3
The potential is a spherically-symmetric central potential because its functional form has only radialdistance dependance (no angular). r−12 term in the expression is the repulsive term that arises fromPauli repulsions at short range due to overlapping electronic orbitals. The r−6 term defines the attractivepart of the force.
Figure 1: Plot for Lennard-Jones potential [4]
This, being a short range interaction potential, it doesnot make sense to calculate the interaction potentialfor longer distances. So the notion of cutoff distance was introduced.
We define our interaction potential as [8] [2]
V (rij) =
{V (rij)− Vc − ∂V (rij)
∂rij(r − rc) r < rc
0 r > rc
This further introduces modifications in calculation of different quantities. But this, most importantlypreserves the continuity of the potential and the force. More analysis over this has been done later.
2.1.1 Derivation Of Lennard-Jones’ Force
Lets start by defining, Fij as Force on ith particle due to the jth one.
Vij(r) = 4((1
rij)12 − (
1
rij)6)
Fij(r) = −∂Vij(r)
Fij(x) = −[∂V
∂rij
∂rij∂x
]
Fij(x) =
(−xijrij
)[48
r12ij− 48
r6ij
]
The net force on the system is zero because of the absence of any sort of external influence/forces onthe body. This also suggests that the “Centre Of Mass” of the body should not change for differenttimesteps.
4
2.2 The Coulomb potential
Electrostatic potential/ coulomb potential is a long range central potential that arises owing to chargeson different entities. Mathematically it is denoted as
V =q1q2
4πεr12(5)
It is a long range interaction. So, it makes no sense to define a cutoff distance. So we introduce K-spacecalculations for all calculations within the cutoff distance and R space calculations for all calculationsbeyond the cutoff distance.
Figure 2: Central interactions [6]
2.3 Harmonic bond potential
Harmonic potential is depicted as the elastic potential energy of the bonds in the systems. Mathemati-cally, it is given as
Vh = K(r − r0)2 (6)
Here K refers to the bond parameter and r0 refers to the natural/ relaxed length of the bond.
2.4 Dihedral potential
Dihedral potential is mathematically denoted as
V = Kangle(θ − θ0)2 (7)
Here, Kangle refers to the bond-angle parameter and θ refers to the angle formed by two neighbouringbonds.
3 Ensembles
Ensembles is reffered to a collection of things governed by a law. Statistical ensemble refers to a collectionof microscopic particles governed/defined by certain macroscopic parameters.
There are a number of statistical ensembles like
5
1. NVT: In this type of ensemble the “Number, Volume and Temperature” remains constant. This isequivalent to a box of finite size containing N number of particles maintained at a finite tempera-ture,T. This is equivalent to a canonical ensemble.
For these systems,
P (E) = exp(−βE) (8)
Here β = 1kBT
; kB = Boltzman’s constant.
2. NPT: In this type of ensemble the “Number, Volume and Temperature” remains constant. It isoften used in order to study phase transitions.
3. NVE: The system is isolated and E is fixed. This is equivalent to a microcanonical ensemble
and calculate various thermodynamic parameters like Energy, Pressure, Temperature, etc. This wouldbe a sample system created in order to familarize us with the molecular dynamics methods.
These parameters are often calculated by use of virial theorem [9], which relates microscopic quantitiesto macroscopic ones.
2 〈KE〉 = −N∑k=1
〈Fk.rk〉 (9)
KE = Kinetic energy;Fk = Force on kth particle.rk = position of kth particle.
4 Maxwell-Boltzman Distributions
Maxwell-Boltzman distribution describes the velocity-component distribution for free particles not boundby any interaction potentials. The particles are considered to be in classical domain. This distributioncan be thought of as the magnitude of a 3-dimensional vector whose components are independent andnormally distributed with mean 0 and standard deviation a.
The general functional form of the distribution of the ith component of velocity is given by
vi ∼√
m
2πkBTexp
(−mv2i2kBT
)(10)
Here,
µ = 0;σ =kBT
m
Where, µ = centre of the gaussian curve; σ = standard deviation; T = Temperature
5 Box-Mueller algorithm
Box-mueller method is a well-practised technique for sampling of gaussian random numbers with a givenµ and σ. It involves two independent normal sampling of variables X and Y. In polar coordinates thejoint distribution p(x,y) is,
p(x, y) = p(x)p(y) =1
2πexp(
x2 + y2
2)
p(x, y) =1
2πexp(
r2
2)
This clearly is the product of two density functions
6
1. An exponential distribution over squared radii.
2. a uniform distribution over angles
Now, if we make another connection between the exponential distribution and the uniform distribution,namely that:
Exp(λ) =log(Unif(0, 1))
λ;
r ∼√
(− 2 log(Unif(0, 1)))
This gives us a way to generate points from the joint Gaussian distribution by sampling from twoindependent uniform distributions, one for r and another for θ, and transforming them into Cartesiancoordinates. Basically, the algorithm consists of three basic steps
1. Draw, u1, u2 ∼ Unif(0, 1)
2. r =√−2 log(u1) ,
3. θ = 2πu2,
4. Transform back to cartesan coordinates.
A small python code for this has been provided below.
import random
def generate_normal(mu, sigma):
u = random.random()
v = random.random()
z1 = sqrt(-2 * log(u)) * sin(2 * pi * v)
z2 = sqrt(-2 * log(u)) * cos(2 * pi * v)
x1 = mu + z1 * sigma
x2 = mu + z2 * sigma
return x2
The code can generate two normal distributions with a given value of µ and σ.
6 Initial Conditions (Setting up the system)
We require various initial conditions in order to initiate the time evolution. The initial conditions include
1. Setting up initial positions of all types of particles by appropriately placing molecules throughoutthe box
2. Setting up velocities for all particles following Maxwell-Boltzman distributions and satisfying theequipartion theorem which relates microscopic quantities to macroscopic ones.⟨
N∑i=1
1
2miv
2i
⟩=
3
2NkBT (11)
Here, vi = velocity of ith entity; kB = Boltzman’s constant; T = Temperature; N = Number ofentities.In equation (11), only linear motion has been considered. We used ”Box-Mueller” formalism inorder to generate initial gaussian configuration.
7
7 Time Evolution Of The System
7.1 Velocity-Verlet algorithm
Any time evolution in classical dynamics problem involves solving of a second order differential equation,x′′ = F (x)/m
By Taylor expansion,
x(t+ h) = x(t) + hx(t)′ +h2
2x(t)′′ +O(h3) (12)
x(t+ h) = x(t) + hv(t) +h2
2
F (x(t))
m+O(h3) (13)
v(t+ h) = v(t) + hv(t)′ +h2
2v(t)′′ +O(h3) (14)
And again we have,
v(t+ h)′ = v(t)′ + hv(t)′′ +O(h2) (15)
So, the equation v(t+ h) becomes
v(t+ h) = v(t) + hv(t)′ +h
2(v(t+ h)′ − v(t)′) +O(h3) (16)
Using the equation of motions,
v(t+ h) = v(t) + hv(t)′ +h
2m(F (x((t+ h)))− F (x((t)))) +O(h3) (17)
velocity Verlet algorithm has been decribed below.
xk+1 = xk + hvk +h2
2m(18a)
vk+1 = vk +h
2m(F (xk) + F (xk+1)) (18b)
7.2 Leapfrog algorithm
Leap-frog algorithm for time evolution has been described below. [2]
r(t+ dt) = r(t) + dtv(t+1
2dt) +O(dt3), (19a)
v(t+1
2dt) = v(t− 1
2dt) + a(t)dt+O(dt2), (19b)
v(t) =1
2(v(t+
1
2dt) + v(t− 1
2dt)) +O(dt2), (19c)
The integrators mentioned here are all time-reversal integrators which are essential for studying physicalsystems in long time scales.
8
8 Calculation Of Pressure
Pressure is calculated by relating macroscopic parameters to microscopic quantities like force, positions,velocities etc. through the virial equation.
Mathematically, Pressure, P is given by, [2]
P =NkbT
V
1
3V
⟨N∑i=1
ri.fi
⟩(20)
Here V = Volume; ri = position of ith particle; fi = force on the ith particleThe pressure calculation includes the calculation of the “pressure tensor”.
9 Periodic Boundry Conditions
In our simulations we are not interested in “surface effects”. In any physical systems like a glass of wateror a chamber filled with gas etc.,the number of particles is very high. Thus the surface effects are low.But we use a smaller number of particles in order to cut our computational costs. This in turn leads tovery high surface effects.
We use “periodic boundry conditions” to get over these problems. Periodic boundry conditions replicatethe cubical boxes, forming an infinite lattice. Each image box is a perfect replication of the original boxwith all its particles. If one particle passes through the boundry into another box, its image from anotherbox enters through opposite side in identical manner. [2] [7]
A schematic image for PBC has been shown below.
Figure 3: Periodic Boundry Condition [7]
This computational trick not only helps us simulate an environment with a huge number of particles,but also prevents surface effects. The unit cellmay be modified as per the requirements of the system.
9.1 Minimum Image Convention
The minimum image convention states that, in a periodic system, the longest cutoff should be equal tohalf the length of box vector. This is an essential requirement because, it prevents the calculation ofduplicate forces between a particle and its image. [7]
9
10 LAMMPS: Large-scale Atomic/Molecular Massively Paral-lel Simulator
LAMMPS is an open source, classical molecular dynamics code. It simulates molecular motions andrecords/calculates various data associated with the simulations. We used LAMMPS simulations through-out our project.
11 Visual Molecular Dynamics (VMD)
VMD is a visualization tool for analyzing molecular dynamics problems. This uses 3D graphics in orderto animate and analyze molecular dynamics.
Figure 4: An example of VMD snapshot
12 Systems
12.1 1000-particle 3D-LJ system
The system consisted of 1000 particles arranged homogenously in a box which interact only by Lennard-Jones potential. The system was modelled in NPT, NVT and NVE ensembles. We studied and tabulatedquantities like temperature, pressure, radial distribution functions etc. We expected a general van-der-waal’s gas behaviour.
We analyzed the temperature, pressure, energies and forces associated with the system. We organisedvarious checks to determine if the dynamics was actually making sense physically. For this we calcu-lated the “Centre Of Mass” of the system and net force on the system. We found that the COM wasapproximately at the centre of the box and the net force on the system was zero (All our calculationswere carried out in scaled units). We also did radial probability distribution measurments.
We had already discussed about the requirement to introduce the concept of cutoffs for short rangeforces. We plotted the values of epair against cut-off distances in order to get an idea about the impactthe cutoff distance has on our simulations. 5
This clearly shows that after a certain value cutoff change in cutoff results in no remarkable change ininteraction potential. it can easily be noted that for cutoff distance beyond 6, the value doesnot changemuch.
10
Figure 5: LJ interaction potential vs cutoff distance
Again we observed the changes in the behaviour of simulations with longer time evolutions, differentvelocity seeds, different initial conditions etc.
12.2 30-monomer chain neutral polymer
We initially arranged 30 monomer long polymer in a box and allowed them to evolve under harmonicbond interactions. We used scaled units in our calculations. We further did radius of gyration and endto end length of the polymer calculations.
Figure 6: VMD image snapshots of 30-monomer long polymer at initial and final time step
Further, we changed the interaction parameters and calculated those quantities again. We observed thatthe end-end distance in case of a rigid polymer was higher than the end-end distance of a less rigid (moreelastic) polymer. Similarly, the radius of gyration of the polymers increased with increasing ridgidity.The graphs provide a perfect illustration of the fact.
We then, tried to create our own polymer chains with different chain lengths and observed their impli-cations over the “end to end distance” and “radius of gyration”. We ran the whole simulations in scaledunits and in the absence of any solvent molecules.
11
Figure 7: End-End distance plot Figure 8: Radius Of Gyration plot
12.3 30-monomer chain charged polymer
We modified the c programs used in order to create neutral chain polymers to create charged polymerswith counterions. We, initially increased the charge density on individual monomer and observed theshape and size they took at the end of 106 cycles.
We observed that initially the polymer remains in collapsed state because it exists in a poor solvent(comprising of counterions). But as we in crease the charge density, the counterions begin to condenseover the polymer. The electrostatic forces gains over entropic forces and the polymer straightens. Furtherincrease of charge density, results in all counterions condensing over the polymer surface. This createsdipoles and the whole polymer behaves like a neutral polymer. So, it again collapses under entropic
forces. We define a quantity, A = q2lBr0
, where lB stands for bjerrum length below which electrostaticinteraction dominates thermal fluctuations, that acts as a marker of charge density. We studied differentpolymers with different A values and tabulated their behaviour, radius of gyration etc. [1]
Figure 9: Initial configuration (Fully charged) Figure 10: A = 0.055 (Fully charged)
12
Figure 11: A = 0.892 (Fully charged) Figure 12: A = 6.752 (Fully charged)
Figure 13: A = 0.892 (Fully charged) Figure 14: A = 6.752 (Fully charged)
13
We also tried this with different types of polymer like block-charged and alternatively charged. The Vmdimages for those can be found below. The color codes:
1. Blue: Charged part of the polymer
2. White: Uncharged part of the polymer
3. Red: The counterions
Figure 15: A = 0.055 (BlockCharged)
Figure 16: A = 0.892 (BlockCharged)
Figure 17: A = 14.28 (BlockCharged)
Figure 18: A = 0.055 (AlternateCharged)
Figure 19: A = 0.892 (AlternateCharged)
Figure 20: A = 14.28 (AlternateCharged)
The figures above have been scaled differently. Thus, it makes no sense to compare their sizes directly.Thus, we made comparisions among them by computing their radius of gyration values. The radius ofgyration gave us a measure of the size and shape of the molecule.
We can specifically note that in case of block polymers, for the case of “A = 14.28”, the polymer acquiredthe shape of “8” with upper lobe bigger than the lower one. The collapse for both parts of the polymeris independent of each other for this case.
14
Figure 21: Radius Of Gyration Comparisions
Figure 22: Radius Of Gyration Comparisions (Zoomed in view)
We had some observations from this
1. In case of fully charged polymer, with increase of A, the polymer went from collapsed form toelongated form (at around A = 0.892) but then it again came back to its collapsed form. Thus theradius of gyration values show an initial increase followed by a decrease.
2. We observe a similar behaviour for alternatively charged polymer. But, its change from initialvalue was not that high.
3. We observed a slightly different kind of behaviour in case of block charged polymer. We didnotobserve any peak in this case. Rather we saw a continous increase in radius of gyration values.
15
13 Conclusion
We did a number of simulations during the course of our project. This provided us with the basic ideas tounderstand various simulation and visualisation techniques. We tried to understand and replicate partsof the code associated with the simulation technique. We considered three simple systems and studiedtheir various properties. We tried to replicate the results from [1] and further apply the same idea toother types of polymers. We observed different (some that were expected and some not) behaviourfrom different types of polymers. We also conducted radius of gyration analysis of the structures of thepolymers.
16
Acknowledgements
I would really like to acknowledge the efforts put in by Dr. Vani Vemparala(IMSc), who madethis 6 week learning process really enjoyable. I would like to thank Upayan Baul(Upayan Baul)who helped us in preparing our programs and helped us understand the basics of visual moleculardynamics. Lastly, I would like to thank Abhiram Reddy (NISER) for his constant help throughoutthe project.
17
Appendices
A Calculation Of L-J Forces (With Cutoff)
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<math.h>
using namespace std;
int main()
{
ifstream jn("2605-nvt-u-last1000.dat",ios::in);
ofstream ofl("3005-force-lj-cutoff.dat",ios::out);
int i,j,k=0,np=1000;
long double atomid[1050],typ[1050],xu[1050],yu[1050],zu[1050],en,xr,yr,zr,r2,r22,r66,bx=110,by=110,bz=110,rc=2.5,sg=1.0,rc2;
for(i=1;i<np+1;i++)
{
jn>>atomid[i]>>typ[i]>>xu[i]>>yu[i]>>zu[i];
//cout<<atomid[i]<<’ ’<<ys[i]<<endl;
}
en=0;
rc2=rc*rc*sg*sg;
for(i=1;i<np;i++)
{
for(j=i+1;j<np+1;j++)
{
xr=xu[i]-xu[j];
xr=xr-bx*round(xr/bx);
yr=yu[i]-yu[j];
yr=yr-by*round(yr/by);
zr=zu[i]-zu[j];
18
zr=zr-bz*round(zr/bz);
r2=xr*xr+yr*yr+zr*zr;
if(r2<rc2)
{
r22=1/r2;
r66=r22*r22*r22;
en=en+4*r66*(r66-1);
}
}
}
cout<<en<<endl;
return 0;
}
19
B Calculation Of raial distribution function, g(r)
/*****************************************************************************
The programme to find the radial distribution function of oxygen atom in water
*****************************************************************************/
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
int main()
{
double a,b,c,r1,dr,L,L2,pi,constant,R_max,N_density;
double x[826],y[826],z[826],n[250],g[250],r;
int i,N,R,j,frame,p,No_frame,q;
N=826;//No. of atoms
No_frame=1000;
pi=3.14159265;
L=28.9;//Size of box
L2=L/2;
dr=0.1;
R_max=L2/dr;
//N_density=N/(L*L*L);
//constant=(4/3)*pi*No_frame*N_density*N;
//cout<<constant;
ifstream jn("xyz-O.dat",ios::in);
ofstream mfl("anvy.tsv",ios::out);
ofstream out;
ofstream out_R;
out.open("gr_e_c.dat");
20
//initialisation of array
for(q=0;q<N;q++)
{
x[q]=0;
y[q]=0;
z[q]=0;
}
for(q=0;q<R_max;q++)
{
n[q]=0;
g[q]=0;
}
//main body
for(frame=0;frame<No_frame;frame++)
{
for(i=1;i<=826;i++)
{
jn>>x[i]>>y[i]>>z[i];
}
for(j=1;j<826;j++)
{
for(i=j+1;i<=825;i++)
{ //cout<<"***************************";
if((x[i]-x[j])> L2) x[i] = x[i]-L;
if((x[i]-x[j])<-L2) x[i] = x[i]+L;
if((y[i]-y[j])> L2) y[i] = y[i]-L;
if((y[i]-y[j])<-L2) y[i] = y[i]+L;
if((z[i]-z[j])> L2) z[i] = z[i]-L;
21
if((z[i]-z[j])<-L2) z[i] = z[i]+L;
//separation btw atoms
r=sqrt(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2)+pow((z[i]-z[j]),2)); //rescaling r
R=(r/dr);
out_R<<r<<"\n";
//counting no. of atoms at a distance R*dr
if(R<R_max)
{
n[R]=n[R]+1;
}
}
}
}
//finding g(r)
for(R=1;R<=R_max;R++)
{
r=(R)*dr;
//r1=r+dr;
g[R]=n[R];
mfl<<R<<’ ’<<g[R]<<endl;
}
return 0;
}
22
C Calculation of end-end distance
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<math.h>
using namespace std;
int main()
{
ifstream in("t10-last1000.dat",ios::in);
ofstream out1("re2e-last1000frames-t10.dat",ios::out);
//ofstream out2("re2e-2.dat",ios::out);
int i,j,k,Nmonomer,frame,Nframe;
long double xu[40],yu[40],zu[40],Rvector,Rmagnitude,R2,xr,yr,zr,xrv,yrv,zrv,sumxr,sumyr,sumzr,sumR,sumxrv,sumyrv,sumzrv;
Nmonomer=30;
Nframe=1000;
for(i=1;i<=Nmonomer;i++)
{
xu[i]=0; yu[i]=0; zu[i]=0;
}
sumxr=0;sumyr=0;sumzr=0;sumR=0; sumxrv=0;sumyrv=0;sumzrv=0;
for(frame=0;frame<=Nframe;frame++)
{
for(i=1;i<=Nmonomer;i++)
{
in>>xu[i]>>yu[i]>>zu[i];
xr=xu[30]-xu[1];
yr=yu[30]-yu[1];
zr=zu[30]-zu[1];
23
R2=xr*xr+yr*yr+zr*zr;
Rmagnitude= sqrt(R2);
}
out1<<frame<<’ ’<<Rmagnitude<<endl;
}
return 0;
}
24
D Calculation Of radius of gyration
Below are the c++ codes used to generate the radius of gyration values.
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<math.h>
using namespace std;
int main()
{
ifstream in("req.txt",ios::in);
ofstream out1("val.dat",ios::out);
int i,j,k,frame;
long double xu[50],yu[50],zu[50],sumxu,sumyu,sumzu,xcm,ycm,zcm,rg,rgx2,rgy2,rgz2,Nframe,Nmonomer;
Nmonomer=30;
Nframe=10.0;
sumxu=0; sumyu=0; sumzu=0; rgx2=0; rgy2=0; rgz2=0; rg=0; xcm=0; ycm=0; zcm=0;
for(i=1;i<=Nmonomer;i++)
{
xu[i]=0; yu[i]=0; zu[i]=0;
}
for(frame=0;frame<=Nframe;frame++)
{
for(i=1;i<=Nmonomer;i++)
{
in>>xu[i]>>yu[i]>>zu[i];
}
25
sumxu=0; sumyu=0; sumzu=0; rgx2=0; rgy2=0; rgz2=0; rg=0; xcm=0; ycm=0; zcm=0;
for(j=1;j<=Nmonomer;j++)
{
sumxu=sumxu+xu[j]; sumyu=sumyu+yu[j]; sumzu=sumzu+zu[j];
}
xcm=sumxu/Nmonomer; ycm=sumyu/Nmonomer; zcm=sumzu/Nmonomer;
for(j=1;j<=Nmonomer;j++)
{
rgx2= rgx2 + ((xcm-xu[j])*(xcm-xu[j])); rgy2= rgy2 + ((ycm-yu[j])*(ycm-yu[j])); rgz2= rgz2 + ((zcm-zu[j])*(zcm-zu[j]));
}
rgx2=rgx2/Nmonomer; rgy2=rgy2/Nmonomer; rgz2=rgy2/Nmonomer;
rg= sqrt(rgx2+rgy2+rgz2);
out1<<frame<<’ ’<<rg<<endl;
}
}
26
E Program to create chain of polymer
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 30 //numbers of monomers in a polymer
#define Np 1 //number of polymers
#define L 50.0 //box size
#define M (N+1)
#define b 1.12 //bond length
#define d 1.50 //distance between the polymers
void output();
double x[M],y[M],z[M];
main()
{
void create_chain();
create_chain();
output();
}
void create_chain(n)
{
int i,j,overlap;
double rij,r1,r2,r3,xt,yt,zt;
for(i=1;i<=N;i++)
{
x[i]=-d*N/2.0;
y[i]=i*b-N*b/2;
z[i]=0.0;
}
}
void output()
{
int i,j,type;
type=1;
27
FILE *fp;
fp=fopen("chain.xyz","w");
fprintf(fp,"%d\n",(N*Np));
fprintf(fp,"Atoms\n");
for(i=1;i<=Np;i++)
for(j=1;j<=N;j++)
fprintf(fp,"%d\t%lf\t%lf\t%lf\n",type,x[j]+(i-1)*d,y[j],z[j]);
}
28
F Program to create solvent
/*Generates solvent atoms on a simple cubic lattice*/
/*Output can be used for vmd*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float x[100000],y[100000],z[100000];
void creat_lattice(int,float);
main()
{
int N;
float a;
printf("Enter a number N(number of atoms will be N to the power 3)\n ");
scanf("%d",&N);
printf("Enter the size of the box(consistent with that of the chain)\n ");
scanf("%f",&a);
creat_lattice(N,a);
}
void creat_lattice(int N, float a)
{
int i,j,k,l,m,n;
l=1;
n=N*N*N;
printf("Number of atoms is %d\n",n);
FILE *fp;
fp=fopen("solvent.xyz","w");
fprintf(fp,"%d",n);
fprintf(fp,"\nAtoms\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
for(k=0;k<N;k++)
{
29
x[l]=(i*a)/(N-1)-(a/2.0);
y[l]=(j*a)/(N-1)-(a/2.0);
z[l]=(k*a)/(N-1)-(a/2.0);
fprintf(fp,"%d\t\t%f\t%f\t%f\n",l,x[l],y[l],z[l]);
}
}
}
fclose(fp);
}
30
G Adding solvent to polymer chain and creating the completeLAMMPS input file
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 30 //number of monomers
#define Np 1 //number of polymers
#define Z 1 //valency of counterions
#define L 60.0
#define Nc (N*Np/Z)
#define Ns 100
//#define Qp 1.00 // Q value < aggregation minimum
//#define Qp 3.25 // Q value corresponding to aggregation for monovalent
//#define Qp 2.25 // Q value corresponding to aggregation for divalent
#define Qp 3.50 // high Q value corresponding to aggregation for divalent
#define Qc (-Z*Qp)
#define Qs 0.0
#define M (N+1)*Np
#define S 10000
#define SIGMA 2.0
void readchain();
void readsolvent();
void overlap();
void addcounterion();
void addanion();
void addcation();
void combine();
int solvent,Nmod,list[10000];
double
xp[M],yp[M],zp[M],xt[S],yt[S],zt[S],xs[S],ys[S],zs[S],xc[Nc+1],yc[Nc+1],zc[Nc+1];
main()
{
int i;
readchain(); //reading chain cordinates
31
readsolvent(); //reading solvent cordinates
overlap(); //removing the overlaping solvents
printf("Nmod=%d\n",Nmod);
for(i=1;i<=Nmod;i++) //initialising the list of selected atoms
list[i]=0;
addcounterion(); //selecting solvent atoms as counterions
combine(); //combining everything together for lammps input
}
void readchain()
{
printf("entered readchain\n");
int i,type;
char ch[10];
FILE *fp;
fp=fopen("chain.xyz","r");
if(fp==NULL)
printf("Cant open chain.xyz");
fscanf(fp,"%d",&type);
fscanf(fp,"%s",&ch);
for(i=1;i<=(Np*N);i++)
fscanf(fp,"%d%lf%lf%lf",&type,&xp[i],&yp[i],&zp[i]);
fclose(fp);
printf("Completed readchain\n");
}
void readsolvent()
{
int i,type;
char ch[10];
FILE *fp;
fp=fopen("solvent.xyz","r");
fscanf(fp,"%d",&solvent);
fscanf(fp,"%s",&ch);
for(i=1;i<=solvent;i++)
fscanf(fp,"%d%lf%lf%lf",&type,&xt[i],&yt[i],&zt[i]);
fclose(fp);
printf("Completed readsolvent\n");
32
}
void overlap()
{
int i,j,k,overlap;
double r;
k=0;
for(i=1;i<=solvent;i++)
{
overlap=0;
for(j=1;j<=(2*N);j++)
{
r=sqrt((xt[i]-xp[j])*(xt[i]-xp[j])+(yt[i]-yp[j])*(yt[i]-yp[j])+(zt[i]-zp[j])*(zt[i]-zp[j]));
if(r<SIGMA)
overlap++;
}
if((xt[i]==0)&&(yt[i]==0)&&(zt[i]==0))
overlap++;
if(overlap==0)
{
k++;
xs[k]=xt[i];
ys[k]=yt[i];
zs[k]=zt[i];
}
}
Nmod=k;
printf("Completed overlap\n");
}
void addcounterion()
{
int i,k,j;
i=1;
while(i<=Nc)
33
{
xc[i]=xs[i];
yc[i]=ys[i];
zc[i]=zs[i];
i++;
}
}
void addsolvent()
{
int i,k,j;
i=1;
while(i<=Nc)
{
k=Nmod*1.0*rand()*1.0/(RAND_MAX*1.0)+1.0;
if(list[k]==0)
{
xc[i]=xs[k];
yc[i]=ys[k];
zc[i]=zs[k];
list[k]=1;
i++;
}
}
}
void combine()
{
int
atoms,atom_types,bonds,bond_types,angles,angle_types,dihedrals,dihedral_types,impropers,improper_types,i,j,k,type1,type2,type3,type4;
float mass;
atom_types=3;
bond_types=1;
angles=(N-2)*Np;
angle_types=1;
34
dihedrals=0;
dihedral_types=0;
impropers=0;
improper_types=0;
mass=1.0;
type1=1;
type2=2;
type3=3;
type4=4;
FILE *fp;
fp=fopen("datafile-divalent-A_3.50","w");
fprintf(fp,"Lammps input file\n\n");
fprintf(fp,"\t\t%d\tatoms\n",(N*Np)+Nmod);
fprintf(fp,"\t\t%d\tbonds\n",Np*(N-1));
fprintf(fp,"\t\t%d\tangles\n",angles);
fprintf(fp,"\t\t%d\tdihedrals\n",dihedrals);
fprintf(fp,"\t\t%d\timpropers\n\n",impropers);
fprintf(fp,"\t\t%d\tatom types\n",atom_types);
fprintf(fp,"\t\t%d\tbond types\n",bond_types);
fprintf(fp,"\t\t%d\tangle types\n",angle_types);
fprintf(fp,"\t\t%d\tdihedral types\n",dihedral_types);
fprintf(fp,"\t\t%d\timproper types\n\n",improper_types);
fprintf(fp,"\t%f\t%f\txlo xhi\n",-L/2.0,L/2.0);
fprintf(fp,"\t%f\t%f\tylo yhi\n",-L/2.0,L/2.0);
fprintf(fp,"\t%f\t%f\tzlo zhi\n\n",-L/2.0,L/2.0);
fprintf(fp,"Masses\n\n");
for(i=1;i<atom_types;i++)
fprintf(fp,"\t%d\t%f\n",i,mass);
fprintf(fp,"\t%d\t%f\n\n",i,mass);
fprintf(fp,"Atoms\n\n");
for(i=1;i<=(N*Np);i++)
fprintf(fp,"%d\t%d\t%d\t%f\t%f\t%f\t%f\n",i,(i-1)/N+1,type1,type1,Qp,xp[i],yp[i],zp[i]);
for(i=1;i<=Nc;i++)
fprintf(fp,"%d\t%d\t%d\t%f\t%f\t%f\t%f\n",i+Np*N,Np+1,type2,Qc,xc[i],yc[i],zc[i]);
for(i=(Nc+1);i<=Nmod;i++)
fprintf(fp,"%d\t%d\t%d\t%f\t%f\t%f\t%f\n",i+Np*N,Np+2,type3,Qs,xs[i],ys[i],zs[i]);
35
fprintf(fp,"\nAngles\n\n");
for(i=1;i<=Np;i++)
for(j=1;j<=(N-2);j++)
fprintf(fp,"%d %d %d %d %d\n",j+(i-1)*(N-2),type1,(i-1)*N+j,(i-1)*N+j+1,(i-1)*N+j+2);
fprintf(fp,"\nBonds\n\n");
for(i=1;i<=Np;i++)
for(j=1;j<=(N-1);j++)
fprintf(fp,"\t%d\t%d\t%d\t%d\n",j+(i-1)*(N-1),type1,(i-1)*N+j,(i-1)*N+j+1);
fclose(fp);
}
36
References
[1] Anoop Varghese, Satyavani vemparala and R. Rajesh, J. Chem. Phys 135 154902 (2011)
[2] Dan Frenkel and Berend Smit Understanding Molecular Dynamics And Applications ISBN-0-12-267351-4 (2002)
[3] Verlet Algorithm: http://www.fisica.uniud.it/ ercolessi/md/md/node21.html
[4] Figure 2: http://chemwiki.ucdavis.edu
[5] Figure 1: http://wikipedia.org
[6] Figure 3: http://www.globalspec.com/reference/9929/348308/chapter-4-electrostatics-coulomb-s-law-and-the-superposition-principle
[7] Figure 4: http://cps-www.bu.edu/Wasser/robert/work/node6.html
[8] Truncated potential: http://cps-www.bu.edu/Wasser/robert/work/node6.html
[9] Virial theorem: http://wikipedia.org
37