Author: bugman Date: Fri Mar 22 11:49:43 2013 New Revision: 18944 URL: http://svn.gna.org/viewcvs/relax?rev=18944&view=rev Log: Next block of the manual merger of the frame_order_testing branch. The commands used were: svn merge -r15040:15041 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15041:15042 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15042:15043 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15043:15044 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15044:15045 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15045:15046 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15046:15047 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15047:15048 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15048:15049 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . svn merge -r15049:15050 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/frame_order_testing . A few missing user functions in prompt/ had to be resolved. Modified: trunk/generic_fns/align_tensor.py trunk/maths_fns/frame_order.py trunk/specific_fns/frame_order.py Modified: trunk/generic_fns/align_tensor.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/align_tensor.py?rev=18944&r1=18943&r2=18944&view=diff ============================================================================== --- trunk/generic_fns/align_tensor.py (original) +++ trunk/generic_fns/align_tensor.py Fri Mar 22 11:49:43 2013 @@ -247,7 +247,9 @@ if tensor: tensors = [tensor] else: - tensors = cdp.align_ids + tensors = [] + for i in range(len(cdp.align_tensors)): + tensors.append(cdp.align_tensors[i].name) # Loop over the tensors. for tensor in tensors: @@ -672,7 +674,7 @@ return data -def init(tensor=None, params=None, scale=1.0, angle_units='deg', param_types=0, errors=False): +def init(tensor=None, params=None, scale=1.0, angle_units='deg', param_types=0, align_id=None, domain=None, errors=False): """Function for initialising the alignment tensor. @keyword tensor: The alignment tensor identification string. @@ -683,11 +685,13 @@ @type scale: float @keyword angle_units: The units for the angle parameters (either 'deg' or 'rad'). @type angle_units: str - @keyword param_types: The type of parameters supplied. The flag values correspond to, 0: - {Axx, Ayy, Axy, Axz, Ayz}, and 1: {Azz, Axx-yy, Axy, Axz, Ayz}. + @keyword param_types: The type of parameters supplied. The flag values correspond to, 0: {Axx, Ayy, Axy, Axz, Ayz}, and 1: {Azz, Axx-yy, Axy, Axz, Ayz}. @type param_types: int - @keyword errors: A flag which determines if the alignment tensor data or its errors are - being input. + @keyword align_id: The alignment ID string that the tensor corresponds to. + @type align_id: str or None + @keyword domain: The domain label. + @type domain: str or None + @keyword errors: A flag which determines if the alignment tensor data or its errors are being input. @type errors: bool """ @@ -703,11 +707,16 @@ if not angle_units in valid_types: raise RelaxError("The alignment tensor 'angle_units' argument " + repr(angle_units) + " should be either 'deg' or 'rad'.") - # Add the tensor ID to the current data pipe. - if not hasattr(cdp, 'align_ids'): - cdp.align_ids = [] - if tensor not in cdp.align_ids: - cdp.align_ids.append(tensor) + # Check that the domain is defined. + if domain and (not hasattr(cdp, 'domain') or domain not in cdp.domain.keys()): + raise RelaxError("The domain '%s' has not been defined. Please use the domain user function." % domain) + + # Add the align ID to the current data pipe if needed. + if align_id: + if not hasattr(cdp, 'align_ids'): + cdp.align_ids = [] + if align_id not in cdp.align_ids: + cdp.align_ids.append(align_id) # Add the align_tensors object to the data pipe. if not errors: @@ -869,6 +878,12 @@ # Unknown parameter combination. else: raise RelaxUnknownParamCombError('param_types', param_types) + + # Set the domain and alignment ID. + if domain: + set_domain(tensor=tensor, domain=domain) + if align_id: + set_domain(tensor=tensor, align_id=align_id) def map_bounds(param): @@ -1841,6 +1856,28 @@ """ +def set_align_id(tensor=None, align_id=None): + """Set the align ID string for the given tensor. + + @keyword tensor: The alignment tensor label. + @type tensor: str + @keyword align_id: The alignment ID string. + @type align_id: str + """ + + # Loop over the tensors. + match = False + for tensor_cont in cdp.align_tensors: + # Find the matching tensor and then store the ID. + if tensor_cont.name == tensor: + tensor_cont.align_id = align_id + match = True + + # The tensor label doesn't exist. + if not match: + raise RelaxNoTensorError('alignment', tensor) + + def set_domain(tensor=None, domain=None): """Set the domain label for the given tensor. Modified: trunk/maths_fns/frame_order.py URL: http://svn.gna.org/viewcvs/relax/trunk/maths_fns/frame_order.py?rev=18944&r1=18943&r2=18944&view=diff ============================================================================== --- trunk/maths_fns/frame_order.py (original) +++ trunk/maths_fns/frame_order.py Fri Mar 22 11:49:43 2013 @@ -45,7 +45,7 @@ class Frame_order: """Class containing the target function of the optimisation of Frame Order matrix components.""" - def __init__(self, model=None, init_params=None, full_tensors=None, full_in_ref_frame=None, rdcs=None, rdc_errors=None, rdc_weights=None, rdc_vect=None, rdc_const=None, pcs=None, pcs_errors=None, pcs_weights=None, pcs_atoms=None, temp=None, frq=None, paramag_centre=None, scaling_matrix=None, pivot_opt=False): + def __init__(self, model=None, init_params=None, full_tensors=None, full_in_ref_frame=None, rdcs=None, rdc_errors=None, rdc_weights=None, rdc_vect=None, rdc_const=None, pcs=None, pcs_errors=None, pcs_weights=None, pcs_atoms=None, temp=None, frq=None, paramag_centre=None, scaling_matrix=None, pivot=None, pivot_opt=False): """Set up the target functions for the Frame Order theories. @keyword model: The name of the Frame Order model. @@ -82,6 +82,8 @@ @type paramag_centre: numpy rank-1, 3D array or rank-2, Nx3 array @keyword scaling_matrix: The square and diagonal scaling matrix. @type scaling_matrix: numpy rank-2 array + @keyword pivot: The pivot point for the ball-and-socket joint motion. This is needed if PCS or PRE values are used. + @type pivot: numpy rank-1, 3D array or None @keyword pivot_opt: A flag which if True will allow the pivot point of the motion to be optimised. @type pivot_opt: bool """ @@ -108,6 +110,7 @@ self.frq = frq self.paramag_centre = paramag_centre self.total_num_params = len(init_params) + self._param_pivot = pivot self.pivot_opt = pivot_opt # Tensor setup. @@ -189,8 +192,8 @@ if self.rdc_flag or self.pcs_flag: for i in xrange(self.num_align): # Loop over the RDCs. - for j in xrange(self.num_rdc): - if self.rdc_flag: + if self.rdc_flag: + for j in xrange(self.num_rdc): if isNaN(self.rdc[i, j]): # Set the flag. self.missing_rdc[i, j] = 1 @@ -209,8 +212,8 @@ self.rdc_error[i, j] = self.rdc_error[i, j] / sqrt(rdc_weights[i, j]) # Loop over the PCSs. - for j in xrange(self.num_pcs): - if self.pcs_flag: + if self.pcs_flag: + for j in xrange(self.num_pcs): if isNaN(self.pcs[i, j]): # Set the flag. self.missing_pcs[i, j] = 1 @@ -243,14 +246,16 @@ self.pcs_const[i] = pcs_constant(self.temp[i], self.frq[i], 1.0) * 1e30 # PCS function, gradient, and Hessian matrices. - self.pcs_theta = zeros((self.num_align, self.num_pcs), float64) - self.dpcs_theta = zeros((self.total_num_params, self.num_align, self.num_pcs), float64) - self.d2pcs_theta = zeros((self.total_num_params, self.total_num_params, self.num_align, self.num_pcs), float64) + if self.pcs_flag: + self.pcs_theta = zeros((self.num_align, self.num_pcs), float64) + self.dpcs_theta = zeros((self.total_num_params, self.num_align, self.num_pcs), float64) + self.d2pcs_theta = zeros((self.total_num_params, self.total_num_params, self.num_align, self.num_pcs), float64) # RDC function, gradient, and Hessian matrices. - self.rdc_theta = zeros((self.num_align, self.num_rdc), float64) - self.drdc_theta = zeros((self.total_num_params, self.num_align, self.num_rdc), float64) - self.d2rdc_theta = zeros((self.total_num_params, self.total_num_params, self.num_align, self.num_rdc), float64) + if self.rdc_flag: + self.rdc_theta = zeros((self.num_align, self.num_rdc), float64) + self.drdc_theta = zeros((self.total_num_params, self.num_align, self.num_rdc), float64) + self.d2rdc_theta = zeros((self.total_num_params, self.total_num_params, self.num_align, self.num_rdc), float64) # The target function aliases. if model == 'pseudo-ellipse': @@ -550,7 +555,7 @@ # Unpack the parameters. if self.pivot_opt: - pivot = params[:3] + self._param_pivot = params[:3] ave_pos_alpha, ave_pos_beta, ave_pos_gamma, axis_theta, axis_phi, sigma_max = params[3:] else: ave_pos_alpha, ave_pos_beta, ave_pos_gamma, axis_theta, axis_phi, sigma_max = params @@ -575,36 +580,37 @@ RT_ave = transpose(self.R_ave) # Pre-calculate all the necessary vectors. - if self.pivot_opt: - self.calc_vectors(pivot) + self.calc_vectors(self._param_pivot) # Loop over each alignment. for i in xrange(self.num_align): - # Loop over the RDCs. - for j in xrange(self.num_rdc): - # The back calculated RDC. - if self.rdc_flag and not self.missing_rdc[i, j]: - self.rdc_theta[i, j] = rdc_tensor(self.rdc_const[j], self.rdc_vect[j], self.A_3D_bc[i]) - - # Loop over the PCSs. - for j in xrange(self.num_pcs): - # The back calculated PCS. - if self.pcs_flag and not self.missing_pcs[i, j]: - # Forwards and reverse rotations. - if self.full_in_ref_frame[i]: - R_ave = RT_ave - else: - R_ave = self.R_ave - - # The numerical integration. - self.pcs_theta[i, j] = pcs_numeric_int_rotor(sigma_max=sigma_max, c=self.pcs_const[i], r_pivot_atom=self.r_pivot_atom[j], r_ln_pivot=self.r_ln_pivot, A=self.A_3D[i], R_ave=R_ave, R_eigen=self.R_eigen, RT_eigen=RT_eigen, Ri_prime=self.Ri_prime) - - # Calculate and sum the single alignment chi-squared value (for the RDC). + # RDCs. if self.rdc_flag: + # Loop over the RDCs. + for j in xrange(self.num_rdc): + # The back calculated RDC. + if not self.missing_rdc[i, j]: + self.rdc_theta[i, j] = rdc_tensor(self.rdc_const[j], self.rdc_vect[j], self.A_3D_bc[i]) + + # Calculate and sum the single alignment chi-squared value (for the RDC). chi2_sum = chi2_sum + chi2(self.rdc[i], self.rdc_theta[i], self.rdc_error[i]) - # Calculate and sum the single alignment chi-squared value (for the PCS). + # PCS. if self.pcs_flag: + # Loop over the PCSs. + for j in xrange(self.num_pcs): + # The back calculated PCS. + if not self.missing_pcs[i, j]: + # Forwards and reverse rotations. + if self.full_in_ref_frame[i]: + R_ave = RT_ave + else: + R_ave = self.R_ave + + # The numerical integration. + self.pcs_theta[i, j] = pcs_numeric_int_rotor(sigma_max=sigma_max, c=self.pcs_const[i], r_pivot_atom=self.r_pivot_atom[j], r_ln_pivot=self.r_ln_pivot, A=self.A_3D[i], R_ave=R_ave, R_eigen=self.R_eigen, RT_eigen=RT_eigen, Ri_prime=self.Ri_prime) + + # Calculate and sum the single alignment chi-squared value (for the PCS). chi2_sum = chi2_sum + chi2(self.pcs[i], self.pcs_theta[i], self.pcs_error[i]) # Return the chi-squared value. Modified: trunk/specific_fns/frame_order.py URL: http://svn.gna.org/viewcvs/relax/trunk/specific_fns/frame_order.py?rev=18944&r1=18943&r2=18944&view=diff ============================================================================== --- trunk/specific_fns/frame_order.py (original) +++ trunk/specific_fns/frame_order.py Fri Mar 22 11:49:43 2013 @@ -114,7 +114,7 @@ param_vect = [] # Pivot point. - if 'pcs' in self._base_data_types(): + if not self._pivot_fixed(): for i in range(3): param_vect.append(cdp.pivot[i]) @@ -212,7 +212,7 @@ return scaling_matrix # The pivot point. - if 'pcs' in data_types: + if not self._pivot_fixed(): for i in range(3): scaling_matrix[i, i] = 1e2 @@ -921,7 +921,7 @@ data_types = self._base_data_types() # The pivot point. - if 'pcs' in data_types: + if not self._pivot_fixed(): num += 3 # Average domain position parameters. @@ -954,23 +954,42 @@ return num - def _pivot(self, pivot=None): + def _pivot(self, pivot=None, fix=None): """Set the pivot point for the 2 body motion. - @param pivot: The pivot point of the two bodies (domains, etc.) in the structural - coordinate system. + @keyword pivot: The pivot point of the two bodies (domains, etc.) in the structural coordinate system. @type pivot: list of num + @keyword fix: A flag specifying if the pivot point should be fixed during optimisation. + @type fix: bool """ # Test if the current data pipe exists. pipes.test() - # Set the pivot point. + # Set the pivot point and fixed flag. cdp.pivot = pivot + cdp.pivot_fixed = fix # Convert to floats. for i in range(3): cdp.pivot[i] = float(cdp.pivot[i]) + + + def _pivot_fixed(self): + """Determine if the pivot is fixed or not. + + @return: The answer to the question. + @rtype: bool + """ + + # The PCS is loaded. + if 'pcs' in self._base_data_types(): + # The fixed flag is not set. + if hasattr(cdp, 'pivot_fixed') and not cdp.pivot_fixed: + return False + + # The point is fixed. + return True def _ref_domain(self, ref=None): @@ -1080,13 +1099,18 @@ if 'rdc' in data_types: rdcs, rdc_err, rdc_weight, rdc_vect, rdc_const = self._minimise_setup_rdcs(sim_index=sim_index) + # The fixed pivot point. + pivot = None + if hasattr(cdp, 'pivot'): + pivot = cdp.pivot + # Pivot optimisation. - pivot_opt = False - if 'pcs' in data_types: - pivot_opt = True + pivot_opt = True + if self._pivot_fixed(): + pivot_opt = False # Set up the optimisation function. - target = frame_order.Frame_order(model=cdp.model, init_params=param_vector, full_tensors=full_tensors, full_in_ref_frame=full_in_ref_frame, rdcs=rdcs, rdc_errors=rdc_err, rdc_weights=rdc_weight, rdc_vect=rdc_vect, rdc_const=rdc_const, pcs=pcs, pcs_errors=pcs_err, pcs_weights=pcs_weight, pcs_atoms=pcs_atoms, temp=temp, frq=frq, paramag_centre=paramag_centre, scaling_matrix=scaling_matrix, pivot_opt=pivot_opt) + target = frame_order.Frame_order(model=cdp.model, init_params=param_vector, full_tensors=full_tensors, full_in_ref_frame=full_in_ref_frame, rdcs=rdcs, rdc_errors=rdc_err, rdc_weights=rdc_weight, rdc_vect=rdc_vect, rdc_const=rdc_const, pcs=pcs, pcs_errors=pcs_err, pcs_weights=pcs_weight, pcs_atoms=pcs_atoms, temp=temp, frq=frq, paramag_centre=paramag_centre, scaling_matrix=scaling_matrix, pivot=pivot, pivot_opt=pivot_opt) # Return the data. return target, param_vector, data_types, scaling_matrix @@ -1127,7 +1151,7 @@ cdp.params = [] # The pivot parameters. - if 'pcs' in self._base_data_types(): + if not self._pivot_fixed(): cdp.params.append('pivot_x') cdp.params.append('pivot_y') cdp.params.append('pivot_z') @@ -1198,7 +1222,7 @@ raise RelaxNaNError('chi-squared') # Pivot point. - if 'pcs' in self._base_data_types(): + if not self._pivot_fixed(): # Store the pivot. cdp.pivot = param_vector[:3]