Skip to content

Commit 155898a

Browse files
committed
u
1 parent ba027fd commit 155898a

File tree

2 files changed

+19
-49
lines changed

2 files changed

+19
-49
lines changed

dpgen/data/gen.py

+16-47
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@ def make_scale_ABACUS(jdata):
726726

727727

728728
def pert_scaled(jdata):
729-
if "init_fp_style" not in jdata:
730-
jdata["init_fp_style"] = "VASP"
729+
### Extract data from jdata
730+
jdata["init_fp_style"] = jdata.get("init_fp_style", "VASP")
731731
out_dir = jdata["out_dir"]
732732
scale = jdata["scale"]
733733
pert_box = jdata["pert_box"]
@@ -744,6 +744,7 @@ def pert_scaled(jdata):
744744
if "from_poscar" in jdata:
745745
from_poscar = jdata["from_poscar"]
746746

747+
### Get the current working directory and the system path
747748
cwd = os.getcwd()
748749
path_sp = os.path.join(out_dir, global_dirname_03)
749750
assert os.path.isdir(path_sp)
@@ -752,35 +753,31 @@ def pert_scaled(jdata):
752753
sys_pe.sort()
753754
os.chdir(cwd)
754755

755-
pert_cmd = os.path.dirname(__file__)
756-
pert_cmd = os.path.join(pert_cmd, "tools")
757-
pert_cmd = os.path.join(pert_cmd, "create_random_disturb.py")
756+
### Construct the perturbation command
757+
python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py")
758758
fp_style = "vasp"
759759
poscar_name = "POSCAR"
760760
if jdata["init_fp_style"] == "ABACUS":
761761
fp_style = "abacus"
762762
poscar_name = "STRU"
763-
pert_cmd = (
764-
sys.executable
765-
+ " "
766-
+ pert_cmd
767-
+ " -etmax %f -ofmt %s %s %d %f > /dev/null"
768-
% (pert_box, fp_style, poscar_name, pert_numb, pert_atom)
769-
)
763+
764+
pert_cmd = sys.executable + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null"
765+
766+
### Loop over each system and scale
770767
for ii in sys_pe:
771768
for jj in scale:
772-
path_work = path_sp
773-
path_work = os.path.join(path_work, ii)
774-
path_work = os.path.join(path_work, f"scale-{jj:.3f}")
769+
path_work = os.path.join(path_sp, ii, f"scale-{jj:.3f}")
775770
assert os.path.isdir(path_work)
776771
os.chdir(path_work)
777772
sp.check_call(pert_cmd, shell=True)
773+
774+
### Loop over each perturbation
778775
for kk in range(pert_numb):
779776
if fp_style == "vasp":
780-
pos_in = "POSCAR%d.vasp" % (kk + 1)
777+
pos_in = f"POSCAR{kk}.vasp"
781778
elif fp_style == "abacus":
782-
pos_in = "STRU%d.abacus" % (kk + 1)
783-
dir_out = "%06d" % (kk + 1)
779+
pos_in = f"STRU{kk}.abacus"
780+
dir_out = f"{kk:06d}"
784781
create_path(dir_out)
785782
if fp_style == "vasp":
786783
pos_out = os.path.join(dir_out, "POSCAR")
@@ -805,35 +802,7 @@ def pert_scaled(jdata):
805802
else:
806803
shutil.copy2(pos_in, pos_out)
807804
os.remove(pos_in)
808-
kk = -1
809-
if fp_style == "vasp":
810-
pos_in = "POSCAR"
811-
elif fp_style == "abacus":
812-
pos_in = "STRU"
813-
dir_out = "%06d" % (kk + 1)
814-
create_path(dir_out)
815-
if fp_style == "vasp":
816-
pos_out = os.path.join(dir_out, "POSCAR")
817-
elif fp_style == "abacus":
818-
pos_out = os.path.join(dir_out, "STRU")
819-
if not from_poscar:
820-
if fp_style == "vasp":
821-
poscar_shuffle(pos_in, pos_out)
822-
elif fp_style == "abacus":
823-
stru_in = get_abacus_STRU(pos_in)
824-
stru_out = shuffle_stru_data(stru_in)
825-
with open(pos_out, "w") as fp:
826-
fp.write(
827-
make_abacus_scf_stru(
828-
stru_out,
829-
pp_file,
830-
orb_file_names,
831-
dpks_descriptor_name,
832-
type_map=jdata["elements"],
833-
)
834-
)
835-
else:
836-
shutil.copy2(pos_in, pos_out)
805+
837806
os.chdir(cwd)
838807

839808

dpgen/data/tools/create_random_disturb.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def create_disturbs_ase_dev(
123123
cell0 = atoms.get_cell()
124124

125125
# creat nfile ofmt files.
126-
for fid in range(1, nfile + 1):
126+
# for fid in range(1, nfile + 1): # C.Thang Nguyen: Why not start from 0?
127+
for fid in range(nfile):
127128
# Use copy(), otherwise it will modify the input atoms every time.
128129
atoms_d = atoms.copy()
129130

@@ -194,7 +195,7 @@ def create_disturbs_abacus_dev(
194195
cell0 = stru["cells"]
195196

196197
# creat nfile ofmt files.
197-
for fid in range(1, nfile + 1):
198+
for fid in range(nfile):
198199
# Use copy(), otherwise it will modify the input atoms every time.
199200
stru_d = stru.copy()
200201

0 commit comments

Comments
 (0)