-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelaxation.py
108 lines (86 loc) · 2.8 KB
/
relaxation.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
from pathlib import Path
from dflow.python import (OP, OPIO, Artifact, OPIOSign, upload_packages)
import os
import shutil
from monty.serialization import loadfn
from dpgen.auto_test.common_equi import (make_equi, post_equi)
if "__file__" in locals():
upload_packages.append(__file__)
class RelaxMake(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'parameters': Artifact(Path),
'structure': Artifact(Path),
'potential': Artifact(Path)
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'inter': dict,
'tasks': Artifact(Path)
})
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
op_out = OPIO({
"inter": loadfn(op_in['parameters'])["relaxation"],
"tasks": Path("relaxation")
})
inter_parameter = loadfn(op_in['parameters'])["interaction"]
relax_param = loadfn(op_in['parameters'])["relaxation"]
confs = [str(op_in['structure'].parent)]
cwd = os.getcwd()
make_equi(confs, inter_parameter, relax_param)
relaxtaion = os.path.join(confs[0], 'relaxation')
relax_task = os.path.join(relaxtaion, 'relax_task')
os.chdir(relaxtaion)
if os.path.islink('frozen_model.pb'):
os.remove('frozen_model.pb')
shutil.copyfile(op_in['potential'], 'frozen_model.pb')
os.chdir(relax_task)
if os.path.islink('frozen_model.pb') and os.path.islink('POSCAR'):
os.remove('frozen_model.pb')
os.remove('POSCAR')
shutil.copyfile(op_in['potential'], 'frozen_model.pb')
shutil.copyfile(op_in['structure'], 'POSCAR')
os.chdir(cwd)
shutil.copytree(relaxtaion, 'relaxation')
return op_out
class RelaxPost(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'result_tasks': Artifact(Path),
'parameters': Artifact(Path)
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'result_json': Artifact(Path),
'relaxation_finished': Artifact(Path),
})
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
op_out = OPIO({
"result_json": Path("result.json"),
"relaxation_finished": Path("relaxation"),
})
confs = [str(op_in["result_tasks"].parent)]
inter_param = loadfn(op_in['parameters'])["interaction"]
cwd = os.getcwd()
post_equi(confs, inter_param)
os.chdir(cwd)
shutil.copytree(op_in["result_tasks"], 'relaxation')
return op_out
if __name__ == "__main__":
pass