Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix antisite generation in mixed-valence systems #210

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pymatgen/analysis/defects/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ def generate(
Returns:
Generator[Vacancy, None, None]: Generator that yields a list of ``Vacancy`` objects.
"""
all_species = [*map(_element_str, structure.composition.elements)]
rm_species = all_species if rm_species is None else [*map(str, rm_species)]
all_species = {*map(_element_str, structure.composition.elements)}
rm_species = all_species if rm_species is None else {*map(str, rm_species)}

if not set(rm_species).issubset(all_species):
if not rm_species.issubset(all_species):
msg = f"rm_species({rm_species}) must be a subset of the structure's species ({all_species})."
raise ValueError(
msg,
Expand Down Expand Up @@ -235,7 +235,7 @@ def generate(
structure: The bulk structure the anti-site defects are generated from.
**kwargs: Additional keyword arguments for the ``Substitution.generate`` function.
"""
all_species = [*map(_element_str, structure.composition.elements)]
all_species = {*map(_element_str, structure.composition.elements)}
subs = collections.defaultdict(list)
for u, v in combinations(all_species, 2):
subs[u].append(v)
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict
from pathlib import Path
import numpy as np

import pytest
from monty.serialization import loadfn
Expand All @@ -23,6 +24,15 @@ def gan_struct(test_dir):
return Structure.from_file(test_dir / "GaN.vasp")


@pytest.fixture(scope="session")
def mixed_valence_struct(test_dir):
return Structure(
lattice=np.array([[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]]),
species=["Cu+", "Cu+", "Cu2+", "O2-"],
coords=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5]],
)


@pytest.fixture(scope="session")
def stable_entries_Mg_Ga_N(test_dir):
return loadfn(test_dir / "stable_entries_Mg_Ga_N.json")
Expand Down
7 changes: 7 additions & 0 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def test_antisite_generator(gan_struct) -> None:
assert sorted(def_names) == ["Ga_N", "N_Ga"]


def test_mixed_valence_antisite_generator(mixed_valence_struct) -> None:
anti_gen = AntiSiteGenerator().get_defects(mixed_valence_struct)
def_names = [defect.name for defect in anti_gen]
assert "Cu_Cu" not in def_names
assert set(def_names) == {"Cu_O", "O_Cu"}


def test_interstitial_generator(gan_struct) -> None:
gen = InterstitialGenerator().get_defects(
gan_struct, insertions={"Mg": [[0, 0, 0]]}
Expand Down
Loading