Project

General

Profile

Creating a new Leginon node » History » Version 8

Anchi Cheng, 09/15/2014 07:22 PM

1 1 Jim Pulokas
h1. Creating a new Leginon node
2
3
The basic steps that will be described in detail below are:
4
5 6 Anchi Cheng
* Code the core functionality in a new subclass
6
* Define required attribute for all node classes:
7
** Node Settings and its defaults
8
** GUI Panel
9
** Input/Output Events
10
* Define new data type or event this node produces
11
* Make the gui
12 1 Jim Pulokas
* register it with the list of available nodes
13
14 5 Jim Pulokas
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.
15 1 Jim Pulokas
16 6 Anchi Cheng
h2. Example
17 1 Jim Pulokas
18 6 Anchi Cheng
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.
19 5 Jim Pulokas
20 6 Anchi Cheng
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).
21
22
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.
23
24 1 Jim Pulokas
h2. Code the core functionality
25
26 6 Anchi Cheng
* 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
27 1 Jim Pulokas
28 6 Anchi Cheng
In our example, see leginon/buffercycler.py source:trunk/leginon/buffercycler.py
29
30
The new class inherits conditioner.Conditioner.  It defines the string for condition type in setCTypes, and how to call buffer cycling.
31
32 8 Anchi Cheng
h2.  Define the required attributes for all nodes
33 6 Anchi Cheng
34
h3. Settings
35
36
* 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.
37
* To make the class uses the new settings class, it is defined in the module.
38
39
In our example
40
# look at the difference in leginon/leginondata.py for r18567, a new subclass of ConditionerSettingsData is defined as BufferCyclerSettingsData without adding anything new.
41
# we define the settings class used in buffercycler.py
42
<pre>
43
settingsclass = leginondata.BufferCyclerSettingsData
44
</pre>
45
# The defaults of the buffer cycler settings are also inherited from conditioner.Conditioner
46 7 Anchi Cheng
<pre>
47 6 Anchi Cheng
defaultsettings = conditioner.Conditioner.defaultsettings
48 7 Anchi Cheng
</pre>
49 6 Anchi Cheng
50
h3. GUI panel class
51
52
<pre>
53
panelclass = leginon.gui.wx.BufferCycler.Panel
54
</pre>
55
makes the class load the gui panel
56
57
h3. Input/Output Events
58
59
We inherit the eventinputs of the parent class in the example.
60
<pre>
61
eventinputs = conditioner.Conditioner.eventinputs
62
</pre>
63
64
h2. Define new data type or event this node produces
65
66
New output data type should be defined in leginondata.py, and new event, if any, defined in event.py
67
68
Neither is needed in the example.
69
70 1 Jim Pulokas
h2. Create the user interface
71 5 Jim Pulokas
72 6 Anchi Cheng
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.
73 1 Jim Pulokas
74 6 Anchi Cheng
# Make a new file under leginon/gui/wx for the gui definition.  In the example: gui/wx/BufferCycler.py
75
# Define Panel Class
76
# OnSettingsTool method, SettingsDialog class, and ScrolledSettings are redefined in this module so that the local one is used.
77
78 5 Jim Pulokas
h2. Register the node
79
80 6 Anchi Cheng
Register the node by adding it to leginon/allnodes.py as shown in the modification made in r18567
81
82 2 Jim Pulokas
83 4 Jim Pulokas
back to [[Leginon Developer Guide]]