-
Notifications
You must be signed in to change notification settings - Fork 258
/
cgoCircle.py
100 lines (75 loc) · 2.5 KB
/
cgoCircle.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
This script was initially copied from https://pymolwiki.org/index.php/CgoCircle on Sept. 23, 2024.
The PyMOL Wiki page containing the code that was copied is licensed under GNU Free Documentation License 1.2.
Probable Author: Jason Vertrees.
"""
import math
import pymol
from pymol.cgo import *
from pymol import cmd
def cgoCircle(x, y, z, r=8.0, cr=1.0, cg=0.4, cb=0.8, w=2.0):
"""
Create a CGO circle
PARAMS
x, y, z
X, Y and Z coordinates of the origin
r
Radius of the circle
cr, cg, cb
Color triplet, [r,g,b] where r,g,b are all [0.0,1.0].
w
Line width of the circle
RETURNS
the CGO object (it also loads it into PyMOL, too).
"""
x = float(x)
y = float(y)
z = float(z)
r = abs(float(r))
cr = abs(float(cr))
cg = abs(float(cg))
cb = abs(float(cb))
w = float(w)
obj = [ BEGIN, LINES, COLOR, cr, cg, cb ]
for i in range(180):
obj.append( VERTEX )
obj.append(r*math.cos(i) + x )
obj.append(r*math.sin(i) + y )
obj.append(z)
obj.append( VERTEX )
obj.append(r*math.cos(i+0.1) + x )
obj.append(r*math.sin(i+0.1) + y )
obj.append(z)
obj.append(END)
cName = cmd.get_unused_name("circle_")
cmd.load_cgo( obj, cName )
cmd.set("cgo_line_width", w, cName )
return obj
def circleSelection( selName, r=None, cr=1.0, cg=0.4, cb=0.8, w=2.0 ):
"""
circleSelection -- draws a cgo circle around a given selection or object
PARAMS
selName
Name of the thing to encircle.
r
Radius of circle.
DEFAULT: This cript automatically defines the radius for you. If
you select one atom and the resultant circle is too small, then
you can override the script's calculation of r and specify your own.
cr, cg, cb
red, green and blue coloring, each a value in the range [0.0, 1.0]
RETURNS
The circle object.
"""
((minX, minY, minZ), (maxX, maxY, maxZ)) = cmd.get_extent(selName)
if r==None:
r = max( [maxX-minX, maxY-minY, maxZ-minZ] )
stored.coords = []
cmd.iterate_state(1, selName, "stored.coords.append([x,y,z])")
l = len(stored.coords)
centerX = sum(map(lambda x: x[0], stored.coords)) / l
centerY = sum(map(lambda x: x[1], stored.coords)) / l
centerZ = sum(map(lambda x: x[2], stored.coords)) / l
return cgoCircle( centerX, centerY, centerZ, r, cr, cg, cb, w )
cmd.extend( "cgoCircle", cgoCircle )
cmd.extend( "circleSelection", circleSelection )