Here's a slightly improved version. It only kicks in if dpi is specified. I
think that you could make the obvious modifications to the help message and
argument list and use it as a replacement for cmd.ray (as long as you're
aware of the fact that the argument list will be different).

#!/usr/bin/env pymol

from pymol import cmd

def rayy(width=-1,height=-1,dpi=-1,units='in',**kwargs):
    """
    Slightly better version of the ray command.
    You can specify width and height in the units of your choice, e.g.

    rayy 3,2,units=in,dpi=300
    rayy 3in,2in
    rayy 1in, 2 cm, dpi=600

    Extra keyword arguments get passed on to the normal ray command.

    Units can be 'in' or 'cm'.

    For backwards compatibility, the conversion to dpi (or dots per
    centimeter) is only performed when dpi is specified.
    """
    if type(dpi) in [type('')]: dpi = int(dpi)
    in_per_cm = 0.393700787
    def todots(x,units,dpi):
        if type(x) in [type('')]:
            x = x.lower()
            if 'in' in x:
                units = 'in'
            elif 'cm' in x:
                units = 'cm'
            x = float(x.replace(units,'').strip())
        if (dpi == -1):
            return x
        if units ==   'cm':   x = x * in_per_cm
        elif units == 'in': pass
        else:         raise ValueError('Unknown units (%s)'%units)
        print '%s%s at %sdpi'%(x,units,dpi)
        return int(x * dpi)
    # How do we get current width/height of viewport? MainSceneGetSize
perhaps
    # But it doesn't matter, as PyMOL will autoscale internally for us when
given -1.
    try:
        width,height = todots(width,units,dpi),todots(height,units,dpi)
    except ValueError:
        print "Unknown units"
        return
    print 'width',width,'height',height
    cmd.ray(width=width,height=height,**kwargs)
cmd.extend('rayy',rayy)


On Thu, Jan 21, 2010 at 2:39 PM, Michael Lerner <
mglerner+sourcefo...@gmail.com <mglerner%2bsourcefo...@gmail.com>> wrote:

> I think this works. It handles different units (in and cm). If you leave
> out width or height, it gets scaled correctly. If you  leave them both out,
> you get whatever the current viewport size is (is there something better?).
>
> #!/usr/bin/env pymol
>
> from pymol import cmd
>
> def rayy(width=-1,height=-1,dpi=300,units='in',**kwargs):
>     """
>     Slightly better version of the ray command.
>     You can specify width and height in the units of your choice, e.g.
>
>     rayy 3,2,units=in,dpi=300
>     rayy 3in,2in
>     rayy 1in, 2 cm, dpi=600
>
>     Extra keyword arguments get passed on to the normal ray command.
>     """
>     if type(dpi) in [type('')]: dpi = int(dpi)
>     in_per_cm = 0.393700787
>     def todots(x,units,dpi):
>         if type(x) in [type('')]:
>             x = x.lower()
>             if 'in' in x:   units = 'in'
>             elif 'cm' in x: units = 'cm'
>             x = float(x.replace(units,'').strip())
>         if units ==   'cm':   x = x * in_per_cm
>         elif units == 'in': pass
>         else:         raise ValueError('Unknown units (%s)'%units)
>         print x,units,dpi
>         return int(x * dpi)
>     # How do we get current width/height of viewport? MainSceneGetSize
> perhaps
>     # But it doesn't matter, as PyMOL will autoscale internally for us.
>     try:
>         height,width = todots(height,units,dpi),todots(width,units,dpi)
>     except ValueError:
>         print "Unknown units"
>         return
>     print 'width',width,'height',height
>     cmd.ray(width=width,height=height,**kwargs)
>     #cmd.png(self.filename.getvalue(), dpi=int(self.dpi.getvalue()))
> cmd.extend('rayy',rayy)
>
> On Thu, Jan 21, 2010 at 11:52 AM, Michael Lerner <
> mglerner+sourcefo...@gmail.com <mglerner%2bsourcefo...@gmail.com>> wrote:
>
>> The ray command bugs me, so I'll take a stab at improving it this
>> afternoon.
>>
>> Can someone tell me how to get the size of the current viewport?
>>
>> This solution:
>>
>> http://www.mail-archive.com/pymol-users@lists.sourceforge.net/msg05888.html
>>
>> width,height = cmd.get_session()['main'][0:2]
>>
>>
>> doesn't seem to work for me:
>>
>> PyMOL>print sorted(cmd.get_session().keys())
>> ['cache', 'color_ext', 'colors', 'editor', 'movie', 'names', 'scene_dict',
>> 'scene_order', 'selector_secrets', 'session', 'settings', 'unique_settings',
>> 'version', 'view', 'view_dict', 'wizard']
>>
>> -Michael
>>
>> On Wed, Jan 20, 2010 at 3:54 PM, Tsjerk Wassenaar <tsje...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> > ray 10cm, 20cm, dpi=300?
>>> > ray 2.5in, 5in, dpi=300?
>>>
>>> I'd slightly modify that to read:
>>>
>>> ray 10,10,units=cm,resolution=300
>>>
>>> where units can be pixels (default), cm, inches, meters, yards,
>>> lightyears...
>>>
>>> Cheers,
>>>
>>> Tsjerk
>>>
>>>
>>> --
>>> Tsjerk A. Wassenaar, Ph.D.
>>>
>>> Computational Chemist
>>> Medicinal Chemist
>>> Neuropharmacologist
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Throughout its 18-year history, RSA Conference consistently attracts the
>>> world's best and brightest in the field, creating opportunities for
>>> Conference
>>> attendees to learn about information security's most important issues
>>> through
>>> interactions with peers, luminaries and emerging and established
>>> companies.
>>> http://p.sf.net/sfu/rsaconf-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
>>>
>>
>>
>>
>> --
>> Michael Lerner, Ph.D.
>> IRTA Postdoctoral Fellow
>> Laboratory of Computational Biology NIH/NHLBI
>> 5635 Fishers Lane, Room T909, MSC 9314
>> Rockville, MD 20852 (UPS/FedEx/Reality)
>> Bethesda MD 20892-9314 (USPS)
>>
>
>
>
> --
> Michael Lerner, Ph.D.
> IRTA Postdoctoral Fellow
> Laboratory of Computational Biology NIH/NHLBI
> 5635 Fishers Lane, Room T909, MSC 9314
> Rockville, MD 20852 (UPS/FedEx/Reality)
> Bethesda MD 20892-9314 (USPS)
>



-- 
Michael Lerner, Ph.D.
IRTA Postdoctoral Fellow
Laboratory of Computational Biology NIH/NHLBI
5635 Fishers Lane, Room T909, MSC 9314
Rockville, MD 20852 (UPS/FedEx/Reality)
Bethesda MD 20892-9314 (USPS)
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-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