-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunCASTEP.py
More file actions
71 lines (64 loc) · 2.26 KB
/
runCASTEP.py
File metadata and controls
71 lines (64 loc) · 2.26 KB
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
#!/usr/bin/env python
'''
Author: Ran Zheng
Source of demofiles: http://www.castep.org/Tutorials/BasicsAndBonding
'''
import psutil as psl
import time as t
import os
def checkProcessIsExist(processName):
'''
Check if the process processName exists.
'''
flag = False
for pid in psl.pids():
# Check if process name contains the given processName.
if psl.Process(pid).name().lower() == processName.lower():
flag = True
break
return flag
def getFiles(suffix,dir=os.getcwd()):
'''
Get the file name of the specified folder *dir* and its subfolders in the specified format.
'''
rename = []
# Iterate through the specified folder and its subfolders.
for root,directory,files in os.walk(dir,topdown=True):
for filename in files:
# Split filename and suffix.
fname,suf = os.path.splitext(filename)
# Check if suf name contains the given suffix.
if suf.lower() == suffix.lower():
rename.append(os.path.join(root,fname))
return(rename)
# Notes: You need to prepare .param file corresponding to .cell file in the folder where you need to calculate.
suffix = '.cell'
# You can set fpath to any folder path you want to calculate, and the path where runCASTEP.py is located as the default path.
fpath = os.getcwd()
fname = getFiles(suffix,fpath)
# Number of CPU cores, you can customize **ncore** according to your CPU cores.
ncore = 4
processName = 'castep.mpi'
taskId = 1
if len(fname) > 0:
for name in fname:
cmd = 'mpirun -np '+ str(ncore)+' castep.mpi ' + name
print('Task No.: '+ str(taskId)+'; Task Name: '+name)
if taskId == 1:
# Execute castep.mpi command
os.system(cmd)
else:
while True:
if checkProcessIsExist(processName):
# Pause 1.5 seconds to avoid frequent judgments
t.sleep(1.5)
continue
else:
# Execute CASTEP
os.system(cmd)
break
print()
taskId += 1
print('Task completed!')
else:
print("No files in " + suffix + " format exist in the specified folder and its subfolders")