Skip to content

Commit

Permalink
Ensure sorted defect supercell structure returned
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Oct 11, 2023
1 parent dbeb6a9 commit 6da183b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 4 additions & 2 deletions doped/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,16 @@ def _remove_site_oxi_state(site):
if dummy_species is not None:
sc_defect_struct.insert(len(self.structure * sc_mat), dummy_species, sc_site.frac_coords)

sorted_sc_defect_struct = sc_defect_struct.get_sorted_structure() # ensure proper sorting

return (
(
sc_defect_struct,
sorted_sc_defect_struct,
sc_site,
equiv_sites,
)
if return_sites
else sc_defect_struct
else sorted_sc_defect_struct
)

def as_dict(self):
Expand Down
17 changes: 12 additions & 5 deletions doped/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ def poscar(self) -> Poscar:
"""
Return Poscar object with comment.
"""
return Poscar(self.structure, comment=self.poscar_comment)
unsorted_poscar = Poscar(self.structure, comment=self.poscar_comment)

# check if POSCAR should be sorted:
if len(unsorted_poscar.site_symbols) == len(set(unsorted_poscar.site_symbols)):
# no duplicates, return poscar as is
return unsorted_poscar

return Poscar(self.structure, comment=self.poscar_comment, sort_structure=True)

@property
def kpoints(self):
Expand Down Expand Up @@ -1891,9 +1898,9 @@ def _format_defect_entries_input(

@staticmethod
def _write_defect(args):
defect_species, defect_entry, output_dir, unperturbed_poscar, vasp_gam, bulk, kwargs = args
defect_species, defect_relax_set, output_dir, unperturbed_poscar, vasp_gam, bulk, kwargs = args
defect_dir = os.path.join(output_dir, defect_species)
defect_entry.write_all(
defect_relax_set.write_all(
defect_dir=defect_dir,
unperturbed_poscar=unperturbed_poscar,
vasp_gam=vasp_gam,
Expand Down Expand Up @@ -2022,14 +2029,14 @@ def write_files(
args_list = [
(
defect_species,
defect_entry,
defect_relax_set,
output_dir,
unperturbed_poscar,
vasp_gam,
bulk if i == 0 else False, # only write bulk folder(s) for first defect
kwargs,
)
for i, (defect_species, defect_entry) in enumerate(self.defect_sets.items())
for i, (defect_species, defect_relax_set) in enumerate(self.defect_sets.items())
]
with Pool(processes=processes or cpu_count() - 1) as pool:
for _ in tqdm(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
"tabulate",
"matplotlib>=3.5.2",
"numpy>=1.21.0",
"pymatgen>=2023.5.8", # imposed by pymatgen-analysis-defects
"pymatgen>=2023.8.10",
"pymatgen-analysis-defects>=2023.8.22",
"shakenbreak>=3.2.0",
"pandas",
Expand Down

0 comments on commit 6da183b

Please sign in to comment.