-
Notifications
You must be signed in to change notification settings - Fork 0
/
au2ang.py
executable file
·40 lines (30 loc) · 931 Bytes
/
au2ang.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
#!/usr/bin/python
# Arnfinn Hykkerud Steindal, Tromso Apr 2010; May 2012
# Read an xyz file (-i FILENAME) and convert from
# atomic units to angstrom.
import sys
import math
from optparse import OptionParser
def au2ang(value):
new_value = value*0.529177249
return new_value
parser = OptionParser()
parser.add_option("-i", "--input",dest="filename", help="the file to read")
(options, args) = parser.parse_args()
file = open(options.filename,'r')
lines = file.readlines()
file.close()
b= len(options.filename)
newfile = open(options.filename[0:b-4]+"_ang.xyz","w")
newfile.write(lines[0]+lines[1])
newlines=""
for line in lines[2:]:
words = line.split()
try:
x=au2ang(float(words[1]))
y=au2ang(float(words[2]))
z=au2ang(float(words[3]))
except:
break
newfile.write(line.replace(words[1],str(x)).replace(words[2],str(y)).replace(words[3],str(z)))
newfile.close()