-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbodel.py
100 lines (84 loc) · 3.45 KB
/
nbodel.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
#
#Karnjit Parmar
#2021
#
#!/usr/bin/env python
import glob, os
import sys
comfilename = "mynewfile.txt"
def writefile(comfilename, filetype):
charge = 0
multiplicity = 1
xyz_path = os.path.join(os.getcwd(), comfilename)
xyzfile = open(xyz_path, 'r')
if(namefile == True):
comfilename = sys.argv[3]
new_file_path = os.path.join(os.getcwd(), comfilename + ".com")
comfile = open(new_file_path,'w')
comfile.write("%chk=" + comfilename + ".chk")
comfile.write('\n%mem=00\n%nproc=32\n')
comfile.write("# M062X/6-31+G(d,p) pop=nbo6del nosymm gfoldprint")
comfile.write('\n\n' + comfilename + '\n\n')
#write charge + multiplicity
comfile.write(str(charge) + ' ' + str(multiplicity) + '\n')
xyzlen = xyzfile.readlines()
type(xyzlen)
for i in range(0, len(xyzlen)):
if (i>1):
comfile.write(xyzlen[i])
if(int(filetype) == 1):
comfile.write('\n$nbo BNDIDX $end\n $del lewis $end\n\n')
if(int(filetype) == 2 and namefile == False):
length = (len(sys.argv)-2)/2
comfile.write('\n$nbo BNDIDX $end\n $del \n delete ' + str(int(length)) + ' elements')
for i in range(2, len(sys.argv)-1):
if(i%2 == 0):
comfile.write('\n ' + sys.argv[i] + ' ' + sys.argv[i+1])
comfile.write('\n$end\n\n')
if(int(filetype) == 2 and namefile == True):
length = (len(sys.argv)-3)/2
comfile.write('\n$nbo BNDIDX $end\n $del \n delete ' + str(int(length)) + ' elements')
for i in range(3, len(sys.argv)-1):
if(i%2 == 0):
comfile.write('\n ' + sys.argv[i] + ' ' + sys.argv[i+1])
comfile.write('\n$end\n\n')
def usage():
print("Usage:")
print("--------------------------------------\n")
print("-l\t: Delete all non-Lewis type interactions (pi->pi* NBO, etc). Removes all \n\t stereoelectronic interactions.")
print("\t\t -Requires no inputfile and will process all .xyz files in the current folder")
print("\n\t\t example: > nbo.py -l\n\n")
print("-o\t: Delete all specified NBO orbital interactions.")
print("\t\t -Requires input orbitals to be specified (Format: donor, acceptor)")
print("\t\t -Requires no input file and will process all .xyz files in the current folder")
print("\n\t\t\n example: nbo.py -l 1 3 6 7 12 15\n")
print("\n\t\t will delete the following donor->acceptor pairs of NBOs: 1->3, 6->7, 12->15\n\n")
noinput = True
namefile = False
if(len(sys.argv) == 1):
usage()
if(len(sys.argv) > 1):
if(sys.argv[2] == '-n'):
namefile = True
if(sys.argv[1] == '-o'):
noinput = False
os.chdir(os.getcwd())
if((len(sys.argv)-2)%2 == 0 and len(sys.argv) > 2):
print("Deleting all non-Lewis type interactions (pi->pi* NBO, etc)")
for file in glob.glob("*.xyz"):
print("writing file:")
print(file)
writefile(file,2)
else:
print("\n<<Odd number of orbitals/no orbitals specified!>>")
if(sys.argv[1] == '-l'):
noinput = False
print("Writing generic file to delete all non-Lewis type interactions (pi->pi* NBO, etc)")
os.chdir(os.getcwd())
for file in glob.glob("*.xyz"):
print("writing file:")
print(file)
writefile(file,1)
if(noinput):
print("\n\n<<Unrecognized input>> \n\n")
usage()