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