-
Notifications
You must be signed in to change notification settings - Fork 0
/
micanpymol_python2.py
80 lines (66 loc) · 2.75 KB
/
micanpymol_python2.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
76
77
78
79
import subprocess
import tempfile
import os
import shutil
class TemporaryDirectory(object):
# For Python2: taken from https://qiita.com/everylittle/items/aa7c6f612ff0a9db7f01
def __init__(self, suffix="", prefix="tmp", dir=None):
self.__name = tempfile.mkdtemp(suffix, prefix, dir)
def __enter__(self):
return self.__name
def __exit__(self, exc, value, tb):
self.cleanup()
@property
def name(self):
return self.__name
def cleanup(self):
shutil.rmtree(self.__name)
def mican(mobile, target, option=""):
#make temporary dir and do everything there
with TemporaryDirectory() as dname:
#turn off zooming when loading: set auto_zoom, off
old_auto_zoom=cmd.get("auto_zoom")
cmd.set("auto_zoom","off")
# print tmp dir name
print("Temporary directory =" + dname)
# print(os.path.exists(dname))
# make sure you have mican in PATH
# directly giving 'execute' full path below is good alternative
# For example : execute = "/usr/bin/mican"
execute = "mican"
tmptarget = dname + "/target.pdb"
tmpmobile = dname + "/mobile.pdb"
tmpout = dname + "/aligned.pdb"
# save pdb for mican
pymol.cmd.save(tmptarget, target)
pymol.cmd.save(tmpmobile, mobile)
modeoption = "-" + option
option2 = "-o"
outfile = tmpout
mican = [execute, tmpmobile, tmptarget, option2, outfile]
for op in option.split():
if(op == "-o"):
print("option -o is reserved")
raise CmdException
mican.append(op)
# proc=subprocess.Popen(mican,stdout = subprocess.PIPE)
proc=subprocess.check_call(mican)
#proc=subprocess.Popen(mican)
#print(proc.stdout.decode("utf8")) # print result to pymol console
pymol.cmd.load(outfile, "aligned")
pymol.cmd.split_states("aligned")
pymol.cmd.select("mobileback",mobile + " and backbone")
pymol.cmd.align("mobileback", "aligned_0001 and backbone")
# use cmd pair_fit if you think align is not good
# print("Using cmd.align instead of cmd.pair_fit")
# pymol.cmd.pair_fit("mobileback", "aligned_0001 and backbone")
pymol.cmd.delete("mobileback")
pymol.cmd.delete("aligned")
pymol.cmd.delete("aligned_0001")
pymol.cmd.delete("aligned_0002")
# pymol.cmd.quit()
# reset auto_zoom as you had set
cmd.set("auto_zoom",old_auto_zoom)
pymol.cmd.extend("mican", mican)
cmd.auto_arg[0]['mican'] = cmd.auto_arg[0]['align']
cmd.auto_arg[1]['mican'] = cmd.auto_arg[1]['align']