-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjudge_scf_conv.py
139 lines (125 loc) · 5.14 KB
/
judge_scf_conv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os
import sys
import re
sys.path.append(sys.path[0])
from libs.modify_file import modify_parameter
tot_dir=sys.argv[1].strip("/")
mode=sys.argv[2]
str_name=tot_dir.split("/")[-1]
scf_not_conv_time=2 # scf not convergence time
code_path=sys.path[0]
process=1
input_name=f"{tot_dir}/in_{mode}_{str_name}"
output_name=f"{tot_dir}/out_{mode}_{str_name}"
print(output_name)
flat_info=open("%s/flat.save/FLAT_INFO"%code_path).readlines()
for lines in flat_info:
if lines.find("flat_number=")!=-1:
flat_number=int(lines.split("flat_number=")[-1].split("#")[0])
if lines.find("node_num=")!=-1:
node_num=int(lines.split("node_num=")[-1].split("#")[0])
if lines.find("ppn_num")!=-1:
ppn_num_man=int(lines.split("ppn_num=")[-1].split("#")[0])
if ppn_num_man==0:
ppn_set=0
elif ppn_num_man!=0:
ppn_set=1
if lines.find("wall_time=")!=-1:
wall_time=lines.split("wall_time=")[-1].split("#")[0].strip("\n")
def JOB_func(flat_number):
type_hpc=""
if (flat_number==1)|(flat_number==2):
type_hpc="pbs"
elif (flat_number==3):
type_hpc="sbatch"
return type_hpc
dir_file=(os.popen("pwd").read())
current_dir=max(dir_file.split('\n'))
type_hpc_out=JOB_func(flat_number)
if type_hpc_out=="sbatch":
sub_method="sbatch"
del_method="scancel"
elif type_hpc_out=="pbs":
sub_method="qsub"
del_method="qdel"
replace_line=open("%s/replace.py"%code_path).readlines()
for i in replace_line:
if i.find("JOB=")!=-1:
JOB_name=i.split("JOB=")[-1].split("#")[0].split("\"")[1]
if os.path.isfile(output_name)==0:
raise ValueError("Not Running!")
input_cont=open(input_name).readlines()
E_must_conv=True
E_max_step=100
for line in input_cont:
if "scf_must_converge" in line and "!" not in line and "false" in line:
E_must_conv=False
if "electron_maxstep" in line and "!" not in line:
E_max_step=int(line.split("=")[-1].strip("\n").strip(",").strip())
def count_consecutive(arr,E_max_step):
count = 0
if arr[-1] != E_max_step and arr[-2] != E_max_step:
return 0
for i in range(len(arr) - 1, -1, -1): # 从数组的末尾开始遍历
if arr[i] == E_max_step:
count += 1 # 如果元素是max_step,增加计数器
else:
break # 如果元素不是max_step,结束循环
return count
def scf_conv_judge():
out_scf_conv=os.popen(f"grep \"convergence has\" {output_name}").readlines()
if len(out_scf_conv)<scf_not_conv_time:
raise ValueError("Not enough data!")
conv_steps=[int(i.split("in")[-1].split("itera")[0].strip()) for i in out_scf_conv]
conv_not_achiev=count_consecutive(conv_steps,E_max_step)
return conv_not_achiev
mix_beta=os.popen(f"grep mixing_beta {input_name}").readlines()
mixing_beta=0.7
for i in mix_beta:
if "!" not in i:
mixing_beta=float(i.strip("\n").strip(",").split("=")[-1].strip())
conv_not_achiev=(scf_conv_judge())
print(conv_not_achiev)
job_id=os.popen(f"python {code_path}/job_on_hpc_id.py {tot_dir}").readline().strip("\n").strip()
job_state=os.popen(f"python {code_path}/job_on_hpc.py {tot_dir}").readline().strip("\n").strip()
if E_must_conv==False:
if conv_not_achiev>scf_not_conv_time:
print(f"!!!Modify\n***********************{job_state}")
if job_id!="Not here" and job_state!="waiting on line":
print(f"{del_method} {job_id}")
if process==1:
os.system(f"{del_method} {job_id}")
print(f"change into {tot_dir}")
if process==1:
os.chdir(tot_dir)
print(f"modify in_{mode}_{str_name}, beta={mixing_beta*0.8:.3}")
if process==1:
modify_parameter("./",f"{str_name}","mixing_beta",f"{mixing_beta*0.8:.3}","&electrons"," ")
print(f"mv out_{mode}_{str_name} out_buffer")
if process==1:
os.system(f"bcon.sh out_{mode}_{str_name} in_{mode}_{str_name}")
os.system(f"mv out_{mode}_{str_name} out_buffer")
print(f"{sub_method} {JOB_name}")
if process==1:
os.system(f"{sub_method} {JOB_name}")
print(f"change into {current_dir}")
if process==1:
os.chdir(current_dir)
#modify_parameter(tot_dir,f"{str_name}","mixing_beta",0.2,"&electrons"," ")
elif job_id=="Not here":
print(f"change into {tot_dir}")
if process==1:
os.chdir(tot_dir)
print(f"modify in_{mode}_{str_name}, beta={mixing_beta*0.8:.3}")
if process==1:
modify_parameter("./",f"{str_name}","mixing_beta",f"{mixing_beta*0.8:.3}","&electrons"," ")
print(f"mv out_{mode}_{str_name} out_buffer")
if process==1:
os.system(f"bcon.sh out_{mode}_{str_name} in_{mode}_{str_name}")
os.system(f"mv out_{mode}_{str_name} out_buffer")
#print(f"{sub_method} {JOB_name}")
print(f"change into {current_dir}")
if process==1:
os.chdir(current_dir)
else:
print(f"!!!Nothing to be done\n***********************{job_state}")