forked from Ianiusha/Uselfuls_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_to_Zmatrix.py
63 lines (41 loc) · 1.12 KB
/
convert_to_Zmatrix.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
#!/usr/bin/python
# Anna Tomberg
# convert Avogadro's compact zMatrix to ORCA format
# requires the last star after the end of the xyz coordinates
import re
import sys
fo = open(sys.argv[1] , "r")
line_counter = 1
lines = fo.readlines()
fo.close()
for line in lines:
if line.startswith("* int"):
break
line_counter += 1
new_coords = []
for x in range(line_counter, len(lines)):
temp = lines[x].split()
if temp[0] == '*':
break
else:
new_line = [0]
m = re.search('([a-zA-Z]+)([0-9]+)', temp[0])
new_line[0]=(m.group(1)) # atoms in molecule
atoms = []
values = []
for i in range(1,len(temp)):
#print i, temp[i]
if (i%2): # atom columns
m = re.search('([a-zA-Z]+)([0-9]+)', temp[i])
atoms.append(m.group(2))
else: # value columns
values.append(temp[i])
atoms = atoms + [0] * (3 - len(atoms))
values = values + ['0.0000'] * (3 - len(values))
new_coords.append(new_line + atoms + values)
fo = open(sys.argv[1] , "a")
fo.write('\n')
for line in (new_coords):
print( " ".join(str(x) for x in line))
fo.write(" ".join(str(x) for x in line)+'\n')
fo.close()