shakenbreak.input module#
Module containing functions to generate rattled and bond-distorted structures,
as well as input files to run Gamma point relaxations with VASP
, CP2K
,
Quantum-Espresso
, FHI-aims
and CASTEP
.
- class shakenbreak.input.Distortions(defect_entries: DefectsGenerator | list | dict | DefectEntry, oxidation_states: dict | None = None, dict_number_electrons_user: dict | None = None, distortion_increment: float = 0.1, bond_distortions: list | None = None, local_rattle: bool = False, distorted_elements: dict | None = None, distorted_atoms: list | None = None, dimer_bond_length: float | None = None, **mc_rattle_kwargs)[source]#
Bases:
object
Class to apply rattle and bond distortion to all defects in
defect_entries
(each defect as adoped
orpymatgen
DefectEntry
object).Initialises the relevant information for generating
ShakeNBreak
distorted structures for defect entries indefect_entries
.The default distortions generated have the bond lengths of
X
nearest neighbours distorted by -60% to +60% (bond_distortions
) in increments of 10% (distortion_increment
), whereX
is equal to the excess charge for that defect species (e.g.2
forv_Cd_0
; see SnB tutorial: https://shakenbreak.readthedocs.io/en/latest/ShakeNBreak_Example_Workflow.html or npj theory paper: https://doi.org/10.1038/s41524-023-00973-1 for more info). Additionally, a dimer distortion will be included by default for each vacancy defect (seedistortions.apply_dimer_distortion
for more info), and distortions which result in inter-atomic distances less than 1 Å are excluded (unless Hydrogen is present).Rattling is then performed by applying random displacements to atomic positions, with the displacement distances randomly drawn from a Gaussian distribution of standard deviation
stdev
, using a Monte Carlo algorithm which disfavours moves that bring atoms closer thand_min
. Rattling behaviour can be controlled withmc_rattle_kwargs
, see thedistortions.rattle()
docstring for more info. Note that by default, rattling is not applied to the defect site or distorted neighbours, but to all other atoms in the supercell, however this can be controlled with theactive_atoms
kwarg (inmc_rattle_kwargs
).The nearest neighbours to distort are chosen by taking all sites (or those matching
distorted_element
/distorted_atoms
, if provided), then sorting by distance to the defect site (rounded to 2 decimal places) and site index, and then taking the firstnum_nearest_neighbours
of these. If there are multiple non-degenerate combinations of (nearly) equidistant NNs to distort (e.g. cis vs trans when distorting 2 NNs in a 4 NN square coordination), then the combination with distorted NNs closest to each other is chosen.The bond distortion and rattling approaches are highly customisable via
kwargs
to this class and its methods, so see the argument descriptions for more info.- Parameters:
defect_entries (Union[DefectsGenerator, list, dict, DefectEntry]) –
Either a
DefectsGenerator
object fromdoped
, or a list/dictionary of, or single,DefectEntry
object(s). E.g.:[DefectEntry(), DefectEntry(), ...]
, or singleDefectEntry
. If aDefectsGenerator
object or a dictionary (->{defect_species: DefectEntry}
), the defect folder names will be set equal todefect_species
(with charge states included). If a list or singleDefectEntry
object is provided, the defect folder names will be set equal toDefectEntry.name
if thename
attribute is set for all inputDefectEntry
s, otherwise generated according to thedoped
convention (see: https://doped.readthedocs.io/en/latest/generation_tutorial.html).Defect charge states (from which bond distortions are determined) are taken from the
DefectEntry.charge_state
property.Alternatively, a defects dict generated by
ChargedDefectStructures
fromPyCDT
/doped<2.0
can also be used as input, and the defect names and charge states generated by these codes will be used E.g.:{"bulk": {..}, "vacancies": [{...}, {...},], ...}
oxidation_states (
dict
) – Dictionary of oxidation states for species in your material, used to determine the number of defect neighbours to distort (e.g {“Cd”: +2, “Te”: -2}). If none is provided, the oxidation states will be guessed based on the bulk composition and most common oxidation states of any extrinsic species.dict_number_electrons_user (
dict
) – Optional argument to set the number of extra/missing charge (negative of electron count change) for the input defects in their neutral state, as a dictionary with format {‘defect_name’: charge_change} where charge_change is the negative of the number of extra/missing electrons. (Default: None)distortion_increment (
float
) – Bond distortion increment. Distortion factors will range from 0 to +/-0.6, in increments ofdistortion_increment
. Recommended values: 0.1-0.3 (Default: 0.1)bond_distortions (
list
) – List of bond distortions to apply to nearest neighbours, instead of the default set described above (e.g. [-0.5, 0.5]). (Default: None)local_rattle (
bool
) – Whether to apply random displacements that tail off as we move away from the defect site. Not recommended as typically worsens performance. If False (default), all supercell sites are rattled with the same amplitude (full rattle). (Default: False)distorted_elements (
dict
) – Optional argument to specify the neighbouring elements to distort for each defect, in the form of a dictionary with format {‘defect_name’: [‘element1’, ‘element2’, …]} (e.g {‘vac_1_Cd’: [‘Te’]}). If None, the closest neighbours to the defect are chosen. (Default: None)distorted_atoms (
list
) – Optional argument to specify the indices of the neighbouring atoms to distort for each defect (with indices starting from 0, matching python /pymatgen
0-indexing) for each defect, in the form of a dictionary with format:{'defect_name': [index_1, index_2, ...]}
(e.g{'vac_1_Cd': [0, 2]}
). If None (default), the closest neighbours to the defect are chosen.dimer_bond_length (
float
) – The bond length to set generated dimers in dimer distortions to, in Å. IfNone
(default), usesdistortions.get_dimer_bond_length
to estimate the dimer bond length in each case.**mc_rattle_kwargs (
dict
) –Additional keyword arguments to pass to
hiphive
’smc_rattle
function. These include:- stdev (
float
): Standard deviation (in Å) of the Gaussian distribution from which random atomic displacement distances are drawn during rattling. Default is set to 10% of the nearest neighbour distance in the bulk supercell.
- stdev (
- d_min (
float
): Minimum interatomic distance (in Å) in the rattled structure. Monte Carlo rattle moves that put atoms at distances less than this will be heavily penalised. Default is to set this to 80% of the nearest neighbour distance in the bulk supercell.
- d_min (
- max_disp (
float
): Maximum atomic displacement (in Å) during Monte Carlo rattling. Rarely occurs and is used primarily as a safety net. (Default: 2.0)
- max_disp (
- max_attempts (
int
): Limit for how many attempted rattle moves are allowed a single atom.
- max_attempts (
- active_atoms (
list
): List of the atomic indices which should undergo Monte Carlo rattling. By default, all atoms are rattled. (Default: None)
- active_atoms (
- seed (
int
): Seed from which rattle random displacements are generated. Default is to set
seed = int(distortion_factor*100
) (i.e. +40% distortion -> distortion_factor = 1.4 -> seed = 140, Rattled -> distortion_factor = 1 (no bond distortion) -> seed = 100)
- seed (
- apply_distortions(verbose: bool | None = None) tuple[dict, dict] [source]#
Applies a range of bond distortions (given by
self.bond_distortions
) and rattling to the unperturbed defect supercell structures of all defects inself.defect_entries
, usingapply_snb_distortions()
.Returns a dictionary with the distorted (and undistorted) structures for each charge state of each defect. If file generation is desired, instead use the methods
write_<code>_files()
.Note that by default, rattling is not applied to the defect site or distorted neighbours, but to all other atoms in the supercell, however this can be controlled with the
active_atoms
kwarg (inmc_rattle_kwargs
). Rattling is performed by applying random displacements to atomic positions, with the displacement distances randomly drawn from a Gaussian distribution of standard deviationstdev
, using a Monte Carlo algorithm which disfavours moves that bring atoms closer thand_min
. Rattling behaviour can be controlled withmc_rattle_kwargs
, see thedistortions.rattle()
docstring for more info.The nearest neighbours to distort are chosen by taking all sites (or those matching
distorted_element
/distorted_atoms
, if provided), then sorting by distance to the defect site (rounded to 2 decimal places) and site index, and then taking the firstnum_nearest_neighbours
of these. If there are multiple non-degenerate combinations of (nearly) equidistant NNs to distort (e.g. cis vs trans when distorting 2 NNs in a 4 NN square coordination), then the combination with distorted NNs closest to each other is chosen.The bond distortion and rattling approaches are highly customisable via
kwargs
to this class and its methods, so see the argument descriptions for more info.- Parameters:
verbose (
bool
) – Whether to print distortion information (bond atoms and distances) for each charged defect. (Default: None – medium level verbosity)- Returns:
Tuple of a dictionary with the distorted and undistorted structures for each charge state of each defect, in the format: ``` {‘defect_name’: {
- ’charges’: {
- {charge_state}: {
‘structures’: {…},
},
},
and dictionary with distortion parameters for each defect.
- Return type:
tuple
- classmethod from_structures(defects: list, bulk: Structure, oxidation_states: dict | None = None, padding: int = 1, dict_number_electrons_user: dict | None = None, distortion_increment: float = 0.1, bond_distortions: list | None = None, local_rattle: bool = False, distorted_elements: dict | None = None, distorted_atoms: list | None = None, **mc_rattle_kwargs) Distortions [source]#
Initialise
Distortions
from defect and bulk structures.See the
Distortions
docstring for information on behaviour and arguments.- Parameters:
defects (
list_or_Structure
) –List of defect structures, or a single defect structure for which to generate distorted structures. If auto site-matching fails, the fractional coordinates or index of the defect site (in defect_structure for interstitials/substitutions, in bulk_structure for vacancies) can be provided in the format:
[(defect Structure, frac_coords/index), ...]
to aid site-matching.Defect charge states (from which bond distortions are determined) are set to the range: 0 - {Defect oxidation state}, with a
padding
(default = 1) on either side of this range.bulk (
pymatgen.core.structure.Structure
) – Bulk supercell structure, matching defect supercells.oxidation_states (
dict
) – Dictionary of oxidation states for species in your material, used to determine the number of defect neighbours to distort (e.g {“Cd”: +2, “Te”: -2}). If none is provided, the oxidation states will be guessed based on the bulk composition and most common oxidation states of any extrinsic species.padding (
int
) – Defect charge states are set to the range: 0 - {Defect oxidation state}, with apadding
(default = 1) on either side of this range.dict_number_electrons_user (
dict
) – Optional argument to set the number of extra/missing charge (negative of electron count change) for the input defects in their neutral state, as a dictionary with format {‘defect_name’: charge_change} where charge_change is the negative of the number of extra/missing electrons. (Default: None)distortion_increment (
float
) – Bond distortion increment. Distortion factors will range from 0 to +/-0.6, in increments ofdistortion_increment
. Recommended values: 0.1-0.3 (Default: 0.1)bond_distortions (
list
) – List of bond distortions to apply to nearest neighbours, instead of the default set (e.g. [-0.5, 0.5]). (Default: None)local_rattle (
bool
) – Whether to apply random displacements that tail off as we move away from the defect site. Not recommended as typically worsens performance. If False (default), all supercell sites are rattled with the same amplitude (full rattle). (Default: False)distorted_elements (
dict
) – Optional argument to specify the neighbouring elements to distort for each defect, in the form of a dictionary with format {‘defect_name’: [‘element1’, ‘element2’, …]} (e.g {‘vac_1_Cd’: [‘Te’]}). If None, the closest neighbours to the defect are chosen. (Default: None)distorted_atoms (
list
) – Optional argument to specify the indices of the neighbouring atoms to distort for each defect (with indices starting from 0, matching python /pymatgen
0-indexing), in the form of a dictionary with format:{'defect_name': [atom1, atom2, ...]}
(e.g{'vac_1_Cd': [0, 1]}
). If None, the closest neighbours to the defect are chosen. (Default: None)**mc_rattle_kwargs (
dict
) –Additional keyword arguments to pass to
hiphive
’smc_rattle
function. These include:- stdev (
float
): Standard deviation (in Å) of the Gaussian distribution from which random atomic displacement distances are drawn during rattling. Default is set to 10% of the nearest neighbour distance in the bulk supercell.
- stdev (
- d_min (
float
): Minimum interatomic distance (in Å) in the rattled structure. Monte Carlo rattle moves that put atoms at distances less than this will be heavily penalised. Default is to set this to 80% of the nearest neighbour distance in the bulk supercell.
- d_min (
- max_disp (
float
): Maximum atomic displacement (in Å) during Monte Carlo rattling. Rarely occurs and is used primarily as a safety net. (Default: 2.0)
- max_disp (
- max_attempts (
int
): Limit for how many attempted rattle moves are allowed a single atom.
- max_attempts (
- active_atoms (
list
): List of the atomic indices which should undergo Monte Carlo rattling. By default, all atoms are rattled. (Default: None)
- active_atoms (
- seed (
int
): Seed from which rattle random displacements are generated. Default is to set seed = int(distortion_factor*100) (i.e. +40% distortion -> distortion_factor = 1.4 -> seed = 140, Rattled -> distortion_factor = 1 (no bond distortion) -> seed = 100)
- seed (
- write_castep_files(input_file: str | None = '/home/docs/checkouts/readthedocs.org/user_builds/shakenbreak/checkouts/latest/shakenbreak/SnB_input_files/castep.param', write_structures_only: bool | None = False, output_path: str = '.', verbose: bool | None = None) tuple[dict, dict] [source]#
Generates input
.cell
and.param
files for CASTEP relaxations of all output structures fromDistortions.apply_distortions()
.See the
Distortions.apply_distortions()
docstring for info on the distortion generation approach.- Parameters:
input_file (
str
, optional) – Path to CASTEP input (.param
) file. If not set, default input file will be used (seeshakenbreak/SnB_input_files/castep.param
).write_structures_only (
bool
, optional) – Whether to only write the structure files (in CIF format) (without calculation inputs). (Default: False)output_path (
str
, optional) – Path to directory in which to write distorted defect structures and calculation inputs. (Default is current directory: “.”)verbose (
bool
, optional) – Whether to print distortion information (bond atoms and distances). (Default: None – medium level verbosity)
- Returns:
Tuple of dictionaries with new defects_dict (containing the distorted structures) and defect distortion parameters.
- Return type:
tuple
- write_cp2k_files(input_file: str | None = None, write_structures_only: bool | None = False, output_path: str = '.', verbose: bool | None = None) tuple[dict, dict] [source]#
Generates input files for CP2K relaxations of all output structures from
Distortions.apply_distortions()
.See the
Distortions.apply_distortions()
docstring for info on the distortion generation approach.- Parameters:
input_file (
str
, optional) – Path to CP2K input file. If not set, default input file will be used (seeshakenbreak/SnB_input_files/cp2k_input.inp
).write_structures_only (
bool
, optional) – Whether to only write the structure files (in CIF format) (without calculation inputs). (Default: False)output_path (
str
, optional) – Path to directory in which to write distorted defect structures and calculation inputs. (Default is current directory: “.”)verbose (
bool
, optional) – Whether to print distortion information (bond atoms and distances). (Default: None – medium level verbosity)
- Returns:
Tuple of dictionaries with new defects_dict (containing the distorted structures) and defect distortion parameters.
- Return type:
tuple
- write_distortion_metadata(output_path: str = '.', defect: str | None = None, charge: int | None = None) None [source]#
Write distortion metadata to file.
If the file already exists then the previous metadata will be renamed to
distortion_metadata_<datetime>.json
(if it differs from the current metadata), and also combined with the current metadata if compatible (i.e. if they are using similar distortion parameters and only differ in the set of defects / charge states / distortions used), before writing this combined metadata to file.If defect and/or charge are specified, then only distortion metadata for that defect and/or charge state will be written.
- Parameters:
output_path (
str
) – Path to directory where the metadata file will be written.defect (
str
) – Name of the defect for which to write the metadata. If None, the metadata for all defects will be written. (Default: None)charge (
int
) – Charge state of the defect for which to write the metadata. If None, the metadata for all charge states of the defect will be written. (Default: None)
- Returns:
None
- write_espresso_files(pseudopotentials: dict | None = None, input_parameters: str | None = None, input_file: str | None = None, write_structures_only: bool | None = False, output_path: str = '.', verbose: bool | None = None, profile=None) tuple[dict, dict] [source]#
Generates input files for Quantum Espresso relaxations of all output structures from
Distortions.apply_distortions()
.See the
Distortions.apply_distortions()
docstring for info on the distortion generation approach.- Parameters:
pseudopotentials (
dict
, optional) – Dictionary matching element to pseudopotential name. (Defaults: None)input_parameters (
dict
, optional) – Dictionary of user Quantum Espresso input parameters, to overwrite/update ShakeNBreak defaults (seeshakenbreak/SnB_input_files/qe_input.yaml
). (Default: None)input_file (
str
, optional) – Path to Quantum Espresso input file, to overwrite/update ShakeNBreak defaults (seeshakenbreak/SnB_input_files/qe_input.yaml
). If bothinput_parameters
andinput_file
are provided, the input_parameters will be used. (Default: None)write_structures_only (
bool
, optional) – Whether to only write the structure files (in CIF format) (without calculation inputs). (Default: False)output_path (
str
, optional) – Path to directory in which to write distorted defect structures and calculation inputs. (Default is current directory: “.”)verbose (
bool
) – Whether to print distortion information (bond atoms and distances). (Default: None – medium level verbosity)profile (
BaseProfile
, optional) – ASE profile object to use for theEspresso()
calculator class, if using ase>=3.23. IfNone
(default), set toEspressoProfile(command="pw.x", pseudo_dir=".")
.
- Returns:
Tuple of dictionaries with new defects_dict (containing the distorted structures) and defect distortion parameters.
- Return type:
tuple
- write_fhi_aims_files(input_file: str | None = None, ase_calculator=None, write_structures_only: bool | None = False, output_path: str = '.', verbose: bool | None = None, profile=None) tuple[dict, dict] [source]#
Generates input geometry and control files for FHI-aims relaxations of all output structures from
Distortions.apply_distortions()
.See the
Distortions.apply_distortions()
docstring for info on the distortion generation approach.Note that if using ASE >= 3.23 and not
write_structures_only
, the$AIMS_SPECIES_DIR
environment variable must be set.- Parameters:
input_file (
str
, optional) – Path to FHI-aims input file, to overwrite/updateshakenbreak
default ones. If bothinput_file
andase_calculator
are provided, the ase_calculator will be used.ase_calculator (
Aims
,AimsTemplate
, optional) – Either anAims
(ASE calculator) orAimsTemplate
object to obtain parameters from, for FHI-aims calculations. If not set,ShakeNBreak
default values will be used. Recommended to check these! (Default: None)write_structures_only (
bool
, optional) – Whether to only write the structure files (ingeometry.in
format), without thecontrol.in
file.output_path (
str
, optional) – Path to directory in which to write distorted defect structures and calculation inputs. (Default is current directory: “.”)verbose (
bool
, optional) – Whether to print distortion information (bond atoms and distances). (Default: None – medium level verbosity)profile (
BaseProfile
, optional) – ASE profile object to use for theAims()
calculator class, if using ase>=3.23. IfNone
(default), set toAimsProfile(command="fhiaims.x")
.
- Returns:
Tuple of dictionaries with new defects_dict (containing the distorted structures) and defect distortion parameters.
- Return type:
tuple
- write_vasp_files(user_incar_settings: dict | None = None, user_potcar_functional: str | None = 'PBE', user_potcar_settings: dict | None = None, output_path: str = '.', verbose: bool | None = None, **kwargs) tuple[dict, dict] [source]#
Generates the input files for
vasp_gam
relaxations of all output structures fromDistortions.apply_distortions()
.See the
Distortions.apply_distortions()
docstring for info on the distortion generation approach.- Parameters:
user_incar_settings (
dict
) – Dictionary of user VASP INCAR settings (e.g. {“ENCUT”: 300, …}), to overwrite theShakenBreak
defaults for those tags. Highly recommended to look at outputINCAR
s, orshakenbreak/SnB_input_files/incar.yaml
to see what the defaultINCAR
settings are. Note that any flags that aren’t numbers or True/False need to be input as strings with quotation marks (e.g.{"ALGO": "All"}
). (Default: None)user_potcar_functional (str) – POTCAR functional to use. Default is “PBE” and if this fails, tries “PBE_52”, then “PBE_54”.
user_potcar_settings (
dict
) – Dictionary of user VASP POTCAR settings, to overwrite/update thedoped
defaults (e.g. {‘Fe’: ‘Fe_pv’, ‘O’: ‘O’}}). Highly recommended to look at outputPOTCAR
s, orshakenbreak/SnB_input_files/default_POTCARs.yaml
, to see what the defaultPOTCAR
settings are. (Default: None)write_files (
bool
) – Whether to write output files (Default: True)output_path (
str
) – Path to directory in which to write distorted defect structures and calculation inputs. (Default is current directory = “.”)verbose (
bool
) – Whether to print distortion information (bond atoms and distances). (Default: None – medium level verbosity)kwargs – Additional keyword arguments to pass to
_create_vasp_input()
(Mainly for testing purposes).
- Returns:
tuple of dictionaries with new defects_dict (containing the distorted structures) and defect distortion parameters.
- Return type:
tuple
- shakenbreak.input.apply_snb_distortions(defect_entry: DefectEntry, num_nearest_neighbours: int, bond_distortions: list, local_rattle: bool = False, stdev: float | None = None, d_min: float | None = None, distorted_element: str | None = None, distorted_atoms: list | None = None, oxidation_states: dict | None = None, verbose: bool = False, dimer_bond_length: float | None = None, **mc_rattle_kwargs) dict [source]#
Applies a range of bond distortions (given by
bond_distortions
) and rattling tonum_nearest_neighbours
of the unperturbed defect supercell structure ofdefect_entry
, generating a range of distorted structures, usingdistort_and_rattle_defect_entry()
.Note that by default, rattling is not applied to the defect site or distorted neighbours, but to all other atoms in the supercell, however this can be controlled with the
active_atoms
kwarg. Rattling is performed by applying random displacements to atomic positions, with the displacement distances randomly drawn from a Gaussian distribution of standard deviationstdev
, using a Monte Carlo algorithm which disfavours moves that bring atoms closer thand_min
. Rattling behaviour can be controlled withmc_rattle_kwargs
, see thedistortions.rattle()
docstring for more info. Note that dimer distortions can be generated by including"Dimer"
in thebond_distortions
list; seedistortions.apply_dimer_distortion()
for more info.The nearest neighbours to distort are chosen by taking all sites (or those matching
distorted_element
/distorted_atoms
, if provided), then sorting by distance to the defect site (rounded to 2 decimal places) and site index, and then taking the firstnum_nearest_neighbours
of these. If there are multiple non-degenerate combinations of (nearly) equidistant NNs to distort (e.g. cis vs trans when distorting 2 NNs in a 4 NN square coordination), then the combination with distorted NNs closest to each other is chosen.- Parameters:
defect_entry (
DefectEntry
) – The defect to distort, as adoped
/pymatgen
DefectEntry
.num_nearest_neighbours (
int
) – Number of defect nearest neighbours to apply bond distortions to.bond_distortions (
list
) – List of specific distortions to apply to defect nearest neighbours (e.g. [-0.5, 0.5]). If “Dimer” is included, then a dimer distortion is also generated.local_rattle (
bool
) – Whether to apply random displacements that tail off as we move away from the defect site. If False, all supercell sites are rattled with the same amplitude. (Default: False)stdev (
float
) – Standard deviation (in Angstroms) of the Gaussian distribution from which random atomic displacement distances are drawn during rattling. Default is set to 10% of the bulk nearest neighbour distance.d_min (
float
, optional) – Minimum interatomic distance (in Angstroms) in the rattled structure. Monte Carlo rattle moves that put atoms at distances less than this will be heavily penalised. Default is to set this to 80% of the nearest neighbour distance in the bulk supercell.distorted_element (
str
, optional) – Neighbouring element to distort. If None, the closest neighbours to the defect will be chosen. (Default: None)distorted_atoms (
list
, optional) – List of atomic indices which should undergo bond distortions, using 0-indexing (i.e. python /pymatgen
indexing). If None, the closest neighbours to the defect will be chosen. (Default: None)oxidation_states (
dict
) – Dictionary with oxidation states of the atoms in the material (e.g. {“Cd”: +2, “Te”: -2}).verbose (
bool
) – Whether to print distortion information. (Default: False)dimer_bond_length (
float
) – The bond length to set generated dimers in dimer distortions to, in Å. IfNone
(default), usesdistortions.get_dimer_bond_length
to estimate the dimer bond length in each case.**mc_rattle_kwargs (
dict
) –Additional keyword arguments to pass to
hiphive
’smc_rattle
function. These include:- max_disp (
float
): Maximum atomic displacement (in Å) during Monte Carlo rattling. Rarely occurs and is used primarily as a safety net. (Default: 2.0)
- max_disp (
- max_attempts (
int
): Limit for how many attempted rattle moves are allowed a single atom.
- max_attempts (
- active_atoms (
list
): List of the atomic indices which should undergo Monte Carlo rattling. By default, all atoms are rattled. (Default: None)
- active_atoms (
- seed (
int
): Seed from which rattle random displacements are generated. Default is to set
seed = int(distortion_factor*100)
(i.e. +40% distortion -> distortion_factor = 1.4 -> seed = 140, Rattled -> distortion_factor = 1 (no bond distortion) -> seed = 100)
- seed (
- Returns:
Dictionary with distorted defect structure and the distortion parameters.
- Return type:
dict
- shakenbreak.input.bold_print(string: str) None [source]#
Prints the input string in bold.
- Parameters:
string (
str
) – String to print in bold.
- shakenbreak.input.distort_and_rattle_defect_entry(defect_entry: DefectEntry, num_nearest_neighbours: int, distortion_factor: float | str, local_rattle: bool = False, stdev: float | None = None, d_min: float | None = None, active_atoms: list | None = None, distorted_element: str | None = None, distorted_atoms: list | None = None, oxidation_states: dict | None = None, verbose: bool = False, dimer_bond_length: float | None = None, **mc_rattle_kwargs) dict [source]#
Applies bond distortions and rattling to
num_nearest_neighbours
of the unperturbed defect supercell structure ofdefect_entry
using thedistort_and_rattle()
function fromshakenbreak.distortions
.The defect site is specified by either:
fractional coordinates (for vacancies), or
defect site index (for substitutions/interstitials).
Note that by default, rattling is not applied to the defect site or distorted neighbours, but to all other atoms in the supercell, however this can be controlled with the
active_atoms
kwarg. Rattling is performed by applying random displacements to atomic positions, with the displacement distances randomly drawn from a Gaussian distribution of standard deviationstdev
, using a Monte Carlo algorithm which disfavours moves that bring atoms closer thand_min
. Rattling behaviour can be controlled withmc_rattle_kwargs
, see thedistortions.rattle()
docstring for more info. Note that dimer distortions can be generated by settingdistortion_factor
to “Dimer”; seedistortions.apply_dimer_distortion()
for more info.The nearest neighbours to distort are chosen by taking all sites (or those matching
distorted_element
/distorted_atoms
, if provided), then sorting by distance to the defect site (rounded to 2 decimal places) and site index, and then taking the firstnum_nearest_neighbours
of these. If there are multiple non-degenerate combinations of (nearly) equidistant NNs to distort (e.g. cis vs trans when distorting 2 NNs in a 4 NN square coordination), then the combination with distorted NNs closest to each other is chosen.- Parameters:
defect_entry (
DefectEntry
) – The defect to distort, as adoped
/pymatgen
DefectEntry
.num_nearest_neighbours (
int
) – Number of defect nearest neighbours to apply bond distortions to.distortion_factor (
float
) – The distortion factor or distortion name (“Dimer”) to apply to the bond distance between the defect and nearest neighbours. Typical choice is between 0.4 (-60%) and 1.6 (+60%).local_rattle (
bool
) – Whether to apply random displacements that tail off as we move away from the defect site. If False, all supercell sites are rattled with the same amplitude. (Default: False)stdev (
float
) – Standard deviation (in Angstroms) of the Gaussian distribution from which random atomic displacement distances are drawn during rattling. Default is set to 10% of the bulk nearest neighbour distance.d_min (
float
) – Minimum interatomic distance (in Angstroms) in the rattled structure. Monte Carlo rattle moves that put atoms at distances less than this will be heavily penalised. Default is to set this to 80% of the nearest neighbour distance in the defect supercell (ignoring interstitials).active_atoms (
list
, optional) – List (or array) of which atomic indices should undergo Monte Carlo rattling. Default is to apply rattle to all atoms except the defect and the bond-distorted neighbours.distorted_element (
str
, optional) – Neighbouring element to distort. If None, the closest neighbours to the defect will be chosen. (Default: None)distorted_atoms (
list
, optional) – List of atomic indices which should undergo bond distortions, using 0-indexing (i.e. python /pymatgen
indexing). If None, the closest neighbours to the defect will be chosen. (Default: None)oxidation_states (
dict
) – Dictionary with oxidation states of the atoms in the material (e.g. {“Cd”: +2, “Te”: -2}).verbose (
bool
) – Whether to print distortion information. (Default: False)dimer_bond_length (
float
) – The bond length to set generated dimers in dimer distortions to, in Å. IfNone
(default), usesdistortions.get_dimer_bond_length
to estimate the dimer bond length.**mc_rattle_kwargs (
dict
) –Additional keyword arguments to pass to
hiphive
’smc_rattle
function. These include:- max_disp (
float
): Maximum atomic displacement (in Å) during Monte Carlo rattling. Rarely occurs and is used primarily as a safety net. (Default: 2.0)
- max_disp (
- max_attempts (
int
): Limit for how many attempted rattle moves are allowed a single atom.
- max_attempts (
- active_atoms (
list
): List of the atomic indices which should undergo Monte Carlo rattling. By default, all atoms are rattled. (Default: None)
- active_atoms (
- seed (
int
): Seed for setting up NumPy random state from which rattle random displacements are generated.
- seed (
- Returns:
Dictionary with distorted defect structure and the distortion parameters.
- Return type:
dict
- shakenbreak.input.generate_defect_object(single_defect_dict: dict, bulk_dict: dict, charges: list | None = None, verbose: bool = False) Defect [source]#
Create
Defect
object from adoped
/PyCDT
single_defect_dict
.- Parameters:
single_defect_dict (
dict
) –doped
/PyCDT
defect dictionary.bulk_dict (
dict
) –doped
/PyCDT
entry for bulk in thedefect_entries
dictionary, (e.g.{"vacancies": {}, "interstitials": {}, "bulk": {},}
)charges (
list
) – List of charge states for the defect.verbose (
bool
) – Whether to print information about the defect object being parsed. (Default is False).
Returns:
Defect
- shakenbreak.input.identify_defect(defect_structure, bulk_structure, defect_coords=None, defect_index=None, oxi_state=None) Defect [source]#
By comparing the defect and bulk structures, identify the defect present and its site in the supercell, and generate a
doped
Defect
object from this.- Parameters:
defect_structure (
Structure
) – Defect structurebulk_structure (
Structure
) – Bulk structuredefect_coords (
list
) – Fractional coordinates of the defect site in the supercell.defect_index (
int
) – Index of the defect site in the supercell. For vacancies, this should be the site index in the bulk structure, while for substitutions and interstitials it should be the site index in the defect structure.oxi_state (
int
,float
,str
) – Oxidation state of the defect site. If not provided, will be automatically determined from the defect structure.
Returns:
Defect