Hi Amit (and other users),

Here's a script which can be used to put marks on the positions of every atom in a selection. There are several types of marks included now, e.g. cube, rhombic dodecahedron, tetrahedron, plus and star. Using a matrix operator these can be extended a bit, to 2D counterparts for example, or to elongated or rotated shapes. I should still include some documentation but in brief the usage is as follows:

graph selection = '(all)', shape = 'plus' | 'sphere' | 'star' | 'tetrahedron' | 'dodecahedron', size = 1, r = 0.10, rgb1 = [1,0,0], rgb2 = [0,0,1], mtx = [[1,0,0],[0,1,0],[0,0,1]], name = "graph"

Selection should be obvious, as is shape. Size is a relative indicator for the size, though at present I haven't fixed things such that a size 1 tetrahedron matches a size 1 dodecahedron. r is the radius of the lines. rgb1 and rgb2 are the start and end color for each line. mtx is the matrix operator, which works on the original shape centered around the origin (before translation to the point of the atom from the selection).

Hope this already works a bit as wanted. I'll be trying to make it a bit better in the future ;)

Cheers,

Tsjerk

Amit Chourasia wrote:

Tsjerk,

Great I'll look forward to see your script.
By that time I'll also gain some familiarity with Python.

For spline related stuff I found this in archive.
set ribbon_trace,1
This will create ribbons for arbitrary atoms, but they should be seperate
objects if we dont want them connected by one ribbon.

Have a nice time in Rome. I wish to travel to Venice sometime.

Thanks and Regards
--Amit



-----Original Message-----
From: Tsjerk Wassenaar [mailto:t.a.wassen...@chem.rug.nl]
Sent: Thursday, May 13, 2004 3:04 AM
To: a...@sdsc.edu
Subject: Re: [PyMOL] 3d plotting in pymol



Hi Amit,

This isn't too difficult actually, and I have done something alike
recently. What it comes down to is to write some python extensions and
have definitions for the CGO shapes you want to use. Then you can read
the coordinates for the atoms ( sel =
cmd.get_selection("selection_string")  and reading coordinates from
sel.atom[i].coord ) and add these coordinates to your CGO object. Doing
this for all atoms and loading it back into pymol would give you what
you want. I'm not completely sure where I have the script I wrote. But I
can have a look in about a week (when I get back from Rome) and write
the script if it hasn't been done already (the feature sounds cool
enough ;) ).

Wouldn't have ideas on the spline at this moment.

Cheers,

Tsjerk

Amit Chourasia wrote:

Hi,
I am trying to use pymol as a 3d plotting tool.

I have few questions

1)Is there a way to add represenation in pymol. ?
For instance I would like to see the atom as a triangle or nhedron.
I was going through CGO objects that looks promising to what I want to
accomplish. What I am looking for is to add represenation module and
use them.

2)Is there a method to represent a group of atoms connected by cartoon
even if the chains are not biologically feasable. What I am looking
for is you have bunch of points(atoms) through which the ribbon should
pass like a spline curve.

Any inputs and pointers would be most appreciated.

Thanks
--Amit







--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- :)
-- :)   Tsjerk A. Wassenaar, M.Sc.
-- :)   Molecular Dynamics Group
-- :)   Dept. of Biophysical Chemistry
-- :)   University of Groningen
-- :)   Nijenborgh 4
-- :)   9747 AG Groningen
-- :)   The Netherlands
-- :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- :)
-- :)   Hi! I'm a .signature virus!
-- :)   Copy me into your ~/.signature to help me spread!
-- :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- :)
-- :)   Tsjerk A. Wassenaar, M.Sc.
-- :)   Molecular Dynamics Group
-- :)   Dept. of Biophysical Chemistry
-- :)   University of Groningen
-- :)   Nijenborgh 4
-- :)   9747 AG Groningen
-- :)   The Netherlands
-- :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- :)
-- :)   Hi! I'm a .signature virus!
-- :)   Copy me into your ~/.signature to help me spread!
-- :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from pymol.cgo import *
from pymol import cmd
from math import *

## Multiplying a vector b by matrix a ##
def mvmult(a, b):
    return [ a[0][0]*b[0]+a[0][1]*b[1]+a[0][2]*b[2],
             a[1][0]*b[0]+a[1][1]*b[1]+a[1][2]*b[2],
             a[2][0]*b[0]+a[2][1]*b[1]+a[2][2]*b[2] ]

## Multiplying a vector b by scalar a ##
def svmult(a, b):
    return [a*b[0], a*b[1], a*b[2]]

#-------- Definition of shapes
#
#PROTOTYPE:
#
# def shape(
#        position=[0,0,0],                          Position
#        size=1,                                    General size
#        axisradius=0.1,                            Axis radius for cylinders 
and sausages
#        rgb1=[1,1,1],                              Color, or start color for 
cylinders and sausages
#        rgb2=[1,1,1],                              End color for cylinders and 
sausages
#        mtx=[[1,0,0],[0,1,0],[0,0,1]])             Matrix operator for 
deformation
#

def 
sphere(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    obj = [SPHERE, position[0], position[1], position[2], 0.5*axisradius, 
rgb1[0], rgb1[1], rgb1[2]]
    return obj

def 
plus(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    lines = [ [ [-0.5, 0.0, 0.0],[ 0.5, 0.0, 0.0] ],
              [ [ 0.0,-0.5, 0.0],[ 0.0, 0.5, 0.0] ],
              [ [ 0.0, 0.0,-0.5],[ 0.0, 0.0, 0.5] ] ]
    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

def 
star(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    cos60 = 0.5*sqrt(3)
    sin60 = 0.5
    lines = [ [ [-0.5, 0.0, 0.0],[ 0.5, 0.0, 0.0] ],
              [ [-sin60, cos60, 0.0], [ sin60,-cos60, 0.0] ],
              [ [-sin60,-cos60, 0.0], [ sin60, cos60, 0.0] ],
              [ [-sin60, 0.0, cos60], [ sin60, 0.0,-cos60] ],
              [ [-sin60, 0.0,-cos60], [ sin60, 0.0, cos60] ] ]
    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

def 
cube(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    lines = [ [ [-0.5,-0.5,-0.5], [ 0.5,-0.5,-0.5] ],
              [ [-0.5,-0.5,-0.5], [-0.5, 0.5,-0.5] ],
              [ [-0.5,-0.5,-0.5], [-0.5,-0.5, 0.5] ],
              [ [ 0.5, 0.5, 0.5], [-0.5, 0.5, 0.5] ],
              [ [ 0.5, 0.5, 0.5], [ 0.5,-0.5, 0.5] ],
              [ [ 0.5, 0.5, 0.5], [ 0.5, 0.5,-0.5] ],
              [ [-0.5, 0.5,-0.5], [ 0.5, 0.5,-0.5] ],
              [ [-0.5, 0.5,-0.5], [-0.5, 0.5, 0.5] ],
              [ [-0.5,-0.5, 0.5], [ 0.5,-0.5, 0.5] ],
              [ [-0.5,-0.5, 0.5], [-0.5, 0.5, 0.5] ],
              [ [ 0.5,-0.5,-0.5], [ 0.5, 0.5,-0.5] ],
              [ [ 0.5,-0.5,-0.5], [ 0.5,-0.5, 0.5] ] ]
    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

def 
tetrahedron(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    a = [0,1,0]
    cos104_90 = cos(pi*104.90/180)
    sin104_90 = sin(pi*104.90/180)
    sin120    = sin(pi*120/180)
    cos120    = cos(pi*120/180)
    b = mvmult([[cos104_90, sin104_90, 0],[-sin104_90,cos104_90,0],[0,0,1]],a)
    c = mvmult([[cos120, 0, sin120],[0,1,0],[-sin120,0,cos120]],b)
    d = mvmult([[cos120, 0, sin120],[0,1,0],[-sin120,0,cos120]],c)
    lines = [ [ a, b ],
              [ a, c ],
              [ a, d ],
              [ b, c ],
              [ b, d ],
              [ c, d ]]
    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

def 
tetrahedron1(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    a = [0,1,0]
    cos104_90 = cos(pi*104.90/180)
    sin104_90 = sin(pi*104.90/180)
    sin120    = sin(pi*120/180)
    cos120    = cos(pi*120/180)
    b = mvmult([[cos104_90, sin104_90, 0],[-sin104_90,cos104_90,0],[0,0,1]],a)
    c = mvmult([[cos120, 0, sin120],[0,1,0],[-sin120,0,cos120]],b)
    d = mvmult([[cos120, 0, sin120],[0,1,0],[-sin120,0,cos120]],c)
    lines = [ [ [0,0,0], a ],
              [ [0,0,0], b ],
              [ [0,0,0], c ],
              [ [0,0,0], d ]]
    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

def 
rdodec(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    # vertices:
    # The base cube, centered around (0,0,0)
    a = [  0.5,  0.5,  0.5 ]
    b = [  0.5,  0.5, -0.5 ]
    c = [  0.5, -0.5,  0.5 ]
    d = [  0.5, -0.5, -0.5 ]
    e = [ -0.5,  0.5,  0.5 ]
    f = [ -0.5,  0.5, -0.5 ]
    g = [ -0.5, -0.5,  0.5 ]
    h = [ -0.5, -0.5, -0.5 ]
    # The conjugated octahedron of the base cube
    i = [  1.0,  0.0,  0.0 ]
    j = [  0.0,  1.0,  0.0 ]
    k = [  0.0,  0.0,  1.0 ]
    l = [ -1.0,  0.0,  0.0 ]
    m = [  0.0, -1.0,  0.0 ]
    n = [  0.0,  0.0, -1.0 ]

    lines = [ [ i, a ],
              [ i, b ],
              [ i, c ],
              [ i, d ],
              [ j, a ],
              [ j, b ],
              [ j, e ],
              [ j, f ],
              [ k, a ],
              [ k, c ],
              [ k, e ],
              [ k, g ],
              [ l, e ],
              [ l, f ],
              [ l, g ],
              [ l, h ],
              [ m, c ],
              [ m, d ],
              [ m, g ],
              [ m, h ],
              [ n, b ],
              [ n, d ],
              [ n, f ],
              [ n, h ] ]

    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

def 
octahedron(position=[0,0,0],size=1,axisradius=1,rgb1=[1,1,1],rgb2=[1,1,1],mtx=[[1,0,0],[0,1,0],[0,0,1]]):
    obj = []
    for i in lines:
        i[0] = mvmult(mtx,i[0])
        i[1] = mvmult(mtx,i[1])
        i[0] = svmult(size,i[0])
        i[1] = svmult(size,i[1])
        obj.extend([SAUSAGE,
                    i[0][0] + position[0], i[0][1] + position[1], i[0][2] + 
position[2],
                    i[1][0] + position[0], i[1][1] + position[1], i[1][2] + 
position[2],
                    axisradius, rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], 
rgb2[2]])
    return obj

shapefunctions = {"sphere": sphere,
                  "plus": plus,
                  "star": star,
                  "cube": cube,
                  "tetrahedron": tetrahedron,
                  "rdodec": rdodec,
                  "octahedron": octahedron}

def graph(sel="(all)", shape="plus", size=1, r=0.10, rgb1=[1,0,0], 
rgb2=[0,0,1], mtx=[[1,0,0],[0,1,0],[0,0,1]], name="graph"):
    sel = cmd.get_model(sel)

    ln = len(sel.atom)

    obj = []
    for i in range(ln):
        (x, y, z) = sel.atom[i].coord
        
obj.extend(shapefunctions[shape](sel.atom[i].coord,size,r,rgb1,rgb2,mtx))

    cmd.load_cgo(obj, name)

cmd.extend('graph',graph)

Reply via email to