From 175e914f6ba01ca0ece624d5831e4bd359f3908e Mon Sep 17 00:00:00 2001 From: Sean Kavanagh Date: Mon, 13 May 2024 13:46:02 +0100 Subject: [PATCH] Update `Defect` initialisation code to match `pymatgen` update --- doped/analysis.py | 4 ++++ doped/core.py | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/doped/analysis.py b/doped/analysis.py index 72470efc..b5f970ec 100644 --- a/doped/analysis.py +++ b/doped/analysis.py @@ -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: diff --git a/doped/core.py b/doped/core.py index 561d41ca..ab84e5d1 100644 --- a/doped/core.py +++ b/doped/core.py @@ -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: @@ -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): @@ -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() @@ -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) @@ -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) @@ -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: