"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/components/relax_data.py" (2 Dec 2019, 19451 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "relax_data.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1.3_vs_5.0.0.

    1 ###############################################################################
    2 #                                                                             #
    3 # Copyright (C) 2009-2010 Michael Bieri                                       #
    4 # Copyright (C) 2009-2014,2019 Edward d'Auvergne                              #
    5 #                                                                             #
    6 # This file is part of the program relax (http://www.nmr-relax.com).          #
    7 #                                                                             #
    8 # This program is free software: you can redistribute it and/or modify        #
    9 # it under the terms of the GNU General Public License as published by        #
   10 # the Free Software Foundation, either version 3 of the License, or           #
   11 # (at your option) any later version.                                         #
   12 #                                                                             #
   13 # This program is distributed in the hope that it will be useful,             #
   14 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   16 # GNU General Public License for more details.                                #
   17 #                                                                             #
   18 # You should have received a copy of the GNU General Public License           #
   19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   20 #                                                                             #
   21 ###############################################################################
   22 
   23 # Module docstring.
   24 """Module containing the classes for GUI components involving relaxation data."""
   25 
   26 # Python module imports.
   27 import wx
   28 import wx.lib.buttons
   29 
   30 # relax module imports.
   31 import dep_check
   32 from graphics import fetch_icon
   33 from gui.components.base_list import Base_list
   34 from gui.components.relax_data_meta import Relax_data_meta_list
   35 from gui.icons import Relax_icons
   36 from gui.misc import add_border
   37 from gui.string_conv import float_to_gui, gui_to_str, str_to_gui
   38 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
   39 from gui.wizards.wiz_objects import Wiz_window
   40 from lib.text.gui import r1, r2
   41 from status import Status; status = Status()
   42 from user_functions.data import Uf_info; uf_info = Uf_info()
   43 
   44 
   45 # Some IDs for the menu entries.
   46 MENU_RELAX_DATA_DELETE = wx.NewId()
   47 MENU_RELAX_DATA_DISPLAY = wx.NewId()
   48 MENU_SPECTROMETER_FREQUENCY = wx.NewId()
   49 MENU_RELAX_DATA_PEAK_INTENSITY_TYPE = wx.NewId()
   50 MENU_RELAX_DATA_TEMP_CALIBRATION = wx.NewId()
   51 MENU_RELAX_DATA_TEMP_CONTROL = wx.NewId()
   52 MENU_RELAX_DATA_TYPE = wx.NewId()
   53 
   54 
   55 
   56 class Relax_data_list(Base_list):
   57     """The GUI element for listing loaded relaxation data."""
   58 
   59     def action_relax_data_delete(self, event):
   60         """Launch the relax_data.delete user function.
   61 
   62         @param event:   The wx event.
   63         @type event:    wx event
   64         """
   65 
   66         # The current selection.
   67         item = self.element.GetFirstSelected()
   68 
   69         # No selection.
   70         if item == -1:
   71             id = None
   72 
   73         # Selected item.
   74         else:
   75             # The spectrum ID.
   76             id = gui_to_str(self.element.GetItemText(item))
   77 
   78         # Launch the dialog.
   79         uf_store['relax_data.delete'](ri_id=id)
   80 
   81 
   82     def action_relax_data_display(self, event):
   83         """Launch the relax_data.display user function.
   84 
   85         @param event:   The wx event.
   86         @type event:    wx event
   87         """
   88 
   89         # The current selection.
   90         item = self.element.GetFirstSelected()
   91 
   92         # The spectrum ID.
   93         id = gui_to_str(self.element.GetItemText(item))
   94 
   95         # Launch the dialog.
   96         uf_store['relax_data.display'](ri_id=id)
   97 
   98 
   99     def action_relax_data_peak_intensity_type(self, event):
  100         """Launch the relax_data.peak_intensity_type user function.
  101 
  102         @param event:   The wx event.
  103         @type event:    wx event
  104         """
  105 
  106         # The current selection.
  107         item = self.element.GetFirstSelected()
  108 
  109         # The spectrum ID.
  110         id = gui_to_str(self.element.GetItemText(item))
  111 
  112         # The current type.
  113         type = None
  114         if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'peak_intensity_type') and id in cdp.exp_info.peak_intensity_type:
  115             type = cdp.exp_info.peak_intensity_type[id]
  116 
  117         # Launch the dialog.
  118         if type == None:
  119             uf_store['relax_data.peak_intensity_type'](ri_id=id)
  120         else:
  121             uf_store['relax_data.peak_intensity_type'](ri_id=id, type=type)
  122 
  123 
  124     def action_relax_data_temp_calibration(self, event):
  125         """Launch the relax_data.temp_calibration user function.
  126 
  127         @param event:   The wx event.
  128         @type event:    wx event
  129         """
  130 
  131         # The current selection.
  132         item = self.element.GetFirstSelected()
  133 
  134         # The spectrum ID.
  135         id = gui_to_str(self.element.GetItemText(item))
  136 
  137         # The current method.
  138         method = None
  139         if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_calibration') and id in cdp.exp_info.temp_calibration:
  140             method = cdp.exp_info.temp_calibration[id]
  141 
  142         # Launch the dialog.
  143         if method == None:
  144             uf_store['relax_data.temp_calibration'](ri_id=id)
  145         else:
  146             uf_store['relax_data.temp_calibration'](ri_id=id, method=method)
  147 
  148 
  149     def action_relax_data_temp_control(self, event):
  150         """Launch the relax_data.temp_control user function.
  151 
  152         @param event:   The wx event.
  153         @type event:    wx event
  154         """
  155 
  156         # The current selection.
  157         item = self.element.GetFirstSelected()
  158 
  159         # The spectrum ID.
  160         id = gui_to_str(self.element.GetItemText(item))
  161 
  162         # The current method.
  163         method = None
  164         if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_control') and id in cdp.exp_info.temp_control:
  165             method = cdp.exp_info.temp_control[id]
  166 
  167         # Launch the dialog.
  168         if method == None:
  169             uf_store['relax_data.temp_control'](ri_id=id)
  170         else:
  171             uf_store['relax_data.temp_control'](ri_id=id, method=method)
  172 
  173 
  174     def action_relax_data_type(self, event):
  175         """Launch the relax_data.type user function.
  176 
  177         @param event:   The wx event.
  178         @type event:    wx event
  179         """
  180 
  181         # The current selection.
  182         item = self.element.GetFirstSelected()
  183 
  184         # The spectrum ID.
  185         id = gui_to_str(self.element.GetItemText(item))
  186 
  187         # The current type.
  188         type = None
  189         if hasattr(cdp, 'ri_type') and id in cdp.ri_type:
  190             type = cdp.ri_type[id]
  191 
  192         # Launch the dialog.
  193         if type == None:
  194             uf_store['relax_data.type'](ri_id=id)
  195         else:
  196             uf_store['relax_data.type'](ri_id=id, ri_type=type)
  197 
  198 
  199     def action_spectrometer_frequency(self, event):
  200         """Launch the spectrometer.frequency user function.
  201 
  202         @param event:   The wx event.
  203         @type event:    wx event
  204         """
  205 
  206         # The current selection.
  207         item = self.element.GetFirstSelected()
  208 
  209         # The spectrum ID.
  210         id = gui_to_str(self.element.GetItemText(item))
  211 
  212         # The current frequency.
  213         frq = None
  214         if hasattr(cdp, 'spectrometer_frq') and id in cdp.spectrometer_frq:
  215             frq = cdp.spectrometer_frq[id]
  216 
  217         # Launch the dialog.
  218         if frq == None:
  219             uf_store['spectrometer.frequency'](id=id)
  220         else:
  221             uf_store['spectrometer.frequency'](id=id, frq=frq)
  222 
  223 
  224     def setup(self):
  225         """Override the base variables."""
  226 
  227         # GUI variables.
  228         self.title = "Relaxation data list"
  229         self.observer_base_name = "relaxation data list"
  230 
  231         # The column titles.
  232         self.columns = [
  233             "Relaxation data ID",
  234             "Data type",
  235             "Frequency (Hz)"
  236         ]
  237 
  238         # Button set up.
  239         self.button_placement = 'top'
  240         self.button_size = (170, 40)
  241         self.button_info = [
  242             {
  243                 'object': 'button_add',
  244                 'label': ' Add',
  245                 'icon': fetch_icon('oxygen.actions.list-add-relax-blue', "22x22"),
  246                 'method': self.wizard_relax_data,
  247                 'tooltip': "Read relaxation data from a file."
  248             }, {
  249                 'object': 'button_bruker',
  250                 'label': ' Add',
  251                 'icon': fetch_icon('relax.bruker_add', "22x22"),
  252                 'method': self.wizard_bruker,
  253                 'tooltip': "Read a Bruker Dynamics Center relaxation data file."
  254             }, {
  255                 'object': 'button_delete',
  256                 'label': ' Delete',
  257                 'icon': fetch_icon('oxygen.actions.list-remove', "22x22"),
  258                 'method': self.action_relax_data_delete,
  259                 'tooltip': "Delete loaded relaxation data from the relax data store."
  260             }, {
  261                 'object': 'button_metadata',
  262                 'label': ' View metadata',
  263                 'icon': fetch_icon('oxygen.mimetypes.text-x-texinfo', "22x22"),
  264                 'method': self.view_metadata,
  265                 'tooltip': "View and edit the relaxation data metadata."
  266             }
  267         ]
  268 
  269         # The right click popup menu.
  270         self.popup_menus = [
  271             {
  272                 'id': MENU_RELAX_DATA_DELETE,
  273                 'text': "&Delete the relaxation data",
  274                 'icon': fetch_icon(uf_info.get_uf('relax_data.delete').gui_icon),
  275                 'method': self.action_relax_data_delete
  276             }, {
  277                 'id': MENU_RELAX_DATA_DISPLAY,
  278                 'text': "Dis&play the relaxation data",
  279                 'icon': fetch_icon(uf_info.get_uf('relax_data.display').gui_icon),
  280                 'method': self.action_relax_data_display
  281             }, {
  282                 'id': MENU_SPECTROMETER_FREQUENCY,
  283                 'text': "Set the relaxation data &frequency",
  284                 'icon': fetch_icon(uf_info.get_uf('spectrometer.frequency').gui_icon),
  285                 'method': self.action_spectrometer_frequency
  286             }, {
  287                 'id': MENU_RELAX_DATA_PEAK_INTENSITY_TYPE,
  288                 'text': "Set the peak &intensity type",
  289                 'icon': fetch_icon(uf_info.get_uf('relax_data.peak_intensity_type').gui_icon),
  290                 'method': self.action_relax_data_peak_intensity_type
  291             }, {
  292                 'id': MENU_RELAX_DATA_TEMP_CALIBRATION,
  293                 'text': "Set the temperature &calibration",
  294                 'icon': fetch_icon(uf_info.get_uf('relax_data.temp_calibration').gui_icon),
  295                 'method': self.action_relax_data_temp_calibration
  296             }, {
  297                 'id': MENU_RELAX_DATA_TEMP_CONTROL,
  298                 'text': "Set the temperature c&ontrol",
  299                 'icon': fetch_icon(uf_info.get_uf('relax_data.temp_control').gui_icon),
  300                 'method': self.action_relax_data_temp_control
  301             }, {
  302                 'id': MENU_RELAX_DATA_TYPE,
  303                 'text': "Set the relaxation data &type",
  304                 'icon': fetch_icon(uf_info.get_uf('relax_data.type').gui_icon),
  305                 'method': self.action_relax_data_type
  306             }
  307         ]
  308 
  309 
  310     def update_data(self):
  311         """Method called from self.build_element_safe() to update the list data."""
  312 
  313         # Translation table for the Rx data types.
  314         table = {
  315             "NOE": "Steady-state NOE",
  316             "R1": "%s longitudinal relaxation" % r1,
  317             "R2": "%s transverse relaxation" % r2
  318         }
  319 
  320         # Expand the number of rows to match the number of relaxation IDs, and add the IDs.
  321         n = 0
  322         if hasattr(cdp, 'ri_ids'):
  323             # The number of IDs.
  324             n = len(cdp.ri_ids)
  325 
  326             # Add all the data.
  327             for i in range(n):
  328                 # Set the IDs.
  329                 id = cdp.ri_ids[i]
  330                 if dep_check.wx_classic:
  331                     self.element.InsertStringItem(i, str_to_gui(id))
  332                 else:
  333                     self.element.InsertItem(i, str_to_gui(id))
  334 
  335                 # Set the data types.
  336                 if dep_check.wx_classic:
  337                     self.element.SetStringItem(i, 1, str_to_gui(table[cdp.ri_type[id]]))
  338                 else:
  339                     self.element.SetItem(i, 1, str_to_gui(table[cdp.ri_type[id]]))
  340 
  341                 # Set the frequencies.
  342                 if dep_check.wx_classic:
  343                     self.element.SetStringItem(i, 2, float_to_gui(cdp.spectrometer_frq[id]))
  344                 else:
  345                     self.element.SetItem(i, 2, float_to_gui(cdp.spectrometer_frq[id]))
  346 
  347 
  348     def view_metadata(self, event=None):
  349         """Launch the metadata window.
  350 
  351         @keyword event: The wx event.
  352         @type event:    wx event
  353         """
  354 
  355         # Launch.
  356         Metadata_window(self.gui)
  357 
  358 
  359     def wizard_bruker(self, event):
  360         """Launch the Bruker Dynamics Centre data reading wizard.
  361 
  362         @param event:   The wx event.
  363         @type event:    wx event
  364         """
  365 
  366         # The wizard.
  367         self.wizard_exec(bruker=True)
  368 
  369 
  370     def wizard_exec(self, bruker=False):
  371         """Launch the Rx peak loading wizard.
  372 
  373         @keyword bruker:    A flag which if True will launch the Bruker Dynamics Centre data reading wizard and if False will launch the relaxation data reading wizard
  374         @type bruker:       bool
  375         """
  376 
  377         # Change the cursor to busy.
  378         wx.BeginBusyCursor()
  379 
  380         # The title.
  381         if bruker:
  382             title = "The Bruker Dynamics Centre data reading wizard"
  383         else:
  384             title = "The relaxation data reading wizard"
  385 
  386         # Destroy any pre-existing wizards.
  387         if hasattr(self, 'wizard'):
  388             self.wizard.Destroy()
  389 
  390         # Initialise a wizard.
  391         self.wizard = Wiz_window(parent=self.gui, size_x=1000, size_y=750, title=title)
  392         self.page_indices = {}
  393 
  394         # The reading page.
  395         if bruker:
  396             page = uf_store['bruker.read'].create_page(self.wizard, sync=True)
  397         else:
  398             page = uf_store['relax_data.read'].create_page(self.wizard, sync=True)
  399         self.page_indices['read'] = self.wizard.add_page(page, skip_button=True, proceed_on_error=False)
  400 
  401         # The peak intensity type page.
  402         page = uf_store['relax_data.peak_intensity_type'].create_page(self.wizard, sync=True)
  403         self.page_indices['peak_intensity_type'] = self.wizard.add_page(page, apply_button=True, skip_button=True)
  404         page.on_display_post = self.wizard_update_int_type
  405 
  406         # The temperature calibration page.
  407         page = uf_store['relax_data.temp_calibration'].create_page(self.wizard, sync=True)
  408         self.page_indices['temp_calibration'] = self.wizard.add_page(page, apply_button=True, skip_button=True)
  409         page.on_display_post = self.wizard_update_temp_calibration
  410 
  411         # The temperature control page.
  412         page = uf_store['relax_data.temp_control'].create_page(self.wizard, sync=True)
  413         self.page_indices['temp_control'] = self.wizard.add_page(page, apply_button=True)
  414         page.on_display_post = self.wizard_update_temp_control
  415 
  416         # Reset the cursor.
  417         if wx.IsBusy():
  418             wx.EndBusyCursor()
  419 
  420         # Run the wizard.
  421         self.wizard.run()
  422 
  423 
  424     def wizard_relax_data(self, event):
  425         """Launch the relaxation data reading wizard.
  426 
  427         @param event:   The wx event.
  428         @type event:    wx event
  429         """
  430 
  431         # The wizard.
  432         self.wizard_exec(bruker=False)
  433 
  434 
  435     def wizard_update_int_type(self):
  436         """Update the relax_data.peak_intensity_type page based on previous data."""
  437 
  438         # The relax_data.peak_intensity_type page.
  439         page = self.wizard.get_page(self.page_indices['read'])
  440 
  441         # Get the Rx ID.
  442         id = page.uf_args['ri_id'].GetValue()
  443 
  444         # Set the ID in the relax_data.peak_intensity_type page.
  445         page = self.wizard.get_page(self.page_indices['peak_intensity_type'])
  446         page.uf_args['ri_id'].SetValue(value=id)
  447 
  448 
  449     def wizard_update_temp_calibration(self):
  450         """Update the relax_data.temp_calibration page based on previous data."""
  451 
  452         # The relax_data.temp_calibration page.
  453         page = self.wizard.get_page(self.page_indices['read'])
  454 
  455         # Get the Rx ID.
  456         id = page.uf_args['ri_id'].GetValue()
  457 
  458         # Set the ID in the relax_data.temp_calibration page.
  459         page = self.wizard.get_page(self.page_indices['temp_calibration'])
  460         page.uf_args['ri_id'].SetValue(value=id)
  461 
  462 
  463     def wizard_update_temp_control(self):
  464         """Update the relax_data.temp_control page based on previous data."""
  465 
  466         # The relax_data.temp_control page.
  467         page = self.wizard.get_page(self.page_indices['read'])
  468 
  469         # Get the Rx ID.
  470         id = page.uf_args['ri_id'].GetValue()
  471 
  472         # Set the ID in the relax_data.temp_control page.
  473         page = self.wizard.get_page(self.page_indices['temp_control'])
  474         page.uf_args['ri_id'].SetValue(value=id)
  475 
  476 
  477 
  478 class Metadata_window(wx.Frame):
  479     """The relaxation data metadata window."""
  480 
  481     def __init__(self, parent):
  482         """Set up the export window.
  483 
  484         @param parent:  The parent object.
  485         @type parent:   wx.Frame instance
  486         """
  487 
  488         # The window style.
  489         style = wx.DEFAULT_FRAME_STYLE
  490 
  491         # Initialise the base class, setting the main GUI window as the parent.
  492         super(Metadata_window, self).__init__(parent, -1, style=style)
  493 
  494         # Some default values.
  495         self.size_x = 1200
  496         self.size_y = 500
  497         self.border = 5
  498         self.spacer = 10
  499 
  500         # Set up the frame.
  501         sizer = self.setup_frame()
  502 
  503         # Add the relaxation data metadata list GUI element, with spacing.
  504         sizer.AddSpacer(15)
  505         self.relax_data = Relax_data_meta_list(parent=self.main_panel, box=sizer, id='BMRB export', proportion=1)
  506 
  507         # Open the window.
  508         if status.show_gui:
  509             self.Show()
  510 
  511 
  512     def handler_close(self, event):
  513         """Event handler for the close window action.
  514 
  515         @param event:   The wx event.
  516         @type event:    wx event
  517         """
  518 
  519         # Unregister the observers.
  520         self.relax_data.observer_register(remove=True)
  521 
  522         # Close the window.
  523         event.Skip()
  524 
  525 
  526     def setup_frame(self):
  527         """Set up the relax controller frame.
  528         @return:    The sizer object.
  529         @rtype:     wx.Sizer instance
  530         """
  531 
  532         # Set the frame title.
  533         self.SetTitle("Relaxation data metadata")
  534 
  535         # Set up the window icon.
  536         self.SetIcons(Relax_icons())
  537 
  538         # Place all elements within a panel (to remove the dark grey in MS Windows).
  539         self.main_panel = wx.Panel(self, -1)
  540 
  541         # Use a grid sizer for packing the main elements.
  542         main_sizer = wx.BoxSizer(wx.VERTICAL)
  543         self.main_panel.SetSizer(main_sizer)
  544 
  545         # Build the central sizer, with borders.
  546         sizer = add_border(main_sizer, border=self.border, packing=wx.VERTICAL)
  547 
  548         # Close the window cleanly (unregistering observers).
  549         self.Bind(wx.EVT_CLOSE, self.handler_close)
  550 
  551         # Set the default size of the controller.
  552         self.SetSize((self.size_x, self.size_y))
  553 
  554         # Centre the frame.
  555         self.Centre()
  556 
  557         # Return the central sizer.
  558         return sizer