Skip to content

Commit

Permalink
Update Defect initialisation code to match pymatgen update
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed May 13, 2024
1 parent af3ab8a commit 175e914
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions doped/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ def defect_from_structures(
} # note that we now define the Defect in the bulk supercell, rather than the primitive structure
# as done during generation. Future work could try mapping the relaxed defect site back to the
# primitive cell, however interstitials will be very tricky for this...
if def_type == "interstitial":
for_monty_defect["multiplicity"] = 1 # multiplicity needed for interstitial initialisation with
# pymatgen-analysis-defects, so set to 1 here. Set later for interstitials during parsing anyway
# (see below)
defect = MontyDecoder().process_decoded(for_monty_defect)

if not return_all_info:
Expand Down
23 changes: 14 additions & 9 deletions doped/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class DefectEntry(thermo.DefectEntry):
"""
Subclass of ``pymatgen.analysis.defects.thermo.DefectEntry`` with
additional attributes used by doped.
additional attributes used by ``doped``.
Core Attributes:
defect:
Expand Down Expand Up @@ -1415,7 +1415,7 @@ def __init__(
):
"""
Subclass of ``pymatgen.analysis.defects.core.Defect`` with additional
attributes and methods used by doped.
attributes and methods used by ``doped``.
Args:
structure (Structure):
Expand Down Expand Up @@ -1675,7 +1675,10 @@ def get_supercell_structure(
)[0]

sc_defect = self.__class__(
structure=self.structure * sc_mat, site=sc_site, oxi_state=self.oxi_state
structure=self.structure * sc_mat,
site=sc_site,
oxi_state=self.oxi_state,
multiplicity=1, # so doesn't break for interstitials
)
sc_defect_struct = sc_defect.defect_structure
sc_defect_struct.remove_oxidation_states()
Expand Down Expand Up @@ -1822,11 +1825,11 @@ def doped_defect_from_pmg_defect(defect: core.Defect, bulk_oxi_states=False, **d
return defect_type._from_pmg_defect(defect, bulk_oxi_states=bulk_oxi_states, **doped_kwargs)


class Vacancy(core.Vacancy, Defect):
class Vacancy(Defect, core.Vacancy):
def __init__(self, *args, **kwargs):
"""
Subclass of ``pymatgen.analysis.defects.core.Vacancy`` with additional
attributes and methods used by doped.
attributes and methods used by ``doped``.
"""
super().__init__(*args, **kwargs)

Expand All @@ -1838,11 +1841,11 @@ def __repr__(self) -> str:
return f"{self.name} vacancy defect at site [{frac_coords_string}] in structure"


class Substitution(core.Substitution, Defect):
class Substitution(Defect, core.Substitution):
def __init__(self, *args, **kwargs):
"""
Subclass of ``pymatgen.analysis.defects.core.Substitution`` with
additional attributes and methods used by doped.
additional attributes and methods used by ``doped``.
"""
super().__init__(*args, **kwargs)

Expand All @@ -1854,12 +1857,14 @@ def __repr__(self) -> str:
return f"{self.name} substitution defect at site [{frac_coords_string}] in structure"


class Interstitial(core.Interstitial, Defect):
class Interstitial(Defect, core.Interstitial):
def __init__(self, *args, **kwargs):
"""
Subclass of ``pymatgen.analysis.defects.core.Interstitial`` with
additional attributes and methods used by doped.
additional attributes and methods used by ``doped``.
"""
if "multiplicity" not in kwargs: # will break for Interstitials if not set
kwargs["multiplicity"] = 1
super().__init__(*args, **kwargs)

def __repr__(self) -> str:
Expand Down

0 comments on commit 175e914

Please sign in to comment.