Author: bugman Date: Wed Jul 23 11:47:41 2008 New Revision: 6942 URL: http://svn.gna.org/viewcvs/relax?rev=6942&view=rev Log: Split the rdc module in half, shifting the alignment tensor components into their own module. Added: branches/rdc_analysis/maths_fns/alignment_tensor.py - copied, changed from r6940, branches/rdc_analysis/maths_fns/rdc.py Modified: branches/rdc_analysis/maths_fns/rdc.py Copied: branches/rdc_analysis/maths_fns/alignment_tensor.py (from r6940, branches/rdc_analysis/maths_fns/rdc.py) URL: http://svn.gna.org/viewcvs/relax/branches/rdc_analysis/maths_fns/alignment_tensor.py?p2=branches/rdc_analysis/maths_fns/alignment_tensor.py&p1=branches/rdc_analysis/maths_fns/rdc.py&r1=6940&r2=6942&rev=6942&view=diff ============================================================================== --- branches/rdc_analysis/maths_fns/rdc.py (original) +++ branches/rdc_analysis/maths_fns/alignment_tensor.py Wed Jul 23 11:47:41 2008 @@ -21,132 +21,10 @@ ############################################################################### # Module docstring. -"""Module containing functions for the calculation of RDCs.""" +"""Module for the manipulation of alignment tensors.""" # Python imports. -from numpy import sum from numpy.linalg import eigvals - - -def average_rdc_5D(vect, K, A, weights=None): - """Calculate the average RDC for an ensemble set of XH bond vectors, using the 5D notation. - - This function calculates the average RDC for a set of XH bond vectors from a structural - ensemble, using the 5D vector form of the alignment tensor. The formula for this ensemble - average RDC value is:: - - _K_ - 1 \ - <RDC_i> = - > RDC_ik (theta), - K /__ - k=1 - - where K is the total number of structures, k is the index over the multiple structures, RDC_ik - is the back-calculated RDC value for spin system i and structure k, and theta is the parameter - vector consisting of the alignment tensor parameters {Axx, Ayy, Axy, Axz, Ayz}. The - back-calculated RDC is given by the formula:: - - RDC_ik(theta) = (x**2 - z**2)Axx + (y**2 - z**2)Ayy + 2x.y.Axy + 2x.z.Axz + 2y.z.Ayz. - - - @param vect: The unit XH bond vector matrix. The first dimension corresponds to the - structural index, the second dimension is the coordinates of the unit - vector. - @type vect: numpy matrix - @param K: The total number of structures. - @type K: int - @param A: The 5D vector object. The vector format is {Axx, Ayy, Axy, Axz, Ayz}. - @type A: numpy 5D vector - @param weights: The weights for each member of the ensemble. The last weight is assumed to - be missing, and is calculated by this function. Hence the length should be - one less than K. - @type weights: numpy rank-1 array - @return: The average RDC value. - @rtype: float - """ - - # Initial back-calculated RDC value. - val = 0.0 - - # Averaging factor. - if weights == None: - c = 1.0 / K - - # Loop over the structures k. - for k in xrange(K): - # The weights. - if weights != None: - if k == K-1: - c = 1.0 - sum(weights, axis=0) - else: - c = weights[k] - - # Back-calculate the RDC. - val = val + c * (vect[k,0]**2 - vect[k,2]**2)*A[0] + (vect[k,1]**2 - vect[k,2]**2)*A[1] + 2.0*vect[k,0]*vect[k,1]*A[2] + 2.0*vect[k,0]*vect[k,2]*A[3] + 2.0*vect[k,1]*vect[k,2]*A[4] - - # Return the average RDC. - return val - - -def average_rdc_tensor(vect, K, A, weights=None): - """Calculate the average RDC for an ensemble set of XH bond vectors, using the 3D tensor. - - This function calculates the average RDC for a set of XH bond vectors from a structural - ensemble, using the 3D tensorial form of the alignment tensor. The formula for this ensemble - average RDC value is:: - - _K_ - 1 \ - <RDC_i> = - > RDC_ik (theta), - K /__ - k=1 - - where K is the total number of structures, k is the index over the multiple structures, RDC_ik - is the back-calculated RDC value for spin system i and structure k, and theta is the parameter - vector consisting of the alignment tensor. The back-calculated RDC is given by the formula:: - - RDC_ik(theta) = muT . A . mu, - - where mu is the unit XH bond vector, T is the transpose, and A is the alignment tensor matrix. - - - @param vect: The unit XH bond vector matrix. The first dimension corresponds to the - structural index, the second dimension is the coordinates of the unit - vector. - @type vect: numpy matrix - @param K: The total number of structures. - @type K: int - @param A: The alignment tensor. - @type A: numpy rank-2 3D tensor - @param weights: The weights for each member of the ensemble. The last weight is assumed to - be missing, and is calculated by this function. Hence the length should be - one less than K. - @type weights: numpy rank-1 array - @return: The average RDC value. - @rtype: float - """ - - # Initial back-calculated RDC value. - val = 0.0 - - # Averaging factor. - if weights == None: - c = 1.0 / K - - # Loop over the structures k. - for k in xrange(K): - # The weights. - if weights != None: - if k == K-1: - c = 1.0 - sum(weights, axis=0) - else: - c = weights[k] - - # Back-calculate the RDC. - val = val + c * dot(vect[k], dot(A, vect[k])) - - # Return the average RDC. - return val def maxA(tensor): Modified: branches/rdc_analysis/maths_fns/rdc.py URL: http://svn.gna.org/viewcvs/relax/branches/rdc_analysis/maths_fns/rdc.py?rev=6942&r1=6941&r2=6942&view=diff ============================================================================== --- branches/rdc_analysis/maths_fns/rdc.py (original) +++ branches/rdc_analysis/maths_fns/rdc.py Wed Jul 23 11:47:41 2008 @@ -21,11 +21,10 @@ ############################################################################### # Module docstring. -"""Module containing functions for the calculation of RDCs.""" +"""Module for the calculation of RDCs.""" # Python imports. from numpy import sum -from numpy.linalg import eigvals def average_rdc_5D(vect, K, A, weights=None): @@ -147,54 +146,3 @@ # Return the average RDC. return val - - -def maxA(tensor): - """Find the maximal alignment - the Azz component in the alignment frame. - - @param tensor: The alignment tensor object. - @type tensor: numpy rank-2 3D tensor - @return: The Azz component in the alignment frame. - """ - - # Return the value. - return max(abs(eigvals(tensor))) - - -def to_5D(vector_5D, tensor): - """Convert the rank-2 3D alignment tensor matrix to the 5D vector format. - - @param vector_5D: The 5D vector object to populate. The vector format is {Axx, Ayy, Axy, Axz, - Ayz}. - @type vector_5D: numpy 5D vector - @param tensor: The alignment tensor object. - @type tensor: numpy rank-2 3D tensor - """ - - # Convert the matrix form to the vector form. - vector_5D[0] = tensor[0, 0] - vector_5D[1] = tensor[1, 1] - vector_5D[2] = tensor[0, 1] - vector_5D[3] = tensor[0, 2] - vector_5D[4] = tensor[1, 2] - - -def to_tensor(tensor, vector_5D): - """Convert the 5D vector alignment tensor form to the rank-2 3D matrix from. - - @param tensor: The alignment tensor object, in matrix format, to populate. - @type tensor: numpy rank-2 3D tensor - @param vector_5D: The 5D vector object. The vector format is {Axx, Ayy, Axy, Axz, Ayz}. - @type vector_5D: numpy 5D vector - """ - - # Convert the vector form to the matrix form. - tensor[0, 0] = vector_5D[0] - tensor[0, 1] = vector_5D[2] - tensor[0, 2] = vector_5D[3] - tensor[1, 0] = vector_5D[2] - tensor[1, 1] = vector_5D[1] - tensor[1, 2] = vector_5D[4] - tensor[2, 0] = vector_5D[3] - tensor[2, 1] = vector_5D[4] - tensor[2, 2] = -vector_5D[0] -vector_5D[1]