<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=CgoCircle</id>
	<title>CgoCircle - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=CgoCircle"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=CgoCircle&amp;action=history"/>
	<updated>2026-04-15T02:16:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=CgoCircle&amp;diff=6651&amp;oldid=prev</id>
		<title>Pyadmin: 5 revisions</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=CgoCircle&amp;diff=6651&amp;oldid=prev"/>
		<updated>2014-03-28T01:49:14Z</updated>

		<summary type="html">&lt;p&gt;5 revisions&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Overview =&lt;br /&gt;
This script will create a CGO circle with the origin at the specified X,Y,Z coordinates.  Also, you can specify the radius and the colors.  See the examples.&lt;br /&gt;
&lt;br /&gt;
If you want to draw a circle around an object or selection, use '''circleSelection'''.   If you want pure flexibility over your circle then use '''cgoCircle'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''There are two functions here:'''&lt;br /&gt;
&lt;br /&gt;
'''cgoCircle'''&lt;br /&gt;
::&amp;amp;mdash; creates a CGO circle at some user-specified location&lt;br /&gt;
'''circleSelection'''&lt;br /&gt;
::&amp;amp;mdash;creates a circle around the named object or selection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery heights=200px widths=300px perrow=3&amp;gt;&lt;br /&gt;
Image:Circle1.png|Drawn circle.&lt;br /&gt;
Image:Circle2.png|CGO circle.&lt;br /&gt;
Image:Circle3.png|Circles of specified radius.&lt;br /&gt;
Image:CircleR.png|Circle with specified width.&lt;br /&gt;
Image:CircleR2.png|Circle with a line width of 150.  Pores anyone?&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Usage =&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import math&lt;br /&gt;
import pymol&lt;br /&gt;
from pymol.cgo import *&lt;br /&gt;
import random&lt;br /&gt;
&lt;br /&gt;
def cgoCircle(x, y, z, r=8.0, cr=1.0, cg=0.4, cb=0.8, w=2.0):&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  Create a CGO circle&lt;br /&gt;
&lt;br /&gt;
  PARAMS&lt;br /&gt;
        x, y, z&lt;br /&gt;
          X, Y and Z coordinates of the origin&lt;br /&gt;
&lt;br /&gt;
        r&lt;br /&gt;
          Radius of the circle&lt;br /&gt;
&lt;br /&gt;
        cr, cg, cb&lt;br /&gt;
          Color triplet, [r,g,b] where r,g,b are all [0.0,1.0].&lt;br /&gt;
&lt;br /&gt;
        w&lt;br /&gt;
          Line width of the circle&lt;br /&gt;
&lt;br /&gt;
  RETURNS&lt;br /&gt;
        the CGO object (it also loads it into PyMOL, too).&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  x = float(x)&lt;br /&gt;
  y = float(y)&lt;br /&gt;
  z = float(z)&lt;br /&gt;
  r = abs(float(r))&lt;br /&gt;
  cr = abs(float(cr))&lt;br /&gt;
  cg = abs(float(cg))&lt;br /&gt;
  cb = abs(float(cb))&lt;br /&gt;
  w = float(w)&lt;br /&gt;
&lt;br /&gt;
  obj = [ BEGIN, LINES, COLOR, cr, cg, cb ]&lt;br /&gt;
  for i in range(180):&lt;br /&gt;
        obj.append( VERTEX )&lt;br /&gt;
        obj.append(r*math.cos(i) + x )&lt;br /&gt;
        obj.append(r*math.sin(i) + y )&lt;br /&gt;
        obj.append(z)&lt;br /&gt;
        obj.append( VERTEX )&lt;br /&gt;
        obj.append(r*math.cos(i+0.1) + x )&lt;br /&gt;
        obj.append(r*math.sin(i+0.1) + y )&lt;br /&gt;
        obj.append(z)&lt;br /&gt;
  obj.append(END)&lt;br /&gt;
 &lt;br /&gt;
  cName = cmd.get_unused_name(&amp;quot;circle_&amp;quot;)&lt;br /&gt;
  cmd.load_cgo( obj, cName )&lt;br /&gt;
  cmd.set(&amp;quot;cgo_line_width&amp;quot;, w, cName )&lt;br /&gt;
  return obj&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def circleSelection( selName, r=None, cr=1.0, cg=0.4, cb=0.8, w=2.0 ):&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  circleSelection -- draws a cgo circle around a given selection or object&lt;br /&gt;
&lt;br /&gt;
  PARAMS&lt;br /&gt;
        selName&lt;br /&gt;
          Name of the thing to encircle.&lt;br /&gt;
&lt;br /&gt;
        r&lt;br /&gt;
          Radius of circle.&lt;br /&gt;
          DEFAULT: This cript automatically defines the radius for you.  If&lt;br /&gt;
          you select one atom and the resultant circle is too small, then&lt;br /&gt;
          you can override the script's calculation of r and specify your own.&lt;br /&gt;
&lt;br /&gt;
        cr, cg, cb&lt;br /&gt;
          red, green and blue coloring, each a value in the range [0.0, 1.0]&lt;br /&gt;
&lt;br /&gt;
  RETURNS&lt;br /&gt;
        The circle object.&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  ((minX, minY, minZ), (maxX, maxY, maxZ)) = cmd.get_extent(selName)&lt;br /&gt;
&lt;br /&gt;
  if r==None:&lt;br /&gt;
        r = max( [maxX-minX, maxY-minY, maxZ-minZ] )&lt;br /&gt;
&lt;br /&gt;
  stored.coords = []&lt;br /&gt;
  cmd.iterate_state(1, selName, &amp;quot;stored.coords.append([x,y,z])&amp;quot;)&lt;br /&gt;
  l = len(stored.coords)&lt;br /&gt;
&lt;br /&gt;
  centerX = sum(map(lambda x: x[0], stored.coords)) / l&lt;br /&gt;
  centerY = sum(map(lambda x: x[1], stored.coords)) / l&lt;br /&gt;
  centerZ = sum(map(lambda x: x[2], stored.coords)) / l&lt;br /&gt;
&lt;br /&gt;
  return cgoCircle( centerX, centerY, centerZ, r, cr, cg, cb, w )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cmd.extend( &amp;quot;cgoCircle&amp;quot;, cgoCircle )&lt;br /&gt;
cmd.extend( &amp;quot;circleSelection&amp;quot;, circleSelection )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Updates =&lt;br /&gt;
* Line width option&lt;br /&gt;
* better circle naming&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;br /&gt;
[[Category:Math_Scripts]]&lt;br /&gt;
[[Category:CGO]]&lt;/div&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
</feed>