Skip to content

Commit

Permalink
fix bug in make_supercell_abacus (deepmodeling#1212)
Browse files Browse the repository at this point in the history
The `from_struct["atom_types"]` used to be a list but was changed to
numpy array lately, thereby introducing a bug in `make_supercell_abacus`
function.
Also, the key `types` is changed to `atom_types` outside the function,
but not changed in the function.
 This commit fix the two bugs.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
3 people committed May 16, 2023
1 parent 0aec52e commit b0c1271
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions dpgen/generator/lib/abacus_scf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import os
import re

Expand Down Expand Up @@ -401,31 +402,50 @@ def get_abacus_STRU(STRU, INPUT=None, n_ele=None):


def make_supercell_abacus(from_struct, super_cell):
if "types" in from_struct:
from_struct["types"] = (
from_struct["types"] * super_cell[0] * super_cell[1] * super_cell[2]
)
for ix in range(super_cell[0]):
for iy in range(super_cell[1]):
for iz in range(super_cell[2]):
if ix == 0 and iy == 0 and iz == 0:
continue
for ia in range(sum(from_struct["atom_numbs"])):
to_struct = copy.deepcopy(from_struct)

if "atom_types" in from_struct:
new_types = []
# to_struct["atom_types"] = (
# from_struct["atom_types"] * super_cell[0] * super_cell[1] * super_cell[2]
# )
for idx_atm, ina in enumerate(from_struct["atom_numbs"]):
new_types += (
[idx_atm for i in range(ina)]
* super_cell[0]
* super_cell[1]
* super_cell[2]
)
to_struct["atom_types"] = new_types
to_atom_num = (
sum(from_struct["atom_numbs"]) * super_cell[0] * super_cell[1] * super_cell[2]
)
new_coord = np.zeros((to_atom_num, 3))
idx_atm = 0
for ia in range(sum(from_struct["atom_numbs"])):
for ix in range(super_cell[0]):
for iy in range(super_cell[1]):
for iz in range(super_cell[2]):
# if ix == 0 and iy == 0 and iz == 0:
# continue

coord = (
from_struct["coords"][ia]
+ from_struct["cells"][0] * ix
+ from_struct["cells"][1] * iy
+ from_struct["cells"][2] * iz
)
from_struct["coords"] = np.vstack([from_struct["coords"], coord])
from_struct["atom_numbs"] = [
new_coord[idx_atm] = coord
to_struct["coords"] = new_coord
new_numbs = [
i * super_cell[0] * super_cell[1] * super_cell[2]
for i in from_struct["atom_numbs"]
]
from_struct["cells"][0] *= super_cell[0]
from_struct["cells"][1] *= super_cell[1]
from_struct["cells"][2] *= super_cell[2]
return from_struct
to_struct["atom_numbs"] = new_numbs
to_struct["cells"][0] *= super_cell[0]
to_struct["cells"][1] *= super_cell[1]
to_struct["cells"][2] *= super_cell[2]
return to_struct


def make_kspacing_kpoints_stru(stru, kspacing):
Expand Down

0 comments on commit b0c1271

Please sign in to comment.