-
Notifications
You must be signed in to change notification settings - Fork 2
/
xyz2tbl.py
43 lines (38 loc) · 1.08 KB
/
xyz2tbl.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
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
fname = str(sys.argv[1])
else:
fname = 'mol.xyz'
xyz = []
with open(fname,'r') as f:
next(f)
comment_line = True
for line in f:
if comment_line:
mname = str(line)
comment_line = False
else:
try:
(A,x,y,z) = line.split()
xyz.append([str(A),float(x),float(y),float(z)])
except:
print("Found unknown line: {}".format(line))
with open('out.txt','a+') as o:
o.write("""\\begin{{table}}
\\centering
\\caption{{Atomic coordinates of {} (\\AA ngstroms)}}
\\label{{{}}}
\\begin{{tabular}}{{ c c c c }}
\\hline
\\hline
Atomic & & & \\\\
Symbol & X & Y & Z \\\\
\\hline""".format(mname,fname.strip('.xyz')))
for atom in range(0,len(xyz)):
o.write("""\n\t{0} & {1:10.6f} & {2:10.6f} & {3:10.6f} \\\\""".format(xyz[atom][0],xyz[atom][1],xyz[atom][2],xyz[atom][3]))
o.write("""
\\hline
\\hline
\\end{tabular}
\\end{table}\n""")