Skip to content

Commit 39115f2

Browse files
authored
fix: support shuffle_poscar for other formats (#1610)
Fix #1570. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced efficiency in handling atomic configurations by directly modifying coordinates in memory, eliminating the need for intermediate files. - Simplified logic for shuffling atomic indices. - **Bug Fixes** - Removed obsolete function that may have caused confusion in the workflow related to POSCAR file management. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
1 parent cdfef61 commit 39115f2

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

dpgen/generator/run.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,6 @@ def poscar_natoms(lines):
216216
return numb_atoms
217217

218218

219-
def poscar_shuffle(poscar_in, poscar_out):
220-
with open(poscar_in) as fin:
221-
lines = list(fin)
222-
numb_atoms = poscar_natoms(lines)
223-
idx = np.arange(8, 8 + numb_atoms)
224-
np.random.shuffle(idx)
225-
out_lines = lines[0:8]
226-
for ii in range(numb_atoms):
227-
out_lines.append(lines[idx[ii]])
228-
with open(poscar_out, "w") as fout:
229-
fout.write("".join(out_lines))
230-
231-
232219
def expand_idx(in_list):
233220
ret = []
234221
for ii in in_list:
@@ -1272,24 +1259,17 @@ def make_model_devi(iter_index, jdata, mdata):
12721259
conf_path = os.path.join(work_path, "confs")
12731260
create_path(conf_path)
12741261
sys_counter = 0
1262+
rng = np.random.default_rng()
12751263
for ss in conf_systems:
12761264
conf_counter = 0
12771265
for cc in ss:
12781266
if model_devi_engine == "lammps":
12791267
conf_name = make_model_devi_conf_name(
12801268
sys_idx[sys_counter], conf_counter
12811269
)
1282-
orig_poscar_name = conf_name + ".orig.poscar"
12831270
poscar_name = conf_name + ".poscar"
12841271
lmp_name = conf_name + ".lmp"
1285-
if shuffle_poscar:
1286-
os.symlink(cc, os.path.join(conf_path, orig_poscar_name))
1287-
poscar_shuffle(
1288-
os.path.join(conf_path, orig_poscar_name),
1289-
os.path.join(conf_path, poscar_name),
1290-
)
1291-
else:
1292-
os.symlink(cc, os.path.join(conf_path, poscar_name))
1272+
os.symlink(cc, os.path.join(conf_path, poscar_name))
12931273
if "sys_format" in jdata:
12941274
fmt = jdata["sys_format"]
12951275
else:
@@ -1299,6 +1279,8 @@ def make_model_devi(iter_index, jdata, mdata):
12991279
fmt=fmt,
13001280
type_map=jdata["type_map"],
13011281
)
1282+
if shuffle_poscar:
1283+
system.data["coords"] = rng.permuted(system.data["coords"], axis=1)
13021284
if jdata.get("model_devi_nopbc", False):
13031285
system.remove_pbc()
13041286
system.to_lammps_lmp(os.path.join(conf_path, lmp_name))

0 commit comments

Comments
 (0)