|
|
Line 2: |
Line 2: |
| Here is a small plugin to render images with a given DPI. | | Here is a small plugin to render images with a given DPI. |
|
| |
|
| The "Ray" button raytraces, and the "Draw" button just draws the image without raytracing (a fast way to see that the height/width look good). | | The "Draw" button just draws the image without raytracing (a fast way to see that the height/width look good).<br> |
| | | The "Ray" button raytraces first, before saving. |
| It warns you not to have the plugin window on top of your main PyMOL window when you click "Ray". That doesn't seem to be necessary anymore, at least on my MacBook Pro.
| |
|
| |
|
| The functionality is also available as a script (see my .pymolrc [[User:Mglerner|here]]). | | The functionality is also available as a script (see my .pymolrc [[User:Mglerner|here]]). |
|
| |
|
| Here's the imperial version. The metric version follows.
| | First the imperial version. The metric version follows. |
| | |
| To install, save the script as e.g. rendering.py or rendering_metric.py and install via PyMOL's Plugin --> Manage Plugins --> Install menu.
| |
| | |
| <source lang="python">
| |
| #!/usr/bin/env python
| |
| # Plugin contributed by Michael Lerner (mglerner@gmail.com)
| |
| | |
| import Tkinter
| |
| import Pmw
| |
| | |
| try:
| |
| import pymol
| |
| REAL_PYMOL = True
| |
| except ImportError:
| |
| REAL_PYMOL = False
| |
| class pymol:
| |
| class cmd:
| |
| def ray(*args):
| |
| print "ray",args
| |
| def png(*args,**kwargs):
| |
| print "png",args,kwargs
| |
| def draw(*args,**kwargs):
| |
| print "draw",args,kwargs
| |
| ray = staticmethod(ray)
| |
| png = staticmethod(png)
| |
| draw = staticmethod(draw)
| |
| | |
| def __init__(self):
| |
| self.menuBar.addmenuitem('Plugin', 'command',
| |
| 'Launch Rendering Plugin',
| |
| label='Rendering...',
| |
| command = lambda s=self: RenderPlugin(s))
| |
| class RenderPlugin:
| |
| | |
| def __init__(self,app):
| |
| self.parent = app.root
| |
| self.dialog = Pmw.Dialog(self.parent,
| |
| buttons = ('Ray','Draw','Exit'),
| |
| title = 'PyMOL Rendering Plugin',
| |
| command = self.execute)
| |
| self.dialog.withdraw()
| |
| Pmw.setbusycursorattributes(self.dialog.component('hull'))
| |
| | |
| w = Tkinter.Label(self.dialog.interior(),
| |
| text = 'PyMOL Rendering Plugin\nMichael Lerner, 2006 - www.umich.edu/~mlerner/PyMOL\nNOTE: make sure this window is not on top of the PyMOL window.',
| |
| background = 'black',
| |
| foreground = 'white',
| |
| )
| |
| w.pack(expand = 1, fill = 'both', padx = 4, pady = 4)
| |
| | |
| self.notebook = Pmw.NoteBook(self.dialog.interior())
| |
| self.notebook.pack(fill='both',expand=1,padx=10,pady=10)
| |
| | |
| # Set up the Main page
| |
| page = self.notebook.add('Main')
| |
| group = Pmw.Group(page,tag_text='Main options')
| |
| group.pack(fill = 'both', expand = 1, padx = 10, pady = 5)
| |
| self.filename = Pmw.EntryField(group.interior(),
| |
| labelpos='w',
| |
| label_text='Filename',
| |
| value='picture.png',
| |
| )
| |
| self.height = Pmw.EntryField(group.interior(),labelpos='w',
| |
| label_text = 'Height (inches):',
| |
| value = str(4.0),
| |
| validate = {'validator' : 'real',
| |
| 'min':0,}
| |
| )
| |
|
| |
|
| |
| self.width = Pmw.EntryField(group.interior(),labelpos='w',
| |
| label_text = 'Width (inches):',
| |
| value = str(4.0),
| |
| validate = {'validator' : 'real',
| |
| 'min':0,}
| |
| )
| |
| self.dpi = Pmw.EntryField(group.interior(),labelpos='w',
| |
| label_text = 'DPI:',
| |
| value = str(300),
| |
| validate = {'validator' : 'integer',
| |
| 'min':0,}
| |
| )
| |
| entries = (self.height,self.width,self.filename,self.dpi)
| |
| for entry in entries:
| |
| #entry.pack(side='left',fill='both',expand=1,padx=4) # side-by-side
| |
| entry.pack(fill='x',expand=1,padx=4,pady=1) # vertical
| |
| self.notebook.setnaturalsize()
| |
| self.showAppModal()
| |
|
| |
| def showAppModal(self):
| |
| #self.dialog.activate(geometry = 'centerscreenalways', globalMode = 'nograb')
| |
| self.dialog.show()
| |
| #self.dialog.activate(geometry = 'centerscreenalways')
| |
|
| |
| def execute(self, result):
| |
| if result == 'Ray':
| |
| h = int(float(self.height.getvalue()) * int(self.dpi.getvalue()))
| |
| w = int(float(self.width.getvalue()) * int(self.dpi.getvalue()))
| |
| pymol.cmd.ray(w,h)
| |
| pymol.cmd.png(self.filename.getvalue(), dpi=int(self.dpi.getvalue()))
| |
| elif result == 'Draw':
| |
| h = int(float(self.height.getvalue()) * int(self.dpi.getvalue()))
| |
| w = int(float(self.width.getvalue()) * int(self.dpi.getvalue()))
| |
| pymol.cmd.draw(w,h)
| |
| pymol.cmd.png(self.filename.getvalue(), dpi=int(self.dpi.getvalue()))
| |
| else:
| |
| #
| |
| # Doing it this way takes care of clicking on the x in the top of the
| |
| # window, which as result set to None.
| |
| #
| |
| if __name__ == '__main__':
| |
| #
| |
| # dies with traceback, but who cares
| |
| #
| |
| self.parent.destroy()
| |
| else:
| |
| self.dialog.withdraw()
| |
|
| |
|
| |
| # Create demo in root window for testing.
| |
| if __name__ == '__main__':
| |
| class App:
| |
| def my_show(self,*args,**kwargs):
| |
| pass
| |
| app = App()
| |
| app.root = Tkinter.Tk()
| |
| Pmw.initialise(app.root)
| |
| app.root.title('Some Title')
| |
|
| |
| widget = RenderPlugin(app)
| |
| exitButton = Tkinter.Button(app.root, text = 'Exit', command = app.root.destroy)
| |
| exitButton.pack()
| |
| app.root.mainloop()
| |
| </source>
| |
| | |
| | |
| And here's the metric version
| |
| | |
| <source lang="python">
| |
| #!/usr/bin/env python
| |
| # Plugin contributed by Michael Lerner (mglerner@gmail.com)
| |
| | |
| import Tkinter
| |
| import Pmw
| |
|
| |
|
| try:
| | To install, save the script as e.g. rendering_plugin.py or rendering_plugin_metric.py and install via PyMOL's Plugin --> Manage Plugins --> Install menu. |
| import pymol
| |
| REAL_PYMOL = True
| |
| except ImportError:
| |
| REAL_PYMOL = False
| |
| class pymol:
| |
| class cmd:
| |
| def ray(*args):
| |
| print "ray",args
| |
| def png(*args,**kwargs):
| |
| print "png",args,kwargs
| |
| def draw(*args,**kwargs):
| |
| print "draw",args,kwargs
| |
| ray = staticmethod(ray)
| |
| png = staticmethod(png)
| |
| draw = staticmethod(draw)
| |
|
| |
|
| def __init__(self):
| | The plugins are made ready the project, [http://www.pymolwiki.org/index.php/Git_intro Pymol-script-repo]. |
| self.menuBar.addmenuitem('Plugin', 'command',
| |
| 'Launch Metric Rendering Plugin',
| |
| label='Metric Rendering...',
| |
| command = lambda s=self: RenderPlugin(s))
| |
| class RenderPlugin:
| |
|
| |
|
| def __init__(self,app):
| | == Python Code - Imperial version == |
| self.parent = app.root
| | This code has been put under version control. In the project, [http://www.pymolwiki.org/index.php/Git_intro Pymol-script-repo]. |
| self.dialog = Pmw.Dialog(self.parent,
| |
| buttons = ('Ray','Draw','Exit'),
| |
| title = 'PyMOL Rendering Plugin',
| |
| command = self.execute)
| |
| self.dialog.withdraw()
| |
| Pmw.setbusycursorattributes(self.dialog.component('hull'))
| |
|
| |
|
| w = Tkinter.Label(self.dialog.interior(),
| | For a color coded view: |
| text = 'PyMOL Rendering Plugin\nMichael Lerner, 2006 - www.umich.edu/~mlerner/PyMOL\nNOTE: make sure this window is not on top of the PyMOL window.',
| | https://github.com/Pymol-Scripts/Pymol-script-repo/blob/master/plugins/rendering_plugin.py |
| background = 'black',
| | See the raw code or download manually, by right clicking the following link here -> Save as: rendering_plugin.py |
| foreground = 'white',
| | https://raw.github.com/Pymol-Scripts/Pymol-script-repo/master/plugins/rendering_plugin.py |
| )
| |
| w.pack(expand = 1, fill = 'both', padx = 4, pady = 4)
| |
|
| |
|
| self.notebook = Pmw.NoteBook(self.dialog.interior())
| | == Python Code - metric version == |
| self.notebook.pack(fill='both',expand=1,padx=10,pady=10)
| | This code has been put under version control. In the project, [http://www.pymolwiki.org/index.php/Git_intro Pymol-script-repo]. |
|
| |
|
| # Set up the Main page
| | For a color coded view: |
| page = self.notebook.add('Main')
| | https://github.com/Pymol-Scripts/Pymol-script-repo/blob/master/plugins/rendering_plugin_metric.py |
| group = Pmw.Group(page,tag_text='Main options')
| | See the raw code or download manually, by right clicking the following link here -> Save as: rendering_plugin_metric.py |
| group.pack(fill = 'both', expand = 1, padx = 10, pady = 5)
| | https://raw.github.com/Pymol-Scripts/Pymol-script-repo/master/plugins/rendering_plugin_metric.py |
| self.filename = Pmw.EntryField(group.interior(),
| |
| labelpos='w',
| |
| label_text='Filename',
| |
| value='picture.png',
| |
| )
| |
| self.height = Pmw.EntryField(group.interior(),labelpos='w',
| |
| label_text = 'Height (cm):',
| |
| value = str(4.0),
| |
| validate = {'validator' : 'real',
| |
| 'min':0,}
| |
| )
| |
|
| |
|
| |
| self.width = Pmw.EntryField(group.interior(),labelpos='w',
| |
| label_text = 'Width (cm):',
| |
| value = str(4.0),
| |
| validate = {'validator' : 'real',
| |
| 'min':0,}
| |
| )
| |
| self.dpi = Pmw.EntryField(group.interior(),labelpos='w',
| |
| label_text = 'DPI:',
| |
| value = str(300),
| |
| validate = {'validator' : 'integer',
| |
| 'min':0,}
| |
| )
| |
| entries = (self.height,self.width,self.filename,self.dpi)
| |
| for entry in entries:
| |
| #entry.pack(side='left',fill='both',expand=1,padx=4) # side-by-side
| |
| entry.pack(fill='x',expand=1,padx=4,pady=1) # vertical
| |
| self.notebook.setnaturalsize()
| |
| self.showAppModal()
| |
|
| |
| def showAppModal(self):
| |
| #self.dialog.activate(geometry = 'centerscreenalways', globalMode = 'nograb')
| |
| self.dialog.show()
| |
| #self.dialog.activate(geometry = 'centerscreenalways')
| |
|
| |
| def execute(self, result):
| |
| in_per_cm = 0.393700787
| |
| if result == 'Ray':
| |
| h = int(float(self.height.getvalue()) * int(self.dpi.getvalue()))
| |
| w = int(float(self.width.getvalue()) * int(self.dpi.getvalue()))
| |
| h,w = in_per_cm*h,in_per_cm*w
| |
| pymol.cmd.ray(w,h)
| |
| pymol.cmd.png(self.filename.getvalue(), dpi=int(self.dpi.getvalue()))
| |
| elif result == 'Draw':
| |
| h = int(float(self.height.getvalue()) * int(self.dpi.getvalue()))
| |
| w = int(float(self.width.getvalue()) * int(self.dpi.getvalue()))
| |
| h,w = in_per_cm*h,in_per_cm*w
| |
| pymol.cmd.draw(w,h)
| |
| pymol.cmd.png(self.filename.getvalue(), dpi=int(self.dpi.getvalue()))
| |
| else:
| |
| #
| |
| # Doing it this way takes care of clicking on the x in the top of the
| |
| # window, which as result set to None.
| |
| #
| |
| if __name__ == '__main__':
| |
| #
| |
| # dies with traceback, but who cares
| |
| #
| |
| self.parent.destroy()
| |
| else:
| |
| self.dialog.withdraw()
| |
|
| |
|
| |
| # Create demo in root window for testing.
| |
| if __name__ == '__main__':
| |
| class App:
| |
| def my_show(self,*args,**kwargs):
| |
| pass
| |
| app = App()
| |
| app.root = Tkinter.Tk()
| |
| Pmw.initialise(app.root)
| |
| app.root.title('Some Title')
| |
|
| |
| widget = RenderPlugin(app)
| |
| exitButton = Tkinter.Button(app.root, text = 'Exit', command = app.root.destroy)
| |
| exitButton.pack()
| |
| app.root.mainloop()
| |
| </source>
| |
|
| |
|
| [[Category:Plugins]] [[Category:Coloring]] | | [[Category:Plugins]] [[Category:Coloring]] |