pwact 0.1.28__py3-none-any.whl → 0.2.1__py3-none-any.whl
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/active_learning/environment.py +13 -11
- pwact/active_learning/explore/run_model_md.py +110 -0
- pwact/active_learning/explore/select_image.py +10 -5
- pwact/active_learning/init_bulk/direct.py +182 -0
- pwact/active_learning/init_bulk/duplicate_scale.py +1 -1
- pwact/active_learning/init_bulk/explore.py +300 -0
- pwact/active_learning/init_bulk/init_bulk_run.py +87 -47
- pwact/active_learning/init_bulk/relabel.py +149 -116
- pwact/active_learning/label/labeling.py +132 -18
- pwact/active_learning/train/train_model.py +13 -3
- pwact/active_learning/user_input/init_bulk_input.py +55 -6
- pwact/active_learning/user_input/iter_input.py +12 -0
- pwact/active_learning/user_input/resource.py +19 -7
- pwact/active_learning/user_input/scf_param.py +24 -6
- pwact/active_learning/user_input/train_param/nep_param.py +2 -2
- pwact/active_learning/user_input/train_param/optimizer_param.py +1 -1
- pwact/active_learning/user_input/train_param/work_file_param.py +1 -1
- pwact/main.py +18 -9
- pwact/utils/app_lib/do_direct_sample.py +145 -0
- pwact/utils/app_lib/do_eqv2model.py +41 -0
- pwact/utils/app_lib/lammps.py +1 -1
- pwact/utils/constant.py +32 -12
- pwact/utils/file_operation.py +12 -5
- pwact-0.2.1.dist-info/METADATA +17 -0
- {pwact-0.1.28.dist-info → pwact-0.2.1.dist-info}/RECORD +29 -25
- {pwact-0.1.28.dist-info → pwact-0.2.1.dist-info}/WHEEL +1 -1
- pwact-0.1.28.dist-info/METADATA +0 -107
- {pwact-0.1.28.dist-info → pwact-0.2.1.dist-info}/LICENSE +0 -0
- {pwact-0.1.28.dist-info → pwact-0.2.1.dist-info}/entry_points.txt +0 -0
- {pwact-0.1.28.dist-info → pwact-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,300 @@
|
|
|
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, atom.config, ...
|
|
19
|
+
|
|
20
|
+
-----------/result
|
|
21
|
+
-----------------/*_init_config/relax_mvm_*_init_config if need; aimd_mvm_*_init_config if need
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
from pwact.active_learning.user_input.resource import Resource
|
|
27
|
+
from pwact.active_learning.user_input.init_bulk_input import InitBulkParam
|
|
28
|
+
from pwact.active_learning.init_bulk.duplicate_scale import get_config_files_with_order
|
|
29
|
+
|
|
30
|
+
from pwact.utils.constant import PWMAT, INIT_BULK, TEMP_STRUCTURE, SLURM_OUT, DFT_STYLE, PWDATA
|
|
31
|
+
from pwact.active_learning.slurm.slurm import SlurmJob, Mission
|
|
32
|
+
from pwact.utils.slurm_script import get_slurm_job_run_info, split_job_for_group, set_slurm_script_content
|
|
33
|
+
|
|
34
|
+
from pwact.utils.file_operation import write_to_file, link_file, del_file_list_by_patten, copy_file, merge_files_to_one, save_json_file
|
|
35
|
+
from pwact.utils.app_lib.common import link_pseudo_by_atom, set_input_script
|
|
36
|
+
from pwact.data_format.configop import save_config, get_atom_type
|
|
37
|
+
from pwdata import Config
|
|
38
|
+
|
|
39
|
+
class BIGMODEL(object):
|
|
40
|
+
def __init__(self, resource: Resource, input_param:InitBulkParam):
|
|
41
|
+
self.resource = resource
|
|
42
|
+
self.input_param = input_param
|
|
43
|
+
self.init_configs = self.input_param.sys_config
|
|
44
|
+
self.relax_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.relax)
|
|
45
|
+
self.super_cell_scale_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.super_cell_scale)
|
|
46
|
+
self.pertub_dir = os.path.join(self.input_param.root_dir,TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.pertub)
|
|
47
|
+
self.bigmodel_dir = os.path.join(self.input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.bigmodel)
|
|
48
|
+
self.real_bigmodel_dir = os.path.join(self.input_param.root_dir, INIT_BULK.bigmodel)
|
|
49
|
+
|
|
50
|
+
self.direct_dir = os.path.join(self.bigmodel_dir, INIT_BULK.direct)
|
|
51
|
+
self.real_direct_dir = os.path.join(self.real_bigmodel_dir, INIT_BULK.direct)
|
|
52
|
+
|
|
53
|
+
self.model_traj_files = []
|
|
54
|
+
|
|
55
|
+
def make_bigmodel_work(self):
|
|
56
|
+
bigmodel_paths = []
|
|
57
|
+
|
|
58
|
+
for init_config in self.init_configs:
|
|
59
|
+
if init_config.bigmodel is False:
|
|
60
|
+
continue
|
|
61
|
+
init_config_name = "init_config_{}".format(init_config.config_index)
|
|
62
|
+
# 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)
|
|
63
|
+
config_list, config_type = get_config_files_with_order(
|
|
64
|
+
super_cell_scale_dir=self.super_cell_scale_dir,
|
|
65
|
+
relax_dir=self.relax_dir,
|
|
66
|
+
init_config_dirname=init_config_name,
|
|
67
|
+
init_config_path=init_config.config_file,
|
|
68
|
+
pertub_dir=self.pertub_dir,
|
|
69
|
+
dft_style=self.resource.dft_style
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
for index, config in enumerate(config_list):
|
|
73
|
+
if config_type == INIT_BULK.pertub:
|
|
74
|
+
tmp_config_dir = os.path.basename(os.path.basename(os.path.dirname(config)))
|
|
75
|
+
elif config_type == INIT_BULK.super_cell or config_type == INIT_BULK.scale:
|
|
76
|
+
tmp_config_dir = os.path.basename(config).replace(DFT_STYLE.get_postfix(self.resource.dft_style), "")
|
|
77
|
+
elif config_type == INIT_BULK.relax:
|
|
78
|
+
tmp_config_dir = INIT_BULK.relax
|
|
79
|
+
else:
|
|
80
|
+
tmp_config_dir = INIT_BULK.init
|
|
81
|
+
bigmodel_dir = os.path.join(self.bigmodel_dir, init_config_name, tmp_config_dir, "{}_{}".format(index, INIT_BULK.bigmodel))
|
|
82
|
+
if not os.path.exists(bigmodel_dir):
|
|
83
|
+
os.makedirs(bigmodel_dir)
|
|
84
|
+
|
|
85
|
+
self.make_bigmodel_file(
|
|
86
|
+
bigmodel_dir,
|
|
87
|
+
config,
|
|
88
|
+
DFT_STYLE.get_format_by_postfix(os.path.basename(config)),
|
|
89
|
+
init_config.bigmodel_input_file)
|
|
90
|
+
|
|
91
|
+
self.model_traj_files.append(os.path.join(bigmodel_dir, INIT_BULK.bigmodel_traj))
|
|
92
|
+
|
|
93
|
+
bigmodel_paths.append(bigmodel_dir)
|
|
94
|
+
# make slurm script and slurm job
|
|
95
|
+
self.make_bigmodel_slurm_job_files(bigmodel_paths)
|
|
96
|
+
|
|
97
|
+
def check_work_done(self):
|
|
98
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.bigmodel_dir, \
|
|
99
|
+
job_patten="*-{}".format(INIT_BULK.bigmodel_job), \
|
|
100
|
+
tag_patten="*-{}".format(INIT_BULK.bigmodel_tag))
|
|
101
|
+
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
|
|
102
|
+
return slurm_done
|
|
103
|
+
|
|
104
|
+
def do_bigmodel_jobs(self):
|
|
105
|
+
mission = Mission()
|
|
106
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.bigmodel_dir, \
|
|
107
|
+
job_patten="*-{}".format(INIT_BULK.bigmodel_job), \
|
|
108
|
+
tag_patten="*-{}".format(INIT_BULK.bigmodel_tag))
|
|
109
|
+
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
|
|
110
|
+
if slurm_done is False:
|
|
111
|
+
#recover slurm jobs
|
|
112
|
+
if len(slurm_remain) > 0:
|
|
113
|
+
print("Run these bigmodel Jobs:\n")
|
|
114
|
+
print(slurm_remain)
|
|
115
|
+
for i, script_path in enumerate(slurm_remain):
|
|
116
|
+
slurm_job = SlurmJob()
|
|
117
|
+
tag_name = "{}-{}".format(os.path.basename(script_path).split('-')[0].strip(), INIT_BULK.bigmodel_tag)
|
|
118
|
+
tag = os.path.join(os.path.dirname(script_path),tag_name)
|
|
119
|
+
slurm_job.set_tag(tag)
|
|
120
|
+
slurm_job.set_cmd(script_path)
|
|
121
|
+
mission.add_job(slurm_job)
|
|
122
|
+
|
|
123
|
+
if len(mission.job_list) > 0:
|
|
124
|
+
mission.commit_jobs()
|
|
125
|
+
mission.check_running_job()
|
|
126
|
+
mission.all_job_finished()
|
|
127
|
+
# mission.move_slurm_log_to_slurm_work_dir()
|
|
128
|
+
|
|
129
|
+
'''
|
|
130
|
+
description:
|
|
131
|
+
input_file is aimd input control file, for vasp is incar, for pwmat is etot.input
|
|
132
|
+
return {*}
|
|
133
|
+
author: wuxingxing
|
|
134
|
+
'''
|
|
135
|
+
def make_bigmodel_file(self,
|
|
136
|
+
bigmodel_dir:str,
|
|
137
|
+
config_file:str,
|
|
138
|
+
conifg_format:str,
|
|
139
|
+
input_file:str):
|
|
140
|
+
#1. set config file, cvt to poscar format
|
|
141
|
+
target_config = save_config(config=config_file,
|
|
142
|
+
input_format=conifg_format,
|
|
143
|
+
wrap = False,
|
|
144
|
+
direct = True,
|
|
145
|
+
sort = True,
|
|
146
|
+
save_format=PWDATA.vasp_poscar,
|
|
147
|
+
save_path=bigmodel_dir,
|
|
148
|
+
save_name=DFT_STYLE.get_normal_config(DFT_STYLE.vasp)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
atom_type_list, _ = get_atom_type(config_file, conifg_format)
|
|
152
|
+
#2. copy script file
|
|
153
|
+
copy_file(input_file, os.path.join(bigmodel_dir, os.path.basename(input_file)))
|
|
154
|
+
|
|
155
|
+
def make_bigmodel_slurm_job_files(self, bigmodel_dir_list:list[str]):
|
|
156
|
+
del_file_list_by_patten(self.bigmodel_dir, "*{}".format(INIT_BULK.bigmodel_job))
|
|
157
|
+
group_list = split_job_for_group(self.resource.explore_resource.group_size, bigmodel_dir_list, self.resource.explore_resource.parallel_num)
|
|
158
|
+
for group_index, group in enumerate(group_list):
|
|
159
|
+
if group[0] == "NONE":
|
|
160
|
+
continue
|
|
161
|
+
jobname = "bigmodel{}".format(group_index)
|
|
162
|
+
tag_name = "{}-{}".format(group_index, INIT_BULK.bigmodel_tag)
|
|
163
|
+
tag = os.path.join(self.bigmodel_dir, tag_name)
|
|
164
|
+
run_cmd = self.resource.explore_resource.command
|
|
165
|
+
group_slurm_script = set_slurm_script_content(gpu_per_node=self.resource.explore_resource.gpu_per_node,
|
|
166
|
+
number_node = self.resource.explore_resource.number_node,
|
|
167
|
+
cpu_per_node = self.resource.explore_resource.cpu_per_node,
|
|
168
|
+
queue_name = self.resource.explore_resource.queue_name,
|
|
169
|
+
custom_flags = self.resource.explore_resource.custom_flags,
|
|
170
|
+
env_script = self.resource.explore_resource.env_script,
|
|
171
|
+
job_name = jobname,
|
|
172
|
+
run_cmd_template = run_cmd,
|
|
173
|
+
group = group,
|
|
174
|
+
job_tag = tag,
|
|
175
|
+
task_tag = INIT_BULK.bigmodel_tag,
|
|
176
|
+
task_tag_faild = INIT_BULK.bigmodel_tag_failed,
|
|
177
|
+
parallel_num=self.resource.dft_resource.parallel_num,
|
|
178
|
+
check_type=None
|
|
179
|
+
)
|
|
180
|
+
slurm_script_name = "{}-{}".format(group_index, INIT_BULK.bigmodel_job)
|
|
181
|
+
slurm_job_file = os.path.join(self.bigmodel_dir, slurm_script_name)
|
|
182
|
+
write_to_file(slurm_job_file, group_slurm_script, "w")
|
|
183
|
+
|
|
184
|
+
###### for direct
|
|
185
|
+
def get_traj_files(self):
|
|
186
|
+
model_traj_files = []
|
|
187
|
+
config_dix = []
|
|
188
|
+
for init_dix, init_config in enumerate(self.init_configs):
|
|
189
|
+
if init_config.bigmodel is False:
|
|
190
|
+
continue
|
|
191
|
+
init_config_name = "init_config_{}".format(init_config.config_index)
|
|
192
|
+
# 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)
|
|
193
|
+
config_list, config_type = get_config_files_with_order(
|
|
194
|
+
super_cell_scale_dir=self.super_cell_scale_dir,
|
|
195
|
+
relax_dir=self.relax_dir,
|
|
196
|
+
init_config_dirname=init_config_name,
|
|
197
|
+
init_config_path=init_config.config_file,
|
|
198
|
+
pertub_dir=self.pertub_dir,
|
|
199
|
+
dft_style=self.resource.dft_style
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
for index, config in enumerate(config_list):
|
|
203
|
+
if config_type == INIT_BULK.pertub:
|
|
204
|
+
tmp_config_dir = os.path.basename(os.path.basename(os.path.dirname(config)))
|
|
205
|
+
elif config_type == INIT_BULK.super_cell or config_type == INIT_BULK.scale:
|
|
206
|
+
tmp_config_dir = os.path.basename(config).replace(DFT_STYLE.get_postfix(self.resource.dft_style), "")
|
|
207
|
+
elif config_type == INIT_BULK.relax:
|
|
208
|
+
tmp_config_dir = INIT_BULK.relax
|
|
209
|
+
else:
|
|
210
|
+
tmp_config_dir = INIT_BULK.init
|
|
211
|
+
bigmodel_dir = os.path.join(self.bigmodel_dir, init_config_name, tmp_config_dir, "{}_{}".format(index, INIT_BULK.bigmodel))
|
|
212
|
+
model_traj_files.append(os.path.join(bigmodel_dir, INIT_BULK.bigmodel_traj))
|
|
213
|
+
config_dix.append(init_dix)
|
|
214
|
+
return model_traj_files, config_dix
|
|
215
|
+
|
|
216
|
+
def make_direct_work(self):
|
|
217
|
+
if not os.path.exists(self.direct_dir):
|
|
218
|
+
os.makedirs(self.direct_dir)
|
|
219
|
+
# convert configs to xyz format
|
|
220
|
+
model_traj_files, config_dix = self.get_traj_files()
|
|
221
|
+
candidate_dict = {}
|
|
222
|
+
merge_files_to_one(model_traj_files, os.path.join(self.direct_dir, INIT_BULK.candidate_xyz))
|
|
223
|
+
idx = 0
|
|
224
|
+
for traj_idx, traj in enumerate(model_traj_files):
|
|
225
|
+
image = Config(data_path=traj, format=PWDATA.extxyz)
|
|
226
|
+
candidate_dict[idx] = {}
|
|
227
|
+
candidate_dict[idx]["idx"] = config_dix[traj_idx]
|
|
228
|
+
candidate_dict[idx]["num"] = len(image.images)
|
|
229
|
+
idx += 1
|
|
230
|
+
save_json_file(candidate_dict, os.path.join(self.direct_dir, INIT_BULK.candidate_idx))
|
|
231
|
+
# copy script
|
|
232
|
+
copy_file(self.input_param.dft_input.direct_input_list[0].input_file,
|
|
233
|
+
os.path.join(self.direct_dir, os.path.basename(self.input_param.dft_input.direct_input_list[0].input_file)))
|
|
234
|
+
# make slurm script and slurm job
|
|
235
|
+
self.make_direct_slurm_job_files([self.direct_dir])
|
|
236
|
+
|
|
237
|
+
def check_direct_done(self):
|
|
238
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.direct_dir, \
|
|
239
|
+
job_patten="*-{}".format(INIT_BULK.direct_job), \
|
|
240
|
+
tag_patten="*-{}".format(INIT_BULK.direct_tag))
|
|
241
|
+
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
|
|
242
|
+
return slurm_done
|
|
243
|
+
|
|
244
|
+
def do_direct_jobs(self):
|
|
245
|
+
mission = Mission()
|
|
246
|
+
slurm_remain, slurm_success = get_slurm_job_run_info(self.direct_dir, \
|
|
247
|
+
job_patten="*-{}".format(INIT_BULK.direct_job), \
|
|
248
|
+
tag_patten="*-{}".format(INIT_BULK.direct_tag))
|
|
249
|
+
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
|
|
250
|
+
if slurm_done is False:
|
|
251
|
+
#recover slurm jobs
|
|
252
|
+
if len(slurm_remain) > 0:
|
|
253
|
+
print("Run these direct Jobs:\n")
|
|
254
|
+
print(slurm_remain)
|
|
255
|
+
for i, script_path in enumerate(slurm_remain):
|
|
256
|
+
slurm_job = SlurmJob()
|
|
257
|
+
tag_name = "{}-{}".format(os.path.basename(script_path).split('-')[0].strip(), INIT_BULK.direct_tag)
|
|
258
|
+
tag = os.path.join(os.path.dirname(script_path),tag_name)
|
|
259
|
+
slurm_job.set_tag(tag)
|
|
260
|
+
slurm_job.set_cmd(script_path)
|
|
261
|
+
mission.add_job(slurm_job)
|
|
262
|
+
|
|
263
|
+
if len(mission.job_list) > 0:
|
|
264
|
+
mission.commit_jobs()
|
|
265
|
+
mission.check_running_job()
|
|
266
|
+
mission.all_job_finished()
|
|
267
|
+
# mission.move_slurm_log_to_slurm_work_dir()
|
|
268
|
+
|
|
269
|
+
def make_direct_slurm_job_files(self, direct_dir_list:list[str]):
|
|
270
|
+
del_file_list_by_patten(self.direct_dir, "*{}".format(INIT_BULK.direct_job))
|
|
271
|
+
group_list = split_job_for_group(self.resource.direct_resource.group_size, direct_dir_list, self.resource.direct_resource.parallel_num)
|
|
272
|
+
for group_index, group in enumerate(group_list):
|
|
273
|
+
if group[0] == "NONE":
|
|
274
|
+
continue
|
|
275
|
+
jobname = "direct{}".format(group_index)
|
|
276
|
+
tag_name = "{}-{}".format(group_index, INIT_BULK.direct_tag)
|
|
277
|
+
tag = os.path.join(self.direct_dir, tag_name)
|
|
278
|
+
run_cmd = self.resource.direct_resource.command
|
|
279
|
+
group_slurm_script = set_slurm_script_content(gpu_per_node=self.resource.direct_resource.gpu_per_node,
|
|
280
|
+
number_node = self.resource.direct_resource.number_node,
|
|
281
|
+
cpu_per_node = self.resource.direct_resource.cpu_per_node,
|
|
282
|
+
queue_name = self.resource.direct_resource.queue_name,
|
|
283
|
+
custom_flags = self.resource.direct_resource.custom_flags,
|
|
284
|
+
env_script = self.resource.direct_resource.env_script,
|
|
285
|
+
job_name = jobname,
|
|
286
|
+
run_cmd_template = run_cmd,
|
|
287
|
+
group = group,
|
|
288
|
+
job_tag = tag,
|
|
289
|
+
task_tag = INIT_BULK.direct_tag,
|
|
290
|
+
task_tag_faild = INIT_BULK.direct_tag_failed,
|
|
291
|
+
parallel_num=self.resource.dft_resource.parallel_num,
|
|
292
|
+
check_type=None
|
|
293
|
+
)
|
|
294
|
+
slurm_script_name = "{}-{}".format(group_index, INIT_BULK.direct_job)
|
|
295
|
+
slurm_job_file = os.path.join(self.direct_dir, slurm_script_name)
|
|
296
|
+
write_to_file(slurm_job_file, group_slurm_script, "w")
|
|
297
|
+
|
|
298
|
+
def do_post_process(self):
|
|
299
|
+
if os.path.exists(self.bigmodel_dir):
|
|
300
|
+
link_file(self.bigmodel_dir, self.real_bigmodel_dir)
|
|
@@ -5,12 +5,13 @@ from pwact.active_learning.init_bulk.relax import Relax
|
|
|
5
5
|
from pwact.active_learning.init_bulk.duplicate_scale import do_pertub_work, do_post_pertub, pertub_done, \
|
|
6
6
|
duplicate_scale_done, duplicate_scale, do_post_duplicate_scale
|
|
7
7
|
from pwact.active_learning.init_bulk.aimd import AIMD
|
|
8
|
+
from pwact.active_learning.init_bulk.explore import BIGMODEL
|
|
8
9
|
from pwact.active_learning.init_bulk.relabel import Relabel
|
|
9
10
|
from pwact.active_learning.user_input.init_bulk_input import InitBulkParam
|
|
10
11
|
from pwact.active_learning.user_input.resource import Resource
|
|
11
12
|
from pwact.active_learning.slurm.slurm import scancle_job
|
|
12
|
-
from pwact.utils.constant import INIT_BULK, DFT_STYLE, TEMP_STRUCTURE, PWDATA
|
|
13
|
-
from pwact.utils.file_operation import copy_file, copy_dir, search_files, del_file, del_file_list, write_to_file
|
|
13
|
+
from pwact.utils.constant import INIT_BULK, DFT_STYLE, TEMP_STRUCTURE, PWDATA, LABEL_FILE_STRUCTURE
|
|
14
|
+
from pwact.utils.file_operation import copy_file, copy_dir, search_files, del_file, del_file_list, write_to_file, del_file_list_by_patten
|
|
14
15
|
from pwact.data_format.configop import extract_pwdata
|
|
15
16
|
|
|
16
17
|
def init_bulk_run(resource: Resource, input_param:InitBulkParam):
|
|
@@ -42,13 +43,26 @@ def init_bulk_run(resource: Resource, input_param:InitBulkParam):
|
|
|
42
43
|
aimd.do_aimd_jobs()
|
|
43
44
|
aimd.do_post_process()
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
elif input_param.is_bigmodel:
|
|
47
|
+
bigmodel = BIGMODEL(resource, input_param)
|
|
48
|
+
if not bigmodel.check_work_done():
|
|
49
|
+
bigmodel.make_bigmodel_work()
|
|
50
|
+
bigmodel.do_bigmodel_jobs()
|
|
51
|
+
bigmodel.do_post_process()
|
|
52
|
+
|
|
53
|
+
# do direct
|
|
54
|
+
if not bigmodel.check_direct_done():
|
|
55
|
+
bigmodel.make_direct_work()
|
|
56
|
+
bigmodel.do_direct_jobs() # after
|
|
57
|
+
|
|
58
|
+
# do relabel
|
|
59
|
+
if input_param.is_scf:
|
|
60
|
+
relabel = Relabel(resource, input_param)
|
|
61
|
+
if not relabel.check_work_done():
|
|
62
|
+
relabel.make_scf_work()
|
|
63
|
+
relabel.do_scf_jobs()
|
|
64
|
+
relabel.do_post_process()
|
|
65
|
+
|
|
52
66
|
do_collection(resource, input_param)
|
|
53
67
|
|
|
54
68
|
def do_collection(resource: Resource, input_param:InitBulkParam):
|
|
@@ -59,6 +73,8 @@ def do_collection(resource: Resource, input_param:InitBulkParam):
|
|
|
59
73
|
pertub_dir = os.path.join(input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.pertub)
|
|
60
74
|
aimd_dir = os.path.join(input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.aimd)
|
|
61
75
|
collection_dir = os.path.join(input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.collection)
|
|
76
|
+
bigmodel_dir = os.path.join(input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.bigmodel)
|
|
77
|
+
direct_dir = os.path.join(bigmodel_dir, INIT_BULK.direct)
|
|
62
78
|
|
|
63
79
|
real_collection_dir = os.path.join(input_param.root_dir, INIT_BULK.collection)
|
|
64
80
|
real_relax_dir = os.path.join(input_param.root_dir, INIT_BULK.relax)
|
|
@@ -68,7 +84,9 @@ def do_collection(resource: Resource, input_param:InitBulkParam):
|
|
|
68
84
|
|
|
69
85
|
relabel_dir = os.path.join(input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.scf)
|
|
70
86
|
real_relabel_dir = os.path.join(input_param.root_dir, INIT_BULK.scf)
|
|
71
|
-
|
|
87
|
+
real_bigmodel_dir = os.path.join(input_param.root_dir, INIT_BULK.bigmodel)
|
|
88
|
+
real_direct_dir = os.path.join(input_param.root_dir, INIT_BULK.direct)
|
|
89
|
+
|
|
72
90
|
|
|
73
91
|
for init_config in init_configs:
|
|
74
92
|
init_config_name = "init_config_{}".format(init_config.config_index)
|
|
@@ -112,24 +130,66 @@ def do_collection(resource: Resource, input_param:InitBulkParam):
|
|
|
112
130
|
data_shuffle=input_param.data_shuffle,
|
|
113
131
|
interval=1
|
|
114
132
|
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if len(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
# print the dir of pwdatas from aimd
|
|
134
|
+
if input_param.data_format == PWDATA.extxyz:
|
|
135
|
+
pwdatas = search_files(real_collection_dir, "*/{}".format(INIT_BULK.get_save_format(input_param.data_format)))
|
|
136
|
+
elif input_param.data_format == PWDATA.pwmlff_npy: # */PWdata/*.npy
|
|
137
|
+
tmp = search_files(real_collection_dir, "*/{}/*/position.npy".format(INIT_BULK.get_save_format(input_param.data_format)))
|
|
138
|
+
pwdatas = [os.path.dirname(_) for _ in tmp]
|
|
139
|
+
if len(pwdatas) > 0:
|
|
140
|
+
pwdatas = sorted(pwdatas)
|
|
141
|
+
result_lines = ["\"{}\",".format(_) for _ in pwdatas]
|
|
142
|
+
result_lines = "\n".join(result_lines)
|
|
143
|
+
# result_lines = result_lines[:-1] # Filter the last ','
|
|
144
|
+
result_save_path = os.path.join(collection_dir, INIT_BULK.npy_format_name)
|
|
145
|
+
write_to_file(result_save_path, result_lines, mode='w')
|
|
146
|
+
|
|
147
|
+
#6 convert relabel datas
|
|
148
|
+
result_save_path = []
|
|
149
|
+
if input_param.is_scf:
|
|
150
|
+
source_scf = search_files(relabel_dir,\
|
|
151
|
+
"*/{}".format(DFT_STYLE.get_scf_config(resource.dft_style)))
|
|
152
|
+
# init/0-aimd/0-scf/OUTCAR
|
|
153
|
+
source_scf = sorted(source_scf, key=lambda x:int(os.path.basename(os.path.dirname(x))), reverse=False)
|
|
154
|
+
#5. convert the aimd files (for vasp is outcar, for pwmat is movement) to npy format
|
|
155
|
+
extract_pwdata(input_data_list=source_scf,
|
|
156
|
+
intput_data_format= DFT_STYLE.get_format_by_postfix(os.path.basename(source_scf[0])),
|
|
157
|
+
save_data_path = os.path.join(collection_dir, INIT_BULK.scf),
|
|
158
|
+
save_data_name = INIT_BULK.get_save_format(input_param.data_format),
|
|
159
|
+
save_data_format= input_param.data_format,
|
|
160
|
+
data_shuffle=input_param.data_shuffle,
|
|
161
|
+
interval=1
|
|
162
|
+
)
|
|
163
|
+
result_save_path.append(os.path.join(real_collection_dir, INIT_BULK.scf, INIT_BULK.get_save_format(input_param.data_format)))
|
|
164
|
+
#7 bigmodel infos
|
|
165
|
+
if input_param.is_bigmodel:
|
|
166
|
+
if not input_param.is_scf:
|
|
167
|
+
extract_pwdata(input_data_list=[os.path.join(direct_dir, INIT_BULK.direct_traj)],
|
|
168
|
+
intput_data_format= PWDATA.extxyz,
|
|
169
|
+
save_data_path = direct_dir,
|
|
128
170
|
save_data_name = INIT_BULK.get_save_format(input_param.data_format),
|
|
129
171
|
save_data_format= input_param.data_format,
|
|
130
172
|
data_shuffle=input_param.data_shuffle,
|
|
131
173
|
interval=1
|
|
132
174
|
)
|
|
175
|
+
result_save_path.append(os.path.join(real_collection_dir, INIT_BULK.bigmodel, INIT_BULK.direct, INIT_BULK.get_save_format(input_param.data_format)))
|
|
176
|
+
# copy bigmodel and direct files to realdir
|
|
177
|
+
copy_dir(bigmodel_dir, os.path.join(collection_dir, INIT_BULK.bigmodel))
|
|
178
|
+
# delete logs
|
|
179
|
+
if len(result_save_path) > 0:
|
|
180
|
+
_path_path = []
|
|
181
|
+
for _data_path in result_save_path:
|
|
182
|
+
if input_param.data_format == PWDATA.extxyz:
|
|
183
|
+
_path_path.append(_data_path)
|
|
184
|
+
elif input_param.data_format == PWDATA.pwmlff_npy: # */PWdata/*.npy
|
|
185
|
+
tmp = search_files(_data_path, "*/position.npy")
|
|
186
|
+
_path_path.extend([os.path.dirname(_) for _ in tmp])
|
|
187
|
+
|
|
188
|
+
result_lines = ["\"{}\",".format(_) for _ in _path_path]
|
|
189
|
+
result_lines = "\n".join(result_lines)
|
|
190
|
+
# result_lines = result_lines[:-1] # Filter the last ','
|
|
191
|
+
result_save_path = os.path.join(collection_dir, INIT_BULK.npy_format_name)
|
|
192
|
+
write_to_file(result_save_path, result_lines, mode='w')
|
|
133
193
|
|
|
134
194
|
# delete link files
|
|
135
195
|
del_file(real_relax_dir)
|
|
@@ -137,7 +197,10 @@ def do_collection(resource: Resource, input_param:InitBulkParam):
|
|
|
137
197
|
del_file(real_pertub_dir)
|
|
138
198
|
del_file(real_aimd_dir)
|
|
139
199
|
del_file(real_relabel_dir)
|
|
140
|
-
|
|
200
|
+
del_file(real_bigmodel_dir)
|
|
201
|
+
# del slurm logs and tags
|
|
202
|
+
del_file_list_by_patten(os.path.join(collection_dir, INIT_BULK.bigmodel), "slurm-*")
|
|
203
|
+
del_file_list_by_patten(os.path.join(collection_dir, INIT_BULK.bigmodel, INIT_BULK.direct), "slurm-*")
|
|
141
204
|
# copy collection file to target
|
|
142
205
|
copy_dir(collection_dir, real_collection_dir)
|
|
143
206
|
if not input_param.reserve_work:
|
|
@@ -145,29 +208,6 @@ def do_collection(resource: Resource, input_param:InitBulkParam):
|
|
|
145
208
|
temp_work_dir = os.path.join(input_param.root_dir, TEMP_STRUCTURE.tmp_init_bulk_dir)
|
|
146
209
|
del_file_list([temp_work_dir])
|
|
147
210
|
|
|
148
|
-
# print the dir of pwdatas from aimd
|
|
149
|
-
if input_param.data_format == PWDATA.extxyz:
|
|
150
|
-
pwdatas = search_files(real_collection_dir, "*/{}".format(INIT_BULK.get_save_format(input_param.data_format)))
|
|
151
|
-
elif input_param.data_format == PWDATA.pwmlff_npy: # */PWdata/*.npy
|
|
152
|
-
tmp = search_files(real_collection_dir, "*/{}/*/position.npy".format(INIT_BULK.get_save_format(input_param.data_format)))
|
|
153
|
-
pwdatas = [os.path.dirname(_) for _ in tmp]
|
|
154
|
-
if len(pwdatas) > 0:
|
|
155
|
-
pwdatas = sorted(pwdatas)
|
|
156
|
-
result_lines = ["\"{}\",".format(_) for _ in pwdatas]
|
|
157
|
-
result_lines = "\n".join(result_lines)
|
|
158
|
-
# result_lines = result_lines[:-1] # Filter the last ','
|
|
159
|
-
result_save_path = os.path.join(real_collection_dir, INIT_BULK.npy_format_name)
|
|
160
|
-
write_to_file(result_save_path, result_lines, mode='w')
|
|
161
|
-
|
|
162
|
-
# print the dir of relabel_pwdatas from relabel
|
|
163
|
-
relebel_datas = search_files(real_collection_dir, "*/{}".format("scf_pwdata"))
|
|
164
|
-
if len(relebel_datas) > 0:
|
|
165
|
-
pwdatas = sorted(relebel_datas)
|
|
166
|
-
result_lines = ["\"{}\",".format(_) for _ in pwdatas]
|
|
167
|
-
result_lines = "\n".join(result_lines)
|
|
168
|
-
# result_lines = result_lines[:-1] # Filter the last ','
|
|
169
|
-
result_save_path = os.path.join(real_collection_dir, "scf_pwdata")
|
|
170
|
-
write_to_file(result_save_path, result_lines, mode='w')
|
|
171
211
|
|
|
172
212
|
def scancel_jobs(work_dir):
|
|
173
213
|
relax_job = os.path.join(work_dir, TEMP_STRUCTURE.tmp_init_bulk_dir, INIT_BULK.relax)
|