Пример #1
0
    def test_write_read_pipes(self):
        """Test the writing out, and re-reading of data pipes from the state file."""

        # Create a data pipe.
        self.interpreter.pipe.create('test', 'mf')

        # Reset relax.
        reset()

        # The data pipe list.
        pipe_types = deepcopy(VALID_TYPES)
        pipe_types.pop(pipe_types.index("frame order"))

        # Create a few data pipes.
        for i in range(len(pipe_types)):
            self.interpreter.pipe.create('test' + repr(i), pipe_types[i])

        # Write the results.
        self.interpreter.state.save(self.tmpfile)

        # Reset relax.
        reset()

        # Re-read the results.
        self.interpreter.state.load(self.tmpfile)

        # Test the pipes.
        for i in range(len(pipe_types)):
            # Name.
            name = 'test' + repr(i)
            self.assert_(name in ds)

            # Type.
            pipe = get_pipe(name)
            self.assertEqual(pipe.pipe_type, pipe_types[i])
Пример #2
0
    def test_opt_sphere(self):
        """Check that the sphere diffusion tensor optimisation functions correctly."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'sphere'
        ds.diff_type = 'sphere'

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

        # Check the values.
        self.assertAlmostEqual(cdp.chi2, 0.0)
        self.assertEqual(cdp.diff_tensor.fixed, False)
        self.assertEqual(cdp.diff_tensor.type, 'sphere')
        self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*2e7) * 1e9)
        self.assertEqual(cdp.diff_tensor.rotation[0, 0], 1.0)
        self.assertEqual(cdp.diff_tensor.rotation[1, 1], 1.0)
        self.assertEqual(cdp.diff_tensor.rotation[2, 2], 1.0)
        self.assertEqual(cdp.diff_tensor.rotation[0, 1], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[0, 2], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[1, 2], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[1, 0], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[2, 0], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[2, 1], 0.0)
Пример #3
0
    def menu_close_all(self, event):
        """Close all analyses.

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

        # Notebook not created yet, so skip.
        if not hasattr(self, 'notebook'):
            return

        # Execution lock.
        if status.exec_lock.locked():
            return

        # Ask if this should be done.
        msg = "Are you sure you would like to close all analyses?  All data will be erased and the relax data store reset."
        if status.show_gui and Question(msg, title="Close all analyses", size=(350, 150), default=False).ShowModal() == wx.ID_NO:
            return

        # Delete.
        self.delete_all()

        # Reset relax.
        reset()
Пример #4
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Remove the temporary directory and variable (if there is a deletion failure, continue to allow the test suite to survive).
        try:
            deletion(obj=ds, name='tmpdir', dir=True)
        except:
            pass
        try:
            deletion(obj=self, name='tmpdir', dir=True)
        except:
            pass

        # Remove temporary file and variable (if there is a deletion failure, continue to allow the test suite to survive).
        try:
            deletion(obj=ds, name='tmpfile', dir=False)
        except:
            pass
        try:
            deletion(obj=self, name='tmpfile', dir=False)
        except:
            pass

        # Reset relax.
        reset()
Пример #5
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Remove the temporary directory and variable (if there is a deletion failure, continue to allow the test suite to survive).
        try:
            deletion(obj=ds, name='tmpdir', dir=True)
        except:
            pass
        try:
            deletion(obj=self, name='tmpdir', dir=True)
        except:
            pass

        # Remove temporary file and variable (if there is a deletion failure, continue to allow the test suite to survive).
        try:
            # Close the open file handles on the OS level.
            close(ds.tmpfile_handle)

            # Delete the temporary files.
            deletion(obj=ds, name='tmpfile', dir=False)
        except:
            pass
        try:
            # Close the open file handles on the OS level.
            close(self.tmpfile_handle)

            # Delete the temporary files.
            deletion(obj=self, name='tmpfile', dir=False)
        except:
            pass

        # Reset relax.
        reset()
Пример #6
0
    def test_opt_ellipsoid(self):
        """Check that the ellipsoid diffusion tensor optimisation functions correctly."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'ellipsoid'
        ds.diff_type = 'ellipsoid'

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

        # Print out.
        print(cdp.diff_tensor)

        # The real data.
        Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()

        # Check the values.
        self.assertAlmostEqual(cdp.chi2, 0.0)
        self.assertEqual(cdp.diff_tensor.fixed, False)
        self.assertEqual(cdp.diff_tensor.type, 'ellipsoid')

        # Check the ellipsoid.
        self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
Пример #7
0
    def test_write_read_pipes(self):
        """Test the writing out, and re-reading of data pipes from the state file."""

        # Create a data pipe.
        self.interpreter.pipe.create('test', 'mf')

        # Reset relax.
        reset()

        # The data pipe list.
        pipe_types = deepcopy(VALID_TYPES)
        pipe_types.pop(pipe_types.index("frame order"))

        # Create a few data pipes.
        for i in range(len(pipe_types)):
            self.interpreter.pipe.create('test' + repr(i), pipe_types[i])

        # Write the results.
        self.interpreter.state.save(self.tmpfile, compress_type=0, force=True)

        # Reset relax.
        reset()

        # Re-read the results.
        self.interpreter.state.load(self.tmpfile)

        # Test the pipes.
        for i in range(len(pipe_types)):
            # Name.
            name = 'test' + repr(i)
            self.assert_(name in ds)

            # Type.
            pipe = get_pipe(name)
            self.assertEqual(pipe.pipe_type, pipe_types[i])
Пример #8
0
def load_state(state=None, dir=None, verbosity=1, force=False):
    """Function for loading a saved program state.

    @keyword state:     The saved state file.
    @type state:        str
    @keyword dir:       The path of the state file.
    @type dir:          str
    @keyword verbosity: The verbosity level.
    @type verbosity:    int
    @keyword force:     If True, the relax data store will be reset prior to state loading.
    @type force:        bool
    """

    # Open the file for reading.
    file = open_read_file(file_name=state, dir=dir, verbosity=verbosity)

    # Reset.
    if force:
        reset()

    # Make sure that the data store is empty.
    if not ds.is_empty():
        raise RelaxError("The relax data store is not empty.")

    # Restore from the XML.
    ds.from_xml(file)

    # Signal a change in the current data pipe.
    status.observers.pipe_alteration.notify()

    # Signal the state loading
    status.observers.state_load.notify()
Пример #9
0
    def test_opt_sphere(self):
        """Check that the sphere diffusion tensor optimisation functions correctly."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'sphere'
        ds.diff_type = 'sphere'

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

        # Check the values.
        self.assertAlmostEqual(cdp.chi2, 0.0)
        self.assertEqual(cdp.diff_tensor.fixed, False)
        self.assertEqual(cdp.diff_tensor.type, 'sphere')
        self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*2e7) * 1e9)
        self.assertEqual(cdp.diff_tensor.rotation[0, 0], 1.0)
        self.assertEqual(cdp.diff_tensor.rotation[1, 1], 1.0)
        self.assertEqual(cdp.diff_tensor.rotation[2, 2], 1.0)
        self.assertEqual(cdp.diff_tensor.rotation[0, 1], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[0, 2], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[1, 2], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[1, 0], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[2, 0], 0.0)
        self.assertEqual(cdp.diff_tensor.rotation[2, 1], 0.0)
Пример #10
0
    def test_opt_ellipsoid(self):
        """Check that the ellipsoid diffusion tensor optimisation functions correctly."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'ellipsoid'
        ds.diff_type = 'ellipsoid'

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

        # Print out.
        print(cdp.diff_tensor)

        # The real data.
        Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()

        # Check the values.
        self.assertAlmostEqual(cdp.chi2, 0.0)
        self.assertEqual(cdp.diff_tensor.fixed, False)
        self.assertEqual(cdp.diff_tensor.type, 'ellipsoid')

        # Check the ellipsoid.
        self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
Пример #11
0
    def menu_close_all(self, event):
        """Close all analyses.

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

        # Notebook not created yet, so skip.
        if not hasattr(self, 'notebook'):
            return

        # Execution lock.
        if status.exec_lock.locked():
            return

        # Ask if this should be done.
        msg = "Are you sure you would like to close all analyses?  All data will be erased and the relax data store reset."
        if status.show_gui and Question(msg, title="Close all analyses", size=(350, 150), default=False).ShowModal() == wx.ID_NO:
            return

        # Delete.
        self.delete_all()

        # Reset relax.
        reset()
Пример #12
0
    def tearDown(self):
        """Reset the relax data storage object."""

        # Delete the structural data object.
        del self.data

        # Reset relax.
        reset()
Пример #13
0
    def tearDown(self):
        """Reset the relax data storage object."""

        # Reset relax.
        reset()

        # Delete the temporary files.
        delete(self.tmpfile_sphere, fail=False)
        delete(self.tmpfile_spheroid, fail=False)
        delete(self.tmpfile_ellipsoid, fail=False)
Пример #14
0
    def test_exists_mol_res_spin_data_no_pipe(self):
        """Determine if molecule-residue-spin data exists when no data pipe exists.

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # This should fail.
        self.assertRaises(RelaxNoPipeError, mol_res_spin.exists_mol_res_spin_data)
Пример #15
0
    def test_count_spins_no_pipe(self):
        """Test that the counting of the number of spins raises an error when no pipe exists.

        The function tested is pipe_control.mol_res_spin.count_spins().
        """

        # Reset relax.
        reset()

        # Test for the error.
        self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins)
Пример #16
0
    def test_count_spins_no_pipe(self):
        """Test that the counting of the number of spins raises an error when no pipe exists.

        The function tested is pipe_control.mol_res_spin.count_spins().
        """

        # Reset relax.
        reset()

        # Test for the error.
        self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins)
Пример #17
0
    def test_display_fail_no_pipe(self):
        """Failure of the display of the diffusion tensor data structure when there is no data pipe.

        The functions tested are both pipe_control.diffusion_tensor.display() and
        prompt.diffusion_tensor.display().
        """

        # Reset relax.
        reset()

        # Try to display the tensor data.
        self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.display)
Пример #18
0
    def test_exists_mol_res_spin_data_no_pipe(self):
        """Determine if molecule-residue-spin data exists when no data pipe exists.

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # This should fail.
        self.assertRaises(RelaxNoPipeError,
                          mol_res_spin.exists_mol_res_spin_data)
    def test_delete_fail_no_pipe(self):
        """Failure of deletion of the diffusion tensor data structure when there is no data pipe.

        The functions tested are both pipe_control.diffusion_tensor.delete() and
        prompt.diffusion_tensor.delete().
        """

        # Reset relax.
        reset()

        # Try to delete the tensor data.
        self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.delete)
Пример #20
0
    def test_display_fail_no_pipe(self):
        """Failure of the display of the alignment tensor data structure when there is no data pipe.

        The functions tested are both pipe_control.align_tensor.display() and
        prompt.align_tensor.display().
        """

        # Reset relax.
        reset()

        # Try to display the tensor data.
        self.assertRaises(RelaxNoPipeError, self.align_tensor_fns.display, 'Pf1')
Пример #21
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Remove the temporary directory and variable.
        deletion(obj=ds, name="tmpdir", dir=True)
        deletion(obj=self, name="tmpdir", dir=True)

        # Remove temporary file and variable.
        deletion(obj=ds, name="tmpfile", dir=False)
        deletion(obj=self, name="tmpfile", dir=False)

        # Reset relax.
        reset()
Пример #22
0
    def test_delete_fail_no_pipe(self):
        """Failure of deletion of the alignment tensor data structure when there is no data pipe.

        The functions tested are both pipe_control.align_tensor.delete() and
        prompt.align_tensor.delete().
        """

        # Reset relax.
        reset()

        # Try to delete the tensor data.
        self.assertRaises(RelaxNoPipeError, self.align_tensor_fns.delete,
                          'Pf1')
Пример #23
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Remove the temporary directory and variable.
        deletion(obj=ds, name='tmpdir', dir=True)
        deletion(obj=self, name='tmpdir', dir=True)

        # Remove temporary file and variable.
        deletion(obj=ds, name='tmpfile', dir=False)
        deletion(obj=self, name='tmpfile', dir=False)

        # Reset relax.
        reset()
Пример #24
0
    def test_exists_mol_res_spin_data_no_data(self):
        """Determine if molecule-residue-spin data exists when no data exists.

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')

        # This should be False.
        self.failIf(mol_res_spin.exists_mol_res_spin_data())
Пример #25
0
    def test_exists_mol_res_spin_data_no_data(self):
        """Determine if molecule-residue-spin data exists when no data exists.

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')

        # This should be False.
        self.failIf(mol_res_spin.exists_mol_res_spin_data())
Пример #26
0
    def test_count_no_spins(self):
        """Test that the number of spins (zero) can be properly counted.

        The function tested is pipe_control.mol_res_spin.count_spins().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')

        # Test the number of spins counted.
        self.assertEqual(mol_res_spin.count_spins(), 0)
Пример #27
0
    def test_count_no_spins(self):
        """Test that the number of spins (zero) can be properly counted.

        The function tested is pipe_control.mol_res_spin.count_spins().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')

        # Test the number of spins counted.
        self.assertEqual(mol_res_spin.count_spins(), 0)
Пример #28
0
    def tearDown(self):
        """Reset the relax data storage object."""

        # Reset relax.
        reset()

        # Close the open file handles on the OS level.
        close(self.tmpfile_sphere_handle)
        close(self.tmpfile_spheroid_handle)
        close(self.tmpfile_ellipsoid_handle)

        # Delete the temporary files.
        delete(self.tmpfile_sphere, fail=False)
        delete(self.tmpfile_spheroid, fail=False)
        delete(self.tmpfile_ellipsoid, fail=False)
Пример #29
0
    def test_residue_loop_no_pipe(self):
        """Test the proper operation of the residue loop when no data pipe is present.

        The function tested is pipe_control.mol_res_spin.residue_loop().
        """

        # Reset relax.
        reset()

        # Function for the problem of catching an error in a generator function.
        def fail_test():
            for residue in mol_res_spin.residue_loop():
                pass

        # Test for the no pipe error.
        self.assertRaises(RelaxNoPipeError, fail_test)
Пример #30
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Flush all wx events prior to the clean up operations of this method.  This prevents these events from occurring after the GUI elements have been deleted.
        wx.Yield()

        # Remove the temporary directory and variable.
        deletion(obj=ds, name='tmpdir', dir=True)
        deletion(obj=self, name='tmpdir', dir=True)

        # Remove temporary file and variable.
        deletion(obj=ds, name='tmpfile', dir=False)
        deletion(obj=self, name='tmpfile', dir=False)

        # Reset relax.
        reset()
Пример #31
0
    def test_spin_loop_no_pipe(self):
        """Test the proper operation of the spin loop when no data pipe is present.

        The function tested is pipe_control.mol_res_spin.spin_loop().
        """

        # Reset relax.
        reset()

        # Function for the problem of catching an error in a generator function.
        def fail_test():
            for spin in mol_res_spin.spin_loop():
                pass

        # Test for the no pipe error.
        self.assertRaises(RelaxNoPipeError, fail_test)
Пример #32
0
    def test_exists_mol_res_spin_data_single_spin_num(self):
        """Determine if molecule-residue-spin data exists (when a single spin is numbered).

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')
        dp = pipes.get_pipe('orig')

        # Number the first spin.
        dp.mol[0].res[0].spin[0].num = 234

        # This should be True.
        self.failUnless(mol_res_spin.exists_mol_res_spin_data())
Пример #33
0
    def test_exists_mol_res_spin_data_single_mol(self):
        """Determine if molecule-residue-spin data exists (with data for a single molecule).

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')
        dp = pipes.get_pipe('orig')

        # Name the first molecule.
        dp.mol[0].name = 'TOM40'

        # This should be True.
        self.failUnless(mol_res_spin.exists_mol_res_spin_data())
Пример #34
0
    def test_exists_mol_res_spin_data_single_mol(self):
        """Determine if molecule-residue-spin data exists (with data for a single molecule).

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')
        dp = pipes.get_pipe('orig')

        # Name the first molecule.
        dp.mol[0].name = 'TOM40'

        # This should be True.
        self.failUnless(mol_res_spin.exists_mol_res_spin_data())
Пример #35
0
    def test_exists_mol_res_spin_data_single_spin_num(self):
        """Determine if molecule-residue-spin data exists (when a single spin is numbered).

        The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')
        dp = pipes.get_pipe('orig')

        # Number the first spin.
        dp.mol[0].res[0].spin[0].num = 234

        # This should be True.
        self.failUnless(mol_res_spin.exists_mol_res_spin_data())
Пример #36
0
    def test_residue_loop_no_data(self):
        """Test the proper operation of the residue loop when no data is present.

        The function tested is pipe_control.mol_res_spin.residue_loop().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')

        # Loop over the residues.
        i = 0
        for residue in mol_res_spin.residue_loop():
            i = i + 1

        # Test loop length.
        self.assertEqual(i, 0)
Пример #37
0
    def test_spin_loop_no_data(self):
        """Test the proper operation of the spin loop when no data is present.

        The function tested is pipe_control.mol_res_spin.spin_loop().
        """

        # Reset relax.
        reset()

        # Add a data pipe to the data store.
        ds.add(pipe_name='orig', pipe_type='mf')

        # Loop over the spins.
        i = 0
        for spin in mol_res_spin.spin_loop():
            i = i + 1

        # Test loop length.
        self.assertEqual(i, 0)
Пример #38
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Flush all wx events prior to the clean up operations of this method.  This prevents these events from occurring after the GUI elements have been deleted.
        wx.Yield()

        # Remove the temporary directory and variable.
        deletion(obj=ds, name='tmpdir', dir=True)
        deletion(obj=self, name='tmpdir', dir=True)

        # Remove temporary file and variable.
        deletion(obj=ds, name='tmpfile', dir=False)
        deletion(obj=self, name='tmpfile', dir=False)

        # Reset relax.
        reset()

        # Get the wx app.
        self.app = wx.GetApp()

        # Kill all windows.
        self.clean_up_windows()

        # Print out a list of all living windows to help ensure that custom Close() and Destroy() methods are cleaning up all objects.
        print(
            "\n\nList of all living GUI elements - this must only include the main GUI window and the relax controller:"
        )
        all_destroyed = True
        for window in wx.GetTopLevelWindows():
            # Printout.
            print("    Window: %s" % window)
            if isinstance(window, Wiz_window):
                print("        Wizard title: %s" % window.title)
                print("        Wizard pages: %s" % window._pages)

            # Skip the main GUI window and the relax controller.
            if isinstance(window, Main) or isinstance(window, Controller):
                continue

            # Failure of memory management.
            all_destroyed = False
        print("\n\n\n")
Пример #39
0
    def test_test(self):
        """The throwing of RelaxNoPipeError when the pipe does not exist.

        The function tested is pipe_control.pipes.check_pipe().
        """

        # The following should do nothing as the pipes exist.
        pipes.check_pipe()
        pipes.check_pipe('orig')
        pipes.check_pipe('empty')

        # Assert that a RelaxNoPipeError occurs when the pipe doesn't exist.
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'x')

        # Reset relax.
        reset()

        # Now none of the following pipes exist, hence errors should be thrown.
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe)
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'orig')
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'empty')
Пример #40
0
    def test_load_and_reset(self):
        """The resetting of an unpickled and restored relax data storage singleton.

        This tests the normal operation of the pipe_control.state.load() function.
        """

        # Test the contents of the empty singleton.
        self.assertEqual(list(ds.keys()), [])
        self.assertEqual(pipes.cdp_name(), None)
        self.assert_(not hasattr(ds, 'y'))

        # Load the state.
        self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states')

        # Reset relax.
        reset()

        # Test that there are no contents in the reset singleton.
        self.assertEqual(list(ds.keys()), [])
        self.assertEqual(pipes.cdp_name(), None)
        self.assert_(not hasattr(ds, 'y'))
Пример #41
0
    def test_back_calc_spheroid(self):
        """Check the back-calculation of relaxation data for the spherical diffusion tensor."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'spheroid_prolate'
        ds.diff_type = 'spheroid'

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

        # Loop over all spins.
        for i in range(len(cdp.mol[0].res)):
            # Alias.
            spin = cdp.mol[0].res[i].spin[0]

            # Check the values.
            for ri_id in cdp.ri_ids:
                self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
Пример #42
0
    def test_opt_spheroid(self):
        """Check that the spheroid diffusion tensor optimisation functions correctly."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'spheroid_prolate'
        ds.diff_type = 'spheroid'

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

        # Check the values.
        self.assertAlmostEqual(cdp.chi2, 0.0)
        self.assertEqual(cdp.diff_tensor.fixed, False)
        self.assertEqual(cdp.diff_tensor.type, 'spheroid')
        self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*7e7/3.0) * 1e9)
        self.assertAlmostEqual(cdp.diff_tensor.Da * 1e-7, 1.0)
        self.assertAlmostEqual(cdp.diff_tensor.theta, 2.0)
        self.assertAlmostEqual(cdp.diff_tensor.phi, pi-0.5)
Пример #43
0
    def test_opt_spheroid(self):
        """Check that the spheroid diffusion tensor optimisation functions correctly."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'spheroid_prolate'
        ds.diff_type = 'spheroid'

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

        # Check the values.
        self.assertAlmostEqual(cdp.chi2, 0.0)
        self.assertEqual(cdp.diff_tensor.fixed, False)
        self.assertEqual(cdp.diff_tensor.type, 'spheroid')
        self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*7e7/3.0) * 1e9)
        self.assertAlmostEqual(cdp.diff_tensor.Da * 1e-7, 1.0)
        self.assertAlmostEqual(cdp.diff_tensor.theta, 2.0)
        self.assertAlmostEqual(cdp.diff_tensor.phi, pi-0.5)
Пример #44
0
    def test_test(self):
        """The throwing of RelaxNoPipeError when the pipe does not exist.

        The function tested is pipe_control.pipes.check_pipe().
        """

        # The following should do nothing as the pipes exist.
        pipes.check_pipe()
        pipes.check_pipe('orig')
        pipes.check_pipe('empty')

        # Assert that a RelaxNoPipeError occurs when the pipe doesn't exist.
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'x')

        # Reset relax.
        reset()

        # Now none of the following pipes exist, hence errors should be thrown.
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe)
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'orig')
        self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'empty')
Пример #45
0
    def test_back_calc_spheroid(self):
        """Check the back-calculation of relaxation data for the spherical diffusion tensor."""

        # Reset relax.
        reset()

        # The diffusion type (used by the script).
        ds.diff_dir = 'spheroid_prolate'
        ds.diff_type = 'spheroid'

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

        # Loop over all spins.
        for i in range(len(cdp.mol[0].res)):
            # Alias.
            spin = cdp.mol[0].res[i].spin[0]

            # Check the values.
            for ri_id in cdp.ri_ids:
                self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
Пример #46
0
    def tearDown(self):
        """Default tearDown operation - delete temp directories and files and reset relax."""

        # Flush all wx events prior to the clean up operations of this method.  This prevents these events from occurring after the GUI elements have been deleted.
        wx.Yield()

        # Remove the temporary directory and variable.
        deletion(obj=ds, name='tmpdir', dir=True)
        deletion(obj=self, name='tmpdir', dir=True)

        # Remove temporary file and variable.
        deletion(obj=ds, name='tmpfile', dir=False)
        deletion(obj=self, name='tmpfile', dir=False)

        # Reset relax.
        reset()

        # Get the wx app.
        self.app = wx.GetApp()

        # Kill all windows.
        self.clean_up_windows()

        # Print out a list of all living windows to help ensure that custom Close() and Destroy() methods are cleaning up all objects.
        print("\n\nList of all living GUI elements - this must only include the main GUI window and the relax controller:")
        all_destroyed = True
        for window in wx.GetTopLevelWindows():
            # Printout.
            print("    Window: %s" % window)
            if isinstance(window, Wiz_window):
                print("        Wizard title: %s" % window.title)
                print("        Wizard pages: %s" % window._pages)

            # Skip the main GUI window and the relax controller.
            if isinstance(window, Main) or isinstance(window, Controller):
                continue

            # Failure of memory management.
            all_destroyed = False
        print("\n\n\n")
Пример #47
0
    def test_load_and_reset(self):
        """The resetting of an unpickled and restored relax data storage singleton.

        This tests the normal operation of the pipe_control.state.load() function.
        """

        # Test the contents of the empty singleton.
        self.assertEqual(list(ds.keys()), [])
        self.assertEqual(pipes.cdp_name(), None)
        self.assert_(not hasattr(ds, 'y'))

        # Load the state.
        self.state.load_state(state='basic_single_pipe',
                              dir=status.install_path + sep + 'test_suite' +
                              sep + 'shared_data' + sep + 'saved_states')

        # Reset relax.
        reset()

        # Test that there are no contents in the reset singleton.
        self.assertEqual(list(ds.keys()), [])
        self.assertEqual(pipes.cdp_name(), None)
        self.assert_(not hasattr(ds, 'y'))
Пример #48
0
def load_state(state=None, dir=None, verbosity=1, force=False):
    """Function for loading a saved program state.

    @keyword state:     The saved state file.
    @type state:        str
    @keyword dir:       The path of the state file.
    @type dir:          str
    @keyword verbosity: The verbosity level.
    @type verbosity:    int
    @keyword force:     If True, the relax data store will be reset prior to state loading.
    @type force:        bool
    """

    # Open the file for reading.
    file = open_read_file(file_name=state, dir=dir, verbosity=verbosity)

    # Reset.
    if force:
        reset()

    # Make sure that the data store is empty.
    if not ds.is_empty():
        raise RelaxError("The relax data store is not empty.")

    # Restore from the XML.
    ds.from_xml(file)

    # Update all of the required metadata structures.
    for pipe, pipe_name in pipes.pipe_loop(name=True):
        mol_res_spin.metadata_update(pipe=pipe_name)
        interatomic.metadata_update(pipe=pipe_name)

    # Signal a change in the current data pipe.
    status.observers.pipe_alteration.notify()

    # Signal the state loading
    status.observers.state_load.notify()
Пример #49
0
    def state_load(self, event=None, file_name=None):
        """Load the program state.

        @keyword event:     The wx event.
        @type event:        wx event
        @keyword file_name: The name of the file to load (for dialogless operation).
        @type file_name:    str
        """

        # Execution lock.
        if status.exec_lock.locked():
            return

        # Warning.
        if not self.analysis.init_state or not ds.is_empty():
            # The message.
            msg = "Loading a saved relax state file will cause all unsaved data to be lost.  Are you sure you would to open a save file?"

            # The dialog.
            if status.show_gui and Question(msg, default=True, size=(400, 150)).ShowModal() == wx.ID_NO:
                return

        # Open the dialog.
        if not file_name:
            dialog = RelaxFileDialog(parent=self, message='Select the relax save state file', defaultFile='state.bz2', wildcard='relax save files (*.bz2;*.gz)|*.bz2;*.gz|All files (*)|*', style=wx.FD_OPEN)

            # Show the dialog and catch if no file has been selected.
            if status.show_gui and dialog.ShowModal() != wx.ID_OK:
                # Don't do anything.
                return

            # The file.
            file_name = gui_to_str(dialog.get_file())

        # Yield to allow the cursor to be changed.
        wx.Yield()

        # Change the cursor to waiting, and freeze the GUI.
        wx.BeginBusyCursor()
        self.Freeze()

        # Make sure the GUI returns to normal if a failure occurs.
        try:
            # Delete the current tabs.
            self.analysis.delete_all()

            # Reset the relax data store.
            reset()

            # The new save file name.
            self.save_file = file_name

            # Load the relax state.
            if protected_exec(state.load_state, file_name, verbosity=0):
                # Update the core of the GUI to match the new data store.
                self.sync_ds(upload=False)

            # File loading failure.
            else:
                # Reset relax to clear any partially loaded data.
                reset()

                # Reinitialise the GUI data store structure.
                self.init_data()

        # Reset the cursor, and thaw the GUI.
        finally:
            self.Thaw()

            # Turn off the busy cursor.
            if wx.IsBusy():
                wx.EndBusyCursor()
Пример #50
0
    def run_test_suite(self, event=None, categories=['system', 'unit', 'gui']):
        """Execute the full test suite.

        @keyword event:         The wx event.
        @type event:            wx event
        @keyword categories:    The list of test categories to run, for example ['system', 'unit', 'gui'] for all tests.
        @type categories:       list of str
        """

        # Ask if this should be done.
        msg = "In running the test suite, relax will be reset and all data lost.  Are you sure you would like to run the test suite?"
        if Question(msg, parent=self, size=(400, 150), default=False).ShowModal() == wx.ID_NO:
            return

        # Set the test suite flag.
        self.test_suite_flag = True

        # Change the cursor to waiting.
        wx.BeginBusyCursor()

        # Set a new style to stay on top, refreshing to update the style (needed for Mac OS X and MS Windows).
        orig_style = self.controller.GetWindowStyle()
        self.controller.SetWindowStyle(orig_style | wx.STAY_ON_TOP)
        self.controller.Refresh()

        # Make the relax controller modal so that all other windows are deactivated (to stop users from clicking on things).
        self.controller.MakeModal(True)

        # Close all open windows.
        if hasattr(self, 'spin_viewer'):
            self.spin_viewer.Close()
        if hasattr(self, 'pipe_editor'):
            self.pipe_editor.Close()
        if hasattr(self, 'results_viewer'):
            self.results_viewer.Close()
        if hasattr(self, 'relax_prompt'):
            self.relax_prompt.Close()

        # Reset relax.
        reset()

        # Show the relax controller.
        self.show_controller(event)

        # Yield
        wx.GetApp().Yield(True)

        # Prevent all new GUI elements from being shown.
        status.show_gui = False

        # Run the tests (with the import here to break a nasty circular import).
        import test_suite.test_suite_runner
        runner = test_suite.test_suite_runner.Test_suite_runner([], from_gui=True, categories=categories)
        runner.run_all_tests()

        # Reactive the GUI.
        status.show_gui = True

        # Turn off the busy cursor.
        if wx.IsBusy():
            wx.EndBusyCursor()

        # Restore the controller.
        self.controller.SetWindowStyle(orig_style)
        self.controller.MakeModal(False)
        self.controller.Refresh()

        # Unset the test suite flag.
        self.test_suite_flag = False

        # Set the controller main gauge to 100%.
        wx.CallAfter(self.controller.main_gauge.SetValue, 100)