Révision 3 ase/embed.py
embed.py (revision 3) | ||
---|---|---|
9 | 9 |
super(Embed, self).__init__() |
10 | 10 |
# define the atom map |
11 | 11 |
self.atom_map_sys_cl = [] |
12 |
self.atom_map_cl_sys = [] |
|
12 | 13 |
self.linkatoms = [] |
13 | 14 |
# cluster dimensions |
14 | 15 |
self.xyz_cl_min = None |
15 | 16 |
self.xyz_cl_max = None |
16 | 17 |
# set the search radius for link atoms |
17 |
self.d = 10
|
|
18 |
self.d = 10 |
|
18 | 19 |
# define the systems for calculations |
19 | 20 |
self.set_system(system) |
20 | 21 |
self.set_cluster(cluster) |
21 | 22 |
# |
22 | 23 |
self.set_cell([10, 10, 10]) |
23 | 24 |
return |
24 |
|
|
25 |
#--- set the cluster ---
|
|
25 |
|
|
26 |
#--- set the cluster --- |
|
26 | 27 |
def set_cluster(self, atoms): |
27 | 28 |
import copy |
28 | 29 |
# set the min/max cluster dimensions |
... | ... | |
38 | 39 |
self.xyz_cl_min[i] = xyz[i] |
39 | 40 |
if xyz[i] > self.xyz_cl_max[i]: |
40 | 41 |
self.xyz_cl_max[i] = xyz[i] |
41 |
|
|
42 |
|
|
42 | 43 |
# add self.d around min/max cluster dimensions |
43 | 44 |
self.xyz_cl_min -= [self.d, self.d, self.d] |
44 |
self.xyz_cl_max += [self.d, self.d, self.d]
|
|
45 |
self.xyz_cl_max += [self.d, self.d, self.d] |
|
45 | 46 |
# set the cluster for low and high level calculation |
46 | 47 |
self.atoms_cluster = atoms |
47 | 48 |
return |
48 | 49 |
|
49 | 50 |
#--- set the system --- |
50 | 51 |
def set_system(self, atoms): |
51 |
self.atoms_system = atoms
|
|
52 |
self.atoms_system = atoms |
|
52 | 53 |
# assign the label "Cluster (10)" in atom.TAG |
53 | 54 |
for atom in atoms: |
54 | 55 |
atom.set_tag(0) |
... | ... | |
60 | 61 |
dx = r |
61 | 62 |
self.d = dx * 2.1 |
62 | 63 |
return |
63 |
|
|
64 |
|
|
64 | 65 |
#--- return cluster --- |
65 | 66 |
def get_cluster(self): |
66 | 67 |
return self.atoms_cluster |
67 |
|
|
68 |
|
|
68 | 69 |
def get_system(self): |
69 | 70 |
return self.atoms_system |
70 |
|
|
71 |
|
|
71 | 72 |
#--- Embedding --- |
72 | 73 |
def embed(self): |
73 | 74 |
# is the cluster and the host system definied ? |
... | ... | |
87 | 88 |
xyzs_sys=[] |
88 | 89 |
for atom_sys in self.atoms_system: |
89 | 90 |
xyzs_sys.append(atom_sys.get_position()) |
90 |
|
|
91 |
self.atom_map_sys_cl=np.zeros(len(self.atoms_system), int) |
|
92 |
# loop over cluster atoms atom_sys |
|
91 |
|
|
92 |
self.atom_map_sys_cl = np.zeros(len(self.atoms_system), int) |
|
93 |
self.atom_map_cl_sys = np.zeros(len(self.atoms_cluster), int) |
|
94 |
# loop over cluster atoms atom_sys |
|
93 | 95 |
for iat_sys in xrange(len(self.atoms_system)): |
94 | 96 |
# get the coordinates of the system atom atom_sys |
95 | 97 |
xyz_sys = xyzs_sys[iat_sys] |
... | ... | |
104 | 106 |
# set tag (CLUSTER+HOST: 10) to atom_sys |
105 | 107 |
self.atoms_system[iat_sys].set_tag(10) |
106 | 108 |
# map the atom in the atom list |
107 |
self.atom_map_sys_cl[iat_sys]=iat_cl |
|
109 |
self.atom_map_sys_cl[iat_sys] = iat_cl |
|
110 |
self.atom_map_cl_sys[iat_cl] = iat_sys |
|
108 | 111 |
# atom has been identified |
109 | 112 |
bSysOnly = False |
110 | 113 |
break |
... | ... | |
118 | 121 |
xyzs_cl.append(atom_cl.get_position()) |
119 | 122 |
xyzs_sys=[] |
120 | 123 |
for atom_sys in self.atoms_system: |
121 |
xyzs_sys.append(atom_sys.get_position())
|
|
124 |
xyzs_sys.append(atom_sys.get_position()) |
|
122 | 125 |
# FIXME: mapping does not work when cluster atoms are outside of the box |
123 | 126 |
# set the standard link atom |
124 | 127 |
if linkAtom is None: |
... | ... | |
127 | 130 |
nat_cl=len(self.atoms_cluster) |
128 | 131 |
nat_sys=len(self.atoms_system) |
129 | 132 |
# system has pbc? |
130 |
pbc = self.get_pbc()
|
|
133 |
pbc = self.get_pbc() |
|
131 | 134 |
# set the bond table |
132 | 135 |
bonds = [] |
133 | 136 |
# set the 27 cell_vec, starting with the (0,0,0) vector for the unit cell |
... | ... | |
157 | 160 |
# xyz coordinates and covalent radius of the cluster atom iat_cl |
158 | 161 |
xyz_cl = xyzs_cl[iat_cl] |
159 | 162 |
r_cl = covalent_radii[atom_cl.get_atomic_number()] |
160 |
|
|
163 |
|
|
161 | 164 |
# sum over system atoms (iat_sys) |
162 | 165 |
for iat_sys in xrange(nat_sys): |
163 | 166 |
# avoid cluster atoms |
... | ... | |
170 | 173 |
# go only in distance self.d around the cluster |
171 | 174 |
lcont = True |
172 | 175 |
for i in xrange(3): |
173 |
if (xyz_sys[i] < self.xyz_cl_min[i] or
|
|
176 |
if (xyz_sys[i] < self.xyz_cl_min[i] or |
|
174 | 177 |
xyz_sys[i] > self.xyz_cl_max[i]): |
175 | 178 |
lcont = False |
176 | 179 |
break |
... | ... | |
189 | 192 |
print "Distance ", f |
190 | 193 |
print "tol = ",(1+tol/100.),(1-tol/100.),(1-2*tol/100.) |
191 | 194 |
if f <= (1+tol/100.) and f >= (1-2*tol/100.): |
192 |
s = cell_L, iat_cl, iat_sys, r_cl
|
|
195 |
s = cell_L, self.atom_map_cl_sys[iat_cl], iat_sys, r_cl
|
|
193 | 196 |
bonds.append(s) |
194 | 197 |
break |
195 | 198 |
if f <= (1-2*tol/100.): |
196 | 199 |
raise RuntimeError("QMX: The cluster atom", iat_cl, " and the system atom", iat_sys, "came too close") |
197 |
|
|
200 |
|
|
198 | 201 |
r_h = covalent_radii[atomic_numbers[linkAtom]] |
199 | 202 |
for bond in bonds: |
200 |
cell_L, iat_cl, iat_sys, r_cl = bond |
|
203 |
cell_L, iat_cl_sys, iat_sys, r_cl = bond
|
|
201 | 204 |
# assign the tags for the border atoms |
202 | 205 |
atom_sys.set_tag(1) |
203 | 206 |
atom_cl.set_tag(11) |
204 | 207 |
#difference vector for the link atom, scaling |
205 |
xyz_diff = xyzs_sys[iat_sys] + cell_L - xyzs_cl[iat_cl]
|
|
208 |
xyz_diff = xyzs_sys[iat_sys] + cell_L - xyzs_sys[iat_cl_sys]
|
|
206 | 209 |
r = (r_cl + r_h) |
207 | 210 |
xyz_diff *= r / np.sqrt(np.dot(xyz_diff, xyz_diff)) |
208 | 211 |
# determine position of the link atom |
209 |
xyz_diff += xyzs_cl[iat_cl]
|
|
212 |
xyz_diff += xyzs_sys[iat_cl_sys]
|
|
210 | 213 |
# create link atom |
211 | 214 |
atom = Atom(symbol=linkAtom, position=xyz_diff, tag=50) |
212 | 215 |
# add atom to cluster |
213 | 216 |
self.atoms_cluster.append(atom) |
214 | 217 |
# add atom to the linkatoms |
215 |
s = cell_L, iat_cl, iat_sys, r, len(self.atoms_cluster)-1 |
|
218 |
s = cell_L, iat_cl_sys, iat_sys, r, len(self.atoms_cluster)-1
|
|
216 | 219 |
self.linkatoms.append(s) |
217 | 220 |
return |
218 |
|
|
221 |
|
|
219 | 222 |
def set_positions(self, positions_new): |
220 | 223 |
# number of atoms |
221 | 224 |
nat_sys=len(self.atoms_system) |
... | ... | |
226 | 229 |
self.atoms_system[iat_sys].set_position(xyz) |
227 | 230 |
if iat_cl > -1: |
228 | 231 |
self.atoms_cluster[iat_cl].set_position(xyz) |
229 |
|
|
230 |
for cell_L, iat_cl, iat_sys, r, iat in self.linkatoms: |
|
232 |
|
|
233 |
for cell_L, iat_cl_sys, iat_sys, r, iat in self.linkatoms:
|
|
231 | 234 |
# determine position of the link atom |
232 |
xyz_cl = self.atoms_cluster[iat_cl].get_position()
|
|
235 |
xyz_cl = self.atoms_system[iat_cl_sys].get_position()
|
|
233 | 236 |
xyz = self.atoms_system[iat_sys].get_position() - xyz_cl + cell_L |
234 | 237 |
xyz *= r / np.sqrt(np.dot(xyz, xyz)) |
235 | 238 |
xyz += xyz_cl |
236 | 239 |
# update xyz coordinates of the cluster |
237 | 240 |
self.atoms_cluster[iat].set_position(xyz) |
238 |
|
|
241 |
|
|
239 | 242 |
def __getitem__(self, i): |
240 | 243 |
return self.atoms_system.__getitem__(i) |
241 | 244 |
|
242 | 245 |
def get_positions(self): |
243 | 246 |
return self.atoms_system.get_positions() |
244 |
|
|
247 |
|
|
245 | 248 |
def __add__(self, other): |
246 | 249 |
return self.atoms_system.__add__(other) |
247 |
|
|
250 |
|
|
248 | 251 |
def __delitem__(self, i): |
249 | 252 |
return self.atoms_system.__delitem__(i) |
250 |
|
|
253 |
|
|
251 | 254 |
def __len__(self): |
252 | 255 |
return self.atoms_system.__len__() |
256 |
|
|
257 |
def get_chemical_symbols(self, reduce=False): |
|
258 |
return self.atoms_system.get_chemical_symbols(reduce) |
Formats disponibles : Unified diff