Package test_suite :: Package unit_tests :: Package _target_functions :: Module test_n_state_model
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._target_functions.test_n_state_model

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from math import pi 
 24  from numpy import array, float64, ones 
 25  from unittest import TestCase 
 26   
 27  # relax module imports. 
 28  from target_functions.n_state_model import N_state_opt 
 29   
 30   
31 -class Test_n_state_model(TestCase):
32 """Unit tests for the target_functions.n_state_model relax module.""" 33
34 - def test_func1(self):
35 """Unit test 1 of the func() method. 36 37 The number of states is 2 and the number of tensors is 3. All states are equi-probable with 38 Euler rotations of {0, 0, 0}, hence the reduced tensors should be the same size as the full 39 tensors. The target function is designed to be zero. 40 """ 41 42 # Init vals. 43 N = 2 44 init_params = array([0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64) 45 full_tensors = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64) 46 red_data = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64) 47 err = ones(3*5, float64) 48 full_in_ref_frame = [1, 1, 1] 49 50 # Set up the class. 51 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame) 52 53 # Call the target function 3 times. 54 for i in range(3): 55 # Target function. 56 chi2 = model.func_2domain(init_params) 57 58 # Test that the chi2 value is zero each time! 59 self.assertEqual(chi2, 0.0)
60 61
62 - def test_func2(self):
63 """Unit test 2 of the func() method. 64 65 The number of states is 2 and the number of tensors is 3. All states are equi-probable with 66 Euler rotations of {0, 0, 0}, hence the reduced tensors should be the same size as the full 67 tensors. The target function is designed to be one. 68 """ 69 70 # Init vals. 71 N = 2 72 init_params = array([0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64) 73 full_tensors = array([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], float64) 74 red_data = array([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], float64) 75 err = ones(3*5, float64) 76 full_in_ref_frame = [1, 1, 1] 77 78 # Set up the class. 79 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame) 80 81 # Call the target function 3 times. 82 for i in range(3): 83 # Target function. 84 chi2 = model.func_2domain(init_params) 85 86 # Test that the chi2 value is zero each time! 87 self.assertEqual(chi2, 1.0)
88 89
90 - def test_func3(self):
91 """Unit test 3 of the func() method. 92 93 The number of states is 2 and the number of tensors is 3. The first state has a prob of 1.0 94 with Euler rotations of {90, 0, 0}, hence the reduced tensors should be the same size as the full 95 tensors but rotated by 90 degrees. The target function is designed to be zero. 96 """ 97 98 # Init vals. 99 N = 2 100 init_params = array([1.0, -pi/2.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64) 101 full_tensors = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64) 102 red_data = array([0.5, 1.0, 0.0, 0.0, 0.0, 0.5, 1.0, -1.0, 0.0, 0.0, 0.5, 1.0, 0.0, 0.0, 1.0], float64) 103 err = ones(3*5, float64) 104 full_in_ref_frame = [1, 1, 1] 105 106 # Set up the class. 107 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame) 108 109 # Call the target function 3 times. 110 for i in range(3): 111 # Target function. 112 chi2 = model.func_2domain(init_params) 113 114 # Test that the chi2 value is zero each time! 115 self.assertAlmostEqual(chi2, 0.0)
116 117
118 - def test_func4(self):
119 """Unit test 4 of the func() method. 120 121 The number of states is 2 and the number of tensors is 3. All states are equi-probable with 122 Euler rotations of {90, 0, 0} for only the first. The target function is designed to be 123 zero. 124 """ 125 126 # Init vals. 127 N = 2 128 init_params = array([0.5, -pi/2.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64) 129 full_tensors = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.0], float64) 130 red_data = array([0.75, 0.75, 0.0, 0.0, 0.0, 0.75, 0.75, 0.0, 0.0, 0.0, 0.75, 0.75, 0.0, 0.5, 0.5], float64) 131 err = ones(3*5, float64) 132 full_in_ref_frame = [1, 1, 1] 133 134 # Set up the class. 135 model = N_state_opt(model='2-domain', N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err, full_in_ref_frame=full_in_ref_frame) 136 137 # Call the target function 3 times. 138 for i in range(3): 139 # Target function. 140 chi2 = model.func_2domain(init_params) 141 142 # Test that the chi2 value is zero each time! 143 self.assertAlmostEqual(chi2, 0.0)
144