Project

General

Profile

Creating a new Leginon node » History » Revision 9

Revision 8 (Anchi Cheng, 09/15/2014 07:22 PM) → Revision 9/29 (Anchi Cheng, 09/15/2014 07:23 PM)

h1. Creating a new Leginon node 

 The basic steps that will be described in detail below are: 

 * Code the core functionality in a new subclass 
 * Define required attribute for all node classes: 
 ** Node Settings and its defaults 
 ** GUI Panel 
 ** Input/Output Events 
 * Define new data type or event this node produces 
 * Make the gui 
 * register it with the list of available nodes 

 For each task, it is easiest to look at an existing node as an example.    Usually we just make a copy of a node the is similar in function and go from there. 

 h2. Example 

 We have a base class in Leginon that creates a node to fix a particular instrument condition.    The module is leginon/condition.py.    When a FixConditionEvent is sent to it, it will check the database to find whether the condition fixing has been done recently.    If it has past the timeout defined in its settings (Defined by ConditionerSettingsData in leginondata.py), then it will execute the action defined in its fixCondition function, and reset the timer. 

 The FixConditionEvent is sent normally from the final exposure Acquisition Node (named "Exposure", "Tomography" etc. depending on the node class and application".    While the condition is being fixed, the node will wait for it to return before starting to process the targets it received (meaning moving to the acquisition position, focusing, etc). 

 To make a new subclass that triggers the vacuum pump that pumps the buffer area of the scope, we will make a subclass of Conditioner here, called BufferCycler.    There is no settings change, but we want its settings saved separately from the parent. 

 h2. Code the core functionality 

 * Make a new class in your new module.    Let it inherit a class of Leginon nodes.    The lowest base class you can use is node.Node 

 In our example, see leginon/buffercycler.py source:trunk/leginon/buffercycler.py 

 The new class inherits conditioner.Conditioner.    It defines the string for condition type in setCTypes, and how to call buffer cycling. 

 h2.    Define the required attributes for all nodes 

 

 h3. Settings 

 * The data class that is usually added when a new node is added is the one defines its settings in Leginon gui.    Its name should have the class name as prefix. 
 * To make the class uses the new settings class, it is defined in the module. 

 In our example: 

 example 
 # Look look at the difference in leginon/leginondata.py for r18567, a new subclass of ConditionerSettingsData is defined as BufferCyclerSettingsData without adding anything new. 
 # We we define the settings class used in buffercycler.py 
 <pre> 
 settingsclass = leginondata.BufferCyclerSettingsData 
 </pre> 
 # The defaults of the buffer cycler settings are also inherited from conditioner.Conditioner 
 <pre> 
 defaultsettings = conditioner.Conditioner.defaultsettings 
 </pre> 

 

 h3. GUI panel class 

 <pre> 
 panelclass = leginon.gui.wx.BufferCycler.Panel 
 </pre> 
 makes the class load the gui panel 

 h3. Input/Output Events 

 We inherit the eventinputs of the parent class in the example. 
 <pre> 
 eventinputs = conditioner.Conditioner.eventinputs 
 </pre> 

 h2. Define new data type or event this node produces 

 New output data type should be defined in leginondata.py, and new event, if any, defined in event.py 

 Neither is needed in the example. 

 h2. Create the user interface 

 See source:trunk/leginon/gui/wx/BufferCycler.py for an inherited example that does not need any new definition.    This is the minimal definition of Leginon gui. 

 # Make a new file under leginon/gui/wx for the gui definition.    In the example: gui/wx/BufferCycler.py 
 # Define Panel Class 
 # OnSettingsTool method, SettingsDialog class, and ScrolledSettings are redefined in this module so that the local one is used. 

 h2. Register the node 

 Register the node by adding it to leginon/allnodes.py as shown in the modification made in r18567 


 back to [[Leginon Developer Guide]]