-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpysorb_run_qe.backup.py
executable file
·114 lines (93 loc) · 2.94 KB
/
pysorb_run_qe.backup.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
#! /usr/bin/python
#### ------------------------------------------ ####
# last edit: 10.04.15
#
# program to run QE calculations
#### ------------------------------------------ ####
import os, sys, os.path
import subprocess as sub
help = '''
--------------------- pysorb run QE ----------------
Run a QE calculation for each QE inputfile in a given
directory
Options:
-h display help message
-i directory of QE inputfiles
-o directory of QE outputfiles
-c comand to run
------------------------------------------------------
'''
if len(sys.argv)>1:
for i in sys.argv:
if i.startswith('-'):
option=i.split('-')[1]
if option=="i":
input_dir = sys.argv[sys.argv.index('-i')+1]
if option=="o":
output_dir = sys.argv[sys.argv.index('-o')+1]
if option=="c":
pwcomand = sys.argv[sys.argv.index('-c')+1]
if option=="h":
print(help)
sys.exit()
else:
print(help)
sys.exit()
try:
input_dir
except NameError:
print "Input directory not defined. (-i)"
sys.exit()
try:
output_dir
except NameError:
print "Output directory not defined. (-o)"
sys.exit()
# get the files
files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir,f))]
if not os.path.exists(output_dir):
os.makedirs(output_dir)
for f in files:
input_file = f
output_file = ".".join(f.split(".")[:-1]) + ".out"
sub.call(['/bin/bash',
'-i',
'-c',
pwcomand + " <" + input_dir + "/" + input_file + " | tee " + output_dir + "/" + output_file])
# print pwcomand + " <" + input_dir + "/" + input_file + " | tee " + output_dir + "/" + output_file
# run pw.x on input files
#if calc:
# qe_outputdir = "qe_outputfiles"
# e_sys = []
# if not os.path.exists(qe_outputdir):
# os.makedirs(qe_outputdir)
"""
for i in np.arange(len(confs)):
print "Starting QE calculation " + str(i+1) + " of " + str(len(confs)) + "\n"
filename = "conf"+str(i)
if os.path.isfile(qe_outputdir + "/" + filename + ".out"):
os.rename(qe_outputdir + "/" + filename + ".out",
qe_outputdir + "/#" + filename + ".out#")
print "Call: " + pwcomand + " <" + qe_inputdir + "/" + filename + ".in | tee " + qe_outputdir + "/" + filename + ".out"
sub.call(['/bin/bash',
'-i',
'-c',
pwcomand + " <" + qe_inputdir + "/" + filename + ".in | tee " + qe_outputdir + "/" + filename + ".out"])
e_sys.append(ads.getefromfile(qe_outputdir + "/" + filename + ".out"))
e_ads = []
for e in e_sys:
e_ads.append((e_molecule+e_slab)-e)
ef = file(qe_outputdir + "/" + "e.dat", "wb")
i = 0
for e in e_ads:
ef.write("conf" + str(i) + "\t" + e + "\n")
i += 1
ef.close()
print '''
------------------------------------------------------
Result is:
E_sys: ''' + str(e_sys) + '''
E_ads: ''' + str(e_ads) + '''
------------------------------------------------------
'''
"""