forked from sokrypton/ColabFold
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pdb.py
69 lines (65 loc) · 2.07 KB
/
pdb.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
def show_pdb(
use_amber: bool,
jobname: str,
homooligomer,
model_num=1,
show_sidechains=False,
show_mainchains=False,
color="lDDT",
):
import py3Dmol
model_name = f"model_{model_num}"
if use_amber:
pdb_filename = f"{jobname}_relaxed_{model_name}.pdb"
else:
pdb_filename = f"{jobname}_unrelaxed_{model_name}.pdb"
view = py3Dmol.view(js="https://3dmol.org/build/3Dmol.js")
view.addModel(open(pdb_filename, "r").read(), "pdb")
if color == "lDDT":
view.setStyle(
{
"cartoon": {
"colorscheme": {
"prop": "b",
"gradient": "roygb",
"min": 50,
"max": 90,
}
}
}
)
elif color == "rainbow":
view.setStyle({"cartoon": {"color": "spectrum"}})
elif color == "chain":
for n, chain, color in zip(
range(homooligomer),
list("ABCDEFGH"),
["lime", "cyan", "magenta", "yellow", "salmon", "white", "blue", "orange"],
):
view.setStyle({"chain": chain}, {"cartoon": {"color": color}})
if show_sidechains:
BB = ["C", "O", "N"]
view.addStyle(
{
"and": [
{"resn": ["GLY", "PRO"], "invert": True},
{"atom": BB, "invert": True},
]
},
{"stick": {"colorscheme": f"WhiteCarbon", "radius": 0.3}},
)
view.addStyle(
{"and": [{"resn": "GLY"}, {"atom": "CA"}]},
{"sphere": {"colorscheme": f"WhiteCarbon", "radius": 0.3}},
)
view.addStyle(
{"and": [{"resn": "PRO"}, {"atom": ["C", "O"], "invert": True}]},
{"stick": {"colorscheme": f"WhiteCarbon", "radius": 0.3}},
)
if show_mainchains:
BB = ["C", "O", "N", "CA"]
view.addStyle(
{"atom": BB}, {"stick": {"colorscheme": f"WhiteCarbon", "radius": 0.3}}
)
view.zoomTo()
return view