Hi Dean,

Funny, really. Last week I was just playing around a bit with creating
boxes in pymol, e.g. to create a bounding box, and I wanted to have it
transparent. So here's a script, giving you a function 'rect', which
takes two tuples, specifying the far edges of the box:

rect( [x0,y0,z0], [x1,y1,z1],name="box",rgbt=[1,1,0,0.5])

The rgbt argument specifies the color and transparency. Feel free to
go through the code to see how things are done (although you won't
hear me say it's perfect). In case you have any suggestions, also feel
free to contact me, either on or off list.

I hope it helps. Cheers,

Tsjerk

On Wed, Apr 23, 2008 at 5:22 PM, Dean Waldow <wal...@chem.plu.edu> wrote:
>  Hi Folks,
>
> I am very new to pymol and have been learning a lot about using (mac)pymol.
> However, I seem to be unable to make a box which is transparent and has
> color. I have been able to make a box with the *.py script below but when I
> do the ray tracing to get a nice image the box turns to grey / black. I have
> also been able to to make prolate and oblate spheriods using ideas from the
> pymol wiki.
>
> My eventual goal is to have about three slabs or boxes with spheroids at the
> interface of these slabs and my pdb results from a monte carlo simulation
> where the spheriods highlight the changes in shape of my copolymers at the
> interface.
>
> Has anyone succeeded in making colored transparent boxes? Or might there be
> another strategy?
>
> Thanks,
>
> Dean Waldow
>
> Here is the script (modified from one that makes a bounding box I believe)
> that makes my current solid box which turns grey with I issue the ray
> command:
>
>
> from pymol.cgo import *
> from pymol import cmd
> #
> # SEGMENT     1
> box = [
>    LINEWIDTH, 1.0,
>    BEGIN, VERTEX,
>    COLOR, 0.0, 0.0, 0.0,
>
> # Face 1
>    VERTEX,   55.000,   55.000,   55.000,
>    VERTEX,   55.000,    5.000,   55.000,
>    VERTEX,   55.000,    5.000,    5.000,
>
>    VERTEX,   55.000,    5.000,    5.000,
>    VERTEX,   55.000,   55.000,    5.000,
>    VERTEX,   55.000,   55.000,   55.000,
>
> # Face 2
>    VERTEX,    5.000,   55.000,   55.000,
>    VERTEX,    5.000,    5.000,   55.000,
>    VERTEX,    5.000,    5.000,    5.000,
>
>    VERTEX,    5.000,    5.000,    5.000,
>    VERTEX,    5.000,   55.000,    5.000,
>    VERTEX,    5.000,   55.000,   55.000,
>
> # Face 3
>    VERTEX,   55.000,   55.000,   55.000,
>    VERTEX,    5.000,   55.000,   55.000,
>    VERTEX,    5.000,   55.000,    5.000,
>
>    VERTEX,    5.000,   55.000,    5.000,
>    VERTEX,   55.000,   55.000,    5.000,
>    VERTEX,   55.000,   55.000,   55.000,
>
> # Face 4
>    VERTEX,   55.000,    5.000,   55.000,
>    VERTEX,    5.000,    5.000,   55.000,
>    VERTEX,    5.000,    5.000,    5.000,
>
>    VERTEX,    5.000,    5.000,    5.000,
>    VERTEX,   55.000,    5.000,    5.000,
>    VERTEX,   55.000,    5.000,   55.000,
>
> # Face 5
>    VERTEX,   55.000,   55.000,   55.000,
>    VERTEX,    5.000,   55.000,   55.000,
>    VERTEX,    5.000,    5.000,   55.000,
>
>    VERTEX,    5.000,    5.000,   55.000,
>    VERTEX,   55.000,    5.000,   55.000,
>    VERTEX,   55.000,   55.000,   55.000,
>
> # Face 6
>    VERTEX,   55.000,   55.000,    5.000,
>    VERTEX,    5.000,   55.000,    5.000,
>    VERTEX,    5.000,    5.000,    5.000,
>
>    VERTEX,    5.000,    5.000,    5.000,
>    VERTEX,   55.000,    5.000,    5.000,
>    VERTEX,   55.000,   55.000,    5.000,
>
>    END
>    ]
>
> obj = box
>
> cmd.load_cgo(obj,'segment',   1)
>
>
>
> --
>
> ------------------------------------------------------------------------
>
> Dean Waldow, Professor               (253) 535-7533
>
> Department of Chemistry              (253) 536-5055 (FAX)
>
> Pacific Lutheran University          wal...@chem.plu.edu
>
> Tacoma, WA  98447   USA              http://www.chem.plu.edu/waldow/
>
> ------------------------------------------------------------------------
>
> ---> CIRRUS and the Chemistry homepage: <http://www.chem.plu.edu/> <----
>
> ------------------------------------------------------------------------
>
>
>
>
> -------------------------------------------------------------------------
>  This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>  Don't miss this year's exciting event. There's still time to save $100.
>  Use priority code J8TL2D2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
>  PyMOL-users mailing list
>  PyMOL-users@lists.sourceforge.net
>  https://lists.sourceforge.net/lists/listinfo/pymol-users
>
>



-- 
Tsjerk A. Wassenaar, Ph.D.
Junior UD (post-doc)
Biomolecular NMR, Bijvoet Center
Utrecht University
Padualaan 8
3584 CH Utrecht
The Netherlands
P: +31-30-2539931
F: +31-30-2537623
from pymol import cmd
from pymol.cgo import *

def vvsub( a, b ): return a[0]-b[0], a[1]-b[1], a[2]-b[2]
def oprod( a, b ): return a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], 
a[0]*b[1]-a[1]*b[0]
    
def triangle( x, y, z, rgb = [ 1, 1, 1 ] ):
    n = oprod( vvsub( y, x ), vvsub( z, x ) )
    return [
        COLOR, rgb[0], rgb[1], rgb[2],
        NORMAL, n[0], n[1], n[2],
        VERTEX, x[0], x[1], x[2],
        VERTEX, y[0], y[1], y[2],
        VERTEX, z[0], z[1], z[2]
        ]

def square( k, l, m, n, rgb = [ 1, 1, 1 ] ):
    return triangle( k, l, m, rgb ) + triangle( m, n, k, rgb )

def cube( rgbt = [ 1, 1, 1, 0 ], name="cube" ):
    a = [ -1, -1, -1 ]
    b = [ -1, -1,  1 ]
    c = [ -1,  1, -1 ]
    d = [ -1,  1,  1 ]
    e = [  1, -1, -1 ]
    f = [  1, -1,  1 ]
    g = [  1,  1, -1 ]
    h = [  1,  1,  1 ]

    obj = [ BEGIN, TRIANGLES, ALPHA, rgbt[3] ]
    obj.extend( square( a, b, d, c, rgbt ) )
    obj.extend( square( a, e, f, b, rgbt ) )
    obj.extend( square( a, c, g, e, rgbt ) )
    obj.extend( square( c, d, h, g, rgbt ) )
    obj.extend( square( b, f, h, d, rgbt ) )
    obj.extend( square( e, g, h, f, rgbt ) )
    obj.extend( [ END ] )

    cmd.load_cgo( obj, name )

def rect( p=[0,0,0], q=[1,1,1], rgbt = [ 1, 1, 1, 0 ], name="rect" ):
    u = [ min(p[0],q[0]), min(p[1],q[1]), min(p[2],q[2]) ]
    v = [ max(p[0],q[0]), max(p[1],q[1]), max(p[2],q[2]) ]
    
    a = u
    b = [ u[0], u[1], v[2] ]
    c = [ u[0], v[1], u[2] ]
    d = [ u[0], v[1], v[2] ]
    e = [ v[0], u[1], u[2] ]
    f = [ v[0], u[1], v[2] ]
    g = [ v[0], v[1], u[2] ]
    h = v 

    obj = [ BEGIN, TRIANGLES, ALPHA, rgbt[3], ]
    obj.extend( square( a, b, d, c, rgbt ) )
    obj.extend( square( a, e, f, b, rgbt ) )
    obj.extend( square( a, c, g, e, rgbt ) )
    obj.extend( square( c, d, h, g, rgbt ) )
    obj.extend( square( b, f, h, d, rgbt ) )
    obj.extend( square( e, g, h, f, rgbt ) )
    obj.extend( [ END ] )

    cmd.load_cgo( obj, name )

Reply via email to