I wrote this small script that can be used to rotate molecules in PyRx. You can try it by downloading rotate.py and then use File → Run Python Script menu from PyRx to run it. To stop this rotation, click on Python Shell tab under Controls panel, type stop()
and hit Enter. The following is the complete code for rotate.py and it’s intended for (Python) developers who want to learn how it’s done.
def rotate(event): frame.mayaviEngine.scene.camera.azimuth(1); #change 1 to any other degree as needed. frame.mayaviEngine.scene.render() def stop(): frame.timer.Stop() del frame.timer import wx frame.Bind(wx.EVT_TIMER, rotate) frame.timer = wx.Timer(frame) frame.timer.Start(50) #you change the rate here
The rotate
function here calls frame.mayaviEngine.scene.camera.azimuth(1)
which is what we need to do the rotation (.render
is there to update the scene, otherwise we won’t see the changes). I read Advanced Scripting with Mayavi where I found an example code for foscene.camera.azimuth
. To call this function from PyRx, we need to get a handle of frame.mayaviEngine
object. frame
is an instance of MainFrame
class definded in wxMainFrame.py and initialized in runPyRx.py. This is where we store references to various PyRx parts including mayaviEngine
instance. The rest of the code is used to call rotate
function and it’s wxPython specific. I copied the last three lines from PyRx/autodockPage.py where we use wx.Timer
to run AutoDock jobs and to check their status. Please let me know if you have any questions.