Ejemplo n.º 1
0
    def summary(self):
        """Print out a summary of the relax test suite."""

        # Title.
        title(file=sys.stdout, text="Summary of the relax test suite")

        # The skipped tests.
        self.summary_skipped()

        # Subtitle.
        section(file=sys.stdout, text="Synopsis")

        # System/functional test summary.
        if hasattr(self, 'system_result'):
            summary_line("System/functional tests", self.system_result)

        # Unit test summary.
        if hasattr(self, 'unit_result'):
            summary_line("Unit tests", self.unit_result)

        # GUI test summary.
        if hasattr(self, 'gui_result'):
            summary_line("GUI tests", self.gui_result)

        # Synopsis.
        if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result'):
            if self.gui_result == "skip":
                status = self.system_result and self.unit_result
            else:
                status = self.system_result and self.unit_result and self.gui_result
            summary_line("Synopsis", status)

        # End.
        print('\n\n')
Ejemplo n.º 2
0
    def run_verification_tests(self, summary=True, reset=True):
        """Execute the software verification tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        @keyword reset:     A flag which if True will reset the relax status objects for the tests.
        @type reset:        bool
        """

        # Reset the list for skipped tests.
        if reset:
            status.skipped_tests = []

        # Run the tests, catching the keyboard interrupt.
        try:
            # Print a header.
            title(file=sys.stdout, text='Software verification tests')

            # Run the tests.
            verification_runner = Verification_test_runner()
            self.runner.category = 'verification'
            self.verification_result = verification_runner.run(
                self.tests, runner=self.runner)

            # Print out a summary of the test suite.
            if summary:
                self.summary()

        # Catch the keyboard interrupt.
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt:  Terminating all tests.\n")
            return False

        # All tests were run successfully.
        return self.verification_result
Ejemplo n.º 3
0
    def run_verification_tests(self, summary=True, reset=True):
        """Execute the software verification tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        @keyword reset:     A flag which if True will reset the relax status objects for the tests.
        @type reset:        bool
        """

        # Reset the list for skipped tests.
        if reset:
            status.skipped_tests = []

        # Run the tests, catching the keyboard interrupt.
        try:
            # Print a header.
            title(file=sys.stdout, text='Software verification tests')

            # Run the tests.
            verification_runner = Verification_test_runner()
            self.runner.category = 'verification'
            self.verification_result = verification_runner.run(self.tests, runner=self.runner)

            # Print out a summary of the test suite.
            if summary:
                self.summary()

        # Catch the keyboard interrupt.
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt:  Terminating all tests.\n")
            return False

        # All tests were run successfully.
        return True
Ejemplo n.º 4
0
    def summary(self):
        """Print out a summary of the relax test suite."""

        # Title.
        title(file=sys.stdout, text="Summary of the relax test suite")

        # The skipped tests.
        if status.skip_blacklisted_tests:
            self.summary_skipped()

        # Subtitle.
        section(file=sys.stdout, text="Synopsis")

        # System/functional test summary.
        if hasattr(self, 'system_result'):
            summary_line("System/functional tests",
                         self.system_result,
                         width=status.text_width)

        # Unit test summary.
        if hasattr(self, 'unit_result'):
            summary_line("Unit tests",
                         self.unit_result,
                         width=status.text_width)

        # GUI test summary.
        if hasattr(self, 'gui_result'):
            summary_line("GUI tests", self.gui_result, width=status.text_width)

        # Verification test summary.
        if hasattr(self, 'verification_result'):
            summary_line("Software verification tests",
                         self.verification_result,
                         width=status.text_width)

        # Synopsis.
        if hasattr(self, 'system_result') and hasattr(
                self,
                'unit_result') and hasattr(self, 'gui_result') and hasattr(
                    self, 'verification_result'):
            if self.gui_result == "skip":
                test_status = self.system_result and self.unit_result and self.verification_result
            else:
                test_status = self.system_result and self.unit_result and self.gui_result and self.verification_result
            summary_line("Synopsis", test_status, width=status.text_width)

        # End.
        print('\n\n')
Ejemplo n.º 5
0
    def run_unit_tests(self, summary=True):
        """Execute the unit tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        """

        # Print a header.
        title(file=sys.stdout, text='Unit tests')

        # Run the tests.
        unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests')
        self.unit_result = unit_runner.run(runner=self.runner)

        # Print out a summary of the test suite.
        if summary:
            self.summary()
Ejemplo n.º 6
0
    def run_system_tests(self, summary=True):
        """Execute the system/functional tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        """

        # Print a header.
        title(file=sys.stdout, text='System / functional tests')

        # Run the tests.
        system_runner = System_test_runner()
        self.system_result = system_runner.run(self.tests, runner=self.runner)

        # Print out a summary of the test suite.
        if summary:
            self.summary()
Ejemplo n.º 7
0
    def run_gui_tests(self, summary=True):
        """Execute the GUI tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        """

        # Print a header.
        title(file=sys.stdout, text='GUI tests')

        # Run the tests.
        if dep_check.wx_module:
            # Set up the GUI if needed (i.e. not in GUI mode already).
            app = wx.GetApp()
            if app == None:
                # Initialise.
                app = wx.App(redirect=False)

                # Build the GUI.
                app.gui = relax_gui.Main(parent=None, id=-1, title="")

            # Execute the GUI tests.
            gui_runner = GUI_test_runner()
            self.gui_result = gui_runner.run(self.tests, runner=self.runner)

            # Clean up for the GUI, if not in GUI mode.
            if status.test_mode:
                # Terminate the interpreter thread to allow the tests to cleanly exit.
                interpreter_thread = interpreter.Interpreter()
                interpreter_thread.exit()

                # Stop the GUI main loop.
                app.ExitMainLoop()

        # No wx module installed.
        else:
            print("All GUI tests skipped due to the missing/broken wx module.\n")
            self.gui_result = 'skip'

        # Print out a summary of the test suite.
        if summary:
            self.summary()
Ejemplo n.º 8
0
    def run_unit_tests(self, summary=True, reset=True):
        """Execute the unit tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        @keyword reset:     A flag which if True will reset the relax status objects for the tests.
        @type reset:        bool
        @return:            True if the tests were run, False if a KeyboardInterrupt occurred.
        @rtype:             bool
        """

        # Reset the list for skipped tests.
        if reset:
            status.skipped_tests = []

        # Run the tests, catching the keyboard interrupt.
        try:
            # Print a header.
            title(file=sys.stdout, text='Unit tests')

            # Run the tests.
            unit_runner = Unit_test_runner(root_path=status.install_path +
                                           os.sep + 'test_suite' + os.sep +
                                           'unit_tests')
            self.runner.category = 'unit'
            self.unit_result = unit_runner.run(self.tests,
                                               runner=self.runner,
                                               list_tests=self.list_tests)

            # Print out a summary of the test suite.
            if summary and not self.list_tests:
                self.summary()

        # Catch the keyboard interrupt.
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt:  Terminating all tests.\n")
            sys.exit(1)

        # All tests were run successfully.
        return self.unit_result
Ejemplo n.º 9
0
    def test_title(self):
        """Test of the lib.text.sectioning.title() function."""

        # Write out the title.
        file = DummyFileObject()
        title(file=file, text='Test title')

        # Read the results.
        lines = file.readlines()
        print("Formatted title lines:  %s" % lines)

        # Check the title.
        real_lines = [
            '\n',
            '\n',
            '==============\n',
            '= Test title =\n',
            '==============\n',
            '\n',
        ]
        self.assertEqual(len(lines), len(real_lines))
        for i in range(len(lines)):
            self.assertEqual(lines[i], real_lines[i])
Ejemplo n.º 10
0
    def run_unit_tests(self, summary=True, reset=True):
        """Execute the unit tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        @keyword reset:     A flag which if True will reset the relax status objects for the tests.
        @type reset:        bool
        @return:            True if the tests were run, False if a KeyboardInterrupt occurred.
        @rtype:             bool
        """

        # Reset the list for skipped tests.
        if reset:
            status.skipped_tests = []

        # Run the tests, catching the keyboard interrupt.
        try:
            # Print a header.
            title(file=sys.stdout, text='Unit tests')

            # Run the tests.
            unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests')
            self.runner.category = 'unit'
            self.unit_result = unit_runner.run(self.tests, runner=self.runner)

            # Print out a summary of the test suite.
            if summary:
                self.summary()

        # Catch the keyboard interrupt.
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt:  Terminating all tests.\n")
            return False

        # All tests were run successfully.
        return True
Ejemplo n.º 11
0
# Inverted frame rotation.
structure.rotate(R=inv(R))

# Add atoms for the CoMs.
structure.add_atom(atom_name='N', res_name='COM', res_num=1, chain_id='A', pos=[0., 0., 0.], element='Ti', pdb_record='HETATM')
structure.add_atom(atom_name='C', res_name='COM', res_num=1, chain_id='B', pos=[0., 0., dist], element='Ti', pdb_record='HETATM')

# Write out the final structure.
structure.write_pdb('base_system.pdb', force=True)

# The new CoM.
structure.com(atom_id="#C-dom")
c_com_new = cdp.com

# The new paramagnetic centre.
structure.load_spins(spin_id="#N-dom:1001")
centre_new = cdp.mol[0].res[0].spin[0].pos

# Printout.
title(file=sys.stdout, text="The base system")
print("The original system:\n")
print("%-25s %-70s" % ("Paramagnetic centre:", centre))
print("%-25s %-70s" % ("C-domain CoM:", c_com))
print("%-25s %-70s" % ("Inter-CoM distance:", dist))
print("%s\n%s" % ("R:", R))
print("\nThe new system:\n")
print("%-25s %-70s" % ("Paramagnetic centre:", centre_new))
print("%-25s %-70s" % ("C-domain CoM:", c_com_new))
print("%-25s %-70s" % ("Inter-CoM distance:", norm(c_com_new - centre_new)))
Ejemplo n.º 12
0
    def run_gui_tests(self, summary=True, reset=True):
        """Execute the GUI tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        @keyword reset:     A flag which if True will reset the relax status objects for the tests.
        @type reset:        bool
        @return:            True if the tests were run, False if a KeyboardInterrupt occurred.
        @rtype:             bool
        """

        # Reset the list for skipped tests.
        if reset:
            status.skipped_tests = []

        # Run the tests, catching the keyboard interrupt.
        try:
            # Print a header.
            title(file=sys.stdout, text='GUI tests')

            # Run the tests.
            if dep_check.wx_module:
                # Set up the GUI if needed (i.e. not in GUI mode already).
                app = wx.GetApp()
                if app == None:
                    # Initialise.
                    app = wx.App(redirect=False)

                    # Build the GUI.
                    app.gui = relax_gui.Main(parent=None, id=-1, title="")

                # Execute the GUI tests.
                gui_runner = GUI_test_runner()
                self.runner.category = 'gui'
                self.gui_result = gui_runner.run(self.tests, runner=self.runner)

                # Clean up for the GUI, if not in GUI mode.
                if status.test_mode:
                    # Terminate the interpreter thread to allow the tests to cleanly exit.
                    interpreter_thread = interpreter.Interpreter()
                    interpreter_thread.exit()

                    # Stop the GUI main loop.
                    app.ExitMainLoop()

            # No wx module installed.
            else:
                print("All GUI tests skipped due to the missing/broken wx module.\n")
                self.gui_result = 'skip'

            # Print out a summary of the test suite.
            if summary:
                self.summary()

        # Catch the keyboard interrupt.
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt:  Terminating all tests.\n")
            return False

        # All tests were run successfully.
        return True
Ejemplo n.º 13
0
    def __init__(self, pipe_name=None, pipe_bundle=None, results_dir=None, models=[MODEL_R2EFF], grid_inc=11, mc_sim_num=500, modsel='AIC', pre_run_dir=None, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True):
        """Perform a full relaxation dispersion analysis for the given list of models.

        @keyword pipe_name:         The name of the data pipe containing all of the data for the analysis.
        @type pipe_name:            str
        @keyword pipe_bundle:       The data pipe bundle to associate all spawned data pipes with.
        @type pipe_bundle:          str
        @keyword results_dir:       The directory where results files are saved.
        @type results_dir:          str
        @keyword models:            The list of relaxation dispersion models to optimise.
        @type models:               list of str
        @keyword grid_inc:          Number of grid search increments.
        @type grid_inc:             int
        @keyword mc_sim_num:        The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
        @type mc_sim_num:           int
        @keyword modsel:            The model selection technique to use in the analysis to determine which model is the best for each spin cluster.  This can currently be one of 'AIC', 'AICc', and 'BIC'.
        @type modsel:               str
        @keyword pre_run_dir:       The optional directory containing the dispersion auto-analysis results from a previous run.  The optimised parameters from these previous results will be used as the starting point for optimisation rather than performing a grid search.  This is essential for when large spin clusters are specified, as a grid search becomes prohibitively expensive with clusters of three or more spins.  At some point a RelaxError will occur because the grid search is impossibly large.  For the cluster specific parameters, i.e. the populations of the states and the exchange parameters, an average value will be used as the starting point.  For all other parameters, the R20 values for each spin and magnetic field, as well as the parameters related to the chemical shift difference dw, the optimised values of the previous run will be directly copied.
        @type pre_run_dir:          None or str
        @keyword insignificance:    The R2eff/R1rho value in rad/s by which to judge insignificance.  If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected.  This does not affect the 'No Rex' model.  Set this value to 0.0 to use all data.  The value will be passed on to the relax_disp.insignificance user function.
        @type insignificance:       float
        @keyword numeric_only:      The class of models to use in the model selection.  The default of False allows all dispersion models to be used in the analysis (no exchange, the analytic models and the numeric models).  The value of True will activate a pure numeric solution - the analytic models will be optimised, as they are very useful for replacing the grid search for the numeric models, but the final model selection will not include them.
        @type numeric_only:         bool
        @keyword mc_sim_all_models: A flag which if True will cause Monte Carlo simulations to be performed for each individual model.  Otherwise Monte Carlo simulations will be reserved for the final model.
        @type mc_sim_all_models:    bool
        @keyword eliminate:         A flag which if True will enable the elimination of failed models and failed Monte Carlo simulations through the eliminate user function.
        @type eliminate:            bool
        """

        # Printout.
        title(file=sys.stdout, text="Relaxation dispersion auto-analysis", prespace=4)

        # Execution lock.
        status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')

        # Set up the analysis status object.
        status.init_auto_analysis(pipe_bundle, type='relax_disp')
        status.current_analysis = pipe_bundle

        # Store the args.
        self.pipe_name = pipe_name
        self.pipe_bundle = pipe_bundle
        self.results_dir = results_dir
        self.models = models
        self.grid_inc = grid_inc
        self.mc_sim_num = mc_sim_num
        self.modsel = modsel
        self.pre_run_dir = pre_run_dir
        self.insignificance = insignificance
        self.numeric_only = numeric_only
        self.mc_sim_all_models = mc_sim_all_models
        self.eliminate = eliminate

        # No results directory, so default to the current directory.
        if not self.results_dir:
            self.results_dir = getcwd()

        # Data checks.
        self.check_vars()

        # Load the interpreter.
        self.interpreter = Interpreter(show_script=False, quit=False, raise_relax_error=True)
        self.interpreter.populate_self()
        self.interpreter.on(verbose=False)

        # Execute.
        self.run()

        # Finish and unlock execution.
        status.auto_analysis[self.pipe_bundle].fin = True
        status.current_analysis = None
        status.exec_lock.release()
Ejemplo n.º 14
0
    def run_gui_tests(self, summary=True, reset=True):
        """Execute the GUI tests.

        @keyword summary:   A flag which if True will cause a summary to be printed.
        @type summary:      bool
        @keyword reset:     A flag which if True will reset the relax status objects for the tests.
        @type reset:        bool
        @return:            True if the tests were run, False if a KeyboardInterrupt occurred.
        @rtype:             bool
        """

        # Reset the list for skipped tests.
        if reset:
            status.skipped_tests = []

        # Run the tests, catching the keyboard interrupt.
        try:
            # Print a header.
            title(file=sys.stdout, text='GUI tests')

            # Run the tests.
            if dep_check.wx_module:
                # Set up the GUI if needed (i.e. not in GUI mode already).
                app = wx.GetApp()
                if app == None:
                    # Initialise.
                    app = wx.App(redirect=False)

                    # Build the GUI.
                    app.gui = relax_gui.Main(parent=None, id=-1, title="")

                # Execute the GUI tests.
                gui_runner = GUI_test_runner()
                self.runner.category = 'gui'
                self.gui_result = gui_runner.run(self.tests,
                                                 runner=self.runner)

                # Clean up for the GUI, if not in GUI mode.
                if status.test_mode:
                    # Terminate the interpreter thread to allow the tests to cleanly exit.
                    interpreter_thread = interpreter.Interpreter()
                    interpreter_thread.exit()

                    # Stop the GUI main loop.
                    app.ExitMainLoop()

            # No wx module installed.
            else:
                print(
                    "All GUI tests skipped due to the missing/broken wx module.\n"
                )
                self.gui_result = 'skip'

            # Print out a summary of the test suite.
            if summary:
                self.summary()

        # Catch the keyboard interrupt.
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt:  Terminating all tests.\n")
            return False

        # All tests were run successfully.
        return self.gui_result
Ejemplo n.º 15
0
    def __init__(self,
                 pipe_name=None,
                 pipe_bundle=None,
                 file_root='rx',
                 results_dir=None,
                 grid_inc=11,
                 mc_sim_num=500,
                 view_plots=True):
        """Perform relaxation curve fitting.

        To use this auto-analysis, a data pipe with all the required data needs to be set up.  This data pipe should contain the following:

            - All the spins loaded.
            - Unresolved spins deselected.
            - All the peak intensities loaded and relaxation delay times set.
            - Either the baseplane noise RMSD values should be set or replicated spectra loaded.

        @keyword pipe_name:     The name of the data pipe containing all of the data for the analysis.
        @type pipe_name:        str
        @keyword pipe_bundle:   The data pipe bundle to associate all spawned data pipes with.
        @type pipe_bundle:      str
        @keyword file_root:     File root of the output filea.
        @type file_root:        str
        @keyword results_dir:   The directory where results files are saved.
        @type results_dir:      str
        @keyword grid_inc:      Number of grid search increments.
        @type grid_inc:         int
        @keyword mc_sim_num:    The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
        @type mc_sim_num:       int
        @keyword view_plots:    Flag to automatically view grace plots after calculation.
        @type view_plots:       bool
        """

        # Initial printout.
        title(file=sys.stdout, text="Relaxation curve-fitting auto-analysis")

        # Safely execute the full protocol.
        try:
            # Execution lock.
            status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')

            # Set up the analysis status object.
            status.init_auto_analysis(pipe_bundle, type='relax_fit')
            status.current_analysis = pipe_bundle

            # Store the args.
            self.pipe_name = pipe_name
            self.pipe_bundle = pipe_bundle
            self.file_root = file_root
            self.results_dir = results_dir
            if self.results_dir:
                self.grace_dir = results_dir + sep + 'grace'
            else:
                self.grace_dir = 'grace'
            self.mc_sim_num = mc_sim_num
            self.grid_inc = grid_inc
            self.view_plots = view_plots

            # Data checks.
            self.check_vars()

            # Set the data pipe to the current data pipe.
            if self.pipe_name != cdp_name():
                switch(self.pipe_name)

            # Load the interpreter.
            self.interpreter = Interpreter(show_script=False,
                                           raise_relax_error=True)
            self.interpreter.populate_self()
            self.interpreter.on(verbose=False)

            # Execute.
            self.run()

        # Clean up.
        finally:
            # Final printout.
            title(
                file=sys.stdout,
                text="Completion of the relaxation curve-fitting auto-analysis"
            )
            print_elapsed_time(time() - status.start_time)

            # Finish and unlock execution.
            status.auto_analysis[self.pipe_bundle].fin = True
            status.current_analysis = None
            status.exec_lock.release()
Ejemplo n.º 16
0
    def __init__(self, data_pipe_full=None, data_pipe_subset=None, pipe_bundle=None, results_dir=None, grid_inc=11, grid_inc_rigid=21, min_algor='simplex', num_int_pts_grid=50, num_int_pts_subset=[20, 100], func_tol_subset=[1e-2, 1e-2], num_int_pts_full=[100, 1000, 200000], func_tol_full=[1e-2, 1e-3, 1e-4], mc_sim_num=500, mc_int_pts=1000, mc_func_tol=1e-3, models=['rigid', 'free rotor', 'rotor', 'iso cone, free rotor', 'iso cone, torsionless', 'iso cone', 'pseudo-ellipse, torsionless', 'pseudo-ellipse']):
        """Perform the full frame order analysis.

        @param data_pipe_full:          The name of the data pipe containing all of the RDC and PCS data.
        @type data_pipe_full:           str
        @param data_pipe_subset:        The name of the data pipe containing all of the RDC data but only a small subset of ~5 PCS points.
        @type data_pipe_subset:         str
        @keyword pipe_bundle:           The data pipe bundle to associate all spawned data pipes with.
        @type pipe_bundle:              str
        @keyword results_dir:           The directory where files are saved in.
        @type results_dir:              str
        @keyword grid_inc:              The number of grid increments to use in the grid search of certain models.
        @type grid_inc:                 int
        @keyword grid_inc_rigid:        The number of grid increments to use in the grid search of the initial rigid model.
        @type grid_inc_rigid:           int
        @keyword min_algor:             The minimisation algorithm (in most cases this should not be changed).
        @type min_algor:                str
        @keyword num_int_pts_grid:      The number of Sobol' points for the PCS numerical integration in the grid searches.
        @type num_int_pts_grid:         int
        @keyword num_int_pts_subset:    The list of the number of Sobol' points for the PCS numerical integration to use iteratively in the optimisations after the grid search (for the PCS data subset).
        @type num_int_pts_subset:       list of int
        @keyword func_tol_subset:       The minimisation function tolerance cutoff to terminate optimisation (for the PCS data subset, see the minimise user function).
        @type func_tol_subset:          list of float
        @keyword num_int_pts_full:      The list of the number of Sobol' points for the PCS numerical integration to use iteratively in the optimisations after the grid search (for all PCS and RDC data).
        @type num_int_pts_full:         list of int
        @keyword func_tol_full:         The minimisation function tolerance cutoff to terminate optimisation (for all PCS and RDC data, see the minimise user function).
        @type func_tol_full:            list of float
        @keyword mc_sim_num:            The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
        @type mc_sim_num:               int
        @keyword mc_int_num:            The number of Sobol' points for the PCS numerical integration during Monte Carlo simulations.
        @type mc_int_num:               int
        @keyword mc_func_tol:           The minimisation function tolerance cutoff to terminate optimisation during Monte Carlo simulations.
        @type mc_func_tol:              float
        @keyword models:                The frame order models to use in the analysis.  The 'rigid' model must be included as this is essential for the analysis.
        @type models:                   list of str
        """

        # Execution lock.
        status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')

        # Initial printout.
        title(file=sys.stdout, text="Frame order auto-analysis", prespace=7)

        # Store the args.
        self.data_pipe_full = data_pipe_full
        self.data_pipe_subset = data_pipe_subset
        self.pipe_bundle = pipe_bundle
        self.grid_inc = grid_inc
        self.grid_inc_rigid = grid_inc_rigid
        self.min_algor = min_algor
        self.num_int_pts_grid = num_int_pts_grid
        self.num_int_pts_subset = num_int_pts_subset
        self.func_tol_subset = func_tol_subset
        self.num_int_pts_full = num_int_pts_full
        self.func_tol_full = func_tol_full
        self.mc_sim_num = mc_sim_num
        self.mc_int_pts = mc_int_pts
        self.mc_func_tol = mc_func_tol
        self.models = models

        # A dictionary and list of the data pipe names.
        self.pipe_name_dict = {}
        self.pipe_name_list = []

        # Project directory (i.e. directory containing the model-free model results and the newly generated files)
        if results_dir:
            self.results_dir = results_dir + sep
        else:
            self.results_dir = getcwd() + sep

        # Data checks.
        self.check_vars()

        # Load the interpreter.
        self.interpreter = Interpreter(show_script=False, quit=False, raise_relax_error=True)
        self.interpreter.populate_self()
        self.interpreter.on(verbose=False)

        # Execute the full protocol.
        try:
            # The nested model optimisation protocol.
            self.nested_models()

            # The final results does not already exist.
            if not self.read_results(model='final', pipe_name='final'):
                # Model selection.
                self.interpreter.model_selection(method='AIC', modsel_pipe='final', pipes=self.pipe_name_list)

                # The number of integration points.
                self.interpreter.frame_order.num_int_pts(num=self.mc_int_pts)

                # Monte Carlo simulations.
                self.interpreter.monte_carlo.setup(number=self.mc_sim_num)
                self.interpreter.monte_carlo.create_data()
                self.interpreter.monte_carlo.initial_values()
                self.interpreter.minimise(self.min_algor, func_tol=self.mc_func_tol, constraints=False)
                self.interpreter.eliminate()
                self.interpreter.monte_carlo.error_analysis()

                # Finish.
                self.interpreter.results.write(file='results', dir=self.results_dir+'final', force=True)

            # Visualisation of the final results.
            self.visualisation(model='final')

        # Clean up.
        finally:
            # Finish and unlock execution.
            status.exec_lock.release()

        # Save the final program state.
        self.interpreter.state.save('final_state', dir=self.results_dir, force=True)
Ejemplo n.º 17
0
structure.add_atom(atom_name='C',
                   res_name='COM',
                   res_num=1,
                   chain_id='B',
                   pos=[0., 0., dist],
                   element='Ti',
                   pdb_record='HETATM')

# Write out the final structure.
structure.write_pdb('base_system.pdb', force=True)

# The new CoM.
structure.com(atom_id="#C-dom")
c_com_new = cdp.com

# The new paramagnetic centre.
structure.load_spins(spin_id="#N-dom:1001")
centre_new = cdp.mol[0].res[0].spin[0].pos

# Printout.
title(file=sys.stdout, text="The base system")
print("The original system:\n")
print("%-25s %-70s" % ("Paramagnetic centre:", centre))
print("%-25s %-70s" % ("C-domain CoM:", c_com))
print("%-25s %-70s" % ("Inter-CoM distance:", dist))
print("%s\n%s" % ("R:", R))
print("\nThe new system:\n")
print("%-25s %-70s" % ("Paramagnetic centre:", centre_new))
print("%-25s %-70s" % ("C-domain CoM:", c_com_new))
print("%-25s %-70s" % ("Inter-CoM distance:", norm(c_com_new - centre_new)))
Ejemplo n.º 18
0
    def __init__(self,
                 pipe_name=None,
                 pipe_bundle=None,
                 results_dir=None,
                 models=[MODEL_R2EFF],
                 grid_inc=11,
                 mc_sim_num=500,
                 exp_mc_sim_num=None,
                 modsel='AIC',
                 pre_run_dir=None,
                 optimise_r2eff=False,
                 insignificance=0.0,
                 numeric_only=False,
                 mc_sim_all_models=False,
                 eliminate=True,
                 set_grid_r20=False,
                 r1_fit=False):
        """Perform a full relaxation dispersion analysis for the given list of models.

        @keyword pipe_name:                 The name of the data pipe containing all of the data for the analysis.
        @type pipe_name:                    str
        @keyword pipe_bundle:               The data pipe bundle to associate all spawned data pipes with.
        @type pipe_bundle:                  str
        @keyword results_dir:               The directory where results files are saved.
        @type results_dir:                  str
        @keyword models:                    The list of relaxation dispersion models to optimise.
        @type models:                       list of str
        @keyword grid_inc:                  Number of grid search increments.  If set to None, then the grid search will be turned off and the default parameter values will be used instead.
        @type grid_inc:                     int or None
        @keyword mc_sim_num:                The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
        @type mc_sim_num:                   int
        @keyword exp_mc_sim_num:            The number of Monte Carlo simulations for the error analysis in the 'R2eff' model when exponential curves are fitted.  This defaults to the value of the mc_sim_num argument when not given.  When set to '-1', the R2eff errors are estimated from the Covariance matrix.  For the 2-point fixed-time calculation for the 'R2eff' model, this argument is ignored.
        @type exp_mc_sim_num:               int or None
        @keyword modsel:                    The model selection technique to use in the analysis to determine which model is the best for each spin cluster.  This can currently be one of 'AIC', 'AICc', and 'BIC'.
        @type modsel:                       str
        @keyword pre_run_dir:               The optional directory containing the dispersion auto-analysis results from a previous run.  The optimised parameters from these previous results will be used as the starting point for optimisation rather than performing a grid search.  This is essential for when large spin clusters are specified, as a grid search becomes prohibitively expensive with clusters of three or more spins.  At some point a RelaxError will occur because the grid search is impossibly large.  For the cluster specific parameters, i.e. the populations of the states and the exchange parameters, an average value will be used as the starting point.  For all other parameters, the R20 values for each spin and magnetic field, as well as the parameters related to the chemical shift difference dw, the optimised values of the previous run will be directly copied.
        @type pre_run_dir:                  None or str
        @keyword optimise_r2eff:            Flag to specify if the read previous R2eff results should be optimised.  For R1rho models where the error of R2eff values are determined by Monte-Carlo simulations, it can be valuable to make an initial R2eff run with a high number of Monte-Carlo simulations.  Any subsequent model analysis can then be based on these R2eff values, without optimising the R2eff values.
        @type optimise_r2eff:               bool
        @keyword insignificance:            The R2eff/R1rho value in rad/s by which to judge insignificance.  If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected.  This does not affect the 'No Rex' model.  Set this value to 0.0 to use all data.  The value will be passed on to the relax_disp.insignificance user function.
        @type insignificance:               float
        @keyword numeric_only:              The class of models to use in the model selection.  The default of False allows all dispersion models to be used in the analysis (no exchange, the analytic models and the numeric models).  The value of True will activate a pure numeric solution - the analytic models will be optimised, as they are very useful for replacing the grid search for the numeric models, but the final model selection will not include them.
        @type numeric_only:                 bool
        @keyword mc_sim_all_models:         A flag which if True will cause Monte Carlo simulations to be performed for each individual model.  Otherwise Monte Carlo simulations will be reserved for the final model.
        @type mc_sim_all_models:            bool
        @keyword eliminate:                 A flag which if True will enable the elimination of failed models and failed Monte Carlo simulations through the eliminate user function.
        @type eliminate:                    bool
        @keyword set_grid_r20:              A flag which if True will set the grid R20 values from the minimum R2eff values through the r20_from_min_r2eff user function. This will speed up the grid search with a factor GRID_INC^(Nr_spec_freq). For a CPMG experiment with two fields and standard GRID_INC=21, the speed-up is a factor 441.
        @type set_grid_r20:                 bool
        @keyword r1_fit:                    A flag which if True will activate R1 parameter fitting via relax_disp.r1_fit for the models that support it.  If False, then the relax_disp.r1_fit user function will not be called.
        """

        # Initial printout.
        title(file=sys.stdout,
              text="Relaxation dispersion auto-analysis",
              prespace=4)

        # Safely execute the full protocol.
        try:
            # Execution lock.
            status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')

            # Set up the analysis status object.
            status.init_auto_analysis(pipe_bundle, type='relax_disp')
            status.current_analysis = pipe_bundle

            # Store the args.
            self.pipe_name = pipe_name
            self.pipe_bundle = pipe_bundle
            self.results_dir = results_dir
            self.grid_inc = grid_inc
            self.mc_sim_num = mc_sim_num
            self.exp_mc_sim_num = exp_mc_sim_num
            self.models = models
            self.modsel = modsel
            self.pre_run_dir = pre_run_dir
            self.optimise_r2eff = optimise_r2eff
            self.insignificance = insignificance
            self.set_grid_r20 = set_grid_r20
            self.numeric_only = numeric_only
            self.mc_sim_all_models = mc_sim_all_models
            self.eliminate = eliminate
            self.r1_fit = r1_fit

            # No results directory, so default to the current directory.
            if not self.results_dir:
                self.results_dir = getcwd()

            # Data checks.
            self.check_vars()

            # Check for numerical model using numpy version under 1.8.
            # This will result in slow "for loop" calculation through data, making the analysis 5-6 times slower.
            self.check_numpy_less_1_8_and_numerical_model()

            # Load the interpreter.
            self.interpreter = Interpreter(show_script=False,
                                           raise_relax_error=True)
            self.interpreter.populate_self()
            self.interpreter.on(verbose=False)

            # Execute.
            self.run()

        # Clean up.
        finally:
            # Final printout.
            title(file=sys.stdout,
                  text="Completion of the relaxation dispersion auto-analysis",
                  prespace=4)
            print_elapsed_time(time() - status.start_time)

            # Finish and unlock execution.
            status.auto_analysis[self.pipe_bundle].fin = True
            status.current_analysis = None
            status.exec_lock.release()
Ejemplo n.º 19
0
    def __init__(self, pipe_name=None, pipe_bundle=None, results_dir=None, models=[MODEL_R2EFF], grid_inc=11, mc_sim_num=500, exp_mc_sim_num=None, modsel='AIC', pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=False, r1_fit=False):
        """Perform a full relaxation dispersion analysis for the given list of models.

        @keyword pipe_name:                 The name of the data pipe containing all of the data for the analysis.
        @type pipe_name:                    str
        @keyword pipe_bundle:               The data pipe bundle to associate all spawned data pipes with.
        @type pipe_bundle:                  str
        @keyword results_dir:               The directory where results files are saved.
        @type results_dir:                  str
        @keyword models:                    The list of relaxation dispersion models to optimise.
        @type models:                       list of str
        @keyword grid_inc:                  Number of grid search increments.  If set to None, then the grid search will be turned off and the default parameter values will be used instead.
        @type grid_inc:                     int or None
        @keyword mc_sim_num:                The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
        @type mc_sim_num:                   int
        @keyword exp_mc_sim_num:            The number of Monte Carlo simulations for the error analysis in the 'R2eff' model when exponential curves are fitted.  This defaults to the value of the mc_sim_num argument when not given.  When set to '-1', the R2eff errors are estimated from the Covariance matrix.  For the 2-point fixed-time calculation for the 'R2eff' model, this argument is ignored.
        @type exp_mc_sim_num:               int or None
        @keyword modsel:                    The model selection technique to use in the analysis to determine which model is the best for each spin cluster.  This can currently be one of 'AIC', 'AICc', and 'BIC'.
        @type modsel:                       str
        @keyword pre_run_dir:               The optional directory containing the dispersion auto-analysis results from a previous run.  The optimised parameters from these previous results will be used as the starting point for optimisation rather than performing a grid search.  This is essential for when large spin clusters are specified, as a grid search becomes prohibitively expensive with clusters of three or more spins.  At some point a RelaxError will occur because the grid search is impossibly large.  For the cluster specific parameters, i.e. the populations of the states and the exchange parameters, an average value will be used as the starting point.  For all other parameters, the R20 values for each spin and magnetic field, as well as the parameters related to the chemical shift difference dw, the optimised values of the previous run will be directly copied.
        @type pre_run_dir:                  None or str
        @keyword optimise_r2eff:            Flag to specify if the read previous R2eff results should be optimised.  For R1rho models where the error of R2eff values are determined by Monte-Carlo simulations, it can be valuable to make an initial R2eff run with a high number of Monte-Carlo simulations.  Any subsequent model analysis can then be based on these R2eff values, without optimising the R2eff values.
        @type optimise_r2eff:               bool
        @keyword insignificance:            The R2eff/R1rho value in rad/s by which to judge insignificance.  If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected.  This does not affect the 'No Rex' model.  Set this value to 0.0 to use all data.  The value will be passed on to the relax_disp.insignificance user function.
        @type insignificance:               float
        @keyword numeric_only:              The class of models to use in the model selection.  The default of False allows all dispersion models to be used in the analysis (no exchange, the analytic models and the numeric models).  The value of True will activate a pure numeric solution - the analytic models will be optimised, as they are very useful for replacing the grid search for the numeric models, but the final model selection will not include them.
        @type numeric_only:                 bool
        @keyword mc_sim_all_models:         A flag which if True will cause Monte Carlo simulations to be performed for each individual model.  Otherwise Monte Carlo simulations will be reserved for the final model.
        @type mc_sim_all_models:            bool
        @keyword eliminate:                 A flag which if True will enable the elimination of failed models and failed Monte Carlo simulations through the eliminate user function.
        @type eliminate:                    bool
        @keyword set_grid_r20:              A flag which if True will set the grid R20 values from the minimum R2eff values through the r20_from_min_r2eff user function. This will speed up the grid search with a factor GRID_INC^(Nr_spec_freq). For a CPMG experiment with two fields and standard GRID_INC=21, the speed-up is a factor 441.
        @type set_grid_r20:                 bool
        @keyword r1_fit:                    A flag which if True will activate R1 parameter fitting via relax_disp.r1_fit for the models that support it.  If False, then the relax_disp.r1_fit user function will not be called.
        """

        # Printout.
        title(file=sys.stdout, text="Relaxation dispersion auto-analysis", prespace=4)

        # Execution lock.
        status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')

        # Set up the analysis status object.
        status.init_auto_analysis(pipe_bundle, type='relax_disp')
        status.current_analysis = pipe_bundle

        # Store the args.
        self.pipe_name = pipe_name
        self.pipe_bundle = pipe_bundle
        self.results_dir = results_dir
        self.grid_inc = grid_inc
        self.mc_sim_num = mc_sim_num
        self.exp_mc_sim_num = exp_mc_sim_num
        self.models = models
        self.modsel = modsel
        self.pre_run_dir = pre_run_dir
        self.optimise_r2eff = optimise_r2eff
        self.insignificance = insignificance
        self.set_grid_r20 = set_grid_r20
        self.numeric_only = numeric_only
        self.mc_sim_all_models = mc_sim_all_models
        self.eliminate = eliminate
        self.r1_fit = r1_fit

        # No results directory, so default to the current directory.
        if not self.results_dir:
            self.results_dir = getcwd()

        # Data checks.
        self.check_vars()

        # Check for numerical model using numpy version under 1.8.
        # This will result in slow "for loop" calculation through data, making the analysis 5-6 times slower.
        self.check_numpy_less_1_8_and_numerical_model()

        # Load the interpreter.
        self.interpreter = Interpreter(show_script=False, raise_relax_error=True)
        self.interpreter.populate_self()
        self.interpreter.on(verbose=False)

        # Execute.
        try:
            self.run()

        # Finish and unlock execution.
        finally:
            status.auto_analysis[self.pipe_bundle].fin = True
            status.current_analysis = None
            status.exec_lock.release()
Ejemplo n.º 20
0
Archivo: noe.py Proyecto: tlinnet/relax
    def __init__(self,
                 pipe_name=None,
                 pipe_bundle=None,
                 file_root='noe',
                 results_dir=None,
                 save_state=True):
        """Perform relaxation curve fitting.

        To use this auto-analysis, a data pipe with all the required data needs to be set up.  This data pipe should contain the following:

            - All the spins loaded.
            - Unresolved spins deselected.
            - The NOE peak intensities from the saturated and reference spectra.
            - Either the baseplane noise RMSD values should be set or replicated spectra loaded.

        @keyword pipe_name:     The name of the data pipe containing all of the data for the analysis.
        @type pipe_name:        str
        @keyword pipe_bundle:   The data pipe bundle to associate all spawned data pipes with.
        @type pipe_bundle:      str
        @keyword file_root:     File root of the output filea.
        @type file_root:        str
        @keyword results_dir:   The directory where results files are saved.
        @type results_dir:      str
        @keyword save_state:    A flag which if True will cause a relax save state to be created at the end of the analysis.
        @type save_state:       bool
        """

        # Initial printout.
        title(file=sys.stdout, text="Steady-state NOE auto-analysis")

        # Safely execute the full protocol.
        try:
            # Execution lock.
            status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')

            # Set up the analysis status object.
            status.init_auto_analysis(pipe_bundle, type='noe')
            status.current_analysis = pipe_bundle

            # Store the args.
            self.save_state = save_state
            self.pipe_name = pipe_name
            self.pipe_bundle = pipe_bundle
            self.file_root = file_root
            self.results_dir = results_dir
            if self.results_dir:
                self.grace_dir = results_dir + sep + 'grace'
            else:
                self.grace_dir = 'grace'

            # Data checks.
            self.check_vars()

            # Set the data pipe to the current data pipe.
            if self.pipe_name != cdp_name():
                switch(self.pipe_name)

            # Load the interpreter.
            self.interpreter = Interpreter(show_script=False,
                                           raise_relax_error=True)
            self.interpreter.populate_self()
            self.interpreter.on(verbose=False)

            # Execute.
            self.run()

        # Clean up.
        finally:
            # Final printout.
            title(file=sys.stdout,
                  text="Completion of the steady-state NOE auto-analysis")
            print_elapsed_time(time() - status.start_time)

            # Finish and unlock execution.
            status.auto_analysis[self.pipe_bundle].fin = True
            status.current_analysis = None
            status.exec_lock.release()
Ejemplo n.º 21
0
    def __init__(self,
                 stage=1,
                 results_dir=None,
                 num_ens=10000,
                 num_models=10,
                 configs=None,
                 snapshot_dir='snapshots',
                 snapshot_min=None,
                 snapshot_max=None,
                 pseudo=None,
                 noe_file=None,
                 noe_norm=None,
                 rdc_name=None,
                 rdc_file=None,
                 rdc_spin_id1_col=None,
                 rdc_spin_id2_col=None,
                 rdc_data_col=None,
                 rdc_error_col=None,
                 bond_length=None,
                 bond_length_file=None,
                 log=None,
                 bucket_num=200,
                 lower_lim_noe=0.0,
                 upper_lim_noe=600.0,
                 lower_lim_rdc=0.0,
                 upper_lim_rdc=1.0):
        """Set up for the stereochemistry analysis.

        @keyword stage:             Stage of analysis (see the module docstring above for the options).  
        @type stage:                int
        @keyword results_dir:       The optional directory to place all results files into.
        @type results_dir:          None or str
        @keyword num_ens:           Number of ensembles.
        @type num_ens:              int
        @keyword num_models:        Ensemble size.
        @type num_models:           int
        @keyword configs:           All the configurations.
        @type configs:              list of str
        @keyword snapshot_dir:      Snapshot directories (corresponding to the configurations).
        @type snapshot_dir:         list of str
        @keyword snapshot_min:      The number of the first snapshots (corresponding to the configurations).
        @type snapshot_min:         list of int
        @keyword snapshot_max:      The number of the last snapshots (corresponding to the configurations).
        @type snapshot_max:         list of int
        @keyword pseudo:            The list of pseudo-atoms.  Each element is a list of the pseudo-atom name and a list of all those atoms forming the pseudo-atom.  For example, pseudo = [["Q7", ["@H16", "@H17", "@H18"]], ["Q9", ["@H20", "@H21", "@H22"]]].
        @type pseudo:               list of list of str and list of str
        @keyword noe_file:          The name of the NOE restraint file.
        @type noe_file:             str
        @keyword noe_norm:          The NOE normalisation factor (equal to the sum of all NOEs squared).
        @type noe_norm:             float
        @keyword rdc_name:          The label for this RDC data set.
        @type rdc_name:             str
        @keyword rdc_file:          The name of the RDC file.
        @type rdc_file:             str
        @keyword rdc_spin_id1_col:  The spin ID column of the first spin in the RDC file.
        @type rdc_spin_id1_col:     None or int
        @keyword rdc_spin_id2_col:  The spin ID column of the second spin in the RDC file.
        @type rdc_spin_id2_col:     None or int
        @keyword rdc_data_col:      The data column of the RDC file.
        @type rdc_data_col:         int
        @keyword rdc_error_col:     The error column of the RDC file.
        @type rdc_error_col:        int
        @keyword bond_length:       The bond length value in meters.  This overrides the bond_length_file argument.
        @type bond_length:          float or None
        @keyword bond_length_file:  The file of bond lengths for each atom pair in meters.  The first and second columns must be the spin ID strings and the third column must contain the data.
        @type bond_length_file:     float or None
        @keyword log:               Log file output flag (only for certain stages).
        @type log:                  bool
        @keyword bucket_num:        Number of buckets for the distribution plots.
        @type bucket_num:           int
        @keyword lower_lim_noe:     Distribution plot limits.
        @type lower_lim_noe:        int
        @keyword upper_lim_noe:     Distribution plot limits.
        @type upper_lim_noe:        int
        @keyword lower_lim_rdc:     Distribution plot limits.
        @type lower_lim_rdc:        int
        @keyword upper_lim_rdc:     Distribution plot limits.
        @type upper_lim_rdc:        int
        """

        # Initial printout.
        title(file=sys.stdout, text="Stereochemistry auto-analysis")

        # Safely execute the full protocol.
        try:
            # Execution lock.
            status.exec_lock.acquire('auto stereochem analysis',
                                     mode='auto-analysis')

            # Set up the analysis status object.
            status.init_auto_analysis('stereochem', type='stereochem')
            status.current_analysis = 'auto stereochem analysis'

            # Store all the args.
            self.stage = stage
            self.results_dir = results_dir
            self.num_ens = num_ens
            self.num_models = num_models
            self.configs = configs
            self.snapshot_dir = snapshot_dir
            self.snapshot_min = snapshot_min
            self.snapshot_max = snapshot_max
            self.pseudo = pseudo
            self.noe_file = noe_file
            self.noe_norm = noe_norm
            self.rdc_name = rdc_name
            self.rdc_file = rdc_file
            self.rdc_spin_id1_col = rdc_spin_id1_col
            self.rdc_spin_id2_col = rdc_spin_id2_col
            self.rdc_data_col = rdc_data_col
            self.rdc_error_col = rdc_error_col
            self.bond_length = bond_length
            self.bond_length_file = bond_length_file
            self.log = log
            self.bucket_num = bucket_num
            self.lower_lim_noe = lower_lim_noe
            self.upper_lim_noe = upper_lim_noe
            self.lower_lim_rdc = lower_lim_rdc
            self.upper_lim_rdc = upper_lim_rdc

            # Load the interpreter.
            self.interpreter = Interpreter(show_script=False,
                                           raise_relax_error=True)
            self.interpreter.populate_self()
            self.interpreter.on(verbose=False)

            # Create the results directory.
            if self.results_dir:
                mkdir_nofail(self.results_dir)

            # Or use the current working directory.
            else:
                self.results_dir = getcwd()

            # Create a directory for log files.
            if self.log:
                mkdir_nofail(self.results_dir + sep + "logs")

        # Clean up.
        finally:
            # Final printout.
            title(file=sys.stdout,
                  text="Completion of the stereochemistry auto-analysis")
            print_elapsed_time(time() - status.start_time)

            # Finish and unlock execution.
            status.auto_analysis['stereochem'].fin = True
            status.current_analysis = None
            status.exec_lock.release()