Project

General

Profile

Creating a new Leginon node » History » Revision 6

Revision 5 (Jim Pulokas, 08/28/2013 01:43 PM) → Revision 6/29 (Anchi Cheng, 09/15/2014 07:20 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 classes of data type and events that will be created or event this node produces communicated to other nodes 
 * Make Code the gui core functionality 
 * Give it a user interface 
 * 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 Define new data classes 

 We have a base class in Leginon that creates a If your new 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 be generating and new kind of data that you wish to find whether the condition fixing has been done recently.    If it has past the timeout defined store 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 database or pass to return before starting to process other nodes, you should define 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. leginondata.py.    Let Sometimes it inherit is easiest to create a class subclass of Leginon nodes.    The lowest base some existing data class you can use is node.Node 

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

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

 h2. it.    Define the required attribute for all nodes 

 h3. Settings 

 * The data class that is usually added when a Also add any 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 
 # look at the difference in leginon/leginondata.py for r18567, a new subclass of ConditionerSettingsData is defined as BufferCyclerSettingsData without adding anything new. 
 # 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 
 defaultsettings = conditioner.Conditioner.defaultsettings events to event.py. 

 h3. GUI panel class 

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

 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]]