@@ -111,14 +111,15 @@ def __init__(self, symprec: float = 0.01, angle_tolerance: float = 5):
111
111
self .angle_tolerance = angle_tolerance
112
112
113
113
def generate (
114
- self , structure : Structure , substitution : dict [str , list [ str ] ], ** kwargs
114
+ self , structure : Structure , substitution : dict [str , str | list ], ** kwargs
115
115
) -> Generator [Substitution , None , None ]:
116
116
"""Generate subsitutional defects.
117
117
118
118
Args:
119
119
structure: The bulk structure the vacancies are generated from.
120
120
substitution: The substitutions to be made given as a dictionary.
121
- e.g. {"Ga": ["Mg", "Ca"]} means that Ga is substituted with Mg or Ca.
121
+ e.g. {"Ga": "Ca"} means that Ga is substituted with Ca. You
122
+ can also specify a list of elements to substitute with.
122
123
**kwargs: Additional keyword arguments for the ``Substitution`` constructor.
123
124
124
125
Returns:
@@ -131,14 +132,24 @@ def generate(
131
132
el_str = _element_str (site .specie )
132
133
if el_str not in substitution .keys ():
133
134
continue
134
- for sub_el in substitution [el_str ]:
135
+ sub_el = substitution [el_str ]
136
+ if isinstance (sub_el , str ):
135
137
sub_site = PeriodicSite (
136
138
Species (sub_el ),
137
139
site .frac_coords ,
138
140
structure .lattice ,
139
141
properties = site .properties ,
140
142
)
141
143
yield Substitution (structure , sub_site , ** kwargs )
144
+ elif isinstance (sub_el , list ):
145
+ for el in sub_el :
146
+ sub_site = PeriodicSite (
147
+ Species (el ),
148
+ site .frac_coords ,
149
+ structure .lattice ,
150
+ properties = site .properties ,
151
+ )
152
+ yield Substitution (structure , sub_site , ** kwargs )
142
153
143
154
144
155
class AntiSiteGenerator (DefectGenerator ):
@@ -152,6 +163,7 @@ class AntiSiteGenerator(DefectGenerator):
152
163
def __init__ (self , symprec : float = 0.01 , angle_tolerance : float = 5 ):
153
164
self .symprec = symprec
154
165
self .angle_tolerance = angle_tolerance
166
+ self ._sub_gen = SubstitutionGenerator (symprec , angle_tolerance )
155
167
156
168
def generate (
157
169
self ,
@@ -162,14 +174,17 @@ def generate(
162
174
163
175
Args:
164
176
structure: The bulk structure the anti-site defects are generated from.
177
+ **kwargs: Additional keyword arguments for the ``Substitution.generate`` function.
165
178
"""
166
179
all_species = [* map (_element_str , structure .composition .elements )]
167
180
subs = collections .defaultdict (list )
168
181
for u , v in combinations (all_species , 2 ):
169
182
subs [u ].append (v )
170
183
subs [v ].append (u )
171
184
logger .debug (f"All anti-site pairings: { subs } " )
172
- return SubstitutionGenerator .generate (self , structure , subs )
185
+ for site , species in subs .items ():
186
+ for sub in species :
187
+ yield from self ._sub_gen .generate (structure , {site : sub }, ** kwargs )
173
188
174
189
175
190
class InterstitialGenerator (DefectGenerator ):
0 commit comments