-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqTIP4pFF.py
199 lines (149 loc) · 7.02 KB
/
qTIP4pFF.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# q-TIP4P water potential
# Kevin Bishop
from MMTK.ForceFields.ForceField import ForceField
from MMTK_qTIP4p import HarmonicAngleTerm, HarmonicBondTerm, QuarticBondTerm, ElectrostaticTerm, LennardJonesTerm
from MMTK.Units import electrostatic_energy
import numpy as np
class HarmonicAngleForceField(ForceField):
"""
Harmonic angle bend potential between 3 atoms
"""
def __init__(self, atoms, theta_eq, k_theta):
self.atom_indices = map(lambda x: self.getAtomParameterIndices([x])[0],atoms)
self.theta_eq = theta_eq
self.k_theta = k_theta
self.arguments = (self.atom_indices,theta_eq,k_theta)
ForceField.__init__(self, 'harmonic_angle')
def ready(self, global_data):
return True
def supportsPathIntegrals(self):
return True
def evaluatorTerms(self, universe, subset1, subset2, global_data):
if subset1 is not None or subset2 is not None:
raise ValueError("sorry, no subsets here")
f, offsets = self.beadOffsetsAndFactor([self.atom_indices[0],self.atom_indices[1],self.atom_indices[2]], global_data)
highest_offset = offsets[-1][-1]
return [HarmonicAngleTerm(universe,
self.atom_indices + o,
self.theta_eq,
self.k_theta,
o[0]==0 or o[0]==highest_offset) #True if first/last bead (Required for PIGS)
for o in offsets]
class HarmonicBondForceField(ForceField):
"""
Harmonic bond stretch potential between 2 atoms
"""
def __init__(self, atoms, r_eq, k_r):
self.atom_indices = map(lambda x: self.getAtomParameterIndices([x])[0],atoms)
self.r_eq = r_eq
self.k_r = k_r
self.arguments = (self.atom_indices,r_eq,k_r)
ForceField.__init__(self, 'harmonic_bond')
def ready(self, global_data):
return True
def supportsPathIntegrals(self):
return True
def evaluatorTerms(self, universe, subset1, subset2, global_data):
if subset1 is not None or subset2 is not None:
raise ValueError("sorry, no subsets here")
f, offsets = self.beadOffsetsAndFactor([self.atom_indices[0],self.atom_indices[1]], global_data)
highest_offset = offsets[-1][-1]
return [HarmonicBondTerm(universe,
self.atom_indices + o,
self.r_eq,
self.k_r,
o[0]==0 or o[0]==highest_offset)
for o in offsets]
class QuarticBondForceField(ForceField):
"""
Quartic bond stretch potential between 2 atoms
"""
def __init__(self, atoms, D_r, c1, c2, c3, r_eq):
self.atom_indices = map(lambda x: self.getAtomParameterIndices([x])[0],atoms)
self.D_r = D_r
self.c1 = c1
self.c2 = c2
self.c3 = c3
self.r_eq = r_eq
self.arguments = (self.atom_indices,D_r,c1,c2,c3,r_eq)
ForceField.__init__(self, 'quartic_bond')
def ready(self, global_data):
return True
def supportsPathIntegrals(self):
return True
def evaluatorTerms(self, universe, subset1, subset2, global_data):
if subset1 is not None or subset2 is not None:
raise ValueError("sorry, no subsets here")
f, offsets = self.beadOffsetsAndFactor([self.atom_indices[0],self.atom_indices[1]], global_data)
highest_offset = offsets[-1][-1]
return [QuarticBondTerm(universe,
self.atom_indices + o,
self.D_r,
self.c1,
self.c2,
self.c3,
self.r_eq,
o[0]==0 or o[0]==highest_offset)
for o in offsets]
class ElectrostaticForceField(ForceField):
"""
Electrostatic interactions between all charged particles in universe
WILL ONLY WORK WITH WATERS! 3 AND 4 POINT MODELS SPECIFICALLY!
"""
def __init__(self, universe,fraction,o_charge):
#Take the list of objects (molecules) and create a new list where each element in the
#list is another list containing the indices of all the atoms in the molecule
waters = universe.objectList()
water_atoms = map(lambda x: map(lambda y: self.getAtomParameterIndices([y])[0],x.atomList()), waters)
self.atom_indices = water_atoms
self.fraction = fraction
self.o_charge = o_charge
self.arguments = (self.atom_indices,self.fraction,self.o_charge)
ForceField.__init__(self, 'electrostatics')
def ready(self, global_data):
return True
def supportsPathIntegrals(self):
return True
def evaluatorTerms(self, universe, subset1, subset2, global_data):
if subset1 is not None or subset2 is not None:
raise ValueError("sorry, no subsets here")
f, offsets = self.beadOffsetsAndFactor(map(lambda x: x[0],self.atom_indices), global_data)
highest_offset = offsets[-1][-1]
return [ElectrostaticTerm(universe,
np.array(map(lambda x: self.atom_indices[x]+o[x],range(len(o)))),
self.fraction,
self.o_charge,
electrostatic_energy,
o[0]==0 or o[0]==highest_offset)
for o in offsets]
class LennardJonesForceField(ForceField):
"""
Lennard-Jones potential between all of the Oxygens in the water molecules
"""
def __init__(self, universe, epsilon, sigma):
#Get atom indices for oxygens
waters = universe.objectList()
oxygens = map(lambda x: x.atomList()[2],waters) #Oxygen is 2 in atom list
atom_indices = map(lambda x: self.getAtomParameterIndices([x])[0],oxygens)
self.atom_indices = atom_indices
self.epsilon = epsilon
self.sigma = sigma
self.arguments = (self.atom_indices,self.epsilon,self.sigma)
ForceField.__init__(self, 'lennard_jones')
def ready(self, global_data):
return True
def supportsPathIntegrals(self):
return True
def evaluatorTerms(self, universe, subset1, subset2, global_data):
if subset1 is not None or subset2 is not None:
raise ValueError("sorry, no subsets here")
f, offsets = self.beadOffsetsAndFactor(self.atom_indices, global_data)
highest_offset = offsets[-1][-1]
return [LennardJonesTerm(universe,
self.atom_indices + o,
self.epsilon,
self.sigma,
o[0]==0 or o[0]==highest_offset)
for o in offsets]