doped.core module
Core functions and classes for defects in doped.
- class doped.core.Defect(structure: Structure, site: PeriodicSite, multiplicity: int | None = None, oxi_state: float | None = None, equivalent_sites: List[PeriodicSite] | None = None, symprec: float = 0.01, angle_tolerance: float = 5, user_charges: List[int] | None = None, **doped_kwargs)[source]
Bases:
DefectDoped Defect object.
Subclass of pymatgen.analysis.defects.core.Defect with additional attributes and methods used by doped.
- Parameters:
structure – The structure in which to create the defect. Typically the primitive structure of the host crystal for defect generation, and/or the calculation supercell for defect parsing.
site – The defect site in the structure.
multiplicity – The multiplicity of the defect in the structure.
oxi_state – The oxidation state of the defect, if not specified, this will be determined automatically.
equivalent_sites – A list of equivalent sites for the defect in the structure.
symprec – Tolerance for symmetry finding.
angle_tolerance – Angle tolerance for symmetry finding.
user_charges – User specified charge states. If specified,
get_charge_stateswill return this list. IfNoneor empty list the charge states will be determined automatically.**doped_kwargs – Additional keyword arguments to define doped-specific attributes (listed below), in the form
doped_attribute_name=value. (e.g.wyckoff = "4a").
- as_dict()[source]
JSON-serializable dict representation of Defect.
Needs to be redefined because attributes not explicitly specified in subclasses, which is required for monty functions.
- classmethod from_json(filename: str)[source]
Load a Defect object from a json file.
- Parameters:
filename (str) – Filename of json file to load Defect from.
- Returns:
Defect object
- get_supercell_structure(sc_mat: ndarray | None = None, target_frac_coords: ndarray | None = None, return_sites: bool = False, min_image_distance: float = 10.0, min_atoms: int = 50, force_cubic: bool = False, force_diagonal: bool = False, ideal_threshold: float = 0.1, min_length: float | None = None, dummy_species: str | None = None) Structure[source]
Generate the simulation supercell for a defect.
Redefined from the parent class to allow the use of
target_frac_coordsto place the defect at the closest equivalent site to the target fractional coordinates in the supercell, while keeping the supercell fixed (to avoid any issues with defect parsing). Also returns information about equivalent defect sites in the supercell.If
sc_matis None, then the supercell is generated automatically using thedopedalgorithm described in theget_ideal_supercell_matrixfunction docstring indoped.generation.- Parameters:
sc_mat (3x3 matrix) – Transformation matrix of
self.structureto create the supercell. If None, then automatically computed usingget_ideal_supercell_matrixfromdoped.generation.target_frac_coords (3x1 matrix) – If set, the defect will be placed at the closest equivalent site to these fractional coordinates (using self.equivalent_sites).
return_sites (bool) – If True, returns a tuple of the defect supercell, defect supercell site and list of equivalent supercell sites.
dummy_species (str) – Dummy species to highlight the defect position (for visualizing vacancies).
min_image_distance (float) – Minimum image distance in Å of the generated supercell (i.e. minimum distance between periodic images of atoms/sites in the lattice), if
sc_matis None. (Default = 10.0)min_atoms (int) – Minimum number of atoms allowed in the generated supercell, if
sc_matis None. (Default = 50)force_cubic (bool) – Enforce usage of
CubicSupercellTransformationfrompymatgenfor supercell generation (ifsc_matis None). (Default = False)force_diagonal (bool) – If True, return a transformation with a diagonal transformation matrix (if
sc_matis None). (Default = False)ideal_threshold (float) – Threshold for increasing supercell size (beyond that which satisfies
min_image_distanceand min_atoms`) to achieve an ideal supercell matrix (i.e. a diagonal expansion of the primitive or conventional cell). Supercells up to1 + perfect_cell_thresholdtimes larger (rounded up) are trialled, and will instead be returned if they yield an ideal transformation matrix (ifsc_matis None). (Default = 0.1; i.e. 10% larger than the minimum size)min_length (float) – Same as
min_image_distance(kept for compatibility).
- Returns:
The defect supercell structure. If
return_sitesis True, also returns the defect supercell site and list of equivalent supercell sites.
- class doped.core.DefectEntry(defect: ~doped.core.Defect, charge_state: int, sc_entry: ~pymatgen.entries.computed_entries.ComputedStructureEntry, corrections: ~typing.Dict[str, float] = <factory>, corrections_metadata: ~typing.Dict[str, ~typing.Any] = <factory>, sc_defect_frac_coords: ~typing.Tuple[float, float, float] | None = None, bulk_entry: ~pymatgen.entries.computed_entries.ComputedEntry | None = None, entry_id: str | None = None, name: str = '', calculation_metadata: ~typing.Dict = <factory>, degeneracy_factors: ~typing.Dict = <factory>, conventional_structure: ~pymatgen.core.structure.Structure | None = None, conv_cell_frac_coords: ~numpy.ndarray | None = None, equiv_conv_cell_frac_coords: ~typing.List[~numpy.ndarray] = <factory>, _BilbaoCS_conv_cell_vector_mapping: ~typing.List[int] = <factory>, wyckoff: str | None = None, charge_state_guessing_log: ~typing.Dict = <factory>, defect_supercell: ~pymatgen.core.structure.Structure | None = None, defect_supercell_site: ~pymatgen.core.sites.PeriodicSite | None = None, equivalent_supercell_sites: ~typing.List[~pymatgen.core.sites.PeriodicSite] = <factory>, bulk_supercell: ~pymatgen.core.structure.Structure | None = None)[source]
Bases:
DefectEntrySubclass of pymatgen.analysis.defects.thermo.DefectEntry with additional attributes used by doped.
- Core Attributes:
- defect:
doped/pymatgen defect object corresponding to the defect in the entry.
- charge_state:
Charge state of the defect.
- sc_entry:
pymatgenComputedStructureEntryfor the defect supercell.- sc_defect_frac_coords:
The fractional coordinates of the defect in the supercell.
- bulk_entry:
pymatgenComputedEntryfor the bulk supercell reference. Required for calculating the defect formation energy.- corrections:
A dictionary of energy corrections which are summed and added to the defect formation energy.
- corrections_metadata:
A dictionary that acts as a generic container for storing information about how the corrections were calculated. Only used for debugging and plotting purposes.
- Parsing Attributes:
- calculation_metadata:
A dictionary of calculation parameters and data, used to perform charge corrections and compute formation energies.
- degeneracy_factors:
A dictionary of degeneracy factors contributing to the total degeneracy of the defect species (such as spin and configurational degeneracy etc). This is an important factor in the defect concentration equation (see discussion in doi.org/10.1039/D2FD00043A and doi.org/10.1039/D3CS00432E), and so affects the output of the defect concentration / Fermi level functions. This can be edited by the user if the doped defaults are not appropriate (e.g. doped assumes singlet (S=0) state for even-electron defects and doublet (S=1/2) state for odd-electron defects, which is typically the case but can have triplets (S=1) or other multiplets for e.g. bipolarons, quantum / d-orbital / magnetic defects etc).
- Generation Attributes:
- name:
The doped-generated name of the defect entry. See docstrings of DefectsGenerator for the doped naming algorithm.
- conventional_structure:
Conventional cell structure of the host according to the Bilbao Crystallographic Server (BCS) definition, used to determine defect site Wyckoff labels and multiplicities.
- conv_cell_frac_coords:
Fractional coordinates of the defect in the conventional cell.
- equiv_conv_cell_frac_coords:
Symmetry-equivalent defect positions in fractional coordinates of the conventional cell.
- _BilbaoCS_conv_cell_vector_mapping:
A vector mapping the lattice vectors of the spglib-defined conventional cell to that of the Bilbao Crystallographic Server definition (for most space groups the definitions are the same).
- wyckoff:
Wyckoff label of the defect site.
- charge_state_guessing_log:
A log of the input & computed values used to determine charge state probabilities.
- defect_supercell:
pymatgen Structure object of the defect supercell.
- defect_supercell_site:
pymatgen PeriodicSite object of the defect in the defect supercell.
- equivalent_supercell_sites:
List of pymatgen PeriodicSite objects of symmetry-equivalent defect sites in the defect supercell.
- bulk_supercell:
pymatgen Structure object of the bulk (pristine, defect-free) supercell.
- bulk_entry: ComputedEntry | None = None
- bulk_supercell: Structure | None = None
- calculation_metadata: Dict
- charge_state: int
- charge_state_guessing_log: Dict
- conv_cell_frac_coords: ndarray | None = None
- conventional_structure: Structure | None = None
- property corrected_energy: float
The energy of the defect entry with all corrections applied.
- corrections: Dict[str, float]
- corrections_metadata: Dict[str, Any]
- defect_supercell: Structure | None = None
- defect_supercell_site: PeriodicSite | None = None
- degeneracy_factors: Dict
- entry_id: str | None = None
- equilibrium_concentration(chempots: dict | None = None, limit: str | None = None, el_refs: dict | None = None, temperature: float = 300, fermi_level: float = 0, vbm: float | None = None, per_site: bool = False) float[source]
Compute the equilibrium concentration (in cm^-3) for the DefectEntry at a given chemical potential limit, fermi_level and temperature, assuming the dilute limit approximation.
Note that these are the equilibrium defect concentrations! DefectThermodynamics.get_quenched_fermi_level_and_concentrations() can instead be used to calculate the Fermi level and defect concentrations for a material grown/annealed at higher temperatures and then cooled (quenched) to room/operating temperature (where defect concentrations are assumed to remain fixed) - this is known as the frozen defect approach and is typically the most valid approximation (see its docstring for more information, and discussion in 10.1039/D3CS00432E).
The degeneracy/multiplicity factor “g” is an important parameter in the defect concentration equation (see discussion in doi.org/10.1039/D2FD00043A and doi.org/10.1039/D3CS00432E), affecting the final concentration by up to 2 orders of magnitude. This factor is taken from the product of the defect_entry.defect.multiplicity and defect_entry.degeneracy_factors attributes.
- Parameters:
chempots (dict) –
Dictionary of chemical potentials to use for calculating the defect formation energy (and thus concentration). This can have the form of:
{"limits": [{'limit': [chempot_dict]}]}(the format generated bydoped's chemical potential parsing functions (see tutorials)) and specific limits (chemical potential limits) can then be chosen usinglimit.Alternatively this can be a dictionary of chemical potentials for a single limit (limit), in the format:
{element symbol: chemical potential}. If manually specifying chemical potentials this way, you can set theel_refsoption with the DFT reference energies of the elemental phases, in which case it is the formal chemical potentials (i.e. relative to the elemental references) that should be given here, otherwise the absolute (DFT) chemical potentials should be given.If None (default), sets all chemical potentials to 0 (inaccurate formation energies and concentrations!). (Default: None)
limit (str) –
The chemical potential limit for which to calculate the formation energy and thus concentration. Can be either:
None (default), if
chempotscorresponds to a single chemical potential limit - otherwise will use the first chemical potential limit in thechempotsdict.”X-rich”/”X-poor” where X is an element in the system, in which case the most X-rich/poor limit will be used (e.g. “Li-rich”).
A key in the
(self.)chempots["limits"]dictionary.
The latter two options can only be used if
chempotsis in thedopedformat (see chemical potentials tutorial). (Default: None)el_refs (dict) – Dictionary of elemental reference energies for the chemical potentials in the format:
{element symbol: reference energy}(to determine the formal chemical potentials, whenchempotshas been manually specified as{element symbol: chemical potential}). Unnecessary ifchempotsis provided/present in format generated bydoped(see tutorials). (Default: None)temperature (float) – Temperature in Kelvin at which to calculate the equilibrium concentration.
vbm (float) – VBM eigenvalue in the bulk supercell, to use as Fermi level reference point for calculating formation energy. If None (default), will use “vbm” from the calculation_metadata dict attribute if present.
fermi_level (float) – Value corresponding to the electron chemical potential, referenced to the VBM. Default is 0 (i.e. the VBM).
per_site (bool) – Whether to return the concentration as fractional concentration per site, rather than the default of per cm^3. (default: False)
- Returns:
Concentration in cm^-3 (or as fractional per site, if per_site = True) (float)
- equiv_conv_cell_frac_coords: List[ndarray]
- equivalent_supercell_sites: List[PeriodicSite]
- formation_energy(chempots: dict | None = None, limit: str | None = None, el_refs: dict | None = None, vbm: float | None = None, fermi_level: float = 0) float[source]
Compute the formation energy for the DefectEntry at a given chemical potential limit and fermi_level.
- Parameters:
chempots (dict) –
Dictionary of chemical potentials to use for calculating the defect formation energy. This can have the form of:
{"limits": [{'limit': [chempot_dict]}]}(the format generated bydoped's chemical potential parsing functions (see tutorials)) and specific limits (chemical potential limits) can then be chosen usinglimit.Alternatively this can be a dictionary of chemical potentials for a single limit (limit), in the format:
{element symbol: chemical potential}. If manually specifying chemical potentials this way, you can set theel_refsoption with the DFT reference energies of the elemental phases, in which case it is the formal chemical potentials (i.e. relative to the elemental references) that should be given here, otherwise the absolute (DFT) chemical potentials should be given.If None (default), sets all chemical potentials to zero. (Default: None)
limit (str) –
The chemical potential limit for which to calculate the formation energy. Can be either:
None (default), if
chempotscorresponds to a single chemical potential limit - otherwise will use the first chemical potential limit in thechempotsdict.”X-rich”/”X-poor” where X is an element in the system, in which case the most X-rich/poor limit will be used (e.g. “Li-rich”).
A key in the
(self.)chempots["limits"]dictionary.
The latter two options can only be used if
chempotsis in thedopedformat (see chemical potentials tutorial). (Default: None)el_refs (dict) – Dictionary of elemental reference energies for the chemical potentials in the format:
{element symbol: reference energy}(to determine the formal chemical potentials, whenchempotshas been manually specified as{element symbol: chemical potential}). Unnecessary ifchempotsis provided/present in format generated bydoped(see tutorials). (Default: None)vbm (float) – VBM eigenvalue in the bulk supercell, to use as Fermi level reference point for calculating formation energy. If None (default), will use “vbm” from the calculation_metadata dict attribute if present.
fermi_level (float) – Value corresponding to the electron chemical potential, referenced to the VBM. Default is 0 (i.e. the VBM).
- Returns:
Formation energy value (float)
- classmethod from_json(filename: str)[source]
Load a DefectEntry object from a json file.
- Parameters:
filename (str) – Filename of json file to load DefectEntry from.
- Returns:
DefectEntry object
- get_freysoldt_correction(dielectric: float | int | ndarray | list | None = None, defect_locpot: str | Locpot | dict | None = None, bulk_locpot: str | Locpot | dict | None = None, plot: bool = False, filename: str | None = None, axis=None, return_correction_error: bool = False, error_tolerance: float = 0.05, style_file: str | None = None, **kwargs) CorrectionResult[source]
Compute the isotropic Freysoldt (FNV) correction for the defect_entry.
The correction is added to the
defect_entry.correctionsdictionary (to be used in following formation energy calculations). If this correction is used, please cite Freysoldt’s original paper; 10.1103/PhysRevLett.102.016402.- Parameters:
dielectric (float or int or 3x1 matrix or 3x3 matrix) – Total dielectric constant of the host compound (including both ionic and (high-frequency) electronic contributions), in the same xyz Cartesian basis as the supercell calculations. If None, then the dielectric constant is taken from the
defect_entrycalculation_metadataif available.defect_locpot – Path to the output VASP LOCPOT file from the defect supercell calculation, or the corresponding pymatgen Locpot object, or a dictionary of the planar-averaged potential in the form: {i: Locpot.get_average_along_axis(i) for i in [0,1,2]}. If None, will try to use
defect_locpotfrom thedefect_entrycalculation_metadataif available.bulk_locpot – Path to the output VASP LOCPOT file from the bulk supercell calculation, or the corresponding pymatgen Locpot object, or a dictionary of the planar-averaged potential in the form: {i: Locpot.get_average_along_axis(i) for i in [0,1,2]}. If None, will try to use
bulk_locpotfrom thedefect_entrycalculation_metadataif available.plot (bool) – Whether to plot the FNV electrostatic potential plots (for manually checking the behaviour of the charge correction here).
filename (str) – Filename to save the FNV electrostatic potential plots to. If None, plots are not saved.
axis (int or None) – If int, then the FNV electrostatic potential plot along the specified axis (0, 1, 2 for a, b, c) will be plotted. Note that the output charge correction is still that for all axes. If None, then all three axes are plotted.
return_correction_error (bool) – If True, also returns the average standard deviation of the planar-averaged potential difference times the defect charge (which gives an estimate of the error range of the correction energy). Default is False.
error_tolerance (float) – If the estimated error in the charge correction is greater than this value (in eV), then a warning is raised. (default: 0.05 eV)
style_file (str) – Path to a
.mplstylefile to use for the plot. IfNone(default), uses the default doped style (fromdoped/utils/doped.mplstyle).**kwargs – Additional kwargs to pass to pymatgen.analysis.defects.corrections.freysoldt.get_freysoldt_correction (e.g. energy_cutoff, mad_tol, q_model, step).
- Returns:
CorrectionResults (summary of the corrections applied and metadata), and the matplotlib figure object (or axis object if axis specified) if
plotis True, and the estimated charge correction error ifreturn_correction_erroris True.
- get_kumagai_correction(dielectric: float | int | ndarray | list | None = None, defect_region_radius: float | None = None, excluded_indices: List[int] | None = None, defect_outcar: str | Outcar | None = None, bulk_outcar: str | Outcar | None = None, plot: bool = False, filename: str | None = None, return_correction_error: bool = False, error_tolerance: float = 0.05, style_file: str | None = None, **kwargs)[source]
Compute the Kumagai (eFNV) finite-size charge correction for the defect_entry. Compatible with both isotropic/cubic and anisotropic systems.
The correction is added to the
defect_entry.correctionsdictionary (to be used in following formation energy calculations). If this correction is used, please cite the Kumagai & Oba paper: 10.1103/PhysRevB.89.195205Typically for reasonably well-converged supercell sizes, the default
defect_region_radiusworks perfectly well. However, for certain materials at small/intermediate supercell sizes, you may want to adjust this (and/orexcluded_indices) to ensure the best sampling of the plateau region away from the defect position -dopedshould throw a warning in these cases (about the correction error being above the default tolerance (50 meV)). For example, with layered materials, the defect charge is often localised to one layer, so we may want to adjustdefect_region_radiusand/orexcluded_indicesto ensure that only sites in other layers are used for the sampling region (plateau) - see example on doped docs.- Parameters:
dielectric (float or int or 3x1 matrix or 3x3 matrix) – Total dielectric constant of the host compound (including both ionic and (high-frequency) electronic contributions), in the same xyz Cartesian basis as the supercell calculations. If None, then the dielectric constant is taken from the
defect_entrycalculation_metadataif available.defect_region_radius (float) – Radius of the defect region (in Å). Sites outside the defect region are used for sampling the electrostatic potential far from the defect (to obtain the potential alignment). If None (default), uses the Wigner-Seitz radius of the supercell.
excluded_indices (list) – List of site indices (in the defect supercell) to exclude from the site potential sampling in the correction calculation/plot. If None (default), no sites are excluded.
defect_outcar (str or Outcar) – Path to the output VASP OUTCAR file from the defect supercell calculation, or the corresponding pymatgen Outcar object. If None, will try to use the
defect_supercell_site_potentialsfrom thedefect_entrycalculation_metadataif available.bulk_outcar (str or Outcar) – Path to the output VASP OUTCAR file from the bulk supercell calculation, or the corresponding pymatgen Outcar object. If None, will try to use the
bulk_supercell_site_potentialsfrom thedefect_entrycalculation_metadataif available.plot (bool) – Whether to plot the Kumagai site potential plots (for manually checking the behaviour of the charge correction here).
filename (str) – Filename to save the Kumagai site potential plots to. If None, plots are not saved.
return_correction_error (bool) – If True, also returns the standard error of the mean of the sampled site potential differences times the defect charge (which gives an estimate of the error range of the correction energy). Default is False.
error_tolerance (float) – If the estimated error in the charge correction is greater than this value (in eV), then a warning is raised. (default: 0.05 eV)
style_file (str) – Path to a
.mplstylefile to use for the plot. IfNone(default), uses the default doped style (fromdoped/utils/doped.mplstyle).**kwargs – Additional kwargs to pass to pydefect.corrections.efnv_correction.ExtendedFnvCorrection (e.g. charge, defect_region_radius, defect_coords).
- Returns:
CorrectionResults (summary of the corrections applied and metadata), and the matplotlib figure object if
plotis True, and the estimated charge correction error ifreturn_correction_erroris True.
- name: str = ''
- plot_site_displacements(separated_by_direction: bool | None = False, relative_to_defect: bool | None = False, vector_to_project_on: list | None = None, use_plotly: bool | None = False, mpl_style_file: str | None = '')[source]
Plot the site displacements as a function of distance from the defect site.
- Parameters:
separated_by_direction (bool) – Whether to plot the site displacements separated by the x, y and z directions (True) or all together (False). Defaults to False.
relative_to_defect (bool) – Whether to plot the signed displacements along the line from the defect site to that atom. Negative values indicate the atom moves towards the defect (compressive strain), positive values indicate the atom moves away from the defect (tensile strain). Uses the relaxed defect position as reference.
vector_to_project_on – Direction to project the site displacements along (e.g. [0, 0, 1]). Defaults to None (e.g. the displacements are calculated in the cartesian basis x, y, z).
use_plotly (bool) – Whether to use plotly (True) or matplotlib (False).
mpl_style_file (str) – Path to a matplotlib style file to use for the plot. If None, uses the default doped style file.
- sc_defect_frac_coords: Tuple[float, float, float] | None = None
- sc_entry: ComputedStructureEntry
- to_json(filename: str | None = None)[source]
Save the DefectEntry object to a json file, which can be reloaded with the DefectEntry.from_json() class method.
- Parameters:
filename (str) – Filename to save json file as. If None, the filename will be set as “{DefectEntry.name}.json”.
- wyckoff: str | None = None
- class doped.core.Interstitial(*args, **kwargs)[source]
Bases:
Interstitial,DefectSubclass of pymatgen.analysis.defects.core.Interstitial with additional attributes and methods used by doped.
- class doped.core.Substitution(*args, **kwargs)[source]
Bases:
Substitution,DefectSubclass of pymatgen.analysis.defects.core.Substitution with additional attributes and methods used by doped.
- class doped.core.Vacancy(*args, **kwargs)[source]
Bases:
Vacancy,DefectSubclass of pymatgen.analysis.defects.core.Vacancy with additional attributes and methods used by doped.
- doped.core.doped_defect_from_pmg_defect(defect: Defect, bulk_oxi_states=False, **doped_kwargs)[source]
Create the corresponding doped Defect (Vacancy, Interstitial, Substitution) from an input pymatgen Defect object.
- Parameters:
defect – pymatgen Defect object.
bulk_oxi_states – Either a dict of bulk oxidation states to use, or a boolean. If True, re-guesses the oxidation state of the defect (ignoring the pymatgen Defect oxi_state attribute), otherwise uses the already-set oxi_state (default = 0). Used in doped defect generation to make defect setup more robust and efficient (particularly for odd input structures, such as defect supercells etc).
**doped_kwargs – Additional keyword arguments to define doped-specific attributes (see class docstring).