Skip to content

Commit 0e5d2b3

Browse files
committed
Update build_slab tool
1 parent 95d534c commit 0e5d2b3

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

src/abacusagent/modules/structure_editor.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ def build_slab(stru_file: Path,
1010
stru_type: Literal["cif", "poscar", "abacus/stru"] = "cif",
1111
miller_indices: Tuple[int, int, int] = (1, 0, 0),
1212
layers: int = 3,
13-
supercell_2d: Tuple[int, int] = (1, 1),
14-
vacuum: float = 10.0,
15-
vacuum_direction: Literal['a', 'b', 'c'] = 'b'
16-
):
13+
surface_supercell: Tuple[int, int] = (1, 1),
14+
vacuum: float = 15.0,
15+
vacuum_direction: Literal['a', 'b', 'c'] = 'b'):
1716
"""
1817
Build slab from given structure file.
1918
@@ -22,14 +21,14 @@ def build_slab(stru_file: Path,
2221
stru_type (Literal["cif", "poscar", "abacus/stru"]): Type of structure file. Defaults to "cif".
2322
miller_indices (Tuple[int, int, int]): Miller indices of the surface. Defaults to (1, 0, 0), which means (100) surface of the structure.
2423
layers (int, optional): Number of layers of the surface. Note that the layers is number of equivalent layers, not number of layers of atoms. Defaults to 3.
25-
supercell_2d (Tuple[int, int], optional): Supercell size of the surface. Default is (1, 1), which means no supercell.
26-
vacuum (float, optional): Vacuum space along on both sides of the cleaved surface. The total vacuum size will be twice this value. Units in Angstrom. Defaults to 10.0.
24+
surface_supercell (Tuple[int, int], optional): Supercell size of the surface. Default is (1, 1), which means no supercell.
25+
vacuum (float, optional): Vacuum space between the cleaved surface and its periodic image. The total vacuum size will be twice this value. Units in Angstrom. Defaults to 15.0.
2726
vacuum_direction (Literal['a', 'b', 'c']): The direction of the vacuum space. Defaults to 'b'.
2827
Returns:
2928
A dictionary containing the path to the surface structure file.
3029
Keys:
31-
- surface_stru_file: Path to the surface structure file.
30+
- surface_stru_file: Path to the surface structure file. The format of the generated structure file depends on the input structure file.
3231
Raises:
3332
ValueError: If stru_type is not supported.
3433
"""
35-
return _build_slab(stru_file, stru_type, miller_indices, layers, supercell_2d, vacuum, vacuum_direction)
34+
return _build_slab(stru_file, stru_type, miller_indices, layers, surface_supercell, vacuum, vacuum_direction)

src/abacusagent/modules/submodules/structure_editor.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def build_slab(stru_file: Path,
1010
stru_type: Literal["cif", "poscar", "abacus/stru"] = "cif",
1111
miller_indices: Tuple[int, int, int] = (1, 0, 0),
1212
layers: int = 3,
13-
supercell_2d: Tuple[int, int] = (1, 1),
14-
vacuum: float = 10.0,
13+
surface_supercell: Tuple[int, int] = (1, 1),
14+
vacuum: float = 15.0,
1515
vacuum_direction: Literal['a', 'b', 'c'] = 'b'):
1616
"""
1717
Build slab from given structure file.
@@ -21,13 +21,13 @@ def build_slab(stru_file: Path,
2121
stru_type (Literal["cif", "poscar", "abacus/stru"]): Type of structure file. Defaults to "cif".
2222
miller_indices (Tuple[int, int, int]): Miller indices of the surface. Defaults to (1, 0, 0), which means (100) surface of the structure.
2323
layers (int, optional): Number of layers of the surface. Note that the layers is number of equivalent layers, not number of layers of atoms. Defaults to 3.
24-
supercell_2d (Tuple[int, int], optional): Supercell size of the surface. Default is (1, 1), which means no supercell.
25-
vacuum (float, optional): Vacuum space along on both sides of the cleaved surface. The total vacuum size will be twice this value. Units in Angstrom. Defaults to 10.0.
24+
surface_supercell (Tuple[int, int], optional): Supercell size of the surface. Default is (1, 1), which means no supercell.
25+
vacuum (float, optional): Vacuum space between the cleaved surface and its periodic image. The total vacuum size will be twice this value. Units in Angstrom. Defaults to 15.0.
2626
vacuum_direction (Literal['a', 'b', 'c']): The direction of the vacuum space. Defaults to 'b'.
2727
Returns:
2828
A dictionary containing the path to the surface structure file.
2929
Keys:
30-
- surface_stru_file: Path to the surface structure file.
30+
- surface_stru_file: Path to the surface structure file. The format of the generated structure file depends on the input structure file.
3131
Raises:
3232
ValueError: If stru_type is not supported.
3333
"""
@@ -39,8 +39,8 @@ def build_slab(stru_file: Path,
3939
else:
4040
raise ValueError(f"Unsupported structure file type: {stru_type}")
4141

42-
stru_surface = surface(stru_ase, miller_indices, layers, vacuum=vacuum, periodic=True)
43-
stru_surface = make_supercell(stru_surface, [[supercell_2d[0], 0, 0], [0, supercell_2d[1], 0], [0, 0, 1]])
42+
stru_surface = surface(stru_ase, miller_indices, layers, vacuum=vacuum/2, periodic=True)
43+
stru_surface = make_supercell(stru_surface, [[surface_supercell[0], 0, 0], [0, surface_supercell[1], 0], [0, 0, 1]])
4444
stru_surface_abacusstru = AbacusSTRU.from_ase(stru_surface, metadata={
4545
"lattice_constant": A2BOHR,
4646
"atom_type": "cartesian",
@@ -49,16 +49,14 @@ def build_slab(stru_file: Path,
4949

5050
# Permute axis to set vacuum direction along given axis. The vacuum direction create by ase.build.surface is always along z axis.
5151
if vacuum_direction == "a":
52-
stru_surface_abacusstru.permute_lat_vec(mode="cab")
53-
stru_surface_abacusstru.permute_coord(mode="zxy")
52+
stru_surface_abacusstru.permute_lat_vec(mode="cab", rotate_cart_coord=True)
5453
elif vacuum_direction == "b":
55-
stru_surface_abacusstru.permute_lat_vec(mode="bca")
56-
stru_surface_abacusstru.permute_coord(mode="yzx")
54+
stru_surface_abacusstru.permute_lat_vec(mode="bca", rotate_cart_coord=True)
5755
elif vacuum_direction == "c":
5856
pass
5957

6058
h, k, l = miller_indices
6159
surface_stru_file = Path(f"./{stru_file.stem}_{h}{k}{l}_{layers}layer.STRU").absolute()
62-
stru_surface_abacusstru.write(surface_stru_file, fmt="stru")
60+
stru_surface_abacusstru.write(surface_stru_file, fmt=stru_type)
6361

6462
return {'surface_stru_file': surface_stru_file}

0 commit comments

Comments
 (0)