Skip to content

Commit

Permalink
cleanup param passing to supcell
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn committed Aug 20, 2022
1 parent f135a08 commit b2036af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
29 changes: 21 additions & 8 deletions pymatgen/analysis/defects/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,32 @@ def get_supercell_structure(
self,
sc_mat: np.ndarray | None = None,
dummy_species: str | None = None,
**kwargs,
min_atoms: int = 80,
max_atoms: int = 240,
min_length: float = 10.0,
force_diagonal: bool = False,
) -> Structure:
"""Generate the supercell for a defect.
Args:
defect: defect object
sc_mat: supercell matrix
dummy_species: dummy species to highlight the defect position
(for visualization)
kwargs: kwargs for `CubicSupercellTransformation`
sc_mat: supercell matrix if None, the supercell will be determined by `CubicSupercellAnalyzer`.
dummy_species: Dummy species to highlight the defect position (for visualizing vacancies).
max_atoms: Maximum number of atoms allowed in the supercell.
min_atoms: Minimum number of atoms allowed in the supercell.
min_length: Minimum length of the smallest supercell lattice vector.
force_diagonal: If True, return a transformation with a diagonal transformation matrix.
Returns:
defect: defect object
Structure: The supercell structure.
"""
if sc_mat is None:
sc_mat = get_sc_fromstruct(self.structure, **kwargs)
sc_mat = get_sc_fromstruct(
self.structure,
min_atoms=min_atoms,
max_atoms=max_atoms,
min_length=min_length,
force_diagonal=force_diagonal,
)

sc_structure = self.structure * sc_mat
sc_mat_inv = np.linalg.inv(sc_mat)
Expand Down Expand Up @@ -185,6 +195,9 @@ def get_multiplicity(self) -> int:
This is required for concentration analysis and confirms that defect_site is
a site in bulk_structure.
Returns:
int: The multiplicity of the defect.
"""
symm_struct = self.symmetrized_structure
defect_site = self.structure[self.defect_site_index]
Expand Down
9 changes: 8 additions & 1 deletion pymatgen/analysis/defects/supercells.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_sc_fromstruct(
min_atoms: int = 80,
max_atoms: int = 240,
min_length: float = 10.0,
force_diagonal: bool = False,
) -> np.ndarray | np.array | None:
"""Generate the best supercell from a unitcell.
Expand All @@ -38,6 +39,7 @@ def get_sc_fromstruct(
max_atoms: Maximum number of atoms allowed in the supercell.
min_atoms: Minimum number of atoms allowed in the supercell.
min_length: Minimum length of the smallest supercell lattice vector.
force_diagonal: If True, return a transformation with a diagonal transformation matrix.
Returns:
struc_sc: Supercell that is as close to cubic as possible
Expand Down Expand Up @@ -83,6 +85,7 @@ def _cubic_cell(
min_atoms: int = 80,
max_atoms: int = 240,
min_length: float = 10.0,
force_diagonal: bool = False,
) -> np.ndarray | None:
"""Generate the best supercell from a unit cell
Expand All @@ -93,6 +96,7 @@ def _cubic_cell(
max_atoms: Maximum number of atoms allowed in the supercell.
min_atoms: Minimum number of atoms allowed in the supercell.
min_length: Minimum length of the smallest supercell lattice vector.
force_diagonal: If True, return a transformation with a diagonal transformation matrix.
Returns:
3x3 matrix: supercell matrix
Expand All @@ -102,7 +106,10 @@ def _cubic_cell(
)

cst = CubicSupercellTransformation(
min_atoms=min_atoms, max_atoms=max_atoms, min_length=min_length
min_atoms=min_atoms,
max_atoms=max_atoms,
min_length=min_length,
force_diagonal=force_diagonal,
)

try:
Expand Down

0 comments on commit b2036af

Please sign in to comment.