-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathextract_pymol_commands
executable file
·45 lines (40 loc) · 1.6 KB
/
extract_pymol_commands
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
#!/usr/bin/env python
import sys, os
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-o", "--pmlfile", dest="pmlfile", help="write report to FILE.pml",
metavar="FILE.pml", default="~/tmp/rosetta.pml")
parser.add_option("-t", "--tag", dest="tag", help="tag to print, default all", default="")
parser.add_option("-k", "--killpymol", dest="kill", help="kill pymol when run",
action="store_true", default=False)
parser.add_option("-r", "--removeold", dest="rm", help="", action="store_true", default=False)
opt, args = parser.parse_args()
outfile = os.path.expanduser(opt.pmlfile)
if len(args) is 0:
inputstream = sys.stdin
print "pymolcmd: extract lines from STDIN starting with 'PYMOL_CMD %s' and put them in file: %s" % (
opt.tag, outfile)
elif len(args) is 1:
infname = os.path.expanduser(args[0])
inputstream = open(infname)
print "pymolcmd: extract lines from file '%s' starting with 'PYMOL_CMD %s' and put them in file: %s" % (
infname, opt.tag, outfile)
else:
sys.exit("don't know what do to with extra args: " + str(args))
if opt.kill:
print "KILLING MacPyMOL!!!!!"
os.system("killall MacPyMOL")
if opt.rm:
print "REMOVING (if exists)", outfile
if os.path.exists(outfile):
os.remove(outfile)
with open(outfile, 'w') as out:
for l in inputstream.readlines():
if l.startswith("PYMOL_CMD"):
tmp, tag = l.split()[:2]
if not opt.tag or opt.tag == tag:
out.write(l[len(tmp) + len(tag) + 2:])
else:
print l,
if inputstream is not sys.stdin:
inputstream.close()