-
Notifications
You must be signed in to change notification settings - Fork 16
/
crystal_structures.py
211 lines (169 loc) · 6.24 KB
/
crystal_structures.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
"""
pyscal module for creating crystal structures.
"""
import pyscal.catom as pc
import numpy as np
import warnings
def make_crystal(structure, lattice_constant = 1.00, repetitions = None, ca_ratio = 1.633, noise = 0):
"""
Create a basic crystal structure and return it as a list of `Atom` objects
and box dimensions.
Parameters
----------
structure : {'bcc', 'fcc', 'hcp', 'diamond' or 'l12'}
type of the crystal structure
lattice_constant : float, optional
lattice constant of the crystal structure, default 1
repetitions : list of ints of len 3, optional
of type `[nx, ny, nz]`, repetions of the unit cell in x, y and z directions.
default `[1, 1, 1]`.
ca_ratio : float, optional
ratio of c/a for hcp structures, default 1.633
noise : float, optional
If provided add normally distributed noise with standard deviation `noise` to the atomic positions.
Returns
-------
atoms : list of `Atom` objects
list of all atoms as created by user input
box : list of list of floats
list of the type `[[xlow, xhigh], [ylow, yhigh], [zlow, zhigh]]` where each of them are the lower
and upper limits of the simulation box in x, y and z directions respectively.
Examples
--------
>>> atoms, box = make_crystal('bcc', lattice_constant=3.48, repetitions=[2,2,2])
>>> sys = System()
>>> sys.assign_atoms(atoms, box)
"""
if repetitions == None:
nx = 1
ny = 1
nz = 1
else:
nx = repetitions[0]
ny = repetitions[1]
nz = repetitions[2]
#if noise > 0.1:
# warnings.warn("Value of noise is rather high. Atom positions might overlap")
if structure == 'bcc':
coord_no = 2
atomtype = [1, 1]
natoms = coord_no*nx*ny*nz
xfact = 1.
yfact = 1.
zfact = 1.
unitcellx = np.zeros(coord_no)
unitcelly = np.zeros(coord_no)
unitcellz = np.zeros(coord_no)
unitcellx[1] = 0.5*lattice_constant
unitcelly[1] = 0.5*lattice_constant
unitcellz[1] = 0.5*lattice_constant
elif structure == 'fcc':
coord_no = 4
atomtype = [1, 1, 1, 1]
natoms = coord_no*nx*ny*nz
xfact = 1.
yfact = 1.
zfact = 1.
unitcellx = np.zeros(coord_no)
unitcelly = np.zeros(coord_no)
unitcellz = np.zeros(coord_no)
unitcellx[1] = 0.5*lattice_constant
unitcellz[1] = 0.5*lattice_constant
unitcelly[2] = 0.5*lattice_constant
unitcellz[2] = 0.5*lattice_constant
unitcellx[3] = 0.5*lattice_constant
unitcelly[3] = 0.5*lattice_constant
elif structure == 'hcp':
coord_no = 4
atomtype = [1, 1, 1, 1]
natoms = coord_no*nx*ny*nz
xfact = 1.
yfact = np.sqrt(3)
zfact = ca_ratio
unitcellx = np.zeros(coord_no)
unitcelly = np.zeros(coord_no)
unitcellz = np.zeros(coord_no)
unitcellx[1] = 0.5*lattice_constant
unitcelly[1] = 0.5*lattice_constant*yfact
unitcellx[2] = 0.5*lattice_constant
unitcelly[2] = lattice_constant*(1.0/6.0)*yfact
unitcellz[2] = 0.5*lattice_constant*zfact
unitcelly[3] = 2.0*lattice_constant*(1.0/yfact)
unitcellz[3] = 0.5*lattice_constant*zfact
elif structure == 'diamond':
coord_no = 8
atomtype = [1, 1, 1, 1, 1, 1, 1, 1]
natoms = coord_no*nx*ny*nz
xfact = 1.
yfact = 1.
zfact = 1.
unitcellx = np.zeros(coord_no)
unitcelly = np.zeros(coord_no)
unitcellz = np.zeros(coord_no)
unitcellx[1]=0.25*lattice_constant
unitcelly[1]=0.25*lattice_constant
unitcellz[1]=0.25*lattice_constant
unitcellx[2]=0.50*lattice_constant
unitcelly[2]=0.50*lattice_constant
unitcellz[2]=0.00*lattice_constant
unitcellx[3]=0.75*lattice_constant
unitcelly[3]=0.75*lattice_constant
unitcellz[3]=0.25*lattice_constant
unitcellx[4]=0.50*lattice_constant
unitcelly[4]=0.00*lattice_constant
unitcellz[4]=0.50*lattice_constant
unitcellx[5]=0.00*lattice_constant
unitcelly[5]=0.50*lattice_constant
unitcellz[5]=0.50*lattice_constant
unitcellx[6]=0.75*lattice_constant
unitcelly[6]=0.25*lattice_constant
unitcellz[6]=0.75*lattice_constant
unitcellx[7]=0.25*lattice_constant
unitcelly[7]=0.75*lattice_constant
unitcellz[7]=0.75*lattice_constant
elif structure == 'l12':
coord_no = 4
atomtype = [1, 2, 2, 2]
natoms = coord_no*nx*ny*nz
xfact = 1.
yfact = 1.
zfact = 1.
unitcellx = np.zeros(coord_no)
unitcelly = np.zeros(coord_no)
unitcellz = np.zeros(coord_no)
unitcellx[1] = 0.5*lattice_constant
unitcellz[1] = 0.5*lattice_constant
unitcelly[2] = 0.5*lattice_constant
unitcellz[2] = 0.5*lattice_constant
unitcellx[3] = 0.5*lattice_constant
unitcelly[3] = 0.5*lattice_constant
else:
raise ValueError("Unknown crystal structure")
m = 0
co = 1
atoms = []
xh = nx*lattice_constant*xfact
yh = ny*lattice_constant*yfact
zh = nz*lattice_constant*zfact
boxdims = [[0, xh], [0, yh], [0, zh]]
#create structure
for i in range(1, nx+1):
for j in range(1, ny+1):
for k in range(1, nz+1):
for l in range(1, coord_no+1):
m += 1
posx = (unitcellx[l-1]+(lattice_constant*xfact*(float(i)-1)))
posy = (unitcelly[l-1]+(lattice_constant*yfact*(float(j)-1)))
posz = (unitcellz[l-1]+(lattice_constant*zfact*(float(k)-1)))
if noise > 0:
posx = np.random.normal(loc=posx, scale=noise)
posy = np.random.normal(loc=posy, scale=noise)
posz = np.random.normal(loc=posz, scale=noise)
atom = pc.Atom()
atom.pos = [posx, posy, posz]
atom.id = co
atom.type = atomtype[l-1]
atom.loc = co-1
atoms.append(atom)
co += 1
return atoms, boxdims