Skip to content

Commit 73e58b0

Browse files
drew161pslacerda
authored andcommitted
Create cgoCircle
This script was copied from https://pymolwiki.org/index.php/CgoCircle on Sept. 23, 2024. It appears to have been authored by Jason Vertrees.
1 parent 935bc10 commit 73e58b0

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

cgoCircle

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

0 commit comments

Comments
 (0)