Skip to content

Commit bdde522

Browse files
authored
ASE supercell generation (#22)
* ase sc * fixed tests
1 parent e30d92b commit bdde522

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pymatgen/analysis/defects/supercells.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ def _ase_cubic(base_struture, min_atoms: int = 80, max_atoms: int = 240):
126126
from ase.build import find_optimal_cell_shape, get_deviation_from_optimal_cell_shape
127127
from pymatgen.io.ase import AseAtomsAdaptor
128128

129+
_logger.info("ASE cubic supercell generation.")
130+
129131
aaa = AseAtomsAdaptor()
130132
ase_atoms = aaa.get_atoms(base_struture)
131133
lower = math.ceil(min_atoms / base_struture.num_sites)
132134
upper = math.floor(max_atoms / base_struture.num_sites)
133135
min_dev = (float("inf"), None)
134136
for size in range(lower, upper + 1):
137+
_logger.info(f"Trying size {size} out of {upper}.")
135138
sc = find_optimal_cell_shape(
136139
ase_atoms.cell, target_size=size, target_shape="sc"
137140
)

tests/test_supercells.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22

33
from pymatgen.analysis.defects.supercells import (
4+
_ase_cubic,
45
get_matched_structure_mapping,
56
get_sc_fromstruct,
67
)
@@ -18,3 +19,10 @@ def test_supercells(gan_struct):
1819
np.testing.assert_allclose(
1920
sc.lattice.abc, sc2.lattice.abc
2021
) # the sc_mat can be reconstructed from the sc
22+
23+
24+
def test_ase_supercells(gan_struct):
25+
sc_mat = _ase_cubic(gan_struct, min_atoms=4, max_atoms=8)
26+
sc = gan_struct * sc_mat
27+
assert 4 <= sc.num_sites <= 8
28+
assert False

0 commit comments

Comments
 (0)