hpc-task 0.1.3__tar.gz → 0.2.0__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.
- {hpc_task-0.1.3 → hpc_task-0.2.0}/PKG-INFO +1 -1
- hpc_task-0.2.0/hpc_task/hpc_calculator/vasp.py +88 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task.egg-info/PKG-INFO +1 -1
- {hpc_task-0.1.3 → hpc_task-0.2.0}/setup.py +1 -1
- {hpc_task-0.1.3 → hpc_task-0.2.0}/tests/test_task.py +28 -0
- hpc_task-0.1.3/hpc_task/hpc_calculator/vasp.py +0 -46
- {hpc_task-0.1.3 → hpc_task-0.2.0}/LICENSE +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/README.md +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task/__init__.py +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task/hpc.py +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task/hpc_calculator/__init__.py +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task/hpc_calculator/lasp.py +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task/templates/__init__.py +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task.egg-info/SOURCES.txt +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task.egg-info/dependency_links.txt +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task.egg-info/requires.txt +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/hpc_task.egg-info/top_level.txt +0 -0
- {hpc_task-0.1.3 → hpc_task-0.2.0}/setup.cfg +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from ase.calculators import calculator
|
|
6
|
+
from ase.calculators.vasp import Vasp as ase_Vasp
|
|
7
|
+
import ase.io
|
|
8
|
+
from hpc_task.hpc import HPCTask
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Vasp(ase_Vasp):
|
|
12
|
+
def __init__(self,
|
|
13
|
+
atoms=None,
|
|
14
|
+
restart=None,
|
|
15
|
+
directory='.',
|
|
16
|
+
label='vasp',
|
|
17
|
+
command=None,
|
|
18
|
+
hpctask:HPCTask=None,
|
|
19
|
+
**kwargs):
|
|
20
|
+
super().__init__(
|
|
21
|
+
atoms=atoms,
|
|
22
|
+
restart=restart,
|
|
23
|
+
directory=directory,
|
|
24
|
+
label=label,
|
|
25
|
+
command=command,
|
|
26
|
+
**kwargs
|
|
27
|
+
)
|
|
28
|
+
self.hpctask = hpctask
|
|
29
|
+
|
|
30
|
+
def _run(self, command=None, out=None, directory=None):
|
|
31
|
+
"""Method to explicitly execute VASP"""
|
|
32
|
+
if command is None:
|
|
33
|
+
command = self.command
|
|
34
|
+
|
|
35
|
+
if self.hpctask is not None:
|
|
36
|
+
remote_cmd = f"gosh-remote -vv client run '{command}'"
|
|
37
|
+
returncode, stderr, stdout = self.hpctask.execute(remote_cmd)
|
|
38
|
+
|
|
39
|
+
else:
|
|
40
|
+
result = subprocess.run(command,
|
|
41
|
+
shell=True,
|
|
42
|
+
cwd=directory,
|
|
43
|
+
capture_output=True,
|
|
44
|
+
text=True)
|
|
45
|
+
stdout = result.stdout
|
|
46
|
+
returncode = result.returncode
|
|
47
|
+
stderr = result.stderr
|
|
48
|
+
if out is not None:
|
|
49
|
+
out.write(stdout)
|
|
50
|
+
return returncode, stderr
|
|
51
|
+
|
|
52
|
+
def execute_only(self):
|
|
53
|
+
"""
|
|
54
|
+
仅仅执行 command 命令,从文件夹中读取 INCAR、POTCAR、POSCAR、KPOINTS
|
|
55
|
+
"""
|
|
56
|
+
self.read_potcar(filename=self._indir('POTCAR'))
|
|
57
|
+
self.read_incar(filename=self._indir('INCAR'))
|
|
58
|
+
self.read_kpoints(filename=self._indir('KPOINTS'))
|
|
59
|
+
atoms = ase.io.read(filename=self._indir('POSCAR'))
|
|
60
|
+
# 需要读进去ase-sort.dat,否则结果会报错
|
|
61
|
+
sortfile = self._indir('ase-sort.dat')
|
|
62
|
+
if os.path.isfile(sortfile):
|
|
63
|
+
self.sort = []
|
|
64
|
+
self.resort = []
|
|
65
|
+
with open(sortfile) as fd:
|
|
66
|
+
for line in fd:
|
|
67
|
+
sort, resort = line.split()
|
|
68
|
+
self.sort.append(int(sort))
|
|
69
|
+
self.resort.append(int(resort))
|
|
70
|
+
else:
|
|
71
|
+
# Redo the sorting
|
|
72
|
+
self.initialize(atoms)
|
|
73
|
+
|
|
74
|
+
command = self.make_command(self.command)
|
|
75
|
+
with self._txt_outstream() as out:
|
|
76
|
+
errorcode, stderr = self._run(command=command,
|
|
77
|
+
out=out,
|
|
78
|
+
directory=self.directory)
|
|
79
|
+
|
|
80
|
+
if errorcode:
|
|
81
|
+
raise calculator.CalculationFailed(
|
|
82
|
+
'{} in {} returned an error: {:d} stderr {}'.format(
|
|
83
|
+
self.name, Path(self.directory).resolve(), errorcode,
|
|
84
|
+
stderr))
|
|
85
|
+
|
|
86
|
+
# Read results from calculation
|
|
87
|
+
self.update_atoms(atoms)
|
|
88
|
+
self.read_results()
|
|
@@ -153,3 +153,31 @@ class TestHPCTask:
|
|
|
153
153
|
# finish job
|
|
154
154
|
hpc.postrun()
|
|
155
155
|
hpc.close()
|
|
156
|
+
|
|
157
|
+
def test_hpc_vasp_execute_only(self):
|
|
158
|
+
workdir = 'test_hpc_vasp_execute_only'
|
|
159
|
+
Path(workdir).mkdir(parents=True, exist_ok=True)
|
|
160
|
+
shutil.copyfile('test_files/INCAR', Path(workdir)/'INCAR')
|
|
161
|
+
shutil.copyfile('test_files/POSCAR', Path(workdir)/'POSCAR')
|
|
162
|
+
shutil.copyfile('test_files/POTCAR', Path(workdir)/'POTCAR')
|
|
163
|
+
shutil.copyfile('test_files/KPOINTS', Path(workdir)/'KPOINTS')
|
|
164
|
+
|
|
165
|
+
# 队列占据
|
|
166
|
+
hpc = HPCTask(workdir=workdir)
|
|
167
|
+
hpc.scriptdir = '/data/bin/remote.job'
|
|
168
|
+
hpc.connect(target_host, jump_host)
|
|
169
|
+
hpc.prerun()
|
|
170
|
+
calc = hpc_Vasp(
|
|
171
|
+
directory=workdir,
|
|
172
|
+
command='mpirun -np 2 vasp_gam',
|
|
173
|
+
hpctask=hpc, # 这个非常关键
|
|
174
|
+
)
|
|
175
|
+
# 计算
|
|
176
|
+
calc.execute_only()
|
|
177
|
+
atoms = calc.atoms
|
|
178
|
+
atoms.calc = calc
|
|
179
|
+
e = atoms.get_potential_energy()
|
|
180
|
+
print(f"Energy of N2 is {e} eV.")
|
|
181
|
+
# finish job
|
|
182
|
+
hpc.postrun()
|
|
183
|
+
hpc.close()
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import subprocess
|
|
2
|
-
|
|
3
|
-
from ase.calculators.vasp import Vasp as ase_Vasp
|
|
4
|
-
from hpc_task.hpc import HPCTask
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class Vasp(ase_Vasp):
|
|
8
|
-
def __init__(self,
|
|
9
|
-
atoms=None,
|
|
10
|
-
restart=None,
|
|
11
|
-
directory='.',
|
|
12
|
-
label='vasp',
|
|
13
|
-
command=None,
|
|
14
|
-
hpctask:HPCTask=None,
|
|
15
|
-
**kwargs):
|
|
16
|
-
super().__init__(
|
|
17
|
-
atoms=atoms,
|
|
18
|
-
restart=restart,
|
|
19
|
-
directory=directory,
|
|
20
|
-
label=label,
|
|
21
|
-
command=command,
|
|
22
|
-
**kwargs
|
|
23
|
-
)
|
|
24
|
-
self.hpctask = hpctask
|
|
25
|
-
|
|
26
|
-
def _run(self, command=None, out=None, directory=None):
|
|
27
|
-
"""Method to explicitly execute VASP"""
|
|
28
|
-
if command is None:
|
|
29
|
-
command = self.command
|
|
30
|
-
|
|
31
|
-
if self.hpctask is not None:
|
|
32
|
-
remote_cmd = f"gosh-remote -vv client run '{command}'"
|
|
33
|
-
returncode, stderr, stdout = self.hpctask.execute(remote_cmd)
|
|
34
|
-
|
|
35
|
-
else:
|
|
36
|
-
result = subprocess.run(command,
|
|
37
|
-
shell=True,
|
|
38
|
-
cwd=directory,
|
|
39
|
-
capture_output=True,
|
|
40
|
-
text=True)
|
|
41
|
-
stdout = result.stdout
|
|
42
|
-
returncode = result.returncode
|
|
43
|
-
stderr = result.stderr
|
|
44
|
-
if out is not None:
|
|
45
|
-
out.write(stdout)
|
|
46
|
-
return returncode, stderr
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|