Author: bugman Date: Mon Nov 26 17:59:56 2007 New Revision: 4055 URL: http://svn.gna.org/viewcvs/relax?rev=4055&view=rev Log: Added a set of unit tests for the data.align_tensor module and its class methods. Added: branches/N_state_model/test_suite/unit_tests/_data/test_align_tensor.py - copied, changed from r4053, branches/N_state_model/test_suite/unit_tests/_data/test_diff_tensor.py Copied: branches/N_state_model/test_suite/unit_tests/_data/test_align_tensor.py (from r4053, branches/N_state_model/test_suite/unit_tests/_data/test_diff_tensor.py) URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/unit_tests/_data/test_align_tensor.py?p2=branches/N_state_model/test_suite/unit_tests/_data/test_align_tensor.py&p1=branches/N_state_model/test_suite/unit_tests/_data/test_diff_tensor.py&r1=4053&r2=4055&rev=4055&view=diff ============================================================================== --- branches/N_state_model/test_suite/unit_tests/_data/test_diff_tensor.py (original) +++ branches/N_state_model/test_suite/unit_tests/_data/test_align_tensor.py Mon Nov 26 17:59:56 2007 @@ -26,291 +26,248 @@ from unittest import TestCase # relax module imports. -from data.diff_tensor import DiffTensorData, DiffTensorSimList +from data.align_tensor import AlignTensorData, AlignTensorSimList from relax_errors import RelaxError -class Test_diff_tensor(TestCase): - """Unit tests for the data.diff_tensor relax module.""" - - def calc_spheroid_objects(self, tm, Da, theta, phi): - """Function for calculating the spheroidal diffusion tensor objects.""" +class Test_align_tensor(TestCase): + """Unit tests for the data.align_tensor relax module.""" + + def calc_objects(self, Axx, Ayy, Axy, Axz, Ayz): + """Function for calculating the alignment tensor objects.""" # The parameter values. - Diso = 1/(6*tm) - Dpar = Diso + 2.0/3.0 * Da - Dper = Diso - 1.0/3.0 * Da - Dratio = Dpar / Dper - - # Vectors. - Dpar_unit = array([sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)]) + Azz = 1.0 - Axx - Ayy + Axxyy = Axx - Ayy # Matrices. - tensor_diag = array([[ Dper, 0.0, 0.0], - [ 0.0, Dper, 0.0], - [ 0.0, 0.0, Dpar]]) - rotation = array([[ cos(theta) * cos(phi), -sin(phi), sin(theta) * cos(phi) ], - [ cos(theta) * sin(phi), cos(phi), sin(theta) * sin(phi) ], - [ -sin(theta), 0.0, cos(theta) ]]) - tensor = dot(rotation, dot(tensor_diag, transpose(rotation))) + tensor_diag = array([[ Axx, 0.0, 0.0], + [ 0.0, Ayy, 0.0], + [ 0.0, 0.0, Azz]]) # Return the objects. - return Diso, Dpar, Dper, Dratio, Dpar_unit, tensor_diag, rotation, tensor + return Azz, Axxyy, tensor_diag def setUp(self): - """Set 'self.diff_data' to an empty instance of the DiffTensorData class.""" - - self.diff_data = DiffTensorData() - - - def test_append_spheroid_sim(self): - """Test the appending of Monte Carlo simulation spheroidal diffusion tensor parameters. + """Set 'self.align_data' to an empty instance of the AlignTensorData class.""" + + self.align_data = AlignTensorData() + + + def test_append_sim(self): + """Test the appending of Monte Carlo simulation alignment tensor parameters. The following parameters will be appended to empty lists: - tm: 8 ns - Da: -1e7 - theta: 150 degrees - phi: 30 degrees + Axx: -16.6278 Hz + Ayy: 6.13037 Hz + Axy: 7.65639 Hz + Axz: -1.89157 Hz + Ayz: 19.2561 Hz """ # The MC sim parameter values. - tm = 8e-9 - Da = -1e7 - theta = (150 / 360.0) * 2.0 * pi - phi = (30 / 360.0) * 2.0 * pi - - # Set the diffusion type. - self.diff_data.type = 'spheroid' - - # Set the MC sim diffusion parameter lists. - self.diff_data.tm_sim = DiffTensorSimList('tm', self.diff_data) - self.diff_data.Da_sim = DiffTensorSimList('Da', self.diff_data) - self.diff_data.theta_sim = DiffTensorSimList('theta', self.diff_data) - self.diff_data.phi_sim = DiffTensorSimList('phi', self.diff_data) + Axx = -16.6278 + Ayy = 6.13037 + Axy = 7.65639 + Axz = -1.89157 + Ayz = 19.2561 + + # Set the MC sim alignment parameter lists. + self.align_data.Axx_sim = AlignTensorSimList('Axx', self.align_data) + self.align_data.Ayy_sim = AlignTensorSimList('Ayy', self.align_data) + self.align_data.Axy_sim = AlignTensorSimList('Axy', self.align_data) + self.align_data.Axz_sim = AlignTensorSimList('Axz', self.align_data) + self.align_data.Ayz_sim = AlignTensorSimList('Ayz', self.align_data) # Append the values. - self.diff_data.tm_sim.append(tm) - self.diff_data.Da_sim.append(Da) - self.diff_data.theta_sim.append(theta) - self.diff_data.phi_sim.append(phi) - - # Test the set values. - self.assertEqual(self.diff_data.type, 'spheroid') - self.assertEqual(self.diff_data.tm_sim[0], tm) - self.assertEqual(self.diff_data.Da_sim[0], Da) - self.assertEqual(self.diff_data.theta_sim[0], theta) - self.assertEqual(self.diff_data.phi_sim[0], phi) - - # Calculate the diffusion tensor objects. - Diso, Dpar, Dper, Dratio, Dpar_unit, tensor_diag, rotation, tensor = self.calc_spheroid_objects(tm, Da, theta, phi) - - # Test the automatically created values. - self.assertEqual(self.diff_data.Diso_sim[0], Diso) - self.assertEqual(self.diff_data.Dpar_sim[0], Dpar) - self.assertEqual(self.diff_data.Dper_sim[0], Dper) - self.assertEqual(self.diff_data.Dratio_sim[0], Dratio) - - # Test the vectors. - self.assertEqual(self.diff_data.Dpar_unit_sim[0].tostring(), Dpar_unit.tostring()) - - # Test the matrices. - self.assertEqual(self.diff_data.tensor_diag_sim[0].tostring(), tensor_diag.tostring()) - self.assertEqual(self.diff_data.rotation_sim[0].tostring(), rotation.tostring()) - self.assertEqual(self.diff_data.tensor_sim[0].tostring(), tensor.tostring()) - - - def test_set_Diso(self): - """Test that the Diso parameter cannot be set.""" - - # Assert that a RelaxError occurs when Diso is set (to the tm value of 10 ns). - self.assertRaises(RelaxError, setattr, self.diff_data, 'Diso', 1/(6*1e-8)) - - # Make sure that the Diso parameter has not been set. - self.assert_(not hasattr(self.diff_data, 'Diso')) - - - def test_set_spheroid_errors(self): + self.align_data.Axx_sim.append(Axx) + self.align_data.Ayy_sim.append(Ayy) + self.align_data.Axy_sim.append(Axy) + self.align_data.Axz_sim.append(Axz) + self.align_data.Ayz_sim.append(Ayz) + + # Test the set values. + self.assertEqual(self.align_data.Axx_sim[0], Axx) + self.assertEqual(self.align_data.Ayy_sim[0], Ayy) + self.assertEqual(self.align_data.Axy_sim[0], Axy) + self.assertEqual(self.align_data.Axz_sim[0], Axz) + self.assertEqual(self.align_data.Ayz_sim[0], Ayz) + + # Calculate the diffusion tensor objects. + Azz, Axxyy, tensor_diag = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) + + # Test the automatically created values. + self.assertEqual(self.align_data.Azz_sim[0], Azz) + self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) + + # Test the matrices. + self.assertEqual(self.align_data.tensor_diag_sim[0].tostring(), tensor_diag.tostring()) + + + def test_set_Azz(self): + """Test that the Azz parameter cannot be set.""" + + # Assert that a RelaxError occurs when Azz is set. + self.assertRaises(RelaxError, setattr, self.align_data, 'Azz', -23.0) + + # Make sure that the Azz parameter has not been set. + self.assert_(not hasattr(self.align_data, 'Azz')) + + + def test_set_errors(self): """Test the setting of spheroidal diffusion tensor parameter errors. The following parameter errors will be set: - tm: 1 ns - Da: 1e3 - theta: 3 degrees - phi: 5 degrees + Axx: 0.3 Hz + Ayy: 0.5 Hz + Axy: 0.4 Hz + Axz: 0.1 Hz + Ayz: 0.2 Hz """ # The parameter errors. - tm = 1e-8 - Da = 1e3 - theta = (3 / 360.0) * 2.0 * pi - phi = (5 / 360.0) * 2.0 * pi - - # Set the diffusion type. - self.diff_data.type = 'spheroid' + Axx = 0.3 + Ayy = 0.5 + Axy = 0.4 + Axz = 0.1 + Ayz = 0.2 # Set the diffusion parameters. - self.diff_data.tm_err = tm - self.diff_data.Da_err = Da - self.diff_data.theta_err = theta - self.diff_data.phi_err = phi - - # Test the set values. - self.assertEqual(self.diff_data.type, 'spheroid') - self.assertEqual(self.diff_data.tm_err, tm) - self.assertEqual(self.diff_data.Da_err, Da) - self.assertEqual(self.diff_data.theta_err, theta) - self.assertEqual(self.diff_data.phi_err, phi) - - # Calculate the diffusion tensor objects. - Diso, Dpar, Dper, Dratio, Dpar_unit, tensor_diag, rotation, tensor = self.calc_spheroid_objects(tm, Da, theta, phi) - - # Test the automatically created values. - self.assertEqual(self.diff_data.Diso_err, Diso) - self.assertEqual(self.diff_data.Dpar_err, Dpar) - self.assertEqual(self.diff_data.Dper_err, Dper) - self.assertEqual(self.diff_data.Dratio_err, Dratio) - - # Test the vectors. - self.assertEqual(self.diff_data.Dpar_unit_err.tostring(), Dpar_unit.tostring()) - - - def test_set_spheroid_params(self): - """Test the setting of spheroidal diffusion tensor parameters. + self.align_data.Axx_err = Axx + self.align_data.Ayy_err = Ayy + self.align_data.Axy_err = Axy + self.align_data.Axz_err = Axz + self.align_data.Ayz_err = Ayz + + # Test the set values. + self.assertEqual(self.align_data.Axx_err, Axx) + self.assertEqual(self.align_data.Ayy_err, Ayy) + self.assertEqual(self.align_data.Axy_err, Axy) + self.assertEqual(self.align_data.Axz_err, Axz) + self.assertEqual(self.align_data.Ayz_err, Ayz) + + # Calculate the diffusion tensor objects. + Azz, Axxyy, tensor_diag = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) + + # Test the automatically created values. + self.assertEqual(self.align_data.Azz_err, Azz) + self.assertEqual(self.align_data.Axxyy_err, Axxyy) + + # Test the matrices. + self.assertEqual(self.align_data.tensor_diag_err.tostring(), tensor_diag.tostring()) + + + def test_set_params(self): + """Test the setting of alignment tensor parameters. The following parameters will be set: - tm: 20 ns - Da: 2e6 - theta: 60 degrees - phi: 290 degrees + Axx: -16.6278 Hz + Ayy: 6.13037 Hz + Axy: 7.65639 Hz + Axz: -1.89157 Hz + Ayz: 19.2561 Hz """ # The parameter values. - tm = 2e-8 - Da = 2e6 - theta = (60 / 360.0) * 2.0 * pi - phi = (290 / 360.0) * 2.0 * pi - - # Set the diffusion type. - self.diff_data.type = 'spheroid' + Axx = -16.6278 + Ayy = 6.13037 + Axy = 7.65639 + Axz = -1.89157 + Ayz = 19.2561 # Set the diffusion parameters. - self.diff_data.tm = tm - self.diff_data.Da = Da - self.diff_data.theta = theta - self.diff_data.phi = phi - - # Test the set values. - self.assertEqual(self.diff_data.type, 'spheroid') - self.assertEqual(self.diff_data.tm, tm) - self.assertEqual(self.diff_data.Da, Da) - self.assertEqual(self.diff_data.theta, theta) - self.assertEqual(self.diff_data.phi, phi) - - # Calculate the diffusion tensor objects. - Diso, Dpar, Dper, Dratio, Dpar_unit, tensor_diag, rotation, tensor = self.calc_spheroid_objects(tm, Da, theta, phi) - - # Test the automatically created values. - self.assertEqual(self.diff_data.Diso, Diso) - self.assertEqual(self.diff_data.Dpar, Dpar) - self.assertEqual(self.diff_data.Dper, Dper) - self.assertEqual(self.diff_data.Dratio, Dratio) - - # Test the vectors. - self.assertEqual(self.diff_data.Dpar_unit.tostring(), Dpar_unit.tostring()) - - # Test the matrices. - self.assertEqual(self.diff_data.tensor_diag.tostring(), tensor_diag.tostring()) - self.assertEqual(self.diff_data.rotation.tostring(), rotation.tostring()) - self.assertEqual(self.diff_data.tensor.tostring(), tensor.tostring()) - - - def test_set_spheroid_sim(self): - """Test the setting of Monte Carlo simulation spheroidal diffusion tensor parameters. + self.align_data.Axx = Axx + self.align_data.Ayy = Ayy + self.align_data.Axy = Axy + self.align_data.Axz = Axz + self.align_data.Ayz = Ayz + + # Test the set values. + self.assertEqual(self.align_data.Axx, Axx) + self.assertEqual(self.align_data.Ayy, Ayy) + self.assertEqual(self.align_data.Axy, Axy) + self.assertEqual(self.align_data.Axz, Axz) + self.assertEqual(self.align_data.Ayz, Ayz) + + # Calculate the diffusion tensor objects. + Azz, Axxyy, tensor_diag = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) + + # Test the automatically created values. + self.assertEqual(self.align_data.Azz, Azz) + self.assertEqual(self.align_data.Axxyy, Axxyy) + + # Test the matrices. + self.assertEqual(self.align_data.tensor_diag.tostring(), tensor_diag.tostring()) + + + def test_set_sim(self): + """Test the setting of Monte Carlo simulation alignment tensor parameters. Firstly the following parameters will be appended to empty lists: - tm: 2 ns - Da: 1e5 - theta: 0 degrees - phi: 360 degrees + Axx: -16.6278 Hz + Ayy: 6.13037 Hz + Axy: 7.65639 Hz + Axz: -1.89157 Hz + Ayz: 19.2561 Hz These MC sim values will then be explicity overwritten by setting the first elements of the lists to: - tm: 0.5 ns - Da: 3e5 - theta: 2 degrees - phi: 0 degrees - """ - - # Set the diffusion type. - self.diff_data.type = 'spheroid' - - # Set the MC sim diffusion parameter lists. - self.diff_data.tm_sim = DiffTensorSimList('tm', self.diff_data) - self.diff_data.Da_sim = DiffTensorSimList('Da', self.diff_data) - self.diff_data.theta_sim = DiffTensorSimList('theta', self.diff_data) - self.diff_data.phi_sim = DiffTensorSimList('phi', self.diff_data) + Axx: 0.3 Hz + Ayy: 0.5 Hz + Axy: 0.4 Hz + Axz: 0.1 Hz + Ayz: 0.2 Hz + """ + + # Set the MC sim alignment parameter lists. + self.align_data.Axx_sim = AlignTensorSimList('Axx', self.align_data) + self.align_data.Ayy_sim = AlignTensorSimList('Ayy', self.align_data) + self.align_data.Axy_sim = AlignTensorSimList('Axy', self.align_data) + self.align_data.Axz_sim = AlignTensorSimList('Axz', self.align_data) + self.align_data.Ayz_sim = AlignTensorSimList('Ayz', self.align_data) # Append the initial values. - self.diff_data.tm_sim.append(2e-9) - self.diff_data.Da_sim.append(1e5) - self.diff_data.theta_sim.append(0.0) - self.diff_data.phi_sim.append(2.0 * pi) + self.align_data.Axx_sim.append(-16.6278) + self.align_data.Ayy_sim.append(6.13037) + self.align_data.Axy_sim.append(7.65639) + self.align_data.Axz_sim.append(-1.89157) + self.align_data.Ayz_sim.append(19.2561) # The new MC sim parameter values. - tm = 0.5e-9 - Da = 3e5 - theta = (2 / 360.0) * 2.0 * pi - phi = 0.0 + Axx = 0.3 + Ayy = 0.5 + Axy = 0.4 + Axz = 0.1 + Ayz = 0.2 # Set the MC sim parameter values (overwriting the initial values). - self.diff_data.tm_sim[0] = tm - self.diff_data.Da_sim[0] = Da - self.diff_data.theta_sim[0] = theta - self.diff_data.phi_sim[0] = phi - - # Test the set values. - self.assertEqual(self.diff_data.type, 'spheroid') - self.assertEqual(self.diff_data.tm_sim[0], tm) - self.assertEqual(self.diff_data.Da_sim[0], Da) - self.assertEqual(self.diff_data.theta_sim[0], theta) - self.assertEqual(self.diff_data.phi_sim[0], phi) - - # Calculate the diffusion tensor objects. - Diso, Dpar, Dper, Dratio, Dpar_unit, tensor_diag, rotation, tensor = self.calc_spheroid_objects(tm, Da, theta, phi) - - # Test the automatically created values. - self.assertEqual(self.diff_data.Diso_sim[0], Diso) - self.assertEqual(self.diff_data.Dpar_sim[0], Dpar) - self.assertEqual(self.diff_data.Dper_sim[0], Dper) - self.assertEqual(self.diff_data.Dratio_sim[0], Dratio) - - # Test the vectors. - self.assertEqual(self.diff_data.Dpar_unit_sim[0].tostring(), Dpar_unit.tostring()) - - # Test the matrices. - self.assertEqual(self.diff_data.tensor_diag_sim[0].tostring(), tensor_diag.tostring()) - self.assertEqual(self.diff_data.rotation_sim[0].tostring(), rotation.tostring()) - self.assertEqual(self.diff_data.tensor_sim[0].tostring(), tensor.tostring()) - - - def test_set_tm(self): - """Test the setting of the tm parameter. - - The tm parameter will be set to 10 ns. The setting of tm should automatically create the - Diso parameter. - """ - - # Set the diffusion type. - self.diff_data.type = 'sphere' - - # Set the tm value to 10 ns. - self.diff_data.tm = 1e-8 - - # Test that the tm parameter has been set correctly. - self.assert_(hasattr(self.diff_data, 'tm')) - self.assertEqual(self.diff_data.tm, 1e-8) - - # Test that the Diso parameter has been set correctly. - self.assert_(hasattr(self.diff_data, 'Diso')) - self.assertEqual(self.diff_data.Diso, 1/(6*1e-8)) + self.align_data.Axx_sim[0] = Axx + + # Test the set values. + self.assertEqual(self.align_data.Axx_sim[0], Axx) + self.assertEqual(self.align_data.Ayy_sim[0], Ayy) + self.assertEqual(self.align_data.Axy_sim[0], Axy) + self.assertEqual(self.align_data.Axz_sim[0], Axz) + self.assertEqual(self.align_data.Ayz_sim[0], Ayz) + + # Calculate the diffusion tensor objects. + Azz, Axxyy, tensor_diag = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) + + # Test the automatically created values. + self.assertEqual(self.align_data.Azz_sim[0], Azz) + self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) + + # Test the matrices. + self.assertEqual(self.align_data.tensor_diag_sim[0].tostring(), tensor_diag.tostring()) + + + def test_set_Axx(self): + """Test the setting of the Axx parameter.""" + + # Set the Axx value to 10 Hz. + self.align_data.Axx = 10.0 + + # Test that the Axx parameter has been set correctly. + self.assert_(hasattr(self.align_data, 'Axx')) + self.assertEqual(self.align_data.Axx, 10.0)