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

Improve function pert_scaled #1563

Merged
merged 28 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d5b058f
Simplify API version message
thangckt May 27, 2024
8c4210b
u
thangckt May 27, 2024
cb6e88e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 27, 2024
e1d7c0c
u
thangckt May 28, 2024
ee5b52a
Update Dispatcher.py
thangckt May 28, 2024
d7fe8af
Merge branch 'devel' into simplify
thangckt May 28, 2024
ba027fd
Update utils.py
thangckt May 28, 2024
155898a
u
thangckt May 30, 2024
20b3480
Merge pull request #19 from deepmodeling/devel
thangckt May 30, 2024
bbe0fc5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
4e9bcd3
Update gen.py
thangckt May 30, 2024
44ebb1b
Merge branch 'simplify' of https://github.com/thangckt/dpgen into sim…
thangckt May 30, 2024
c0f302b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
2444446
Update gen.py
thangckt May 30, 2024
7208872
Update gen.py
thangckt May 30, 2024
ee921da
u
thangckt May 30, 2024
69b32fb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
6fe378f
u
thangckt May 30, 2024
bebbacf
Merge branch 'simplify' of https://github.com/thangckt/dpgen into sim…
thangckt May 30, 2024
f634e01
Update surf.py
thangckt May 30, 2024
95313c7
u
thangckt Jun 20, 2024
d226d87
Update gen.py
thangckt Jun 20, 2024
f0083a1
Update surf.py
thangckt Jun 20, 2024
d6d1d12
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 20, 2024
314d159
Merge branch 'devel' into simplify
thangckt Jul 10, 2024
5ad52f3
Merge branch 'devel' into simplify
thangckt Aug 23, 2024
0a0dcb3
u
thangckt Aug 23, 2024
cc0efbd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2024
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
73 changes: 24 additions & 49 deletions dpgen/data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,7 @@ def make_scale_ABACUS(jdata):


def pert_scaled(jdata):
if "init_fp_style" not in jdata:
jdata["init_fp_style"] = "VASP"
### Extract data from jdata
out_dir = jdata["out_dir"]
scale = jdata["scale"]
pert_box = jdata["pert_box"]
Expand All @@ -744,6 +743,7 @@ def pert_scaled(jdata):
if "from_poscar" in jdata:
from_poscar = jdata["from_poscar"]

### Get the current working directory and the system path
cwd = os.getcwd()
path_sp = os.path.join(out_dir, global_dirname_03)
assert os.path.isdir(path_sp)
Expand All @@ -752,35 +752,38 @@ def pert_scaled(jdata):
sys_pe.sort()
os.chdir(cwd)

pert_cmd = os.path.dirname(__file__)
pert_cmd = os.path.join(pert_cmd, "tools")
pert_cmd = os.path.join(pert_cmd, "create_random_disturb.py")
fp_style = "vasp"
poscar_name = "POSCAR"
if jdata["init_fp_style"] == "ABACUS":
### Construct the perturbation command
init_fp_style = jdata.get("init_fp_style", "VASP")
if init_fp_style == "VASP":
fp_style = "vasp"
poscar_name = "POSCAR"
elif init_fp_style == "ABACUS":
thangckt marked this conversation as resolved.
Show resolved Hide resolved
fp_style = "abacus"
poscar_name = "STRU"

python_exec = os.path.join(
os.path.dirname(__file__), "tools", "create_random_disturb.py"
)
pert_cmd = (
sys.executable
+ " "
+ pert_cmd
+ " -etmax %f -ofmt %s %s %d %f > /dev/null"
% (pert_box, fp_style, poscar_name, pert_numb, pert_atom)
+ f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null"
)
thangckt marked this conversation as resolved.
Show resolved Hide resolved

### Loop over each system and scale
for ii in sys_pe:
for jj in scale:
path_work = path_sp
path_work = os.path.join(path_work, ii)
path_work = os.path.join(path_work, f"scale-{jj:.3f}")
path_work = os.path.join(path_sp, ii, f"scale-{jj:.3f}")
assert os.path.isdir(path_work)
os.chdir(path_work)
sp.check_call(pert_cmd, shell=True)

### Loop over each perturbation
for kk in range(pert_numb):
if fp_style == "vasp":
pos_in = "POSCAR%d.vasp" % (kk + 1)
pos_in = f"POSCAR{kk}.vasp"
elif fp_style == "abacus":
pos_in = "STRU%d.abacus" % (kk + 1)
dir_out = "%06d" % (kk + 1)
pos_in = f"STRU{kk}.abacus"
dir_out = f"{kk:06d}"
create_path(dir_out)
if fp_style == "vasp":
pos_out = os.path.join(dir_out, "POSCAR")
Expand All @@ -805,35 +808,7 @@ def pert_scaled(jdata):
else:
shutil.copy2(pos_in, pos_out)
os.remove(pos_in)
kk = -1
thangckt marked this conversation as resolved.
Show resolved Hide resolved
if fp_style == "vasp":
pos_in = "POSCAR"
elif fp_style == "abacus":
pos_in = "STRU"
dir_out = "%06d" % (kk + 1)
create_path(dir_out)
if fp_style == "vasp":
pos_out = os.path.join(dir_out, "POSCAR")
elif fp_style == "abacus":
pos_out = os.path.join(dir_out, "STRU")
if not from_poscar:
if fp_style == "vasp":
poscar_shuffle(pos_in, pos_out)
elif fp_style == "abacus":
stru_in = get_abacus_STRU(pos_in)
stru_out = shuffle_stru_data(stru_in)
with open(pos_out, "w") as fp:
fp.write(
make_abacus_scf_stru(
stru_out,
pp_file,
orb_file_names,
dpks_descriptor_name,
type_map=jdata["elements"],
)
)
else:
shutil.copy2(pos_in, pos_out)

os.chdir(cwd)


Expand Down Expand Up @@ -866,7 +841,7 @@ def make_vasp_md(jdata, mdata):

for ii in sys_ps:
for jj in scale:
for kk in range(pert_numb + 1):
for kk in range(pert_numb):
path_work = path_md
path_work = os.path.join(path_work, ii)
path_work = os.path.join(path_work, f"scale-{jj:.3f}")
Expand Down Expand Up @@ -987,7 +962,7 @@ def make_abacus_md(jdata, mdata):

for ii in sys_ps:
for jj in scale:
for kk in range(pert_numb + 1):
for kk in range(pert_numb):
path_work = path_md
path_work = os.path.join(path_work, ii)
path_work = os.path.join(path_work, f"scale-{jj:.3f}")
Expand Down
32 changes: 13 additions & 19 deletions dpgen/data/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import dpgen.data.tools.fcc as fcc
import dpgen.data.tools.hcp as hcp
import dpgen.data.tools.sc as sc
from dpgen import ROOT_PATH, dlog
thangckt marked this conversation as resolved.
Show resolved Hide resolved
from dpgen import dlog
njzjz marked this conversation as resolved.
Show resolved Hide resolved
from dpgen.dispatcher.Dispatcher import make_submission_compat
from dpgen.generator.lib.utils import symlink_user_forward_files
from dpgen.remote.decide_machine import convert_mdata
Expand Down Expand Up @@ -501,26 +501,25 @@ def pert_scaled(jdata):
sys_pe.sort()
os.chdir(cwd)

python_exec = os.path.join(
os.path.dirname(__file__), "tools", "create_random_disturb.py"
)
pert_cmd = (
sys.executable
+ " "
+ os.path.join(ROOT_PATH, "data/tools/create_random_disturb.py")
)
pert_cmd += " -etmax %f -ofmt vasp POSCAR %d %f > /dev/null" % (
pert_box,
pert_numb,
pert_atom,
+ f" {python_exec} -etmax {pert_box} -ofmt vasp POSCAR {pert_numb} {pert_atom} > /dev/null"
)

### Loop over each system and scale
for ii in sys_pe:
for jj in scale:
path_scale = path_sp
path_scale = os.path.join(path_scale, ii)
path_scale = os.path.join(path_scale, f"scale-{jj:.3f}")
path_scale = os.path.join(path_sp, ii, f"scale-{jj:.3f}")
assert os.path.isdir(path_scale)
os.chdir(path_scale)
dlog.info(os.getcwd())
poscar_in = os.path.join(path_scale, "POSCAR")
assert os.path.isfile(poscar_in)

### Loop over each perturbation
for ll in elongs:
path_elong = path_scale
path_elong = os.path.join(path_elong, f"elong-{ll:3.3f}")
Expand All @@ -529,18 +528,13 @@ def pert_scaled(jdata):
poscar_elong(poscar_in, "POSCAR", ll)
sp.check_call(pert_cmd, shell=True)
for kk in range(pert_numb):
pos_in = "POSCAR%d.vasp" % (kk + 1)
dir_out = "%06d" % (kk + 1)
pos_in = f"POSCAR{kk}.vasp"
dir_out = f"{kk:06d}"
create_path(dir_out)
pos_out = os.path.join(dir_out, "POSCAR")
poscar_shuffle(pos_in, pos_out)
os.remove(pos_in)
kk = -1
pos_in = "POSCAR"
dir_out = "%06d" % (kk + 1)
create_path(dir_out)
pos_out = os.path.join(dir_out, "POSCAR")
poscar_shuffle(pos_in, pos_out)

os.chdir(cwd)


Expand Down
5 changes: 3 additions & 2 deletions dpgen/data/tools/create_random_disturb.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def create_disturbs_ase_dev(
cell0 = atoms.get_cell()

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

Expand Down Expand Up @@ -194,7 +195,7 @@ def create_disturbs_abacus_dev(
cell0 = stru["cells"]

# creat nfile ofmt files.
for fid in range(1, nfile + 1):
for fid in range(nfile):
thangckt marked this conversation as resolved.
Show resolved Hide resolved
# Use copy(), otherwise it will modify the input atoms every time.
stru_d = stru.copy()

Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_gen_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test(self):
self.assertEqual(len(scales), self.scale_numb)
for scale in scales:
perts = glob.glob(os.path.join(scale, "[0-9]*"))
self.assertEqual(len(perts), self.pert_numb + 1)
self.assertEqual(len(perts), self.pert_numb)
thangckt marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_gen_bulk_abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def testSTRU(self):
self.assertEqual(len(scales), self.scale_numb)
for scale in scales:
perts = glob.glob(os.path.join(scale, "[0-9]*"))
self.assertEqual(len(perts), self.pert_numb + 1)
self.assertEqual(len(perts), self.pert_numb)


if __name__ == "__main__":
Expand Down
Loading