pwact 0.1.28__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pwact-0.2.1/PKG-INFO +17 -0
- pwact-0.2.1/README.md +3 -0
- pwact-0.2.1/pwact/active_learning/environment.py +18 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/explore/run_model_md.py +110 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/explore/select_image.py +10 -5
- pwact-0.2.1/pwact/active_learning/init_bulk/direct.py +182 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/init_bulk/duplicate_scale.py +1 -1
- pwact-0.2.1/pwact/active_learning/init_bulk/explore.py +300 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/init_bulk/init_bulk_run.py +87 -47
- pwact-0.2.1/pwact/active_learning/init_bulk/relabel.py +233 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/label/labeling.py +132 -18
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/train/train_model.py +13 -3
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/init_bulk_input.py +55 -6
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/iter_input.py +12 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/resource.py +19 -7
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/scf_param.py +24 -6
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/nep_param.py +2 -2
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/optimizer_param.py +1 -1
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/work_file_param.py +1 -1
- {pwact-0.1.28 → pwact-0.2.1}/pwact/main.py +18 -9
- pwact-0.2.1/pwact/utils/app_lib/do_direct_sample.py +145 -0
- pwact-0.2.1/pwact/utils/app_lib/do_eqv2model.py +41 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/app_lib/lammps.py +1 -1
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/constant.py +32 -12
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/file_operation.py +12 -5
- pwact-0.2.1/pwact.egg-info/PKG-INFO +17 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact.egg-info/SOURCES.txt +4 -0
- {pwact-0.1.28 → pwact-0.2.1}/setup.py +1 -1
- pwact-0.1.28/PKG-INFO +0 -107
- pwact-0.1.28/README.md +0 -93
- pwact-0.1.28/pwact/active_learning/environment.py +0 -16
- pwact-0.1.28/pwact/active_learning/init_bulk/relabel.py +0 -200
- pwact-0.1.28/pwact.egg-info/PKG-INFO +0 -107
- {pwact-0.1.28 → pwact-0.2.1}/LICENSE +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/explore/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/init_bulk/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/init_bulk/aimd.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/init_bulk/relax.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/label/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/slurm/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/slurm/slurm.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/slurm/slurm_tool.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/test/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/test/test.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/train/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/train/dp_kpu.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/cmd_infos.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/model_param.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/nn_feature_type.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/train_param/train_param.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/active_learning/user_input/workdir.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/bin/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/data_format/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/data_format/configop.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/app_lib/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/app_lib/common.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/app_lib/cp2k.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/app_lib/cp2k_dp.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/app_lib/pwmat.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/draw/__init__.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/draw/hist_model_devi.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/format_input_output.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/json_operation.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/pre_al_data_util.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/process_tool.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/slurm_script.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact/utils/tmp.py +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact.egg-info/dependency_links.txt +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact.egg-info/entry_points.txt +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/pwact.egg-info/top_level.txt +0 -0
- {pwact-0.1.28 → pwact-0.2.1}/setup.cfg +0 -0
pwact-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pwact
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: PWACT is an open-source automated active learning platform based on PWMLFF for efficient data sampling.
|
|
5
|
+
Home-page: https://github.com/LonxunQuantum/PWact
|
|
6
|
+
Author: LonxunQuantum
|
|
7
|
+
Author-email: lonxun@pwmat.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# Dependencies
|
|
16
|
+
|
|
17
|
+
Please refer to the [`user manual`](http://doc.lonxun.com/PWMLFF/pwact/)
|
pwact-0.2.1/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import pkg_resources
|
|
3
|
+
def check_envs():
|
|
4
|
+
# for pwmat
|
|
5
|
+
comm_info()
|
|
6
|
+
|
|
7
|
+
def comm_info():
|
|
8
|
+
print("\n" + "=" * 50)
|
|
9
|
+
print(" PWACT Basic Information")
|
|
10
|
+
print("=" * 50)
|
|
11
|
+
print("Version: 0.2.0")
|
|
12
|
+
print("Compatible pwdata: >= 0.5.0")
|
|
13
|
+
print("Compatible MatPL: >= 2025.3")
|
|
14
|
+
print("Contact: support@pwmat.com")
|
|
15
|
+
print("Citation: https://github.com/LonxunQuantum/MatPL")
|
|
16
|
+
print("Manual online: http://doc.lonxun.com/PWMLFF/")
|
|
17
|
+
print("=" * 50)
|
|
18
|
+
print("\n\n")
|
|
@@ -30,8 +30,10 @@ from pwact.utils.draw.hist_model_devi import draw_hist_list
|
|
|
30
30
|
from pwact.utils.app_lib.lammps import make_lammps_input
|
|
31
31
|
from pwact.data_format.configop import save_config, get_atom_type
|
|
32
32
|
|
|
33
|
+
from pwdata import Config
|
|
33
34
|
import os
|
|
34
35
|
import glob
|
|
36
|
+
import numpy as np
|
|
35
37
|
import pandas as pd
|
|
36
38
|
"""
|
|
37
39
|
md_dir:
|
|
@@ -66,11 +68,13 @@ class Explore(object):
|
|
|
66
68
|
self.explore_dir = os.path.join(self.input_param.root_dir, itername, TEMP_STRUCTURE.tmp_run_iter_dir, AL_STRUCTURE.explore)
|
|
67
69
|
self.md_dir = os.path.join(self.explore_dir, EXPLORE_FILE_STRUCTURE.md)
|
|
68
70
|
self.select_dir = os.path.join(self.explore_dir, EXPLORE_FILE_STRUCTURE.select)
|
|
71
|
+
self.direct_dir = os.path.join(self.explore_dir, EXPLORE_FILE_STRUCTURE.direct)
|
|
69
72
|
self.kpu_dir = os.path.join(self.explore_dir, EXPLORE_FILE_STRUCTURE.kpu) # for kpu calculate
|
|
70
73
|
|
|
71
74
|
self.real_explore_dir = os.path.join(self.input_param.root_dir, itername, AL_STRUCTURE.explore)
|
|
72
75
|
self.real_md_dir = os.path.join(self.real_explore_dir, EXPLORE_FILE_STRUCTURE.md)
|
|
73
76
|
self.real_select_dir = os.path.join(self.real_explore_dir, EXPLORE_FILE_STRUCTURE.select)
|
|
77
|
+
self.real_direct_dir = os.path.join(self.real_explore_dir, EXPLORE_FILE_STRUCTURE.direct)
|
|
74
78
|
self.real_kpu_dir = os.path.join(self.real_explore_dir, EXPLORE_FILE_STRUCTURE.kpu) # for kpu calculate
|
|
75
79
|
|
|
76
80
|
def back_explore(self):
|
|
@@ -334,6 +338,14 @@ class Explore(object):
|
|
|
334
338
|
os.path.join(self.select_dir, "model_devi_distribution-{}.png".format(os.path.basename(md_sys_dir)))
|
|
335
339
|
)
|
|
336
340
|
copy_dir(self.select_dir, self.real_select_dir)
|
|
341
|
+
if self.input_param.strategy.direct:
|
|
342
|
+
# delete nouse files
|
|
343
|
+
del_file_list_by_patten(self.direct_dir, "slurm-*")
|
|
344
|
+
del_file_list_by_patten(self.direct_dir, "*tag*")
|
|
345
|
+
# copy direct dir
|
|
346
|
+
copy_dir(source_dir=self.direct_dir,
|
|
347
|
+
target_dir=self.real_direct_dir)
|
|
348
|
+
|
|
337
349
|
|
|
338
350
|
'''
|
|
339
351
|
description:
|
|
@@ -369,4 +381,102 @@ class Explore(object):
|
|
|
369
381
|
print("Image select result:\n {}\n\n".format(summary_info))
|
|
370
382
|
return summary
|
|
371
383
|
|
|
384
|
+
|
|
385
|
+
def make_drct_work(self):
|
|
386
|
+
md_work_list = []
|
|
387
|
+
# read candidate.csv
|
|
388
|
+
candidate = pd.read_csv(os.path.join(self.select_dir, EXPLORE_FILE_STRUCTURE.candidate))
|
|
389
|
+
# make scf work dir
|
|
390
|
+
image_list = None
|
|
391
|
+
for index, row in candidate.iterrows():
|
|
392
|
+
config_index = int(row["config_index"])
|
|
393
|
+
sub_md_sys_path = row["file_path"]
|
|
394
|
+
atom_names = None
|
|
395
|
+
with open(os.path.join(sub_md_sys_path, LAMMPS.atom_type_file), 'r') as rf:
|
|
396
|
+
line = rf.readline()
|
|
397
|
+
atom_names = line.split()
|
|
398
|
+
if image_list is None:
|
|
399
|
+
image_list = Config(data_path=os.path.join(sub_md_sys_path, EXPLORE_FILE_STRUCTURE.traj, "{}{}".format(config_index, LAMMPS.traj_postfix)),
|
|
400
|
+
format=PWDATA.lammps_dump, atom_names=atom_names)
|
|
401
|
+
else:
|
|
402
|
+
image_list.append(Config(data_path=os.path.join(sub_md_sys_path, EXPLORE_FILE_STRUCTURE.traj, "{}{}".format(config_index, LAMMPS.traj_postfix)),
|
|
403
|
+
format=PWDATA.lammps_dump, atom_names=atom_names))
|
|
404
|
+
# cvt_lammps.dump to extxyz
|
|
405
|
+
image_list.to(data_path=self.direct_dir, format=PWDATA.extxyz, data_name="{}".format(EXPLORE_FILE_STRUCTURE.candidate_xyz))
|
|
406
|
+
# copy direct script
|
|
407
|
+
copy_file(self.input_param.strategy.direct_script, os.path.join(self.direct_dir, os.path.basename(self.input_param.strategy.direct_script)))
|
|
408
|
+
# make direct work slurm file
|
|
409
|
+
|
|
410
|
+
self.make_drct_slurm_jobs([self.direct_dir])
|
|
411
|
+
|
|
412
|
+
def make_drct_slurm_jobs(self, md_work_list:list[str]):
|
|
413
|
+
# delete old job file
|
|
414
|
+
del_file_list_by_patten(self.direct_dir, "*{}".format(EXPLORE_FILE_STRUCTURE.direct_job))
|
|
415
|
+
group_list = split_job_for_group(1, md_work_list, 1)
|
|
416
|
+
for g_index, group in enumerate(group_list):
|
|
417
|
+
if group[0] == "NONE":
|
|
418
|
+
continue
|
|
419
|
+
jobname = "direct{}".format(g_index)
|
|
420
|
+
tag_name = "{}-{}".format(g_index, EXPLORE_FILE_STRUCTURE.direct_tag)
|
|
421
|
+
tag = os.path.join(self.direct_dir, tag_name)
|
|
422
|
+
|
|
423
|
+
run_cmd = self.resource.direct_resource.command
|
|
424
|
+
|
|
425
|
+
group_slurm_script = set_slurm_script_content(
|
|
426
|
+
gpu_per_node=self.resource.direct_resource.gpu_per_node,
|
|
427
|
+
number_node = self.resource.direct_resource.number_node, #1
|
|
428
|
+
cpu_per_node = self.resource.direct_resource.cpu_per_node,
|
|
429
|
+
queue_name = self.resource.direct_resource.queue_name,
|
|
430
|
+
custom_flags = self.resource.direct_resource.custom_flags,
|
|
431
|
+
env_script = self.resource.direct_resource.env_script,
|
|
432
|
+
job_name = jobname,
|
|
433
|
+
run_cmd_template = run_cmd,
|
|
434
|
+
group = group,
|
|
435
|
+
job_tag = tag,
|
|
436
|
+
task_tag = EXPLORE_FILE_STRUCTURE.direct_tag,
|
|
437
|
+
task_tag_faild = EXPLORE_FILE_STRUCTURE.direct_tag_faild,
|
|
438
|
+
parallel_num=self.resource.direct_resource.parallel_num,
|
|
439
|
+
check_type=None
|
|
440
|
+
)
|
|
441
|
+
slurm_script_name = "{}-{}".format(g_index, EXPLORE_FILE_STRUCTURE.direct_job)
|
|
442
|
+
slurm_job_file = os.path.join(self.direct_dir, slurm_script_name)
|
|
443
|
+
write_to_file(slurm_job_file, group_slurm_script, "w")
|
|
444
|
+
|
|
445
|
+
def do_drct_jobs(self):
|
|
446
|
+
mission = Mission()
|
|
447
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.direct_dir, \
|
|
448
|
+
job_patten="*-{}".format(EXPLORE_FILE_STRUCTURE.direct_job), \
|
|
449
|
+
tag_patten="*-{}".format(EXPLORE_FILE_STRUCTURE.direct_tag))
|
|
450
|
+
# for slurm remain, check if tags done
|
|
451
|
+
slurm_done = True if len(slurm_remain) == 0 and len(slurm_success) > 0 else False
|
|
452
|
+
if slurm_done is False:
|
|
453
|
+
slurm_remain = recheck_slurm_by_jobtag(slurm_remain, EXPLORE_FILE_STRUCTURE.md_tag)
|
|
454
|
+
if len(slurm_remain) > 0:
|
|
455
|
+
#recover slurm jobs
|
|
456
|
+
if len(slurm_remain) > 0:
|
|
457
|
+
print("Run these MD Direct Jobs:\n")
|
|
458
|
+
print(slurm_remain)
|
|
459
|
+
for i, script_path in enumerate(slurm_remain):
|
|
460
|
+
slurm_job = SlurmJob()
|
|
461
|
+
tag_name = "{}-{}".format(os.path.basename(script_path).split('-')[0].strip(), EXPLORE_FILE_STRUCTURE.direct_tag)
|
|
462
|
+
tag = os.path.join(os.path.dirname(script_path),tag_name)
|
|
463
|
+
slurm_job.set_tag(tag, job_type=SLURM_JOB_TYPE.direct)
|
|
464
|
+
slurm_job.set_cmd(script_path)
|
|
465
|
+
mission.add_job(slurm_job)
|
|
466
|
+
|
|
467
|
+
if len(mission.job_list) > 0:
|
|
468
|
+
mission.commit_jobs()
|
|
469
|
+
mission.check_running_job()
|
|
470
|
+
mission.all_job_finished()
|
|
471
|
+
|
|
472
|
+
def post_drct(self):
|
|
473
|
+
select_idx = np.loadtxt(os.path.join(self.direct_dir, "{}".format(EXPLORE_FILE_STRUCTURE.select_idx)))
|
|
474
|
+
count = 0
|
|
475
|
+
with open(os.path.join(self.direct_dir, EXPLORE_FILE_STRUCTURE.candidate_xyz), 'r') as file:
|
|
476
|
+
for line in file:
|
|
477
|
+
count += line.count("Lattice")
|
|
372
478
|
|
|
479
|
+
summary = "Direct selection: Before : {} configs, After : {} selected.\n\n".format(select_idx.shape[0], count)
|
|
480
|
+
write_to_file(os.path.join(self.input_param.root_dir, EXPLORE_FILE_STRUCTURE.iter_select_file), summary, mode='a')
|
|
481
|
+
print(summary)
|
|
482
|
+
return summary
|
|
@@ -90,6 +90,11 @@ def select_image(
|
|
|
90
90
|
accurate_pd =None
|
|
91
91
|
rand_candi =None
|
|
92
92
|
remove_candi =None
|
|
93
|
+
|
|
94
|
+
error_pd = pd.DataFrame(columns=EXPLORE_FILE_STRUCTURE.devi_columns)
|
|
95
|
+
accurate_pd = pd.DataFrame(columns=EXPLORE_FILE_STRUCTURE.devi_columns)
|
|
96
|
+
rand_candi = pd.DataFrame(columns=EXPLORE_FILE_STRUCTURE.devi_columns)
|
|
97
|
+
remove_candi = pd.DataFrame(columns=EXPLORE_FILE_STRUCTURE.devi_columns)
|
|
93
98
|
|
|
94
99
|
for md in md_sys_dict.keys():
|
|
95
100
|
sys_dict = md_sys_dict[md]
|
|
@@ -104,10 +109,10 @@ def select_image(
|
|
|
104
109
|
_lower = lower
|
|
105
110
|
_higer = higer
|
|
106
111
|
tmp_error_pd, tmp_accurate_pd, tmp_rand_candi, tmp_remove_candi = select_pd(tmp_devi_pd, _lower, _higer, select_num)
|
|
107
|
-
error_pd = pd.concat([error_pd, tmp_error_pd])
|
|
108
|
-
accurate_pd = pd.concat([accurate_pd, tmp_accurate_pd])
|
|
109
|
-
rand_candi = pd.concat([rand_candi, tmp_rand_candi])
|
|
110
|
-
remove_candi = pd.concat([remove_candi, tmp_remove_candi])
|
|
112
|
+
error_pd = pd.concat([error_pd, tmp_error_pd])
|
|
113
|
+
accurate_pd = pd.concat([accurate_pd, tmp_accurate_pd])
|
|
114
|
+
rand_candi = pd.concat([rand_candi, tmp_rand_candi])
|
|
115
|
+
remove_candi = pd.concat([remove_candi, tmp_remove_candi])
|
|
111
116
|
right_md, error_md = count_mdstop_info(model_devi_files)
|
|
112
117
|
md_run_info = "A total of {} MD trajectories were run. with {} trajectories correctly executed and {} trajectories normally completed. \nFor detailed information, refer to File {}.".format(len(right_md) + len(error_md), len(right_md), len(error_md), EXPLORE_FILE_STRUCTURE.md_traj_error_record)
|
|
113
118
|
|
|
@@ -245,7 +250,7 @@ def count_info(save_dir, error_pd, accurate_pd, rand_candi, remove_candi, md_run
|
|
|
245
250
|
format(error_pd.shape[0], EXPLORE_FILE_STRUCTURE.failed)
|
|
246
251
|
if md_run_info is not None:
|
|
247
252
|
summary_info += md_run_info
|
|
248
|
-
summary_info += "\n
|
|
253
|
+
summary_info += "\n"
|
|
249
254
|
|
|
250
255
|
summary += md_run_info
|
|
251
256
|
summary += "\n"
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""
|
|
2
|
+
do md with bigmodel
|
|
3
|
+
--/work_path/
|
|
4
|
+
------------/relax
|
|
5
|
+
-----------------/*_init_config/*_init_.config, etot.input, pseudo files, final.config, mvms_relax
|
|
6
|
+
------------/super_cell_scale
|
|
7
|
+
-----------------/*_init_config/scale.config, from final.config or *_init_.config
|
|
8
|
+
------------/perturb
|
|
9
|
+
--------------------/*_init_config/scale.config or final.config
|
|
10
|
+
----------------------------------/structures/*.config_perturb
|
|
11
|
+
|
|
12
|
+
------------/AIMD
|
|
13
|
+
-----------------/*_init_config/*_config_dir the config file from pertub or *_init_.config
|
|
14
|
+
-------------------------------/etot.input, atom.config, ...
|
|
15
|
+
or
|
|
16
|
+
------------/BIGMODEL
|
|
17
|
+
-----------------/*_init_config/*_config_dir the config file from pertub or *_init_.config
|
|
18
|
+
-------------------------------/bigmodel_md_script.py, POSCAR, ...
|
|
19
|
+
------------/DIRECT
|
|
20
|
+
-----------------/*_init_config/*_config_dir the config file from pertub or *_init_.config
|
|
21
|
+
-------------------------------/direct_script.py, POSCAR, ...
|
|
22
|
+
|
|
23
|
+
-----------/result
|
|
24
|
+
-----------------/*_init_config/relax_mvm_*_init_config if need; aimd_mvm_*_init_config if need
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
import os
|
|
28
|
+
|
|
29
|
+
from pwact.active_learning.user_input.resource import Resource
|
|
30
|
+
from pwact.active_learning.user_input.init_bulk_input import InitBulkParam
|
|
31
|
+
from pwact.active_learning.init_bulk.duplicate_scale import get_config_files_with_order
|
|
32
|
+
|
|
33
|
+
from pwact.utils.constant import PWMAT, INIT_BULK, TEMP_STRUCTURE, SLURM_OUT, DFT_STYLE
|
|
34
|
+
from pwact.active_learning.slurm.slurm import SlurmJob, Mission
|
|
35
|
+
from pwact.utils.slurm_script import get_slurm_job_run_info, split_job_for_group, set_slurm_script_content
|
|
36
|
+
|
|
37
|
+
from pwact.utils.file_operation import write_to_file, link_file, del_file_list_by_patten, copy_file
|
|
38
|
+
from pwact.utils.app_lib.common import link_pseudo_by_atom, set_input_script
|
|
39
|
+
from pwact.data_format.configop import save_config, get_atom_type
|
|
40
|
+
|
|
41
|
+
class DIRECT(object):
|
|
42
|
+
def __init__(self, resource: Resource, input_param:InitBulkParam):
|
|
43
|
+
self.resource = resource
|
|
44
|
+
self.input_param = input_param
|
|
45
|
+
self.init_configs = self.input_param.sys_config
|
|
46
|
+
self.relax_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.relax)
|
|
47
|
+
self.super_cell_scale_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.super_cell_scale)
|
|
48
|
+
self.pertub_dir = os.path.join(self.input_param.root_dir,TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.pertub)
|
|
49
|
+
self.bigmodel_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.bigmodel)
|
|
50
|
+
self.real_bigmodel_dir = os.path.join(self.input_param.root_dir, INIT_BULK.bigmodel)
|
|
51
|
+
self.direct_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.direct)
|
|
52
|
+
self.real_direct_dir = os.path.join(self.input_param.root_dir, INIT_BULK.direct)
|
|
53
|
+
|
|
54
|
+
def make_bigmodel_work(self):
|
|
55
|
+
bigmodel_paths = []
|
|
56
|
+
for init_config in self.init_configs:
|
|
57
|
+
if init_config.bigmodel is False:
|
|
58
|
+
continue
|
|
59
|
+
init_config_name = "init_config_{}".format(init_config.config_index)
|
|
60
|
+
# config_list, config_type = get_config_files_with_order(self.super_cell_scale_dir, self.relax_dir, init_config_name, init_config.config, self.pertub_dir)
|
|
61
|
+
config_list, config_type = get_config_files_with_order(
|
|
62
|
+
super_cell_scale_dir=self.super_cell_scale_dir,
|
|
63
|
+
relax_dir=self.relax_dir,
|
|
64
|
+
init_config_dirname=init_config_name,
|
|
65
|
+
init_config_path=init_config.config_file,
|
|
66
|
+
pertub_dir=self.pertub_dir,
|
|
67
|
+
dft_style=self.resource.dft_style
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
for index, config in enumerate(config_list):
|
|
71
|
+
if config_type == INIT_BULK.pertub:
|
|
72
|
+
tmp_config_dir = os.path.basename(os.path.basename(os.path.dirname(config)))
|
|
73
|
+
elif config_type == INIT_BULK.super_cell or config_type == INIT_BULK.scale:
|
|
74
|
+
tmp_config_dir = os.path.basename(config).replace(DFT_STYLE.get_postfix(self.resource.dft_style), "")
|
|
75
|
+
elif config_type == INIT_BULK.relax:
|
|
76
|
+
tmp_config_dir = INIT_BULK.relax
|
|
77
|
+
else:
|
|
78
|
+
tmp_config_dir = INIT_BULK.init
|
|
79
|
+
bigmodel_dir = os.path.join(self.bigmodel_dir, init_config_name, tmp_config_dir, "{}_{}".format(index, INIT_BULK.bigmodel))
|
|
80
|
+
if not os.path.exists(bigmodel_dir):
|
|
81
|
+
os.makedirs(bigmodel_dir)
|
|
82
|
+
|
|
83
|
+
self.make_bigmodel_file(
|
|
84
|
+
bigmodel_dir=bigmodel_dir,
|
|
85
|
+
config_file=config,
|
|
86
|
+
conifg_format=DFT_STYLE.get_format_by_postfix(os.path.basename(config)),
|
|
87
|
+
input_file=init_config.bigmodel_input_file)
|
|
88
|
+
|
|
89
|
+
bigmodel_paths.append(bigmodel_dir)
|
|
90
|
+
# make slurm script and slurm job
|
|
91
|
+
self.make_bigmodel_slurm_job_files(bigmodel_paths)
|
|
92
|
+
|
|
93
|
+
def check_work_done(self):
|
|
94
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.bigmodel_dir, \
|
|
95
|
+
job_patten="*-{}".format(INIT_BULK.bigmodel_job), \
|
|
96
|
+
tag_patten="*-{}".format(INIT_BULK.bigmodel_tag))
|
|
97
|
+
slurm_done = True if len(slurm_remain) == 0 and len(slurm_success) > 0 else False # len(slurm_remain) > 0 exist slurm jobs need to do
|
|
98
|
+
return slurm_done
|
|
99
|
+
|
|
100
|
+
def do_bigmodel_jobs(self):
|
|
101
|
+
mission = Mission()
|
|
102
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.bigmodel_dir, \
|
|
103
|
+
job_patten="*-{}".format(INIT_BULK.bigmodel_job), \
|
|
104
|
+
tag_patten="*-{}".format(INIT_BULK.bigmodel_tag))
|
|
105
|
+
slurm_done = True if len(slurm_remain) == 0 and len(slurm_success) > 0 else False # len(slurm_remain) > 0 exist slurm jobs need to do
|
|
106
|
+
if slurm_done is False:
|
|
107
|
+
#recover slurm jobs
|
|
108
|
+
if len(slurm_remain) > 0:
|
|
109
|
+
print("Run these bigmodel Jobs:\n")
|
|
110
|
+
print(slurm_remain)
|
|
111
|
+
for i, script_path in enumerate(slurm_remain):
|
|
112
|
+
slurm_job = SlurmJob()
|
|
113
|
+
tag_name = "{}-{}".format(os.path.basename(script_path).split('-')[0].strip(), INIT_BULK.bigmodel_tag)
|
|
114
|
+
tag = os.path.join(os.path.dirname(script_path),tag_name)
|
|
115
|
+
slurm_job.set_tag(tag)
|
|
116
|
+
slurm_job.set_cmd(script_path)
|
|
117
|
+
mission.add_job(slurm_job)
|
|
118
|
+
|
|
119
|
+
if len(mission.job_list) > 0:
|
|
120
|
+
mission.commit_jobs()
|
|
121
|
+
mission.check_running_job()
|
|
122
|
+
mission.all_job_finished()
|
|
123
|
+
# mission.move_slurm_log_to_slurm_work_dir()
|
|
124
|
+
|
|
125
|
+
'''
|
|
126
|
+
description:
|
|
127
|
+
input_file is aimd input control file, for vasp is incar, for pwmat is etot.input
|
|
128
|
+
return {*}
|
|
129
|
+
author: wuxingxing
|
|
130
|
+
'''
|
|
131
|
+
def make_bigmodel_file(
|
|
132
|
+
bigmodel_dir=str,
|
|
133
|
+
config_file=str,
|
|
134
|
+
conifg_format=str,
|
|
135
|
+
input_file=str):
|
|
136
|
+
#1. set config file, cvt to poscar format
|
|
137
|
+
target_config = save_config(config=config_file,
|
|
138
|
+
input_format=conifg_format,
|
|
139
|
+
wrap = False,
|
|
140
|
+
direct = True,
|
|
141
|
+
sort = True,
|
|
142
|
+
save_format=DFT_STYLE.poscar,
|
|
143
|
+
save_path=bigmodel_dir,
|
|
144
|
+
save_name=DFT_STYLE.get_normal_config(DFT_STYLE.vasp)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
atom_type_list, _ = get_atom_type(config_file, conifg_format)
|
|
148
|
+
#2. copy script file
|
|
149
|
+
copy_file(input_file, os.path.join(bigmodel_dir, os.path.basename(input_file)))
|
|
150
|
+
|
|
151
|
+
def make_bigmodel_slurm_job_files(self, bigmodel_dir_list:list[str]):
|
|
152
|
+
del_file_list_by_patten(self.bigmodel_dir, "*{}".format(INIT_BULK.bigmodel_job))
|
|
153
|
+
group_list = split_job_for_group(self.resource.explore_resource.group_size, bigmodel_dir_list, self.resource.explore_resource.parallel_num)
|
|
154
|
+
for group_index, group in enumerate(group_list):
|
|
155
|
+
if group[0] == "NONE":
|
|
156
|
+
continue
|
|
157
|
+
jobname = "bigmodel{}".format(group_index)
|
|
158
|
+
tag_name = "{}-{}".format(group_index, INIT_BULK.bigmodel_tag)
|
|
159
|
+
tag = os.path.join(self.bigmodel_dir, tag_name)
|
|
160
|
+
run_cmd = self.resource.explore_resource.command
|
|
161
|
+
group_slurm_script = set_slurm_script_content(gpu_per_node=self.resource.explore_resource.gpu_per_node,
|
|
162
|
+
number_node = self.resource.explore_resource.number_node,
|
|
163
|
+
cpu_per_node = self.resource.explore_resource.cpu_per_node,
|
|
164
|
+
queue_name = self.resource.explore_resource.queue_name,
|
|
165
|
+
custom_flags = self.resource.explore_resource.custom_flags,
|
|
166
|
+
env_script = self.resource.explore_resource.env_script,
|
|
167
|
+
job_name = jobname,
|
|
168
|
+
run_cmd_template = run_cmd,
|
|
169
|
+
group = group,
|
|
170
|
+
job_tag = tag,
|
|
171
|
+
task_tag = INIT_BULK.bigmodel_tag,
|
|
172
|
+
task_tag_faild = INIT_BULK.bigmodel_tag_failed,
|
|
173
|
+
parallel_num=self.resource.dft_resource.parallel_num,
|
|
174
|
+
check_type=self.resource.dft_style
|
|
175
|
+
)
|
|
176
|
+
slurm_script_name = "{}-{}".format(group_index, INIT_BULK.bigmodel_job)
|
|
177
|
+
slurm_job_file = os.path.join(self.bigmodel_dir, slurm_script_name)
|
|
178
|
+
write_to_file(slurm_job_file, group_slurm_script, "w")
|
|
179
|
+
|
|
180
|
+
def do_post_process(self):
|
|
181
|
+
if os.path.exists(self.bigmodel_dir):
|
|
182
|
+
link_file(self.bigmodel_dir, self.real_bigmodel_dir)
|