Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support shuffle_poscar for other formats #1610

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,6 @@
return numb_atoms


def poscar_shuffle(poscar_in, poscar_out):
with open(poscar_in) as fin:
lines = list(fin)
numb_atoms = poscar_natoms(lines)
idx = np.arange(8, 8 + numb_atoms)
np.random.shuffle(idx)
out_lines = lines[0:8]
for ii in range(numb_atoms):
out_lines.append(lines[idx[ii]])
with open(poscar_out, "w") as fout:
fout.write("".join(out_lines))


def expand_idx(in_list):
ret = []
for ii in in_list:
Expand Down Expand Up @@ -1272,24 +1259,17 @@
conf_path = os.path.join(work_path, "confs")
create_path(conf_path)
sys_counter = 0
rng = np.random.default_rng()
for ss in conf_systems:
conf_counter = 0
for cc in ss:
if model_devi_engine == "lammps":
conf_name = make_model_devi_conf_name(
sys_idx[sys_counter], conf_counter
)
orig_poscar_name = conf_name + ".orig.poscar"
poscar_name = conf_name + ".poscar"
lmp_name = conf_name + ".lmp"
if shuffle_poscar:
os.symlink(cc, os.path.join(conf_path, orig_poscar_name))
poscar_shuffle(
os.path.join(conf_path, orig_poscar_name),
os.path.join(conf_path, poscar_name),
)
else:
os.symlink(cc, os.path.join(conf_path, poscar_name))
os.symlink(cc, os.path.join(conf_path, poscar_name))
if "sys_format" in jdata:
fmt = jdata["sys_format"]
else:
Expand All @@ -1299,6 +1279,8 @@
fmt=fmt,
type_map=jdata["type_map"],
)
if shuffle_poscar:
system.data["coords"] = rng.permuted(system.data["coords"], axis=1)

Check warning on line 1283 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L1283

Added line #L1283 was not covered by tests
if jdata.get("model_devi_nopbc", False):
system.remove_pbc()
system.to_lammps_lmp(os.path.join(conf_path, lmp_name))
Expand Down