Package test_suite :: Package system_tests :: Module align_tensor
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.align_tensor

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-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 tempfile import mktemp 
 24   
 25  # relax module imports. 
 26  from data import Relax_data_store; ds = Relax_data_store() 
 27  from test_suite.system_tests.base_classes import SystemTestCase 
 28   
 29   
30 -class Align_tensor(SystemTestCase):
31 """Class for testing various aspects specific to the alignment tensors.""" 32
33 - def setUp(self):
34 """Function for initialising a few alignment tensors.""" 35 36 # Create a data pipe. 37 self.interpreter.pipe.create('test', 'N-state') 38 39 # Temp file name. 40 ds.tmpfile = mktemp() 41 42 # Tensor name lists. 43 self.full_list = ['0 full', '1 full', '2 full', '3 full', '4 full'] 44 self.red_list = ['0 red', '1 red', '2 red', '3 red', '4 red'] 45 46 # Error. 47 error = 1.47411211147e-05 48 49 # Tensor lists. 50 self.tensors_full = [ 51 (0.00014221982216882766, -0.00014454300156652134, -0.00070779621164871397, -0.00060161949408277324, 0.00020200800707295083), 52 (-0.00014307694949297205, -0.00039671919293883539, -0.00024724524395487659, 0.00031948292975139144, 0.00018868359624777637), 53 (-0.00022967898444150887, -0.00027171643813494106, -0.00021961563147411279, 0.00010337393266477703, 0.00029030226175831515), 54 (0.00043690692358615301, -0.00034379559287467062, -0.00019359695171683388, 0.00030194133983804048, -6.314162250164486e-05), 55 (-0.00026249527958822807, 0.00073561736796410628, 6.3975419225898133e-05, 6.2788017118057252e-05, 0.00020119758245770023) 56 ] 57 self.tensors_red = [ 58 (-0.0004037026160192775, 0.00023172423501111316, -0.00020915186581478394, -0.00028817367472760139, -8.7172337025481604e-05), 59 (0.0003767999506688964, -0.00021492227011444111, 0.00019620694392616774, 0.00027163215478635274, 8.147201253457049e-05), 60 (0.00025970120925482461, -0.00014782823602910519, 0.00013565269563569894, 0.00018741173517420359, 5.6252903270026344e-05), 61 (0.00014574884684542708, -8.3162940224598374e-05, 7.4927100277784987e-05, 0.00010508245294401461, 3.1156238348722986e-05), 62 (-0.00011267453337899962, 6.412308037476237e-05, -5.7897942333203444e-05, -8.1865863377039068e-05, -2.5273427585025123e-05) 63 ] 64 65 # Set up the tensors. 66 for i in range(5): 67 # Load the tensor. 68 self.interpreter.align_tensor.init(tensor=self.full_list[i], params=self.tensors_full[i], param_types=0) 69 self.interpreter.align_tensor.init(tensor=self.red_list[i], params=self.tensors_red[i], param_types=0) 70 71 # Errors. 72 self.interpreter.align_tensor.init(tensor=self.full_list[i], params=(error, error, error, error, error), param_types=0, errors=True) 73 self.interpreter.align_tensor.init(tensor=self.red_list[i], params=(error, error, error, error, error), param_types=0, errors=True) 74 75 # Domain. 76 self.interpreter.align_tensor.set_domain(tensor=self.full_list[i], domain='full') 77 self.interpreter.align_tensor.set_domain(tensor=self.red_list[i], domain='red') 78 79 # Tensor reductions. 80 self.interpreter.align_tensor.reduction(full_tensor=self.full_list[i], red_tensor=self.red_list[i]) 81 82 # Reset some values. 83 cdp.align_tensors[2].set(param='Axx', value=1)
84 85
86 - def test_copy(self):
87 """Test the copying of alignment tensors (to catch U{bug #20338<https://web.archive.org/web/https://gna.org/bugs/?20338>}.""" 88 89 # First reset. 90 self.interpreter.reset() 91 92 # Create a data pipe. 93 self.interpreter.pipe.create('copy test', 'N-state') 94 95 # Initialise one tensor. 96 self.interpreter.align_tensor.init(tensor='orig', params=self.tensors_full[0], param_types=0) 97 98 # Copy the tensor. 99 self.interpreter.align_tensor.copy(tensor_from='orig', tensor_to='new') 100 101 # Checks. 102 self.assertEqual(len(cdp.align_tensors), 2) 103 self.assertEqual(cdp.align_tensors[0].name, 'orig') 104 self.assertEqual(cdp.align_tensors[1].name, 'new')
105 106
107 - def test_fix(self):
108 """Test the align_tensor.fix user function.""" 109 110 # Fix all tensors. 111 self.interpreter.align_tensor.fix() 112 113 # Unfix one tensor. 114 self.interpreter.align_tensor.fix('2 full', fixed=False) 115 116 # Check the fixed flags. 117 flags = [True]*10 118 flags[4] = False 119 for i in range(10): 120 print("Checking the tensor %s: '%s'." % (i, cdp.align_tensors[i].name)) 121 self.assertEqual(cdp.align_tensors[i].fixed, flags[i])
122 123
124 - def test_to_and_from_xml(self):
125 """Test the conversion to and from XML.""" 126 127 # Save the data pipe. 128 self.interpreter.results.write(ds.tmpfile, dir=None, compress_type=0) 129 130 # Create a new data pipe. 131 self.interpreter.pipe.create('new', 'N-state') 132 133 # Load the data. 134 self.interpreter.results.read(ds.tmpfile, dir=None) 135 136 # Checks. 137 self.assertEqual(len(cdp.align_tensors), 10) 138 self.assert_(hasattr(cdp.align_tensors, 'reduction')) 139 for i in range(5): 140 # Full tensors. 141 if i == 1: 142 self.assertAlmostEqual(cdp.align_tensors[i*2].Axx, 1.0) 143 else: 144 self.assertAlmostEqual(cdp.align_tensors[i*2].Sxx, self.tensors_full[i][0]) 145 self.assertAlmostEqual(cdp.align_tensors[i*2].Syy, self.tensors_full[i][1]) 146 self.assertAlmostEqual(cdp.align_tensors[i*2].Sxy, self.tensors_full[i][2]) 147 self.assertAlmostEqual(cdp.align_tensors[i*2].Sxz, self.tensors_full[i][3]) 148 self.assertAlmostEqual(cdp.align_tensors[i*2].Syz, self.tensors_full[i][4]) 149 self.assertEqual(cdp.align_tensors[i*2].name, self.full_list[i]) 150 151 # Reduced tensors. 152 self.assertAlmostEqual(cdp.align_tensors[i*2+1].Sxx, self.tensors_red[i][0]) 153 self.assertAlmostEqual(cdp.align_tensors[i*2+1].Syy, self.tensors_red[i][1]) 154 self.assertAlmostEqual(cdp.align_tensors[i*2+1].Sxy, self.tensors_red[i][2]) 155 self.assertAlmostEqual(cdp.align_tensors[i*2+1].Sxz, self.tensors_red[i][3]) 156 self.assertAlmostEqual(cdp.align_tensors[i*2+1].Syz, self.tensors_red[i][4]) 157 self.assertEqual(cdp.align_tensors[i*2+1].name, self.red_list[i]) 158 159 # Reduction. 160 self.assertEqual(cdp.align_tensors.reduction[i], [i*2, i*2+1])
161