Esempio n. 1
0
    def test_nesting_model_cpmg_2(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test numerical full model return.
        # Define all the models tested in the analysis.
        self_models = [
            MODEL_R2EFF, MODEL_NOREX, MODEL_CR72, MODEL_CR72_FULL, MODEL_IT99,
            MODEL_TSMFK01, MODEL_B14, MODEL_B14_FULL,
            MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_3D,
            MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_STAR,
            MODEL_NS_CPMG_2SITE_STAR_FULL
        ]

        # Define which current model is selected
        model = MODEL_NS_CPMG_2SITE_STAR_FULL
        model_nest = MODEL_NS_CPMG_2SITE_3D_FULL

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1].model,
            model_nest)
Esempio n. 2
0
    def test_nesting_model_cpmg_3(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test silico simple return from a full model request.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_B14_FULL]

        # Define which current model is selected
        model = MODEL_B14_FULL
        model_nest = MODEL_NS_CPMG_2SITE_EXPANDED

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1].model, model_nest)
Esempio n. 3
0
    def test_nesting_model_cpmg_2(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test numerical full model return.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_CR72, MODEL_CR72_FULL, MODEL_IT99, MODEL_TSMFK01, MODEL_B14, MODEL_B14_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_3D, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_STAR, MODEL_NS_CPMG_2SITE_STAR_FULL]

        # Define which current model is selected
        model = MODEL_NS_CPMG_2SITE_STAR_FULL
        model_nest = MODEL_NS_CPMG_2SITE_3D_FULL

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1].model, model_nest)
Esempio n. 4
0
    def test_nesting_model_r1rho_4(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for R1rho experiments."""

        ## Test MODEL_TP02 model request, when model are all R1rho models with fitted R1, and MODEL_DPL94 was fitted first.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02]

        # Define which current model is selected
        model = MODEL_TP02
        model_nest = None

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1], model_nest)
Esempio n. 5
0
    def test_nesting_model_r1rho_1(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for R1rho experiments."""

        ## Test MODEL_MP05 model request, when models are all R1rho models with fitted R1.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]

        # Define which current model is selected
        model = MODEL_MP05
        model_nest = MODEL_TAP03

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1].model, model_nest)
Esempio n. 6
0
    def test_nesting_model_r1rho_ns_3(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for numerical R1rho experiments."""

        ## Test MODEL_NS_R1RHO_3SITE model request, when models are MODEL_NS_R1RHO_2SITE.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE]

        # Define which current model is selected
        model = MODEL_NS_R1RHO_3SITE
        model_nest = MODEL_NS_R1RHO_2SITE

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1].model, model_nest)
Esempio n. 7
0
    def test_nesting_model_cpmg_mmq_2(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG MMQ experiments."""

        ## Test MODEL_NS_MMQ_3SITE_LINEAR model request, when models are MODEL_NS_MMQ_2SITE.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_NS_MMQ_2SITE, MODEL_NS_MMQ_3SITE_LINEAR]

        # Define which current model is selected
        model = MODEL_NS_MMQ_3SITE_LINEAR
        model_nest = MODEL_NS_MMQ_2SITE

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1].model, model_nest)
Esempio n. 8
0
    def test_nesting_model_cpmg_4(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test LM63 model request.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_LM63, MODEL_LM63_3SITE]

        # Define which current model is selected
        model = MODEL_LM63_3SITE
        model_nest = MODEL_LM63

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1].model, model_nest)
Esempio n. 9
0
    def test_nesting_model_cpmg_9(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test MODEL_CR72 model request, when models are MODEL_IT99.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_IT99, MODEL_CR72]

        # Define which current model is selected
        model = MODEL_CR72
        model_nest = None

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(nesting_model(self_models=self_models, model=model)[1], model_nest)
Esempio n. 10
0
    def test_nesting_model_r1rho_4(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for R1rho experiments."""

        ## Test MODEL_TP02 model request, when model are all R1rho models with fitted R1, and MODEL_DPL94 was fitted first.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02]

        # Define which current model is selected
        model = MODEL_TP02
        model_nest = None

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1], model_nest)
Esempio n. 11
0
    def test_nesting_model_cpmg_mmq_1(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG MMQ experiments."""

        ## Test MODEL_MMQ_CR72 model request, when models are MODEL_CR72.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_CR72, MODEL_MMQ_CR72]

        # Define which current model is selected
        model = MODEL_MMQ_CR72
        model_nest = None

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1], model_nest)
Esempio n. 12
0
    def test_nesting_model_cpmg_4(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test LM63 model request.
        # Define all the models tested in the analysis.
        self_models = [MODEL_R2EFF, MODEL_NOREX, MODEL_LM63, MODEL_LM63_3SITE]

        # Define which current model is selected
        model = MODEL_LM63_3SITE
        model_nest = MODEL_LM63

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1].model,
            model_nest)
Esempio n. 13
0
    def test_nesting_model_cpmg_3(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test silico simple return from a full model request.
        # Define all the models tested in the analysis.
        self_models = [
            MODEL_R2EFF, MODEL_NOREX, MODEL_NS_CPMG_2SITE_EXPANDED,
            MODEL_B14_FULL
        ]

        # Define which current model is selected
        model = MODEL_B14_FULL
        model_nest = MODEL_NS_CPMG_2SITE_EXPANDED

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1].model,
            model_nest)
Esempio n. 14
0
    def test_nesting_model_r1rho_1(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for R1rho experiments."""

        ## Test MODEL_MP05 model request, when models are all R1rho models with fitted R1.
        # Define all the models tested in the analysis.
        self_models = [
            MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03,
            MODEL_MP05, MODEL_NS_R1RHO_2SITE
        ]

        # Define which current model is selected
        model = MODEL_MP05
        model_nest = MODEL_TAP03

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1].model,
            model_nest)
Esempio n. 15
0
    def test_nesting_model_r1rho_ns_3(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for numerical R1rho experiments."""

        ## Test MODEL_NS_R1RHO_3SITE model request, when models are MODEL_NS_R1RHO_2SITE.
        # Define all the models tested in the analysis.
        self_models = [
            MODEL_R2EFF, MODEL_NOREX, MODEL_NS_R1RHO_2SITE,
            MODEL_NS_R1RHO_3SITE
        ]

        # Define which current model is selected
        model = MODEL_NS_R1RHO_3SITE
        model_nest = MODEL_NS_R1RHO_2SITE

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1].model,
            model_nest)
Esempio n. 16
0
    def test_nesting_model_cpmg_6(self):
        """Unit test of function nesting_model, which determine which model to nest from, testing for CPMG experiments."""

        ## Test MODEL_CR72_FULL model request, when models are ordered different.
        # Define all the models tested in the analysis.
        self_models = [
            MODEL_R2EFF, MODEL_NOREX, MODEL_B14, MODEL_B14_FULL, MODEL_CR72,
            MODEL_CR72_FULL
        ]

        # Define which current model is selected
        model = MODEL_CR72_FULL
        model_nest = MODEL_B14_FULL

        print("self.models is:", self_models)
        print("Current model to analyse is:", model)
        print("Expected nest model is:", model_nest)

        # Test the return.
        self.assertEqual(
            nesting_model(self_models=self_models, model=model)[1].model,
            model_nest)
Esempio n. 17
0
    def nesting(self, model=None):
        """Support for model nesting.

        If model nesting is detected, the optimised parameters from the simpler model will be used for the more complex model.  The method will then signal if the nesting condition is met for the model, allowing the grid search to be skipped.


        @keyword model: The model to be optimised.
        @type model:    str
        @return:        True if the model parameters is equivalent to the nested model, and all parameters are copied.  False if none or some of the parameters have been translated from the nested model.  Here the Grid search should still be performed.
        @rtype:         bool
        """

        # Printout.
        subsection(file=sys.stdout,
                   text="Nesting and model equivalence checks",
                   prespace=1)

        # The simpler model.
        model_info, comparable_model_info = nesting_model(
            self_models=self.models, model=model)
        if comparable_model_info != None:
            nested_pipe = self.name_pipe(comparable_model_info.model)
        else:
            nested_pipe = None

        # No nesting.
        if not nested_pipe:
            print("No model nesting or model equivalence detected.")
            return False

        # Copying the parameters to a numerical model from an analytic solution.
        if model_info.eq in [EQ_NUMERIC, EQ_SILICO
                             ] and comparable_model_info.eq == EQ_ANALYTIC:
            analytic = True
        else:
            analytic = False

        # Determine if model is equivalent or nested.
        if model_info.params == comparable_model_info.params:
            equivalent = True
        else:
            equivalent = False

        # Printout.
        if equivalent:
            print(
                "Model equivalence detected, copying the optimised parameters from the '%s' model rather than performing a grid search."
                % comparable_model_info.model)
        else:
            print(
                "Model nesting detected, translating the optimised parameters %s from the '%s' model to the parameters %s of model '%s'.  A grid search is issued for the remaining parameters."
                % (comparable_model_info.params, comparable_model_info.model,
                   model_info.params, model))
        if analytic:
            print("The parameters are copied from a %s model to a %s model." %
                  (comparable_model_info.eq, model_info.eq))

        # Get the dictionary of how the model parameters of the current model can be copied.
        par_dic = nesting_param(
            model_params=model_info.params,
            nested_model_params=comparable_model_info.params)

        # Loop over the parameters in current model.
        for param in model_info.params:
            # Extract how parameter is translated.
            param_conv = par_dic[param]

            # If the param_conv is None, then continue.
            if param_conv == None:
                continue

            print("Copying from parameter '%s' to '%s'." % (param_conv, param))

            # Loop over the spins to copy the parameters.
            for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
                # Get the nested spin.
                nested_spin = return_spin(spin_id=spin_id, pipe=nested_pipe)

                # Set value.
                # Some special conversions.
                if param_conv == '1 - pA':
                    val = 1.0 - getattr(nested_spin, 'pA')

                elif param_conv == '0.0':
                    val = 0.0

                else:
                    val = deepcopy(getattr(nested_spin, param_conv))

                # Set the attribute.
                setattr(spin, param, val)

        # Determine if model is equivalent, and should not be Grid searched, or if nested, and some parameters are pre-set. Here Grid search should still be issued.
        return equivalent
Esempio n. 18
0
    def nesting(self, model=None):
        """Support for model nesting.

        If model nesting is detected, the optimised parameters from the simpler model will be used for the more complex model.  The method will then signal if the nesting condition is met for the model, allowing the grid search to be skipped.


        @keyword model: The model to be optimised.
        @type model:    str
        @return:        True if the model parameters is equivalent to the nested model, and all parameters are copied.  False if none or some of the parameters have been translated from the nested model.  Here the Grid search should still be performed.
        @rtype:         bool
        """

        # Printout. 
        subsection(file=sys.stdout, text="Nesting and model equivalence checks", prespace=1)

        # The simpler model.
        model_info, comparable_model_info = nesting_model(self_models=self.models, model=model)
        if comparable_model_info != None:
            nested_pipe = self.name_pipe(comparable_model_info.model)
        else:
            nested_pipe = None

        # No nesting.
        if not nested_pipe:
            print("No model nesting or model equivalence detected.")
            return False

        # Copying the parameters to a numerical model from an analytic solution.
        if model_info.eq in [EQ_NUMERIC, EQ_SILICO] and comparable_model_info.eq == EQ_ANALYTIC:
            analytic = True
        else:
            analytic = False

        # Determine if model is equivalent or nested.
        if model_info.params == comparable_model_info.params:
            equivalent = True
        else:
            equivalent = False

        # Printout.
        if equivalent:
            print("Model equivalence detected, copying the optimised parameters from the '%s' model rather than performing a grid search." % comparable_model_info.model)
        else:
            print("Model nesting detected, translating the optimised parameters %s from the '%s' model to the parameters %s of model '%s'.  A grid search is issued for the remaining parameters." % (comparable_model_info.params, comparable_model_info.model, model_info.params, model))
        if analytic:
            print("The parameters are copied from a %s model to a %s model." % (comparable_model_info.eq, model_info.eq))

        # Get the dictionary of how the model parameters of the current model can be copied.
        par_dic = nesting_param(model_params=model_info.params, nested_model_params=comparable_model_info.params)

        # Loop over the parameters in current model.
        for param in model_info.params:
            # Extract how parameter is translated.
            param_conv = par_dic[param]

            # If the param_conv is None, then continue.
            if param_conv == None:
                continue

            print("Copying from parameter '%s' to '%s'." % (param_conv, param))

            # Loop over the spins to copy the parameters.
            for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
                # Get the nested spin.
                nested_spin = return_spin(spin_id=spin_id, pipe=nested_pipe)

                # Set value.
                # Some special conversions.
                if param_conv == '1 - pA':
                    val = 1.0 - getattr(nested_spin, 'pA')

                elif param_conv == '0.0':
                    val = 0.0

                else:
                    val = deepcopy(getattr(nested_spin, param_conv))

                # Set the attribute.
                setattr(spin, param, val)

        # Determine if model is equivalent, and should not be Grid searched, or if nested, and some parameters are pre-set. Here Grid search should still be issued.
        return equivalent