forked from DanielMarchand/aiida-alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aiida_create_stackingfault_structures.py
executable file
·249 lines (230 loc) · 11.7 KB
/
aiida_create_stackingfault_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
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
#!/usr/bin/env python
import aiida
aiida.load_profile()
from aiida.orm import Group
from aiida.orm import load_node
from aiida_create_solutesupercell_structures import *
import ase
import ase.build
from ase.geometry import get_layers
import click
import json
import os
import numpy as np
import pandas as pd
def get_displacements_array(displacement):
if len(displacement.split(',')) == 3:
d_min,d_max,d_inc = [float(x) for x in displacement.split(',')]
if d_max > 1:
print("WARNING: max displacement {} is larger than 1".format(displacement))
displacements = np.arange(float(d_min),float(d_max),float(d_inc))
else:
displacements = np.array([float(displacement)])
return displacements
def get_layer_frame(structure, miller_index):
layer_indexes, layer_distances = get_layers(structure, miller_index)
repeating_layer_distances = []
for i in range(len(layer_indexes)):
layer_distance = layer_distances[layer_indexes[i]]
repeating_layer_distances.append(layer_distance)
repeating_layer_distances = np.array(repeating_layer_distances)
layer_dict = {'layer_index': layer_indexes,
'layer_distance': repeating_layer_distances}
layer_frame = pd.DataFrame(data=layer_dict)
layer_frame.index.name = "structure_index"
return layer_frame
@click.command()
@click.option('-a', '--lattice_size', required=False,
help="lattice length (in Ang) to use")
@click.option('-me', '--matrix_element', required=False,
help="element to be used as the matrix")
@click.option('-l_surf', '--lattice_and_surface',
type=click.Choice(["FCC_111"]),
help="lattice and surface to be used. "
"FCC_111: <112>(x) <110>(y) <111>(z)", required=False)
@click.option('-cstn', '--customstructure_node',
help="Node containing a custom structure. "
"Must have x_direction, y_direction and surface_plane specified in the extras",
required=False)
@click.option('-pxr', '--periodic_xrepeats', default=1, type=int,
help="periodic repeats in the x (a1) direction")
@click.option('-pyr', '--periodic_yrepeats', default=1, type=int,
help="periodic repeats in the y (a2) direction")
@click.option('-pzr', '--periodic_zrepeats', default=1, type=int,
help="periodic repeats in the z (a3) direction")
@click.option('-dx', '--displacement_x', default='0',
help="Displacements to be made in the x (a1) direction. "
"The amount is expressed as a fraction (between 0 and 1) of the x length "
"(after periodic repeats). The notation is: "
"start,end,increment or displacement_value.")
@click.option('-dy', '--displacement_y', default='0',
help="Displacement to be made in the y (a2) direction. "
"See displacement_x for syntax")
@click.option('-spo', '--special_pointsonly', is_flag=True,
help="Create only undistored and minimum energy displacements. "
"Overides the displacement_{x,y} commands. "
"May not be defined for all lattice/surface combinations. "
"Useful for benchmarking.")
@click.option('-prm', '--primitive', is_flag=True,
help="Create primitive cell version (i.e non-orthogonal). ")
@click.option('-se', '--solute_elements', required=False,
help="Solute element, created at unique distances from the stacking fault."
" Will force the construction of a stable stacking fault."
" Creates solutes at every unique layer away from the SF."
" Can pass a list of elements using comma seperation"
" E.g. Mg,Si,Cu. Can specify the creation of a vacancy using 'Vac'"
" NOTE: will not generate symmetrically equivalent structures."
" E.g. if Mg-Si solute solutes have been generated the script will skip Si-Mg")
@click.option('-msl', '--maxsolute_layer', default=None,
help="Maximum layer to place solutes away from the SF")
@click.option('-tsl', '--testsolute_layer', is_flag=True,
help="Place one solute at the midpoint (test) of the SF")
@click.option('-rsl', '--refsolute', is_flag=True,
help="Place one solute at the origin of an undistorted slab with size of a SF")
@click.option('-sg', '--structure_group_label', required=True,
help="Output AiiDA group to store created structures")
@click.option('-sgd', '--structure_group_description', default="",
help="Description for output AiiDA group")
@click.option('-dr', '--dryrun', is_flag=True,
help="Prints structures and extras but does not store anything")
def launch(lattice_size, matrix_element, lattice_and_surface,
customstructure_node,
periodic_xrepeats, periodic_yrepeats, periodic_zrepeats,
displacement_x, displacement_y, special_pointsonly,
primitive, solute_elements, maxsolute_layer, testsolute_layer,
refsolute, structure_group_label, structure_group_description,
dryrun):
"""
Script for creating stacking fault structures for a given size and matrix element. Generates
a set of distorted structures using the 'tilted cell method', i.e. by adding fractional
increments of the 'x' and 'y' cell vectors to the the 'z', vector.
"""
STABLE_STACKING_NAME = 'stable_stacking'
if not dryrun:
structure_group = Group.objects.get_or_create(
label=structure_group_label, description=structure_group_description)[0]
else:
structure_group = None
extras = {}
if lattice_and_surface:
if lattice_size is None:
raise Exception("Must specifiy a lattice_size if using lattice_and_surface")
if matrix_element is None:
raise Exception("Must specifiy a matrix_element if using lattice_and_surface")
lattice_size = float(lattice_size)
lattice_type, surface_plane = lattice_and_surface.split('_')
surface_plane = "{"+str(surface_plane)+"}"
orthogonal = not primitive
extras = {
'lattice_size':lattice_size,
'lattice_type':lattice_type,
'surface_plane':surface_plane,
'matrix_element':matrix_element,
}
special_points = {'undistorted':[0,0]}
if lattice_and_surface == "FCC_111":
xrepeats = periodic_xrepeats
zrepeats = 3*periodic_zrepeats
extras['z_direction'] = '<111>'
if orthogonal:
yrepeats = 2*periodic_yrepeats
extras['x_direction'] = '<112>'
extras['y_direction'] = '<110>'
extras['orthogonal'] = 'True'
special_points[STABLE_STACKING_NAME] = [0, 2./3.]
else:
yrepeats = periodic_yrepeats
extras['x_direction'] = '<110>'
extras['y_direction'] = '<110>'
extras['orthogonal'] = 'False'
special_points[STABLE_STACKING_NAME] = [1./3., 1./3.]
undistorted_structure = ase.build.fcc111(
matrix_element,
[xrepeats,yrepeats,zrepeats],
orthogonal=orthogonal,
a=lattice_size,
periodic=True,
)
elif customstructure_node:
custom_structure = load_node(customstructure_node)
undistorted_structure = custom_structure.get_ase()
extras = custom_structure.extras
if '_aiida_hash' in extras:
del extras['_aiida_hash']
extras['inputstructure_uuid'] = custom_structure.uuid
#Ensuring that the structure has all the required labels
if 'label' not in extras:
print(("WARNING: label not found in {} extras".format(custom_structure)))
if 'x_direction' not in extras:
print(("WARNING: x_direction not found in {} extras".format(custom_structure)))
if 'y_direction' not in extras:
print(("WARNING: y_direction not found in {} extras".format(custom_structure)))
if 'surface_plane' not in extras:
print(("WARNING: surface_plane not found in {} extras".format(custom_structure)))
undistorted_structure = undistorted_structure.repeat(
[periodic_xrepeats, periodic_yrepeats, periodic_zrepeats]
)
else:
raise Exception("Could not process lattice_and_surface: {}".format(lattice_and_surface))
#Add extras common to specified & custom lattice
extras['periodic_xrepeats'] = periodic_xrepeats
extras['periodic_yrepeats'] = periodic_yrepeats
extras['periodic_zrepeats'] = periodic_zrepeats
undistorted_structure.pbc = [True, True, True] # DFT structures always periodic
a1 = undistorted_structure.get_cell()[0]/float(periodic_xrepeats)
a2 = undistorted_structure.get_cell()[1]/float(periodic_yrepeats)
a3 = undistorted_structure.get_cell()[2]/float(periodic_zrepeats)
dispx_array = get_displacements_array(displacement_x)
dispy_array = get_displacements_array(displacement_y)
displacements = [[d_x, d_y] for d_x in dispx_array for d_y in dispy_array]
special_pointnames = []
if special_pointsonly:
displacements = [] # overide any user displacements
for sp_name in special_points:
d_x, d_y = special_points[sp_name]
displacements.append([d_x, d_y])
special_pointnames.append(sp_name)
if solute_elements:
displacements = [] # overide any user displacements
if STABLE_STACKING_NAME not in special_points:
raise Exception("{} has no stable_stacking structure defined "
"".format(lattice_and_surface))
if refsolute:
d_x, d_y = special_points['undistorted']
special_pointnames.append('undistorted')
else:
d_x, d_y = special_points[STABLE_STACKING_NAME]
special_pointnames.append(STABLE_STACKING_NAME)
displacements.append([d_x, d_y])
for displacement in displacements:
d_x, d_y = displacement
extras['displacement_x'] = d_x
extras['displacement_y'] = d_y
if special_pointsonly:
extras['special_point'] = special_pointnames.pop(0)
distorted_structure = undistorted_structure.copy()
distorted_structure.cell[2] += a1*d_x
distorted_structure.cell[2] += a2*d_y
store_asestructure(distorted_structure, extras, structure_group, dryrun)
solute_elements = prep_elementlist(solute_elements)
for solute_element in solute_elements:
extras['sol1_element'] = solute_element
layer_frame = get_layer_frame(distorted_structure, (0,0,1))
layer_frame = layer_frame.drop_duplicates("layer_index").reset_index()
solute_layers = list(range(int(len(layer_frame)/2)))
if refsolute:
solute_layers = [0]
if testsolute_layer:
solute_layers = [int(len(layer_frame)/2)-1]
for i in solute_layers:
solute_structure = distorted_structure.copy()
solute_index = int(layer_frame.loc[i]['structure_index'])
solute_structure[solute_index].symbol = solute_element
extras['sol1_index'] = solute_index
extras['sol1sf_distance'] = layer_frame.loc[i]['layer_distance']
extras['sol1layer_index'] = int(layer_frame.loc[i]['layer_distance'])
store_asestructure(solute_structure, extras, structure_group, dryrun)
if maxsolute_layer and i >= int(maxsolute_layer):
break
if __name__ == "__main__":
launch()