Hi Troels, Jason, Edward,

nice little problem and nice layouts by Jason and Edward. Let me contribute some code, it follows Edwards approach.

See attachment. Requires psico.

Cheers,
  Thomas

Edward A. Berry wrote, On 10/08/12 20:57:
Jason Vertrees wrote:
Hi Troels,

I've run into this problem a few times, too, but never took the time
to solve it correctly.

A quick plan might look like:
   * cmd.orient on the selection
   * store the view vector (http://www.pymolwiki.org/index.php/Get_View)
   * let C1 = count the number of atoms behind the view vector, using
something like (http://www.pymolwiki.org/index.php/SelInside)
   * invert the view vector
   * let C2 = count the number of atoms behind the view vector, using
something like (http://www.pymolwiki.org/index.php/SelInside)
   * compare C1 to C2, choosing the
   * if C2<  C1 then flip the view

You could use other tricks. I'm sure the community has other ideas.

Calculate center of mass or average of all coordinates
calculate vector from that to point of interest
rotate view so that vector points toward front/camera
translate so point of interest is centerd

maybe reverse the last two steps?

Cheers,

-- Jason


On Sun, Oct 7, 2012 at 10:04 AM, Troels Emtekær Linnet
<tlin...@gmail.com>  wrote:
Hi pymolers.

I am generating a list of residue ID's from some calculations.
Now I want to make a little script that select the residue and sticks it
and then zoom and make .png file.

How do I make sure that the zoom, is viewed from "outside" the protein for
each residue/.png file?

Best

Troels Emtekær Linnet
Ved kløvermarken 9, 1.th
2300 København S
Mobil: +45 60210234

--
Thomas Holder
MPI for Developmental Biology
Spemannstr. 35
D-72076 Tübingen
from pymol import cmd, CmdException

def zoomoutside(selection, ref='', state=-1, operator='byobject',
        quiet=1, **kwargs):
    '''
DESCRIPTION

    Zoom the given selection and orient such that the object center of
    mass is behind the selection center of mass.

USAGE

    zoomoutside selection [, ref [, state ]]

ARGUMENTS

    selection = string: atom selection to zoom on

    ref = string: reference selection to orient behind selection
    {default: byobject <selection>}

SEE ALSO

    zoom, orient
    '''
    from chempy import cpv
    from psico.querying import centerofmass

    state, quiet = int(state), int(quiet)

    if not ref:
        ref = '%s (%s)' % (operator, selection)

    com_sele = centerofmass(selection, state)
    com_ref = centerofmass(ref, state)

    view = list(cmd.get_view())
    camera_rotation = [view[0:3], view[3:6], view[6:9]]

    vec = cpv.sub(com_sele, com_ref)
    vec_camera = cpv.transform(camera_rotation, vec)

    axis = cpv.cross_product(vec_camera, [0.,0.,1.])
    angle = cpv.get_angle(vec_camera, [0.,0.,1.])

    rotation = cpv.rotation_matrix(angle, axis)
    view[:9] = [x
            for row in cpv.multiply(rotation, camera_rotation)
            for x in row]

    cmd.set_view(view)
    cmd.zoom(selection, state=state, **kwargs)

cmd.extend('zoomoutside', zoomoutside)
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
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