Skip to content

Commit 10949aa

Browse files
committed
Merge branch 'master' into generalize-cbf
* master: (21 commits) Fix combo box not showing all options. New virtual screening interface based on AutoDock Vina ecosystem. Update vina.py added initial docstring, revised import section, and added .py to name Create cgoCircle Update tmalign.py List plugins documentation (Pymol-Scripts#146) Fix support for multiple objects selection Add support for multiple object haystack in findseq.py Independent color and as_putty options for color_by_conservation.py (Pymol-Scripts#145) Add output message for findseq + don't create empty selection when seq was not found (Pymol-Scripts#141) Update tmalign.py Outline plugin version 0.2 minor fix An attempt to improve plugin the plugin documentations. Delete documentation.md Rename documentation.html to documentation.md Create documentation.html Port dynoplot to Qt Add tab-completion to findseq ...
2 parents 3ee534f + b05ee9f commit 10949aa

File tree

11 files changed

+3917
-1100
lines changed

11 files changed

+3917
-1100
lines changed

PluginsDocs.md

Lines changed: 2103 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
## PyMOL Script Repository
22

3-
This repository hosts most of the scripts and (single file) plugins from the [PyMOL Wiki](http://www.pymolwiki.org/). If you have a new script or plugin consider place it here. There is a [Git intro](http://www.pymolwiki.org/index.php/Git_intro) page for new contributors.
3+
This repository hosts most of the scripts and (single file) plugins from the [PyMOL Wiki](http://www.pymolwiki.org/). If you have a new script
4+
or plugin consider place it here. There is a [Git intro](http://www.pymolwiki.org/index.php/Git_intro) page for new contributors.
5+
6+
The [PluginsDocs](PluginsDocs.md) file contains documentation for many of the plugins hosted here. They are summarized
7+
by [_summarize.py](_summarize.py) command line script (not a PyMOL one).

_summarize.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import ast
2+
import tempfile
3+
import webbrowser
4+
from collections import defaultdict
5+
from glob import glob
6+
from textwrap import indent
7+
8+
from jinja2 import Template
9+
10+
11+
FOUND = defaultdict(dict)
12+
NeedRefactor = object()
13+
14+
15+
class Visitor1pass(ast.NodeVisitor):
16+
def __init__(self, module):
17+
self.module = module
18+
19+
def visit_Call(self, call):
20+
if hasattr(call.func, 'attr') and call.func.attr == "extend":
21+
if len(call.args) == 2:
22+
if call.func.attr == "extend" and call.func.value.id == "cmd":
23+
funcname = call.args[0].value
24+
FOUND[self.module][funcname] = None
25+
26+
class Visitor2Pass(ast.NodeVisitor):
27+
def __init__(self, module):
28+
self.module = module
29+
30+
def visit_FunctionDef(self, functionDef):
31+
if functionDef.col_offset == 0 and functionDef.name == "__init__":
32+
FOUND[self.module] = NeedRefactor
33+
34+
35+
class Visitor3pass(ast.NodeVisitor):
36+
def __init__(self, module):
37+
self.module = module
38+
39+
def visit_FunctionDef(self, functiondef):
40+
if functiondef.name in FOUND[self.module]:
41+
try:
42+
if isinstance(functiondef.body[0].value.value, str):
43+
docstring = functiondef.body[0].value.value
44+
docstring = indent(docstring, " " * 4)
45+
FOUND[self.module][functiondef.name] = docstring
46+
except Exception as exc:
47+
pass
48+
49+
50+
for module in [*glob("*.py"), *glob("plugins/*.py")]:
51+
if module.startswith('_'):
52+
continue
53+
with open(module) as module_file:
54+
src = ''.join(module_file.readlines())
55+
tree = ast.parse(src, filename=module)
56+
57+
v = Visitor1pass(module)
58+
v.visit(tree)
59+
60+
v = Visitor2Pass(module)
61+
v.visit(tree)
62+
63+
if FOUND[module] is not NeedRefactor:
64+
v = Visitor3pass(module)
65+
v.visit(tree)
66+
else:
67+
del FOUND[module]
68+
print("%s:: NeedRefactor" % module)
69+
70+
tmpl = Template("""
71+
# PyMOL Script Repo: Plugin List
72+
{% for module in commands %}
73+
* ## {{ module }}
74+
{% for command in commands[module] %}
75+
* # {{ command }}
76+
```{{ commands[module][command] }}```
77+
{% endfor %}
78+
{% endfor %}
79+
""")
80+
_, path = tempfile.mkstemp(suffix=".md")
81+
with open(path, "w") as fd:
82+
fd.write(tmpl.render(commands=FOUND))
83+
print("DOCUMENTATION: %s" % path)

cgoCircle.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
This script was initially copied from https://pymolwiki.org/index.php/CgoCircle on Sept. 23, 2024.
3+
4+
The PyMOL Wiki page containing the code that was copied is licensed under GNU Free Documentation License 1.2.
5+
6+
Probable Author: Jason Vertrees.
7+
"""
8+
9+
import math
10+
import pymol
11+
from pymol.cgo import *
12+
from pymol import cmd
13+
14+
def cgoCircle(x, y, z, r=8.0, cr=1.0, cg=0.4, cb=0.8, w=2.0):
15+
"""
16+
Create a CGO circle
17+
18+
PARAMS
19+
x, y, z
20+
X, Y and Z coordinates of the origin
21+
22+
r
23+
Radius of the circle
24+
25+
cr, cg, cb
26+
Color triplet, [r,g,b] where r,g,b are all [0.0,1.0].
27+
28+
w
29+
Line width of the circle
30+
31+
RETURNS
32+
the CGO object (it also loads it into PyMOL, too).
33+
34+
"""
35+
x = float(x)
36+
y = float(y)
37+
z = float(z)
38+
r = abs(float(r))
39+
cr = abs(float(cr))
40+
cg = abs(float(cg))
41+
cb = abs(float(cb))
42+
w = float(w)
43+
44+
obj = [ BEGIN, LINES, COLOR, cr, cg, cb ]
45+
for i in range(180):
46+
obj.append( VERTEX )
47+
obj.append(r*math.cos(i) + x )
48+
obj.append(r*math.sin(i) + y )
49+
obj.append(z)
50+
obj.append( VERTEX )
51+
obj.append(r*math.cos(i+0.1) + x )
52+
obj.append(r*math.sin(i+0.1) + y )
53+
obj.append(z)
54+
obj.append(END)
55+
56+
cName = cmd.get_unused_name("circle_")
57+
cmd.load_cgo( obj, cName )
58+
cmd.set("cgo_line_width", w, cName )
59+
return obj
60+
61+
62+
def circleSelection( selName, r=None, cr=1.0, cg=0.4, cb=0.8, w=2.0 ):
63+
"""
64+
circleSelection -- draws a cgo circle around a given selection or object
65+
66+
PARAMS
67+
selName
68+
Name of the thing to encircle.
69+
70+
r
71+
Radius of circle.
72+
DEFAULT: This cript automatically defines the radius for you. If
73+
you select one atom and the resultant circle is too small, then
74+
you can override the script's calculation of r and specify your own.
75+
76+
cr, cg, cb
77+
red, green and blue coloring, each a value in the range [0.0, 1.0]
78+
79+
RETURNS
80+
The circle object.
81+
82+
"""
83+
((minX, minY, minZ), (maxX, maxY, maxZ)) = cmd.get_extent(selName)
84+
85+
if r==None:
86+
r = max( [maxX-minX, maxY-minY, maxZ-minZ] )
87+
88+
stored.coords = []
89+
cmd.iterate_state(1, selName, "stored.coords.append([x,y,z])")
90+
l = len(stored.coords)
91+
92+
centerX = sum(map(lambda x: x[0], stored.coords)) / l
93+
centerY = sum(map(lambda x: x[1], stored.coords)) / l
94+
centerZ = sum(map(lambda x: x[2], stored.coords)) / l
95+
96+
return cgoCircle( centerX, centerY, centerZ, r, cr, cg, cb, w )
97+
98+
99+
cmd.extend( "cgoCircle", cgoCircle )
100+
cmd.extend( "circleSelection", circleSelection )

color_by_conservation.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
'''
2-
See more here: http://www.pymolwiki.org/index.php/color_by_conservation
1+
from pymol import cmd, CmdException
32

4-
PARAMETERS
5-
aln
6-
(string) the alignment object name
7-
names
8-
(list) a list of object names that are in the alignment;
9-
if (), then PyMOL will attempt to glean the names
10-
from the alignment object
11-
color
12-
(string) valid PyMOL spectrum name
133

14-
as_putty
15-
(0 or 1) if 0 display is not changed, else participating objects are shown
16-
as cartoon putty, colored by the 'color' field
17-
'''
4+
@cmd.extend
5+
def color_by_conservation(aln, names=(), color=None, as_putty=0, _self=cmd):
6+
'''
7+
See more here: http://www.pymolwiki.org/index.php/color_by_conservation
188
19-
from __future__ import print_function
20-
from pymol import cmd
9+
PARAMETERS
10+
aln
11+
(string) the alignment object name
12+
names
13+
(list) a list of object names that are in the alignment;
14+
if (), then PyMOL will attempt to glean the names
15+
from the alignment object
16+
color
17+
(string) valid PyMOL spectrum name
2118
19+
as_putty
20+
(0 or 1) if 0 display is not changed, else participating objects are shown
21+
as cartoon putty, colored by the 'color' field
22+
'''
2223

23-
def color_by_conservation(aln, names=(), color="rainbow", as_putty=0, _self=cmd):
24-
# PyMOL doesn't yet know about object:alignment
25-
# but we need to check that this exists or we might crash
26-
if _self.get_type(aln) not in ("object:", "object:alignment"):
27-
print("Error: Bad or incorrectly specified alignment object.")
28-
return None
24+
if _self.get_type(aln) != "object:alignment":
25+
raise CmdException("Error: Bad or incorrectly specified alignment object.")
2926

30-
r = cmd.get_raw_alignment(aln)
27+
r = _self.get_raw_alignment(aln)
3128

3229
if names == ():
3330
known_objs = []
@@ -48,12 +45,14 @@ def color_by_conservation(aln, names=(), color="rainbow", as_putty=0, _self=cmd)
4845
for y in af:
4946
_self.alter("%s and index %s" % (y[0], y[1]), "b=c", space={'c': c})
5047

51-
if as_putty != 0:
48+
if int(as_putty) != 0:
5249
for obj in known_objs:
5350
_self.show_as("cartoon", "%s" % obj)
5451
_self.cartoon("putty", "%s" % obj)
52+
53+
if color is not None:
54+
for obj in known_objs:
5555
_self.spectrum('b', color, obj)
56-
_self.sort()
57-
_self.rebuild()
58-
return None
59-
cmd.extend("color_by_conservation", color_by_conservation)
56+
57+
_self.sort()
58+
_self.rebuild()

0 commit comments

Comments
 (0)