-
Notifications
You must be signed in to change notification settings - Fork 2
/
unfreeze.py
executable file
·75 lines (60 loc) · 1.73 KB
/
unfreeze.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
#!/usr/bin/python
__author__='Nathan Gallup'
'''
===========================
freeze.py
For unfreezing Turbomole cartesian coordinate atoms quickly from the command line.
February 2015, UCLA
===========================
'''
import sys, os
## Check command line arguments
#if len(sys.argv[1:]) < 2:
# print "Incorrect number of arguments given. Exiting!"
# print "Usage: unfreeze.py <coord> <atoms to be frozen>"
# sys.exit(1)
#
## Check if valid turbomole files
#if (not os.path.isfile(sys.argv[1])):
# print "Not a valid turbomole coord file"
# sys.exit(1)
#if open(sys.argv[1],'r').readline() != "$coord\n":
# print "Not a valid turbomole coord file"
# sys.exit(1)
def unfreeze(coord,*atoms):
# Define usage statement
def usage():
print "Usage: unfreeze.py <coord> <atoms to be frozen>"
# Check validity of command line arguments
if (not os.path.isfile(coord)):
print "Not a valid turbomole coord file"
usage()
sys.exit(1)
if open(coord,'r').readline() != "$coord\n":
print "Not a valid turbomole coord file"
usage()
sys.exit(1)
if len(atoms) == 0:
print "No atoms given. Exiting!"
usage()
sys.exit(1)
# Read in coord atoms
coordFile = open(coord,'r')
coordLines = coordFile.readlines()
atomList = []
for atom in atoms:
atomList.append(int(atom))
# Append f's to lines unless already present
for atom in atomList:
if coordLines[atom].split()[-1] != 'f':
print "No frozen coordinate found for atom %d. Proceeding." % atom
continue
else:
coordLines[atom] = "%s\n" % coordLines[atom].rsplit(' ', 1)[0]
coordFile.close()
# Now write all the data back to file
coordFile = open(coord, 'w')
for line in coordLines:
coordFile.write(line)
if __name__ == '__main__':
unfreeze(sys.argv[1], *sys.argv[2:])