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 26 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
44 changes: 25 additions & 19 deletions dpgen/data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,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 @@ -746,6 +745,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 @@ -754,35 +754,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+1}.vasp"
elif fp_style == "abacus":
pos_in = "STRU%d.abacus" % (kk + 1)
dir_out = "%06d" % (kk + 1)
pos_in = f"STRU{kk+1}.abacus"
dir_out = f"{kk+1:06d}"
create_path(dir_out)
if fp_style == "vasp":
pos_out = os.path.join(dir_out, "POSCAR")
Expand All @@ -807,12 +810,14 @@ def pert_scaled(jdata):
else:
shutil.copy2(pos_in, pos_out)
os.remove(pos_in)

### Handle special case (unperturbed ?)
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)
dir_out = f"{kk+1:06d}"
create_path(dir_out)
if fp_style == "vasp":
pos_out = os.path.join(dir_out, "POSCAR")
Expand All @@ -836,6 +841,7 @@ def pert_scaled(jdata):
)
else:
shutil.copy2(pos_in, pos_out)

os.chdir(cwd)


Expand Down
50 changes: 25 additions & 25 deletions dpgen/data/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 @@ -354,15 +354,16 @@
out_dir = jdata["out_dir"]
potcars = jdata["potcars"]
cwd = os.getcwd()

work_dir = os.path.join(out_dir, global_dirname_02)
assert os.path.isdir(work_dir)
work_dir = os.path.abspath(work_dir)

if os.path.isfile(os.path.join(work_dir, "INCAR")):
os.remove(os.path.join(work_dir, "INCAR"))
if os.path.isfile(os.path.join(work_dir, "POTCAR")):
os.remove(os.path.join(work_dir, "POTCAR"))
shutil.copy2(jdata["relax_incar"], os.path.join(work_dir, "INCAR"))

out_potcar = os.path.join(work_dir, "POTCAR")
with open(out_potcar, "w") as outfile:
for fname in potcars:
Expand Down Expand Up @@ -442,15 +443,12 @@
for jj in scale:
if skip_relax:
pos_src = os.path.join(os.path.join(init_path, ii), "POSCAR")
assert os.path.isfile(pos_src)
thangckt marked this conversation as resolved.
Show resolved Hide resolved
else:
try:
pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR")
assert os.path.isfile(pos_src)
except Exception:
raise RuntimeError(
"not file %s, vasp relaxation should be run before scale poscar"
)
pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR")

Check warning on line 447 in dpgen/data/surf.py

View check run for this annotation

Codecov / codecov/patch

dpgen/data/surf.py#L447

Added line #L447 was not covered by tests
if not os.path.isfile(pos_src):
raise RuntimeError(

Check warning on line 449 in dpgen/data/surf.py

View check run for this annotation

Codecov / codecov/patch

dpgen/data/surf.py#L449

Added line #L449 was not covered by tests
f"file {pos_src} not found, vasp relaxation should be run before scale poscar"
)
njzjz marked this conversation as resolved.
Show resolved Hide resolved
scale_path = os.path.join(work_path, ii)
scale_path = os.path.join(scale_path, f"scale-{jj:.3f}")
create_path(scale_path)
Expand Down Expand Up @@ -503,46 +501,48 @@
sys_pe.sort()
os.chdir(cwd)

### Construct the perturbation command
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}")
path_elong = os.path.join(path_scale, f"elong-{ll:3.3f}")
create_path(path_elong)
os.chdir(path_elong)
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+1}.vasp"
dir_out = f"{kk+1:06d}"
create_path(dir_out)
pos_out = os.path.join(dir_out, "POSCAR")
poscar_shuffle(pos_in, pos_out)
os.remove(pos_in)

### Handle special case (unperturbed ?)
kk = -1
pos_in = "POSCAR"
dir_out = "%06d" % (kk + 1)
dir_out = f"{kk+1:06d}"
create_path(dir_out)
pos_out = os.path.join(dir_out, "POSCAR")
poscar_shuffle(pos_in, pos_out)

os.chdir(cwd)


Expand Down