Skip to content

Commit 63afad7

Browse files
Zikkyingcursoragent
andcommitted
Fix decohesive slabs for tilted lattice vectors
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b024e51 commit 63afad7

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

apex/core/property/Decohesive.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,13 @@ def __gen_slab_pmg(
258258
sorted_frac_coords, sorted_species = zip(*ordered)
259259

260260
a_vec, b_vec, c_vec = slab.lattice.matrix
261-
slab_height = abs(c_vec[2])
261+
# ``reorient_lattice=False`` preserves the input orientation, so the
262+
# slab-normal c vector is not necessarily aligned with Cartesian z.
263+
# Using c_vec[2] therefore produces a zero divisor for valid surfaces
264+
# such as bcc (100) and (110), yielding NaNs in the LAMMPS data file.
265+
slab_height = np.linalg.norm(c_vec)
266+
if slab_height <= np.finfo(float).eps:
267+
raise RuntimeError("Generated slab has a zero-length c lattice vector")
262268
self.is_flip = c_vec[2] < 0
263269
elong_scale = 1 + (abs(vacuum_size) / slab_height)
264270

tests/test_decohesive.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
from monty.serialization import loadfn
9-
from pymatgen.core import Structure
9+
from pymatgen.core import Lattice, Structure
1010
from pymatgen.core.surface import SlabGenerator
1111

1212
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
@@ -99,6 +99,35 @@ def test_make_confs_0(self):
9999
# slb = sl.get_slab()
100100
st2 = Structure(sl.lattice, sl.species, sl.frac_coords)
101101
self.assertEqual(len(st1), len(st2))
102+
103+
def test_make_confs_with_c_vector_not_aligned_to_z(self):
104+
bcc_mo = Structure(
105+
Lattice.cubic(3.16),
106+
["Mo", "Mo"],
107+
[[0, 0, 0], [0.5, 0.5, 0.5]],
108+
)
109+
bcc_mo.to(filename=os.path.join(self.equi_path, "CONTCAR"), fmt="poscar")
110+
parameter = {
111+
"type": "decohesive",
112+
"min_slab_size": 15,
113+
"max_vacuum_size": 1,
114+
"vacuum_size_step": 1,
115+
"miller_index": [1, 0, 0],
116+
"cal_type": "static",
117+
}
118+
119+
tasks = Decohesive(parameter).make_confs(self.target_path, self.equi_path)
120+
zero_vacuum = Structure.from_file(os.path.join(tasks[0], "POSCAR.tmp"))
121+
one_angstrom_vacuum = Structure.from_file(os.path.join(tasks[1], "POSCAR.tmp"))
122+
123+
self.assertTrue(np.isfinite(zero_vacuum.lattice.matrix).all())
124+
self.assertTrue(np.isfinite(one_angstrom_vacuum.lattice.matrix).all())
125+
self.assertAlmostEqual(
126+
np.linalg.norm(one_angstrom_vacuum.lattice.matrix[2])
127+
- np.linalg.norm(zero_vacuum.lattice.matrix[2]),
128+
1.0,
129+
places=8,
130+
)
102131

103132
def __gen_slab_pmg(self, structure: Structure,
104133
plane_miller, slab_size, vacuum_size) -> Structure:

0 commit comments

Comments
 (0)