예제 #1
0
    def associate_auto(self, event):
        """Associate the selected data pipe with a new auto-analysis.

        @param event:   The wx event.
        @type event:    wx event
        """

        # Initialise the GUI data store object if needed.
        if not hasattr(ds, 'relax_gui'):
            self.gui.init_data()

        # The type and data pipe bundle.
        type = get_type(self.selected_pipe)
        bundle = get_bundle(self.selected_pipe)

        # Error checking.
        if self.selected_pipe == None:
            raise RelaxError("No data pipe has been selected - this is not possible.")
        if bundle == None:
            raise RelaxError("The selected data pipe is not associated with a data pipe bundle.")

        # The name.
        names = {
            'noe': 'Steady-state NOE',
            'r1': 'R1 relaxation',
            'r2': 'R2 relaxation',
            'mf': 'Model-free',
            'relax_disp': 'Relaxation dispersion'
        }

        # Create a new analysis with the selected data pipe.
        self.gui.analysis.new_analysis(analysis_type=type, analysis_name=names[type], pipe_name=self.selected_pipe, pipe_bundle=bundle)
예제 #2
0
    def associate_auto(self, event):
        """Associate the selected data pipe with a new auto-analysis.

        @param event:   The wx event.
        @type event:    wx event
        """

        # Initialise the GUI data store object if needed.
        if not hasattr(ds, 'relax_gui'):
            self.gui.init_data()

        # The type and data pipe bundle.
        type = get_type(self.selected_pipe)
        bundle = get_bundle(self.selected_pipe)

        # Error checking.
        if self.selected_pipe == None:
            raise RelaxError("No data pipe has been selected - this is not possible.")
        if bundle == None:
            raise RelaxError("The selected data pipe is not associated with a data pipe bundle.")

        # The name.
        names = {
            'noe': 'Steady-state NOE',
            'r1': 'R1 relaxation',
            'r2': 'R2 relaxation',
            'mf': 'Model-free',
            'relax_disp': 'Relaxation dispersion'
        }

        # Create a new analysis with the selected data pipe.
        self.gui.analysis.new_analysis(analysis_type=type, analysis_name=names[type], pipe_name=self.selected_pipe, pipe_bundle=bundle)
예제 #3
0
    def pipe_switch(self, pipe=None):
        """Switch the page to the given or current data pipe.

        @keyword pipe:  The pipe associated with the page to switch to.  If not supplied, the current data pipe will be used.
        @type pipe:     str or None
        """

        # The data pipe.
        if pipe == None:
            pipe = pipes.cdp_name()

        # No pipes to switch to.
        if pipe == None:
            return

        # Find the page.
        index = self.page_index_from_bundle(pipes.get_bundle(pipe))

        # No matching page.
        if index == None:
            return

        # The page is already active, so do nothing.
        if self._current == index:
            return

        # Switch to the page.
        self.switch_page(index)

        # Notify the observers of the change.
        status.observers.gui_analysis.notify()
예제 #4
0
파일: __init__.py 프로젝트: tlinnet/relax
    def pipe_switch(self, pipe=None):
        """Switch the page to the given or current data pipe.

        @keyword pipe:  The pipe associated with the page to switch to.  If not supplied, the current data pipe will be used.
        @type pipe:     str or None
        """

        # The data pipe.
        if pipe == None:
            pipe = pipes.cdp_name()

        # No pipes to switch to.
        if pipe == None:
            return

        # Find the page.
        index = self.page_index_from_bundle(pipes.get_bundle(pipe))

        # No matching page.
        if index == None:
            return

        # The page is already active, so do nothing.
        if self._current == index:
            return

        # Switch to the page.
        self.switch_page(index)

        # Notify the observers of the change.
        status.observers.gui_analysis.notify()
예제 #5
0
    def update_grid_safe(self):
        """Update the grid with the pipe data."""

        # First freeze the grid, so that the GUI element doesn't update until the end.
        self.grid.Freeze()

        # Acquire the pipe lock.
        status.pipe_lock.acquire('pipe editor window')

        # Delete the rows, leaving a single row.
        self.grid.DeleteRows(numRows=self.grid.GetNumberRows()-1)

        # Clear the contents of the first row.
        for i in range(self.grid.GetNumberCols()):
            self.grid.SetCellValue(0, i, str_to_gui(""))

        # The data pipes.
        pipe_list = pipe_names()
        n = len(pipe_list)

        # Append the appropriate number of rows.
        if n >= 1:
            self.grid.AppendRows(numRows=n-1)

        # Loop over the data pipes.
        for i in range(n):
            # Set the pipe name.
            self.grid.SetCellValue(i, 0, str_to_gui(pipe_list[i]))

            # Set the pipe type.
            self.grid.SetCellValue(i, 1, str_to_gui(get_type(pipe_list[i])))

            # Set the pipe bundle.
            self.grid.SetCellValue(i, 2, str_to_gui(get_bundle(pipe_list[i])))

            # Set the current pipe.
            if pipe_list[i] == cdp_name():
                self.grid.SetCellValue(i, 3, str_to_gui("cdp"))

            # Set the tab the pipe belongs to.
            self.grid.SetCellValue(i, 4, str_to_gui(self.gui.analysis.page_name_from_bundle(get_bundle(pipe_list[i]))))

        # Set the grid properties once finalised.
        for i in range(self.grid.GetNumberRows()):
            # Row properties.
            self.grid.SetRowSize(i, 27)

            # Loop over the columns.
            for j in range(self.grid.GetNumberCols()):
                # Cell properties.
                self.grid.SetReadOnly(i, j)

        # Release the lock.
        status.pipe_lock.release('pipe editor window')

        # Unfreeze.
        self.grid.Thaw()
예제 #6
0
    def update_grid_safe(self):
        """Update the grid with the pipe data."""

        # First freeze the grid, so that the GUI element doesn't update until the end.
        self.grid.Freeze()

        # Acquire the pipe lock.
        status.pipe_lock.acquire('pipe editor window')

        # Delete the rows, leaving a single row.
        self.grid.DeleteRows(numRows=self.grid.GetNumberRows()-1)

        # Clear the contents of the first row.
        for i in range(self.grid.GetNumberCols()):
            self.grid.SetCellValue(0, i, str_to_gui(""))

        # The data pipes.
        pipe_list = pipe_names()
        n = len(pipe_list)

        # Append the appropriate number of rows.
        if n >= 1:
            self.grid.AppendRows(numRows=n-1)

        # Loop over the data pipes.
        for i in range(n):
            # Set the pipe name.
            self.grid.SetCellValue(i, 0, str_to_gui(pipe_list[i]))

            # Set the pipe type.
            self.grid.SetCellValue(i, 1, str_to_gui(get_type(pipe_list[i])))

            # Set the pipe bundle.
            self.grid.SetCellValue(i, 2, str_to_gui(get_bundle(pipe_list[i])))

            # Set the current pipe.
            if pipe_list[i] == cdp_name():
                self.grid.SetCellValue(i, 3, str_to_gui("cdp"))

            # Set the tab the pipe belongs to.
            self.grid.SetCellValue(i, 4, str_to_gui(self.gui.analysis.page_name_from_bundle(get_bundle(pipe_list[i]))))

        # Set the grid properties once finalised.
        for i in range(self.grid.GetNumberRows()):
            # Row properties.
            self.grid.SetRowSize(i, 27)

            # Loop over the columns.
            for j in range(self.grid.GetNumberCols()):
                # Cell properties.
                self.grid.SetReadOnly(i, j)

        # Release the lock.
        status.pipe_lock.release('pipe editor window')

        # Unfreeze.
        self.grid.Thaw()
예제 #7
0
    def menu(self, event):
        """The pop up menu.

        @param event:   The wx event.
        @type event:    wx event
        """

        # Get the row.
        row = event.GetRow()

        # Get the name of the data pipe.
        self.selected_pipe = gui_to_str(self.grid.GetCellValue(row, 0))

        # No data pipe.
        if not self.selected_pipe:
            return

        # The pipe type and bundle.
        pipe_type = get_type(self.selected_pipe)
        pipe_bundle = get_bundle(self.selected_pipe)

        # Initialise the menu.
        menu = wx.Menu()
        items = []

        # Menu entry:  add the data pipe to a bundle.
        if not pipe_bundle:
            items.append(build_menu_item(menu, parent=self, text="&Add the pipe to a bundle", icon=fetch_icon("relax.pipe_bundle"), fn=self.pipe_bundle))

        # Menu entry:  delete the data pipe.
        items.append(build_menu_item(menu, parent=self, text="&Delete the pipe", icon=fetch_icon('oxygen.actions.list-remove', "16x16"), fn=self.pipe_delete))
 
        # Menu entry:  switch to this data pipe.
        items.append(build_menu_item(menu, parent=self, text="&Switch to this pipe", icon=fetch_icon('oxygen.actions.system-switch-user', "16x16"), fn=self.pipe_switch))
 
        # Menu entry:  new auto-analysis tab.
        if pipe_bundle and self.gui.analysis.page_index_from_bundle(pipe_bundle) == None and pipe_type in ['noe', 'r1', 'r2', 'mf', 'relax_disp']:
            items.append(build_menu_item(menu, parent=self, text="&Associate with a new auto-analysis", icon=fetch_icon('oxygen.actions.document-new', "16x16"), fn=self.associate_auto))
 
        # Set up the entries.
        for item in items:
            menu.AppendItem(item)
            if status.exec_lock.locked():
                item.Enable(False)

        # Show the menu.
        if status.show_gui:
            self.PopupMenu(menu)

        # Kill the menu once done.
        menu.Destroy()
예제 #8
0
    def test_pipe_bundle(self):
        """Test the pipe bundle concepts."""

        # Execute the script.
        self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'pipe_bundle.py')

        # Checks.
        self.assertEqual(pipes.cdp_name(), None)
        self.assertEqual(pipes.has_bundle('test bundle 1'), True)
        self.assertEqual(pipes.has_bundle('test bundle 2'), True)
        self.assertEqual(pipes.has_bundle('test bundle 3'), False)
        bundles = sorted(pipes.bundle_names())
        self.assertEqual(bundles, ['test bundle 1', 'test bundle 2'])
        for pipe, name in pipes.pipe_loop(name=True):
            self.assert_(name in ['test pipe 1', 'test pipe 2', 'test pipe 3', 'test pipe 4', 'test pipe 5', 'test pipe 6'])
            self.assert_(pipes.get_bundle(name) in ['test bundle 1', 'test bundle 2'])
예제 #9
0
파일: pipes.py 프로젝트: tlinnet/relax
    def test_pipe_bundle(self):
        """Test the pipe bundle concepts."""

        # Execute the script.
        self.script_exec(status.install_path + sep + 'test_suite' + sep +
                         'system_tests' + sep + 'scripts' + sep +
                         'pipe_bundle.py')

        # Checks.
        self.assertEqual(pipes.cdp_name(), None)
        self.assertEqual(pipes.has_bundle('test bundle 1'), True)
        self.assertEqual(pipes.has_bundle('test bundle 2'), True)
        self.assertEqual(pipes.has_bundle('test bundle 3'), False)
        bundles = sorted(pipes.bundle_names())
        self.assertEqual(bundles, ['test bundle 1', 'test bundle 2'])
        for pipe, name in pipes.pipe_loop(name=True):
            self.assert_(name in [
                'test pipe 1', 'test pipe 2', 'test pipe 3', 'test pipe 4',
                'test pipe 5', 'test pipe 6'
            ])
            self.assert_(
                pipes.get_bundle(name) in ['test bundle 1', 'test bundle 2'])
# relax module imports.
from pipe_control import pipes
import lib.io
from specific_analyses.api import return_api

# Read the state with the setup
var = 'result_06_check_intermediate'
results_dir = os.getcwd() + os.sep + var + os.sep + 'final'
# Load the state with setup data.
state.load(state='results.bz2', dir=results_dir, force=True)

# Show pipes
pipe.display()
pipe_name = pipes.cdp_name()
pipe_bundle = pipes.get_bundle(pipe_name)

# Define write out
write_out = results_dir + os.sep + 'grace'

# chi2 per iteration? But does not work?
grace.write(x_data_type='iter',
            y_data_type='chi2',
            file='iter_chi2.agr',
            dir=write_out,
            force=True)

#############

# This does not do what we want. So let us try manually.
var_ori = 'result_06'
예제 #11
0
    def menu(self, event):
        """The pop up menu.

        @param event:   The wx event.
        @type event:    wx event
        """

        # Get the row.
        row = event.GetRow()

        # Get the name of the data pipe.
        self.selected_pipe = gui_to_str(self.grid.GetCellValue(row, 0))

        # No data pipe.
        if not self.selected_pipe:
            return

        # The pipe type and bundle.
        pipe_type = get_type(self.selected_pipe)
        pipe_bundle = get_bundle(self.selected_pipe)

        # Initialise the menu.
        popup_menus = []

        # Menu entry:  add the data pipe to a bundle.
        if not pipe_bundle:
            popup_menus.append({
                'id': MENU_BUNDLE,
                'text': "&Add the pipe to a bundle",
                'icon': fetch_icon("relax.pipe_bundle"),
                'method': self.pipe_bundle
            })

        # Menu entry:  delete the data pipe.
        popup_menus.append({
            'id': MENU_DELETE,
            'text': "&Delete the pipe",
            'icon': fetch_icon('oxygen.actions.list-remove', "16x16"),
            'method': self.pipe_delete
        })

        # Menu entry:  switch to this data pipe.
        popup_menus.append({
            'id': MENU_SWITCH,
            'text': "&Switch to this pipe",
            'icon': fetch_icon('oxygen.actions.system-switch-user', "16x16"),
            'method': self.pipe_switch
        })

        # Menu entry:  new auto-analysis tab.
        if pipe_bundle and self.gui.analysis.page_index_from_bundle(pipe_bundle) == None and pipe_type in ['noe', 'r1', 'r2', 'mf', 'relax_disp']:
            popup_menus.append({
                'id': MENU_NEW_AUTO_ANALYSIS,
                'text': "&Associate with a new auto-analysis",
                'icon': fetch_icon('oxygen.actions.document-new', "16x16"),
                'method': self.associate_auto
            })

        # Execution lock, so do nothing.
        if status.exec_lock.locked():
            return

        # Initialise the menu.
        menu = wx.Menu()

        # Loop over the menu items.
        for i in range(len(popup_menus)):
            # Alias.
            info = popup_menus[i]

            # Add the menu item.
            menu.AppendItem(build_menu_item(menu, id=info['id'], text=info['text'], icon=info['icon']))

            # Bind clicks.
            self.Bind(wx.EVT_MENU, info['method'], id=info['id'])

        # Pop up the menu.
        if status.show_gui:
            self.PopupMenu(menu)

        # Cleanup.
        menu.Destroy()
예제 #12
0
    def test_tp02_data_to_tp02(self):
        """Test the GUI analysis with the relaxation dispersion 'TP02' model fitting to the 'TP02' synthetic data."""

        # The paths to the data files.
        data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'dispersion' + sep + 'r1rho_off_res_tp02' + sep

        # Simulate the new analysis wizard, selecting the fixed time CPMG experiment.
        analysis = self.new_analysis_wizard(analysis_type='disp')

        # Change the results directory.
        analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir))

        # Create the sequence data.
        self._execute_uf(uf_name='spin.create',
                         res_name='Trp',
                         res_num=1,
                         spin_name='N')
        interpreter.flush()
        self._execute_uf(uf_name='spin.create',
                         res_name='Trp',
                         res_num=2,
                         spin_name='N')
        interpreter.flush()
        self._execute_uf(uf_name='sequence.display')
        interpreter.flush()

        # Set up the nuclear isotopes.
        analysis.spin_isotope()
        uf_store['spin.isotope'].page.SetValue('spin_id', '')
        uf_store['spin.isotope'].wizard._go_next()
        interpreter.flush()  # Required because of the asynchronous uf call.

        # Load the chemical shift data.
        self._execute_uf(uf_name='chemical_shift.read',
                         file='ref_500MHz.list',
                         dir=data_path)
        interpreter.flush()

        # The spectral data.
        frq = [500, 800]
        frq_label = ['500MHz', '800MHz']
        error = 200000.0
        data = []
        spin_lock = [
            None, 1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0,
            4500.0, 5000.0, 5500.0, 6000.0
        ]
        for frq_index in range(len(frq)):
            for spin_lock_index in range(len(spin_lock)):
                # The reference.
                if spin_lock[spin_lock_index] == None:
                    id = 'ref_%s' % frq_label[frq_index]
                    file = "ref_%s.list" % frq_label[frq_index]

                # Normal data.
                else:
                    id = "nu_%s_%s" % (spin_lock[spin_lock_index],
                                       frq_label[frq_index])
                    file = "nu_%s_%s.list" % (spin_lock[spin_lock_index],
                                              frq_label[frq_index])

                # Append the data.
                data.append(
                    [id, file, spin_lock[spin_lock_index], frq[frq_index]])

        # Load the R1 data.
        for frq_index in range(len(frq)):
            label = 'R1_%s' % frq_label[frq_index]
            self._execute_uf(uf_name='relax_data.read',
                             ri_id=label,
                             ri_type='R1',
                             frq=frq[frq_index] * 1e6,
                             file='%s.out' % label,
                             dir=data_path,
                             mol_name_col=1,
                             res_num_col=2,
                             res_name_col=3,
                             spin_num_col=4,
                             spin_name_col=5,
                             data_col=6,
                             error_col=7)
            interpreter.flush()

        # Set up the peak intensity wizard.
        analysis.peak_wizard_launch(None)
        wizard = analysis.peak_wizard

        # The spectra.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='read',
                              file=data_path + file,
                              spectrum_id=id,
                              int_method='height',
                              dim=1)
            wizard._apply(None)
        wizard._skip(None)

        # The error type.
        page = wizard.get_page(wizard.page_indices['err_type'])
        page.selection = 'rmsd'
        wizard._go_next(None)

        # Baseplane RMSD.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='rmsd', spectrum_id=id, error=error)
            wizard._apply(None)
        wizard._skip(None)

        # The experiment type.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='exp_type',
                              spectrum_id=id,
                              exp_type='R1rho')
            wizard._apply(None)
        wizard._skip(None)

        # Set the spectrometer frequency.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='spectrometer_frequency',
                              id=id,
                              frq=H_frq,
                              units='MHz')
            wizard._apply(None)
        wizard._skip(None)

        # Set the relaxation times.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='relax_time', spectrum_id=id, time=0.1)
            wizard._apply(None)
        wizard._skip(None)

        # Set the relaxation dispersion spin-lock field strength (nu1).
        for id, file, field, H_frq in data:
            wizard.setup_page(page='spin_lock_field',
                              spectrum_id=id,
                              field=field)
            wizard._apply(None)
        wizard._skip(None)

        # Set the spin-lock offset.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='spin_lock_offset',
                              spectrum_id=id,
                              offset=110.0)
            wizard._apply(None)
        wizard._skip(None)

        # Flush all wx events (to allow the spectrum list GUI element to populate all its rows).
        wx.Yield()

        # Simulate right clicking in the spectrum list element to test the popup menu.
        analysis.peak_intensity.on_right_click(Fake_right_click())

        # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values).
        # FIXME: skipping the checks for certain wxPython bugs.
        if status.relax_mode != 'gui' and wx.version(
        ) != '2.9.4.1 gtk2 (classic)':
            analysis.peak_intensity.action_relax_disp_spin_lock_field(item=4)
            uf_store['relax_disp.spin_lock_field'].wizard._go_next()
            interpreter.flush()
            analysis.peak_intensity.action_relax_disp_exp_type(item=5)
            uf_store['relax_disp.exp_type'].wizard._go_next()
            interpreter.flush()
            analysis.peak_intensity.action_relax_disp_relax_time(item=0)
            uf_store['relax_disp.relax_time'].wizard._go_next()
            interpreter.flush()
            analysis.peak_intensity.action_spectrometer_frq(item=10)
            uf_store['spectrometer.frequency'].wizard._go_next()
            interpreter.flush()

        # Deselect all but the 'TP02' model.
        models = [MODEL_R2EFF, MODEL_NOREX, MODEL_TP02]
        for i in range(len(analysis.model_field.models_stripped)):
            if analysis.model_field.models_stripped[i] in models:
                analysis.model_field.select[i] = True
            else:
                analysis.model_field.select[i] = False
        analysis.model_field.modify()

        # Set the grid search size and number of MC sims.
        analysis.grid_inc.SetValue(4)
        analysis.mc_sim_num.SetValue(3)

        # Optimisation speedups.
        analysis.opt_func_tol = 1e-10
        analysis.opt_max_iterations = 10000

        # Execute relax.
        analysis.execute(
            wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED,
                            analysis.button_exec_relax.GetId()))

        # Wait for execution to complete.
        analysis.thread.join()

        # Flush all wx events.
        wx.Yield()

        # Exceptions in the thread.
        self.check_exceptions()

        # Check the relax controller.
        # FIXME: skipping the checks for certain wxPython bugs.
        if status.relax_mode != 'gui' and wx.version(
        ) != '2.9.4.1 gtk2 (classic)':
            self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(),
                             100)
            self.assertEqual(self.app.gui.controller.main_gauge.GetValue(),
                             100)

        # The original parameters.
        r1rho_prime = [[10.0, 15.0], [12.0, 18.0]]
        pA = 0.7654321
        kex = 1234.56789
        delta_omega = [7.0, 9.0]

        # The R20 keys.
        r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
        r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)

        # Switch to the 'TP02' model data pipe, then check for each spin.
        switch("%s - %s" % ('TP02', get_bundle()))
        spin_index = 0
        for spin, spin_id in spin_loop(return_id=True):
            # Printout.
            print("\nSpin %s." % spin_id)

            # Check the fitted parameters.
            self.assertAlmostEqual(spin.r2[r20_key1] / 10,
                                   r1rho_prime[spin_index][0] / 10, 4)
            self.assertAlmostEqual(spin.r2[r20_key2] / 10,
                                   r1rho_prime[spin_index][1] / 10, 4)
            self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
            self.assertAlmostEqual(spin.kex / 1000.0, kex / 1000.0, 3)

            # Increment the spin index.
            spin_index += 1
예제 #13
0
파일: __init__.py 프로젝트: tlinnet/relax
    def delete_analysis(self, index, reset=False):
        """Delete the analysis tab and data store corresponding to the index.

        The order of these operations is very important due to the notification of observer objects and the updates, synchronisations, etc. that follow.  If the program debugging mode is on, then printouts at each stage will occur to allow the following of the code and observer object notifications.


        @param index:   The index of the analysis to delete.
        @type index:    int
        """

        # Debugging set up.
        if status.debug:
            fn_name = sys._getframe().f_code.co_name
            mod_name = inspect.getmodule(inspect.stack()[1][0]).__name__
            class_name = self.__class__.__name__
            full_name = "%s.%s.%s" % (mod_name, class_name, fn_name)
            print("\n\n")
            print("debug> %s:  Deleting the analysis at index %s." % (full_name, index))

        # Decrement the number of analyses.
        self._num_analyses -= 1

        # Shift the current page back one if necessary.
        if self._current > index:
            self._current -= 1
            if status.debug:
                print("debug> %s:  Switching the current analysis to index %s." % (full_name, self._current))

        # Execute the analysis delete method, if it exists.
        if hasattr(self._analyses[index], 'delete'):
            if status.debug:
                print("debug> %s:  Executing the analysis specific delete() method." % full_name)
            self._analyses[index].delete()
        wx.Yield()

        # Delete the tab.
        if status.debug:
            print("debug> %s:  Deleting the notebook page." % full_name)
        self.notebook.DeletePage(index)

        # Delete the tab object.
        if status.debug:
            print("debug> %s:  Deleting the analysis GUI object." % full_name)
        self._analyses.pop(index)

        # Data store clean up.
        if not reset:
            # Store the pipe bundle.
            pipe_bundle = ds.relax_gui.analyses[index].pipe_bundle

            # Delete the data store object.
            if status.debug:
                print("debug> %s:  Deleting the data store object." % full_name)
            ds.relax_gui.analyses.pop(index)

            # Delete all data pipes associated with the analysis.
            for pipe in pipes.pipe_names():
                if pipes.get_bundle(pipe) == pipe_bundle:
                    if status.debug:
                        print("debug> %s:  Deleting the data pipe '%s' from the '%s' bundle." % (full_name, pipe, pipe_bundle))
                    pipes.delete(pipe)

        # No more analyses, so in the initial state.
        if self._num_analyses == 0:
            if status.debug:
                print("debug> %s:  Setting the initial state." % full_name)
            self.set_init_state()

        # The current page has been deleted, so handle page switching to another page.
        elif index == self._current:
            # Default to the current page index - so that the switch is to the next page.
            page_index = self._current

            # Switch back one page.
            if self._num_analyses <= self._current:
                page_index = self._current - 1

            # Make the switch.
            if status.debug:
                print("debug> %s:  Switching to page %s." % (full_name, page_index))
            self.switch_page(page_index)

        # Notify the observers of the change.
        status.observers.gui_analysis.notify()
예제 #14
0
    def test_tp02_data_to_tp02(self):
        """Test the GUI analysis with the relaxation dispersion 'TP02' model fitting to the 'TP02' synthetic data."""

        # The paths to the data files.
        data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'+sep

        # Simulate the new analysis wizard, selecting the fixed time CPMG experiment.
        analysis = self.new_analysis_wizard(analysis_type='disp')

        # Change the results directory.
        analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir))

        # Create the sequence data.
        self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=1, spin_name='N')
        interpreter.flush()
        self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=2, spin_name='N')
        interpreter.flush()
        self._execute_uf(uf_name='sequence.display')
        interpreter.flush()

        # Set up the nuclear isotopes.
        analysis.spin_isotope()
        uf_store['spin.isotope'].page.SetValue('spin_id', '')
        uf_store['spin.isotope'].wizard._go_next()
        interpreter.flush()    # Required because of the asynchronous uf call.

        # Load the chemical shift data.
        self._execute_uf(uf_name='chemical_shift.read', file='ref_500MHz.list', dir=data_path)
        interpreter.flush()

        # The spectral data.
        frq = [500, 800]
        frq_label = ['500MHz', '800MHz']
        error = 200000.0
        data = []
        spin_lock = [None, 1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0, 6000.0]
        for frq_index in range(len(frq)):
            for spin_lock_index in range(len(spin_lock)):
                # The reference.
                if spin_lock[spin_lock_index] == None:
                    id = 'ref_%s' % frq_label[frq_index]
                    file = "ref_%s.list" % frq_label[frq_index]

                # Normal data.
                else:
                    id = "nu_%s_%s" % (spin_lock[spin_lock_index], frq_label[frq_index])
                    file = "nu_%s_%s.list" % (spin_lock[spin_lock_index], frq_label[frq_index])

                # Append the data.
                data.append([id, file, spin_lock[spin_lock_index], frq[frq_index]])

        # Load the R1 data.
        for frq_index in range(len(frq)):
            label = 'R1_%s' % frq_label[frq_index]
            self._execute_uf(uf_name='relax_data.read', ri_id=label, ri_type='R1', frq=frq[frq_index]*1e6, file='%s.out'%label, dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
            interpreter.flush()

        # Set up the peak intensity wizard.
        analysis.peak_wizard_launch(None)
        wizard = analysis.peak_wizard

        # The spectra.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='read', file=data_path+file, spectrum_id=id, int_method='height', dim=1)
            wizard._apply(None)
        wizard._skip(None)

        # The error type.
        page = wizard.get_page(wizard.page_indices['err_type'])
        page.selection = 'rmsd'
        wizard._go_next(None)

        # Baseplane RMSD.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='rmsd', spectrum_id=id, error=error)
            wizard._apply(None)
        wizard._skip(None)

        # The experiment type.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='R1rho')
            wizard._apply(None)
        wizard._skip(None)

        # Set the spectrometer frequency.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq, units='MHz')
            wizard._apply(None)
        wizard._skip(None)

        # Set the relaxation times.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='relax_time', spectrum_id=id, time=0.1)
            wizard._apply(None)
        wizard._skip(None)

        # Set the relaxation dispersion spin-lock field strength (nu1).
        for id, file, field, H_frq in data:
            wizard.setup_page(page='spin_lock_field', spectrum_id=id, field=field)
            wizard._apply(None)
        wizard._skip(None)

        # Set the spin-lock offset.
        for id, file, field, H_frq in data:
            wizard.setup_page(page='spin_lock_offset', spectrum_id=id, offset=110.0)
            wizard._apply(None)
        wizard._skip(None)

        # Flush all wx events (to allow the spectrum list GUI element to populate all its rows).
        wx.Yield()

        # Simulate right clicking in the spectrum list element to test the popup menu.
        analysis.peak_intensity.on_right_click(Fake_right_click())

        # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values).
        # FIXME: skipping the checks for certain wxPython bugs.
        if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)':
            analysis.peak_intensity.action_relax_disp_spin_lock_field(item=4)
            uf_store['relax_disp.spin_lock_field'].wizard._go_next()
            interpreter.flush()
            analysis.peak_intensity.action_relax_disp_exp_type(item=5)
            uf_store['relax_disp.exp_type'].wizard._go_next()
            interpreter.flush()
            analysis.peak_intensity.action_relax_disp_relax_time(item=0)
            uf_store['relax_disp.relax_time'].wizard._go_next()
            interpreter.flush()
            analysis.peak_intensity.action_spectrometer_frq(item=10)
            uf_store['spectrometer.frequency'].wizard._go_next()
            interpreter.flush()

        # Deselect all but the 'TP02' model.
        models = [MODEL_R2EFF, MODEL_NOREX, MODEL_TP02]
        for i in range(len(analysis.model_field.models_stripped)):
            if analysis.model_field.models_stripped[i] in models:
                analysis.model_field.select[i] = True
            else:
                analysis.model_field.select[i] = False
        analysis.model_field.modify()

        # Set the grid search size and number of MC sims.
        analysis.grid_inc.SetValue(4)
        analysis.mc_sim_num.SetValue(3)

        # Optimisation speedups.
        analysis.opt_func_tol = 1e-10
        analysis.opt_max_iterations = 10000

        # Execute relax.
        analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId()))

        # Wait for execution to complete.
        analysis.thread.join()

        # Flush all wx events.
        wx.Yield()

        # Exceptions in the thread.
        self.check_exceptions()

        # Check the relax controller.
        # FIXME: skipping the checks for certain wxPython bugs.
        if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)':
            self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100)
            self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100)

        # The original parameters.
        r1rho_prime = [[10.0, 15.0], [12.0, 18.0]]
        pA = 0.7654321
        kex = 1234.56789
        delta_omega = [7.0, 9.0]

        # The R20 keys.
        r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
        r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)

        # Switch to the 'TP02' model data pipe, then check for each spin.
        switch("%s - %s" % ('TP02', get_bundle()))
        spin_index = 0
        for spin, spin_id in spin_loop(return_id=True):
            # Printout.
            print("\nSpin %s." % spin_id)

            # Check the fitted parameters.
            self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
            self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
            self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
            self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3)

            # Increment the spin index.
            spin_index += 1
예제 #15
0
    def delete_analysis(self, index):
        """Delete the analysis tab and data store corresponding to the index.

        The order of these operations is very important due to the notification of observer objects and the updates, synchronisations, etc. that follow.  If the program debugging mode is on, then printouts at each stage will occur to allow the following of the code and observer object notifications.


        @param index:   The index of the analysis to delete.
        @type index:    int
        """

        # Debugging set up.
        if status.debug:
            fn_name = sys._getframe().f_code.co_name
            mod_name = inspect.getmodule(inspect.stack()[1][0]).__name__
            class_name = self.__class__.__name__
            full_name = "%s.%s.%s" % (mod_name, class_name, fn_name)
            print("\n\n")
            print("debug> %s:  Deleting the analysis at index %s." % (full_name, index))

        # Decrement the number of analyses.
        self._num_analyses -= 1

        # Shift the current page back one if necessary.
        if self._current > index:
            self._current -= 1
            if status.debug:
                print("debug> %s:  Switching the current analysis to index %s." % (full_name, self._current))

        # Execute the analysis delete method, if it exists.
        if hasattr(self._analyses[index], 'delete'):
            if status.debug:
                print("debug> %s:  Executing the analysis specific delete() method." % full_name)
            self._analyses[index].delete()

        # Delete the tab.
        if status.debug:
            print("debug> %s:  Deleting the notebook page." % full_name)
        self.notebook.DeletePage(index)

        # Delete the tab object.
        if status.debug:
            print("debug> %s:  Deleting the analysis GUI object." % full_name)
        self._analyses.pop(index)

        # The current page has been deleted, so switch one back (if possible).
        if index == self._current and self._current != 0:
            if status.debug:
                print("debug> %s:  Switching to page %s." % (full_name, self._current-1))
            self.switch_page(self._current-1)

        # No more analyses, so in the initial state.
        if self._num_analyses == 0:
            if status.debug:
                print("debug> %s:  Setting the initial state." % full_name)
            self.set_init_state()

        # Notify the observers of the change.
        status.observers.gui_analysis.notify()

        # Store the pipe bundle.
        pipe_bundle = ds.relax_gui.analyses[index].pipe_bundle

        # Delete the data store object.
        if status.debug:
            print("debug> %s:  Deleting the data store object." % full_name)
        ds.relax_gui.analyses.pop(index)

        # Delete all data pipes associated with the analysis.
        for pipe in pipes.pipe_names():
            if pipes.get_bundle(pipe) == pipe_bundle:
                if status.debug:
                    print("debug> %s:  Deleting the data pipe '%s' from the '%s' bundle." % (full_name, pipe, pipe_bundle))
                pipes.delete(pipe)