forked from raffaelecheula/nanoparticles_ensembles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shape_distribution_fcc_particle.py
329 lines (229 loc) · 10.8 KB
/
shape_distribution_fcc_particle.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env python3
################################################################################
# Raffaele Cheula*[a][b], Matteo Maestri**[a], Giannis Mpourmpakis***[b]
# [a] Politecnico di Milano, [b] University of Pittsburgh
# * raffaele.cheula@polimi.it
# ** matteo.maestri@polimi.it
# *** gmpourmp@pitt.edu
# Modeling Morphology and Catalytic Activity of Nanoparticle Ensembles
# Under Reaction Conditions
# ACS Catalysis 2020
################################################################################
from __future__ import absolute_import, division, print_function
import os, timeit
try: import cPickle as pickle
except: import _pickle as pickle
import numpy as np
from collections import OrderedDict
from ase.build import bulk
from nanoparticles.nanoparticle_units import *
from nanoparticles.nanoparticle_utils import e_relax_from_bond_ols
from nanoparticles.nanoparticle_cython import (calculate_neighbors,
FccParticleShape )
################################################################################
# RUN
################################################################################
run = True
################################################################################
# MEASURE TIME START
################################################################################
measure_time = True
if measure_time is True:
start = timeit.default_timer()
################################################################################
# READ PARTICLES
################################################################################
dirname = 'fcc'
n_max = 1500 # [atom]
step = 10 # [atom]
min_diff_n = 1 # [atom]
min_diff_e = 0. # [eV/atom]
if not os.path.isdir(dirname):
os.mkdir(dirname)
particles_dict = {}
n_particles_old = 0
if run is True:
for n_group in range(0, n_max, step):
group = '{0:04d}_{1:04d}'.format(n_group, n_group+step)
filename = os.path.join(dirname, '{0}_{1}.pkl'.format(dirname, group))
if not os.path.isfile(filename):
particles_dict[n_group] = []
else:
fileobj = open(filename, 'rb')
particles_dict[n_group] = pickle.load(fileobj)
fileobj.close()
n_particles_old += len(particles_dict[n_group])
################################################################################
# PARTICLES DATA
################################################################################
bulk_type = 'fcc'
element = 'Rh'
lattice_constant = +3.8305 # [Ang]
e_coh_bulk = -6.1502 # [eV]
m_bond_ols = +2.6800 # [-]
e_twin = +0.0081 # [eV]
shear_modulus = +155 * (giga*Pa)*(J/eV)*(Ang/mt)**3 # [eV/Ang^3]
k_strain_dec = 3.78e-4 # [-]
k_strain_ico = 4.31e-3 # [-]
e_relax_list = e_relax_from_bond_ols(e_coh_bulk = e_coh_bulk,
m_bond_ols = m_bond_ols)
################################################################################
# BULK
################################################################################
layers_min_100 = 2
layers_max_100 = 8
atoms = bulk(element, bulk_type, a = lattice_constant, cubic = True)
layers_vac = 2 if layers_max_100 % 2 == 0 else 1
size = [layers_max_100+layers_vac]*3
atoms *= size
positions = atoms.get_positions()
cell = np.array(atoms.cell)
interact_len = np.sqrt(2*lattice_constant)*1.2
neighbors = calculate_neighbors(positions = positions ,
cell = cell ,
interact_len = interact_len)
################################################################################
# CALCULATION PARAMETERS
################################################################################
step_dict = OrderedDict()
step_dict[(1,0,0)] = 1/1
step_dict[(1,1,0)] = 1/1
step_dict[(1,1,1)] = 1/1
step_dict[(2,1,0)] = 1/2
step_dict[(2,1,1)] = 1/2
step_dict[(3,1,0)] = 1/3
step_dict[(3,1,1)] = 1/3
step_dict[(3,2,1)] = 1/3
plane_dist_100 = lattice_constant/2
max_spherical = False
if max_spherical is True:
d_max_tot = plane_dist_100*layers_max_100
else:
d_max_tot = 2.*plane_dist_100*layers_max_100
scale_vect = [(1.0, 1.0)]
n_coord_min = 0
translation_vect = [np.array([0.]*3) ,
np.array([lattice_constant/2.]+[0.]*2) ,
np.array([np.sqrt(lattice_constant)/2.]*2+[0.]),
np.array([np.sqrt(lattice_constant)/2.]*3 )]
################################################################################
# CREATE POPULATION OF PARTICLES
################################################################################
c_max_dict = {}
c_min_dict = {}
plane_dist = {}
d_max_dict = {}
d_min_dict = {}
i_max_dict = {}
d_dict = OrderedDict()
layers_dict = OrderedDict()
for hkl in step_dict:
hkl_scal = [i/max(hkl) for i in hkl]
denom = np.sqrt(sum([i**2 for i in hkl_scal]))
c_max_dict[hkl] = sum(hkl_scal)/denom
c_min_dict[hkl] = 1./denom
plane_dist[hkl] = plane_dist_100/denom*step_dict[hkl]
count = 0
miller_symmetry = True
print('\n N particles N processes\n')
for j in range(layers_min_100, layers_max_100):
d_100 = plane_dist_100*j
for hkl in step_dict:
d_max_dict[hkl] = d_100*c_max_dict[hkl]
d_min_dict[hkl] = d_100*c_min_dict[hkl]
i_max_dict[hkl] = int(np.around((d_max_dict[hkl]-d_min_dict[hkl]) /
plane_dist[hkl]))
for (a,b,c,d,e,f,g) in [(a,b,c,d,e,f,g)
for a in range(i_max_dict[(1,1,0)])
for b in range(i_max_dict[(1,1,1)])
for c in range(i_max_dict[(2,1,0)])
for d in range(i_max_dict[(2,1,1)])
for e in range(i_max_dict[(3,1,0)])
for f in range(i_max_dict[(3,1,1)])
for g in range(i_max_dict[(3,2,1)])]:
layers_dict[(1,0,0)] = 0
layers_dict[(1,1,0)] = a
layers_dict[(1,1,1)] = b
layers_dict[(2,1,0)] = c
layers_dict[(2,1,1)] = d
layers_dict[(3,1,0)] = e
layers_dict[(3,1,1)] = f
layers_dict[(3,2,1)] = g
for hkl in layers_dict:
d_dict[hkl] = d_max_dict[hkl]-layers_dict[hkl]*plane_dist[hkl]+1e-3
d_list = [d_dict[xkl] for xkl in d_dict][1:]
if max(d_list) < min(d_list)*1.2 and max(d_list) < d_max_tot:
miller_indices = np.array([hkl for hkl in d_dict])
planes_distances = np.array([d_dict[hkl] for hkl in d_dict])
for scale_one, scale_two in scale_vect:
for translation in translation_vect:
if run is True:
particle = FccParticleShape(
positions = np.copy(positions),
neighbors = np.copy(neighbors),
cell = cell ,
translation = translation ,
miller_indices = miller_indices ,
planes_distances = planes_distances ,
scale_one = scale_one ,
scale_two = scale_two ,
n_coord_min = n_coord_min ,
interact_len = interact_len ,
e_coh_bulk = e_coh_bulk ,
e_relax_list = e_relax_list ,
miller_symmetry = miller_symmetry )
try:
particle.get_shape()
particle.get_energy()
n_atoms = particle.n_atoms
except:
n_atoms = 0
if 0 < n_atoms < n_max:
duplicate = False
duplicates = []
n_group = int(np.floor(n_atoms/float(step))*step)
n_coord_dist = particle.n_coord_dist
e_spec_clean = particle.e_spec_clean
for index in range(len(particles_dict[n_group])):
old = particles_dict[n_group][index]
if (np.array_equal(n_coord_dist,
old.n_coord_dist)):
duplicate = True
break
elif abs(n_atoms-old.n_atoms) <= min_diff_n:
diff_e = e_spec_clean-old.e_spec_clean
if 0. < diff_e < min_diff_e:
duplicate = True
break
elif -min_diff_e < diff_e <= 0.:
duplicates += [index]
for i in sorted(duplicates, reverse = True):
del particles_dict[n_group][i]
if duplicate is False:
particles_dict[n_group] += [particle]
if count % 100 == 0.:
print('{0:13d} {1:13d}'.format(count, 1))
count += 1
################################################################################
# STORE PARTICLES
################################################################################
particles_dict = dict(particles_dict)
if run is True:
for n_group in range(0, n_max, step):
group = '{0:04d}_{1:04d}'.format(n_group, n_group+step)
filename = os.path.join(dirname, '{0}_{1}.pkl'.format(dirname, group))
fileobj = open(filename, 'wb')
pickle.dump(particles_dict[n_group], file = fileobj)
fileobj.close()
n_particles = sum([len(particles_dict[n]) for n in particles_dict])
print('\nNumber of particles tot: {:13d}'.format(n_particles))
print('\nNumber of particles new: {:13d}'.format(n_particles-n_particles_old))
################################################################################
# MEASURE TIME END
################################################################################
if measure_time is True:
stop = timeit.default_timer()-start
print('\nExecution time = {0:6.3} s\n'.format(stop))
################################################################################
# END
################################################################################