This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
zeoliteFFs_construction.py
executable file
·242 lines (174 loc) · 6.51 KB
/
zeoliteFFs_construction.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
from __future__ import print_function
import numpy as np
import math
import itertools
import atomic_data
from force_field_construction import force_field
metals = atomic_data.metals
mass_key = atomic_data.mass_key
class MZHB(force_field):
def __init__(self, system, cutoff, args):
self.system = system
self.cutoff = cutoff
self.args = args
def type_atoms(self):
SG = self.system['graph']
types = []
for atom in SG.nodes(data=True):
name, inf = atom
element_symbol = inf['element_symbol']
nbors = [a for a in SG.neighbors(name)]
nbor_symbols = [SG.nodes[n]['element_symbol'] for n in nbors]
mass = mass_key[element_symbol]
if element_symbol == 'Si':
ty = 'Si'
elif element_symbol == 'O':
ty = 'O'
else:
raise ValueError('No Nicholas type identified for ' + element_symbol + 'with neighbors ' + ' '.join(nbor_symbols))
types.append((ty, element_symbol, mass))
SG.nodes[name]['force_field_type'] = ty
types = set(types)
Ntypes = len(types)
atom_types = dict((ty[0],i+1) for i,ty in zip(range(Ntypes), types))
atom_element_symbols = dict((ty[0], ty[1]) for ty in types)
atom_masses = dict((ty[0],ty[2]) for ty in types)
self.system['graph'] = SG
self.atom_types = atom_types
self.atom_element_symbols = atom_element_symbols
self.atom_masses = atom_masses
def pair_parameters(self, charges=True):
SG = self.system['graph']
atom_types = self.atom_types
params = {}
comments = {}
style = 'lj/cut/coul/long'
sb = 'lj/coul 1.0 1.0 1.0'
for a in atom_types:
ID = atom_types[a]
if a == 'O':
params[ID] = (style, 0.07472, 1.57689)
elif a == 'Si':
params[ID] = (style, 0.19924, 1.95998)
comments[ID] = [a,a]
for name, data in SG.nodes(data=True):
if data['force_field_type'] == 'O':
data['charge'] = -0.35
elif data['force_field_type'] == 'Si':
data['charge'] = 0.70
else:
pass
self.pair_data = {'params':params, 'style':style, 'special_bonds':sb, 'comments':comments}
def bond_parameters(self, bond):
i,j = bond
# divide by two in LAMMPS
if i == 'Si' and j == 'O':
k_ij = 537.31/2.0
r_ij = 1.620
elif i == 'O' and j == 'Si':
k_ij = 537.31/2.0
r_ij = 1.620
else:
raise ValueError('There is a non Si-O bond, which is not yet parametrized for Nicholas')
return ('harmonic', k_ij, r_ij)
def angle_parameters(self, angle):
i,j,k = angle
style = 'harmonic'
if j == 'Si' and i == 'O' and k == 'O':
# divide by two in LAMMPS
K = 156.81169/2.0
theta0 = 109.470
return (style, K, theta0)
elif j == 'O':
# divide by two in LAMMPS
K = 51.19440/2.0
theta0 = 149.800
return (style, K, theta0)
def dihedral_parameters(self):
# dihedrals are the same for everything
pass
def improper_parameters(self, fft_i, O_2_flag):
# there are no impropers
pass
# Si-O bonds
def enumerate_bonds(self):
SG = self.system['graph']
bonds = {}
for e in SG.edges(data=True):
i,j,data = e
fft_i = SG.nodes[i]['force_field_type']
fft_j = SG.nodes[j]['force_field_type']
bond = tuple(sorted([fft_i, fft_j]))
# add to list if bond type already exists, else add a new type
try:
bonds[bond].append((i,j))
except KeyError:
bonds[bond] = [(i,j)]
bond_params = {}
bond_comments = {}
all_bonds = {}
ID = 0
count = 0
# index bonds by ID
for b in bonds:
ID += 1
bond = (b[0], b[1])
params = self.bond_parameters(bond)
bond_params[ID] = list(params)
bond_comments[ID] = [b[0],b[1]]
all_bonds[ID] = bonds[b]
count += len(bonds[b])
self.bond_data = {'all_bonds':all_bonds, 'params':bond_params, 'style':'harmonic', 'count':(count, len(all_bonds)), 'comments':bond_comments}
def enumerate_angles(self):
SG = self.system['graph']
angles = {}
for n in SG.nodes(data=True):
name, data = n
nbors = list(SG.neighbors(name))
for comb in itertools.combinations(nbors, 2):
j = name
i, k = comb
fft_i = SG.nodes[i]['force_field_type']
fft_j = SG.nodes[j]['force_field_type']
fft_k = SG.nodes[k]['force_field_type']
angle = sorted((fft_i, fft_k))
angle = (angle[0], fft_j, angle[1])
# add to list if angle type already exists, else add a new type
try:
angles[angle].append((i,j,k))
except KeyError:
angles[angle] = [(i,j,k)]
angle_params = {}
angle_comments = {}
all_angles = {}
ID = 0
count = 0
styles = []
# index angles by ID
for a in angles:
ID += 1
fft_i, fft_j, fft_k = a
angle = (fft_i, fft_j, fft_k)
params = self.angle_parameters(angle)
styles.append(params[0])
angle_params[ID] = list(params)
angle_comments[ID] = [fft_i, fft_j, fft_k]
all_angles[ID] = angles[a]
count += len(angles[a])
styles = set(styles)
if len(styles) == 1:
style = list(styles)[0]
else:
style = 'hybrid ' + ' '.join(styles)
self.angle_data = {'all_angles':all_angles, 'params':angle_params, 'style':style, 'count':(count, len(all_angles)), 'comments':angle_comments}
def enumerate_dihedrals(self):
pass
def enumerate_impropers(self):
pass
def compile_force_field(self, charges=False):
self.type_atoms()
self.pair_parameters(charges)
self.enumerate_bonds()
self.enumerate_angles()
self.enumerate_dihedrals()
self.enumerate_impropers()