-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeSPINfile.py
More file actions
56 lines (55 loc) · 1.85 KB
/
makeSPINfile.py
File metadata and controls
56 lines (55 loc) · 1.85 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
#Reads CHG file and outputs lines after second iteration of dimensions into new file; SPIN.txt
#input files: CHG
#output files: SPIN
import argparse
parser = argparse.ArgumentParser(description="Arguments for CHG file ",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-chg", nargs='?', default = "./CHG", help="chg file location")
args = parser.parse_args()
config = vars(args)
DLineNum=0
lineCount=0
count=0
count2=0
num2=0
num=0
molName='none'
dNums = ""
#reads chg and finds dimension integers
with open(config['chg'], 'r') as f:
for line in f:
lineCount=lineCount+1
if 'Direct' in line:
DLineNum=lineCount
if DLineNum<=lineCount and DLineNum!=0:
parts = line.strip().split()
if len(parts) == 3:
if all('.' not in part and 'e' not in part.lower() and part.isdigit() for part in parts):
nums = list(map(int, parts))
dNums = line
break
print("Running code to create SPIN.vasp file")
#Reads CHG file and outputs lines after second iteration of the three integers into new file; SPIN.txt
always_print = False
with open(config["chg"], 'r') as f:
molName=f.readline()
for line in f:
if dNums in line:
count2 += 1
with open(config["chg"], 'r') as f, open("SPIN.vasp", "w") as y:
for line in f:
if dNums in line and num2<=(count2):
always_print=False
num += 1
num2 += 1
if molName in line and num==(count2-2):
always_print=True
if dNums in line:
always_print=False
if num == count2:
print(line, file=y, end='')
always_print= True
continue
if always_print:
print(line, file=y, end='')
print("Output files: SPIN.vasp")