So, I did some coding last night and I came up with a fairly good 
looking, albeit a little slow, workaround for drawing wire mesh spheres.
The code is below, the main function is make_mesh. It is a little rough, 
in that they get_neighbors function is quite naive, but it comes out 
looking ok and is ray traceable.

Please let me know if you have any questions,

Matt

 >>>

import math
import numpy as np
import random


def generate_sphere_points(n):
     """
     Returns list of 3d coordinates of points on a sphere using the
     Golden Section Spiral algorithm.

     Arguments:
     n -- number of points to generate

     Returns:
     points -- np array of the points (n x 3)
     """
     points = []
     inc = math.pi * (3 - math.sqrt(5))
     offset = 2 / float(n)
     for k in range(int(n)):
         y = k * offset - 1 + (offset / 2)
         r = math.sqrt(1 - y*y)
         phi = k * inc
         points.append([math.cos(phi)*r, y, math.sin(phi)*r])
     return np.array(points) #MB

def get_neighbors(points, point, num_neighbors):
     '''
     Naive method for finding the nearest neighbors of a
     point on a sphere of points

     Arguments:
     points -- list of points (numpy arrays)
     point -- point of interest
     num_neighbors -- number of neighbors to return

     Returns:
     neighbors -- list of neighboring points
     '''

     distances = [ [pt, np.linalg.norm(point - pt)] for pt in points]

     distances = sorted(distances, key = lambda foo: foo[1])

     #don't return the point itself - i.e. the first one in the list
     neighbors = np.array(distances)[1:(num_neighbors + 1), 0]

     return neighbors



def make_mesh(x,y,z, rad, color = [0,0,0], n = 100, num_neighbors = 6, 
rand_rot = True):
     '''
     Draw a wire mesh sphere of radius rad centered at x,y,z

     Arguments:
     x,y,z -- coordinates of center of sphere
     rad -- radius of the sphere
     n -- number of sphere points -> density of the mesh
     neighbors -- number of nearest neighbors to draw lines with
     rand_rot -- boolean for whether to rotate the spheres a little.
                 This allows for viewing of overlapping pharmacophores

     Returns:
     mesh -- list of cgo floats
     '''
     #get the points centered at the origen
     points = generate_sphere_points(n)

     #expand based on the radius
     points = points * rad

     if rand_rot:
         #generate a random amount to rotate (0 to 2*pi) around the z axis
         rot = random.random() * 2*math.pi

         #set up the transformation matrix
         trans = np.array([[math.cos(rot), -math.sin(rot), 0, 0], \
                           [math.sin(rot), math.cos(rot), 0, 0], \
                           [0, 0, 1, 0], \
                           [0, 0, 0, 1] ])

         #append a 1 to each coordinate vector for doing the transformation
         tmppoints = [ np.array([ pt[0], pt[1], pt[2], 1]) for pt in 
points ]


         #apply the rotation
         tmppoints = np.array([ trans.dot(pt) for pt in tmppoints ])

         #Strip off the 1 that was added
         points = tmppoints[:,:3]

     #center them at the specified location
     points = points + np.array([x,y,z])

     #start building the cgo list
     mesh = [LINES]
     mesh.extend([COLOR, color[0], color[1], color[2]])

     for point in points:
         neighbors = get_neighbors(points, point, num_neighbors)
         for nbr in neighbors:
             mesh.extend([VERTEX, point[0], point[1], point[2]])
             mesh.extend([VERTEX, nbr[0], nbr[1], nbr[2]])

     return mesh








On 10/25/2012 09:54 AM, Jason Vertrees wrote:
> Hi Matt,
>
>> So some brief background, I am writing a pymol plugin for displaying
>> pharmacophores queries from ZincPharmer ( http://zincpharmer.csb.pitt.edu/),
>> which is developed in my lab. Version 1 of my plugin is available here:
>> http://sourceforge.net/projects/pharmer/files/ under the name load_query.
>>
>> Sorry if that quickly turned into an advertisement, but what I would like to
>
> On the contrary, we welcome the promotion of PyMOL extensions! They
> help the community find resources we may not have known about and it
> helps the developer drive usage of his or her tools -- a win-win.  In
> fact, the best way to promote a new script/plugin is to:
>    (1) Create a PyMOLWiki webpage with example code, images, and links
> back to your own project page (if you have one)
>    (2) Email the list an enticing advertisement for your new functionality
>
> Some people have even used PyMOLWiki page view counts in their grant
> applications to show usage.
>
>
>> be able to reproduce in pymol is something like this:
>> http://i.imgur.com/hiX2i.png . Where the wire mesh sphere's represent the
>> pharamacophores. Currently, I am using the cgo sphere's but they do not do
>> well when there are overlapping pharmacophores (a common case).
> We are planning on adding improved graphical and text annotations to
> PyMOL. So, while we cannot currently do what you want we hope to be
> able to in the near future.
>
> Last, I hesitate to suggest this because it's so unsightly, but if you
> need something in the meantime that resembles a mesh sphere (but is
> not exact) you can create your CGO spheres and then do,
>
>      set cgo_debug, 1
>
> No, it won't ray trace like that either -- they'll be converted to full 
> spheres.
>
> Cheers,
>
> -- Jason
>
>
>
>> Hi Matt,
>>
>> There's currently no easy way to do this. Can you please send us some
>> screenshots of what you'd like to see implemented?
>>
>> Cheers,
>>
>> -- Jason
>>
>> On Tue, Oct 23, 2012 at 4:16 PM, Matthew Baumgartner <mp...@pitt.edu> wrote:
>>
>> Hi,
>> Is it now possible to have wire mesh cgo object spheres in pymol?
>> I found this thread from a while ago (2004) but googleing, I didn't
>> find anything more recent.
>>
>>
>> The one sort of work around that I though of was to create pseudo-atoms
>> and somehow modify their radius and then show them as mesh.
>> But I would like to use CGO objects if possible.
>>
>> Does anyone have any suggestions?
>>
>> Thanks,
>> Matt Baumgartner
>>
>>
>>
>> Sphere transparency example included below...
>>
>> ALPHA must preceed COLOR to be effective.
>>
>> PyMOL does not yet do a global sort of tranparent triangles, so there will
>> be artifacts in OpenGL.  Raytracing should look fine however.
>>
>> # from within a .py OR .pym file...
>>
>> from pymol.cgo import *
>> from pymol import cmd
>>
>> obj = [
>>
>>     ALPHA,  1.0,
>>     COLOR,  1.0, 1.0, 1.0,
>>     SPHERE, 0.0, 0.0, 0.0, 0.5,
>>
>>     ALPHA,  0.66,
>>     COLOR,  1.0, 0.0, 0.0,
>>     SPHERE, 1.0, 0.0, 0.0, 0.5,
>>
>>     ALPHA,  0.33,
>>     COLOR,  0.0, 1.0, 0.0,
>>     SPHERE, 0.0, 1.0, 0.0, 0.5,
>>
>>     ALPHA,  0.11,
>>     COLOR,  0.0, 0.0, 1.0,
>>     SPHERE, 0.0, 0.0, 1.0, 0.5,
>> ]
>>
>> cmd.load_cgo(obj,'cgo01')
>>
>> Cheers,war...@delanoscientific.com
>> Warren
>>
>> --
>> Warren L. DeLano, Ph.D.
>> Principal Scientist
>>
>> . DeLano Scientific LLC
>> . 400 Oyster Point Blvd., Suite 213
>> . South San Francisco, CA 94080
>> . Biz:(650)-872-0942  Tech:(650)-872-0834
>> . Fax:(650)-872-0273  Cell:(650)-346-1154
>> . mailto:war...@delsci.com
>>
>>
>> -----Original Message-----
>> From: pymol-users-ad...@lists.sourceforge.net
>> [mailto:pymol-users-ad...@lists.sourceforge.net] On Behalf Of
>> Michael George Lerner
>> Sent: Wednesday, November 17, 2004 9:43 AM
>> To: pymol-users@lists.sourceforge.net
>> Subject: [PyMOL] wire-mesh spheres?
>>
>>
>> Hi,
>>
>> I want to draw a bunch of spheres of various sizes and
>> colors.  I'm currently using cgos for this.  No problem.
>> Now, I also want to draw wire-mesh spheres.  Does anyone have
>> a script for making these?  While I'm at it, is there a way
>> to make cgos transparent?
>>
>> Thanks,
>>
>> -Michael
>>
>> --
>> This isn't a democracy;|                        _  |Michael Lerner
>>    it's a cheer-ocracy.  | ASCII ribbon campaign ( ) |   Michigan
>> -Torrence,  Bring It On|  - against HTML email  X  |  Biophysics
>>                          |                       / \ | mler...@umich
>>
>>
>> -------------------------------------------------------
>> This SF.Net email is sponsored by: InterSystems CACHE FREE
>> OODBMS DOWNLOAD - A multidimensional database that combines
>> robust object and relational technologies, making it a
>> perfect match for Java, C++,COM, XML, ODBC and JDBC.
>> www.intersystems.com/match8
>> _______________________________________________
>> PyMOL-users mailing list
>> PyMOL-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/pymol-users
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Everyone hates slow websites. So do we.
>> Make your web apps faster with AppDynamics
>> Download AppDynamics Lite for free today:
>> http://p.sf.net/sfu/appdyn_sfd2d_oct
>> _______________________________________________
>> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
>> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
>> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>>
>>
>>
>
>


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to