-
Notifications
You must be signed in to change notification settings - Fork 11
/
module_log.py
55 lines (50 loc) · 1.83 KB
/
module_log.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
###########################################
### Date: 2018-12-05 ###
### [email protected] ###
###########################################
# This is a package of modules to record log.
import datetime, getpass, os
# This function is for writing default amp2 log file
def make_amp2_log_default(path,src_path,comment,node,code_data):
with open(path+'/amp2.log','a') as amp2_log:
amp2_start_time = datetime.datetime.now().strftime("\tThe calculation is started at %Y-%m-%d : %H:%M \n")
amp2_log.write('['+comment+']\n')
user_name = getpass.getuser()
amp2_log.write('\tThe calculation is performed by '+user_name+'\n')
amp2_log.write(amp2_start_time)
full_path = os.path.abspath(path)
full_src_path = os.path.abspath(src_path)
amp2_log.write('\tThe current running path is '+full_path+'\n')
amp2_log.write('\tThe source path is '+full_src_path+'\n')
amp2_log.write('\t'+code_data+'\n')
amp2_log.write('\tYour job was run at')
for node_index in node:
amp2_log.write(' '+node_index)
amp2_log.write('\n')
def make_amp2_log(path,comment):
lines = comment.splitlines()
with open(path+'/amp2.log','a') as amp2_log:
for line in lines:
amp2_log.write('\t'+line+'\n')
def node_simple(node_file):
node = []
with open(node_file,'r') as nodefile:
for ll in nodefile.readlines():
if len(node) == 0:
node.append(ll.split()[0])
elif not ll.split()[0] in node:
node.append(ll.split()[0])
return node
def read_code_head(code,head_num):
from module_vasprun import pyhead
code_ver = pyhead(code,head_num)
return code_ver
def write_log_in_outcar(outcar_file,log_file):
if os.path.isfile(outcar_file) and os.path.isfile(log_file):
with open(log_file,'r') as log_inp:
log = log_inp.read()
with open(outcar_file,'r') as out:
outcar = out.read()
with open(outcar_file,'w') as out:
out.write(log+'\n')
out.write(outcar)