Author: bugman Date: Tue Nov 18 15:12:41 2014 New Revision: 26615 URL: http://svn.gna.org/viewcvs/relax?rev=26615&view=rev Log: Conversion of the basis_set argument for the align_tensor.matrix_angles user function. The argument is now a string that accepts the values of 'matrix', 'unitary 5D', and 'geometric 5D' to select between the different matrix angles techniques. This has been updated in the test suite as well. Modified: trunk/pipe_control/align_tensor.py trunk/test_suite/system_tests/scripts/n_state_model/5_state_xz.py trunk/test_suite/unit_tests/_prompt/test_align_tensor.py trunk/test_suite/unit_tests/align_tensor_testing_base.py trunk/user_functions/align_tensor.py Modified: trunk/pipe_control/align_tensor.py URL: http://svn.gna.org/viewcvs/relax/trunk/pipe_control/align_tensor.py?rev=26615&r1=26614&r2=26615&view=diff ============================================================================== --- trunk/pipe_control/align_tensor.py (original) +++ trunk/pipe_control/align_tensor.py Tue Nov 18 15:12:41 2014 @@ -882,17 +882,20 @@ tensor_obj.set(param='align_id', value=align_id) -def matrix_angles(basis_set=0, tensors=None): - """Function for calculating the 5D angles between the alignment tensors. - - The basis set used for the 5D vector construction changes the angles calculated. - - @param basis_set: The basis set to use for constructing the 5D vectors. If set to 0, the - basis set is {Sxx, Syy, Sxy, Sxz, Syz}. If 1, then the basis set is {Szz, - Sxxyy, Sxy, Sxz, Syz}. - @type basis_set: int - @param tensors: An array of tensors to apply SVD to. If None, all tensors will be used. - @type tensors: None or array of str +def matrix_angles(basis_set='matrix', tensors=None): + """Function for calculating the inter-matrix angles between the alignment tensors. + + The basis set defines how the angles are calculated: + + - "matrix", the standard inter-matrix angle. The angle is calculated via the Euclidean inner product of the alignment matrices in rank-2, 3D form divided by the Frobenius norm ||A||_F of the matrices. + - "unitary 5D", the unitary 5D basis set {Sxx, Syy, Sxy, Sxz, Syz}. + - "geometric 5D", the geometric 5D basis set {Szz, Sxxyy, Sxy, Sxz, Syz}. This is also the Pales standard notation. + + + @param basis_set: The basis set to use for calculating the inter-matrix angles. It can be one of "matrix", "unitary 5D", or "geometric 5D". + @type basis_set: str + @param tensors: The list of alignment tensor IDs to calculate inter-matrix angles between. If None, all tensors will be used. + @type tensors: None or list of str """ # Test that alignment tensor data exists. @@ -918,7 +921,7 @@ continue # Unitary basis set. - if basis_set == 0: + if basis_set == 'unitary 5D': # Pack the elements. matrix_5D[i, 0] = tensor.Sxx matrix_5D[i, 1] = tensor.Syy @@ -927,7 +930,7 @@ matrix_5D[i, 4] = tensor.Syz # Geometric basis set. - elif basis_set == 1: + elif basis_set == 'geometric 5D': # Pack the elements. matrix_5D[i, 0] = tensor.Szz matrix_5D[i, 1] = tensor.Sxxyy @@ -936,11 +939,11 @@ matrix_5D[i, 4] = tensor.Syz # Full matrix. - elif basis_set == 2: + elif basis_set == 'matrix': matrix_3D[i] = tensor.A # Normalisation. - if basis_set in [0, 1]: + if basis_set in ['unitary 5D', 'geometric 5D']: norm_5D = linalg.norm(matrix_5D[i]) matrix_5D[i] = matrix_5D[i] / norm_5D @@ -951,13 +954,13 @@ cdp.align_tensors.angles = zeros((tensor_num, tensor_num), float64) # Header printout. - if basis_set == 0: + if basis_set == 'unitary 5D': sys.stdout.write("5d angles in deg between the vectors ") sys.stdout.write("{Sxx, Syy, Sxy, Sxz, Syz}") - elif basis_set == 1: + elif basis_set == 'geometric 5D': sys.stdout.write("5d angles in deg between the vectors ") sys.stdout.write("{Szz, Sxx-yy, Sxy, Sxz, Syz}") - elif basis_set == 2: + elif basis_set == 'matrix': sys.stdout.write("Angles in deg between the matrices ") sys.stdout.write("(using the Euclidean inner product and Frobenius norm)") sys.stdout.write(":\n") @@ -984,7 +987,7 @@ # Second loop over the columns. for j in range(tensor_num): # The 5D angles. - if basis_set in [0, 1]: + if basis_set in ['unitary 5D', 'geometric 5D']: # Dot product. delta = dot(matrix_5D[i], matrix_5D[j]) @@ -996,7 +999,7 @@ theta = arccos(delta) # The full matrix angle. - elif basis_set in [2]: + elif basis_set in ['matrix']: # The Euclidean inner product. nom = inner(matrix_3D[i].flatten(), matrix_3D[j].flatten()) Modified: trunk/test_suite/system_tests/scripts/n_state_model/5_state_xz.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/system_tests/scripts/n_state_model/5_state_xz.py?rev=26615&r1=26614&r2=26615&view=diff ============================================================================== --- trunk/test_suite/system_tests/scripts/n_state_model/5_state_xz.py (original) +++ trunk/test_suite/system_tests/scripts/n_state_model/5_state_xz.py Tue Nov 18 15:12:41 2014 @@ -32,8 +32,8 @@ self._execute_uf(uf_name='align_tensor.svd', basis_set=1, tensors=['chi1 C-dom', 'chi2 C-dom', 'chi3 C-dom', 'chi4 C-dom', 'chi5 C-dom']) # Calculate the angles between the matrices. -self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set=0, tensors=['chi1 C-dom', 'chi2 C-dom', 'chi3 C-dom', 'chi4 C-dom', 'chi5 C-dom']) -self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set=1, tensors=['chi1 C-dom', 'chi2 C-dom', 'chi3 C-dom', 'chi4 C-dom', 'chi5 C-dom']) +self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set='unitary 5D', tensors=['chi1 C-dom', 'chi2 C-dom', 'chi3 C-dom', 'chi4 C-dom', 'chi5 C-dom']) +self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set='geometric 5D', tensors=['chi1 C-dom', 'chi2 C-dom', 'chi3 C-dom', 'chi4 C-dom', 'chi5 C-dom']) # Load the N-terminal alignment tensors. @@ -55,8 +55,8 @@ self._execute_uf(uf_name='align_tensor.svd', basis_set=1, tensors=['chi1 N-dom', 'chi2 N-dom', 'chi3 N-dom', 'chi4 N-dom', 'chi5 N-dom']) # Calculate the angles between the matrices. -self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set=0, tensors=['chi1 N-dom', 'chi2 N-dom', 'chi3 N-dom', 'chi4 N-dom', 'chi5 N-dom']) -self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set=1, tensors=['chi1 N-dom', 'chi2 N-dom', 'chi3 N-dom', 'chi4 N-dom', 'chi5 N-dom']) +self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set='unitary 5D', tensors=['chi1 N-dom', 'chi2 N-dom', 'chi3 N-dom', 'chi4 N-dom', 'chi5 N-dom']) +self._execute_uf(uf_name='align_tensor.matrix_angles', basis_set='geometric 5D', tensors=['chi1 N-dom', 'chi2 N-dom', 'chi3 N-dom', 'chi4 N-dom', 'chi5 N-dom']) # Set up the 5-state model. self._execute_uf(uf_name='n_state_model.select_model', model='2-domain') Modified: trunk/test_suite/unit_tests/_prompt/test_align_tensor.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_prompt/test_align_tensor.py?rev=26615&r1=26614&r2=26615&view=diff ============================================================================== --- trunk/test_suite/unit_tests/_prompt/test_align_tensor.py (original) +++ trunk/test_suite/unit_tests/_prompt/test_align_tensor.py Tue Nov 18 15:12:41 2014 @@ -246,16 +246,99 @@ # Loop over the data types. for data in DATA_TYPES: + # Catch the str argument, and skip it. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.align_tensor_fns.matrix_angles, basis_set=data[1]) + + + def test_matrix_angles_argfail_basis_tensors(self): + """The tensors arg unit test of the align_tensor.matrix_angles() user function.""" + + # Add an alignment tensor. + align_tensor.init(align_id='a', params=(0.0, 0.0, 0.0, 0.0, 0.0)) + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the None and str list arguments, and skip them. + if data[0] == 'None' or data[0] == 'str list': + continue + + # The argument test. + self.assertRaises(RelaxNoneListStrError, self.align_tensor_fns.matrix_angles, tensors=data[1]) + + + def test_reduction_argfail_full_tensor(self): + """Failure of the full_tensor arg of the align_tensor.reduction() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the str argument, and skip it. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.align_tensor_fns.reduction, full_tensor=data[1]) + + + def test_reduction_argfail_red_tensor(self): + """Failure of the red_tensor arg of the align_tensor.reduction() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the str argument, and skip it. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.align_tensor_fns.reduction, full_tensor='test', red_tensor=data[1]) + + def test_set_domain_argfail_tensor(self): + """Failure of the tensor arg of the align_tensor.set_domain() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the str argument, and skip it. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.align_tensor_fns.set_domain, tensor=data[1]) + + + def test_set_domain_argfail_domain(self): + """Failure of the domain arg of the align_tensor.set_domain() user function.""" + + # Loop over the data types. + for data in DATA_TYPES: + # Catch the str argument, and skip it. + if data[0] == 'str': + continue + + # The argument test. + self.assertRaises(RelaxStrError, self.align_tensor_fns.set_domain, domain=data[1]) + + + def test_svd_argfail_basis_set(self): + """The proper failure of the align_tensor.svd() user function for the basis_set argument.""" + + # Add an alignment tensor. + align_tensor.init(align_id='a', params=(0.0, 0.0, 0.0, 0.0, 0.0)) + + # Loop over the data types. + for data in DATA_TYPES: # Catch the int and bin arguments, and skip them. if data[0] == 'int' or data[0] == 'bin': continue # The argument test. - self.assertRaises(RelaxIntError, self.align_tensor_fns.matrix_angles, basis_set=data[1]) - - - def test_matrix_angles_argfail_basis_tensors(self): - """The tensors arg unit test of the align_tensor.matrix_angles() user function.""" + self.assertRaises(RelaxIntError, self.align_tensor_fns.svd, basis_set=data[1]) + + + def test_svd_argfail_basis_tensors(self): + """The tensors arg unit test of the align_tensor.svd() user function.""" # Add an alignment tensor. align_tensor.init(align_id='a', params=(0.0, 0.0, 0.0, 0.0, 0.0)) @@ -267,89 +350,6 @@ continue # The argument test. - self.assertRaises(RelaxNoneListStrError, self.align_tensor_fns.matrix_angles, tensors=data[1]) - - - def test_reduction_argfail_full_tensor(self): - """Failure of the full_tensor arg of the align_tensor.reduction() user function.""" - - # Loop over the data types. - for data in DATA_TYPES: - # Catch the str argument, and skip it. - if data[0] == 'str': - continue - - # The argument test. - self.assertRaises(RelaxStrError, self.align_tensor_fns.reduction, full_tensor=data[1]) - - - def test_reduction_argfail_red_tensor(self): - """Failure of the red_tensor arg of the align_tensor.reduction() user function.""" - - # Loop over the data types. - for data in DATA_TYPES: - # Catch the str argument, and skip it. - if data[0] == 'str': - continue - - # The argument test. - self.assertRaises(RelaxStrError, self.align_tensor_fns.reduction, full_tensor='test', red_tensor=data[1]) - - def test_set_domain_argfail_tensor(self): - """Failure of the tensor arg of the align_tensor.set_domain() user function.""" - - # Loop over the data types. - for data in DATA_TYPES: - # Catch the str argument, and skip it. - if data[0] == 'str': - continue - - # The argument test. - self.assertRaises(RelaxStrError, self.align_tensor_fns.set_domain, tensor=data[1]) - - - def test_set_domain_argfail_domain(self): - """Failure of the domain arg of the align_tensor.set_domain() user function.""" - - # Loop over the data types. - for data in DATA_TYPES: - # Catch the str argument, and skip it. - if data[0] == 'str': - continue - - # The argument test. - self.assertRaises(RelaxStrError, self.align_tensor_fns.set_domain, domain=data[1]) - - - def test_svd_argfail_basis_set(self): - """The proper failure of the align_tensor.svd() user function for the basis_set argument.""" - - # Add an alignment tensor. - align_tensor.init(align_id='a', params=(0.0, 0.0, 0.0, 0.0, 0.0)) - - # Loop over the data types. - for data in DATA_TYPES: - # Catch the int and bin arguments, and skip them. - if data[0] == 'int' or data[0] == 'bin': - continue - - # The argument test. - self.assertRaises(RelaxIntError, self.align_tensor_fns.svd, basis_set=data[1]) - - - def test_svd_argfail_basis_tensors(self): - """The tensors arg unit test of the align_tensor.svd() user function.""" - - # Add an alignment tensor. - align_tensor.init(align_id='a', params=(0.0, 0.0, 0.0, 0.0, 0.0)) - - # Loop over the data types. - for data in DATA_TYPES: - # Catch the None and str list arguments, and skip them. - if data[0] == 'None' or data[0] == 'str list': - continue - - # The argument test. self.assertRaises(RelaxNoneListStrError, self.align_tensor_fns.svd, tensors=data[1]) Modified: trunk/test_suite/unit_tests/align_tensor_testing_base.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/align_tensor_testing_base.py?rev=26615&r1=26614&r2=26615&view=diff ============================================================================== --- trunk/test_suite/unit_tests/align_tensor_testing_base.py (original) +++ trunk/test_suite/unit_tests/align_tensor_testing_base.py Tue Nov 18 15:12:41 2014 @@ -248,7 +248,7 @@ self.align_tensor_fns.init(align_id='5', params=(0, 0, 0, 0, 1)) # Matrix angles. - self.align_tensor_fns.matrix_angles(basis_set=0) + self.align_tensor_fns.matrix_angles(basis_set='unitary 5D') # Test the angles. self.assertAlmostEqual(dp.align_tensors.angles[0, 0], 0.0) Modified: trunk/user_functions/align_tensor.py URL: http://svn.gna.org/viewcvs/relax/trunk/user_functions/align_tensor.py?rev=26615&r1=26614&r2=26615&view=diff ============================================================================== --- trunk/user_functions/align_tensor.py (original) +++ trunk/user_functions/align_tensor.py Tue Nov 18 15:12:41 2014 @@ -302,13 +302,13 @@ uf.display = True uf.add_keyarg( name = "basis_set", - default = 2, - py_type = "int", + default = "matrix", + py_type = "str", desc_short = "basis set", desc = "The basis set to operate with.", wiz_element_type = "combo", - wiz_combo_choices = ["{Sxx, Syy, Sxy, Sxz, Syz}", "{Szz, Sxxyy, Sxy, Sxz, Syz}", "Full matrix angles using the Euclidean inner product"], - wiz_combo_data = [0, 1, 2] + wiz_combo_choices = ["Standard matrix angles via the Euclidean inner product", "Unitary 5D {Sxx, Syy, Sxy, Sxz, Syz}", "Geometric 5D {Szz, Sxxyy, Sxy, Sxz, Syz}"], + wiz_combo_data = ["matrix", "unitary 5D", "geometric 5D"] ) uf.add_keyarg( name = "tensors", @@ -323,9 +323,9 @@ # Description. uf.desc.append(Desc_container()) uf.desc[-1].add_paragraph("This will calculate the inter-matrix angles between all loaded alignment tensors for the current data pipe. For the 5D basis sets, the matrices are first converted to a 5D vector form and then then the inter-vector angles, rather than inter-matrix angles, are calculated. The angles are dependent upon the basis set:") -uf.desc[-1].add_item_list_element("0", "The unitary 5D basis set {Sxx, Syy, Sxy, Sxz, Syz}.") -uf.desc[-1].add_item_list_element("1", "The geometric 5D basis set {Szz, Sxxyy, Sxy, Sxz, Syz}. This is also the Pales standard notation.") -uf.desc[-1].add_item_list_element("2", "The standard inter-matrix angle. This is the default option. The angle is calculated via the Euclidean inner product of the alignment matrices in rank-2, 3D form divided by the Frobenius norm ||A||_F of the matrices.") +uf.desc[-1].add_item_list_element("matrix", "The standard inter-matrix angle. This is the default option. The angle is calculated via the Euclidean inner product of the alignment matrices in rank-2, 3D form divided by the Frobenius norm ||A||_F of the matrices.") +uf.desc[-1].add_item_list_element("unitary 5D", "The unitary 5D basis set {Sxx, Syy, Sxy, Sxz, Syz}.") +uf.desc[-1].add_item_list_element("geometric 5D", "The geometric 5D basis set {Szz, Sxxyy, Sxy, Sxz, Syz}. This is also the Pales standard notation.") uf.desc[-1].add_paragraph("The full matrix angle via the Euclidean inner product is defined as:") uf.desc[-1].add_verbatim(""" / <A1 , A2> \