-
Notifications
You must be signed in to change notification settings - Fork 0
/
VDW.m
59 lines (53 loc) · 1.68 KB
/
VDW.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function atoms = VDW(atoms, bonds)
% function atoms = VDW(atoms, bonds)
%
% This function calculates the van der walls forces for each atom and adds
% this to the force already experienced by each atom.
global PE;
numAtoms = size(atoms,1);
for i = 1:numAtoms - 1
for j = i + 1:numAtoms
numBonds = size(bonds,1);
isBond = false;
for k = 1:numBonds
a = atoms(i).id;
b = atoms(j).id;
c = bonds(k).atom1.id;
d = bonds(k).atom2.id;
if a == c && b == d || ...
a == d && b == c
isBond = true;
break;
end
end
if ~isBond
if atoms(i).weight == 12
eps1 = .027;
r1 = 2.04;
else
eps1 = .020 ;
r1 = 1.62;
end
if atoms(j).weight == 12
eps2 = .027 ;
r2 = 2.04;
else
eps2 = .020;
r2 = 1.62;
end
eps = (eps1 + eps2)/2;
r = (r1 + r2)/2;
dist = atoms(j).pos - atoms(i).pos;
dir = dist / norm(dist);
d = norm(dist);
force = eps * (13.5 * (r^6/d^7) - 22.08 * 10^5/r * ...
exp(-12 * d/r));
atoms(i).force = atoms(i).force + force*dir;
atoms(j).force = atoms(j).force + force*dir;
% Calculate potential energy
PE = PE + eps * (-2.25 * (r/d)^6 + 1.84 * 10^5 *...
exp(-12 * d/r)); % in kcal/mol
end
end
end
end