Author: bugman Date: Thu Nov 14 15:00:49 2013 New Revision: 21450 URL: http://svn.gna.org/viewcvs/relax?rev=21450&view=rev Log: Started to add better pseudo-atom support for the PCS. The new pipe_control.pcs.setup_pseudoatom_pcs() function has been added to deselect the spins which are members of a pseudo-atom. The return_pcs_data() function in the same module now calls this function and builds a list of pseudo-atom flags for use in the target function (though it is still unused). Modified: trunk/pipe_control/pcs.py trunk/specific_analyses/n_state_model/__init__.py trunk/target_functions/n_state_model.py Modified: trunk/pipe_control/pcs.py URL: http://svn.gna.org/viewcvs/relax/trunk/pipe_control/pcs.py?rev=21450&r1=21449&r2=21450&view=diff ============================================================================== --- trunk/pipe_control/pcs.py (original) +++ trunk/pipe_control/pcs.py Thu Nov 14 15:00:49 2013 @@ -25,7 +25,7 @@ # Python module imports. from copy import deepcopy from math import pi, sqrt -from numpy import array, float64, ones, std, zeros +from numpy import array, float64, int32, ones, std, zeros from numpy.linalg import norm from random import gauss import sys @@ -40,7 +40,7 @@ from lib.warnings import RelaxWarning, RelaxNoSpinWarning from pipe_control import grace, pipes from pipe_control.align_tensor import get_tensor_index, get_tensor_object, opt_uses_align_data, opt_uses_tensor -from pipe_control.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_unique, return_spin, spin_index_loop, spin_loop +from pipe_control.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_unique, is_pseudoatom, return_spin, spin_index_loop, spin_loop def back_calc(align_id=None): @@ -756,11 +756,12 @@ @type sim_index: None or int @return: The assembled data structures for using PCSs as the base data for optimisation. These include: - the PCS values. - - the unit vectors connecting the paramagnetic centre (the electron spin) to + - the unit vectors connecting the paramagnetic centre (the electron spin) to the spin. - the PCS weight. - - the nuclear spin. - - the pseudocontact shift constants. - @rtype: tuple of (numpy rank-2 array, numpy rank-2 array, numpy rank-2 array, numpy rank-1 array, numpy rank-1 array) + - the experimental temperatures. + - the spectrometer frequencies. + - pseudo_flags, the list of flags indicating if the interatomic data contains a pseudo-atom (as 1's and 0's). + @rtype: tuple of (numpy rank-2 float64 array, numpy rank-2 float64 array, numpy rank-2 float64 array, list of float, list of float, numpy rank-1 int32 array) """ # Data setup tests. @@ -771,12 +772,16 @@ if not hasattr(cdp, 'spectrometer_frq'): raise RelaxError("The spectrometer frequencies of the experiments have not been set.") + # Sort out pseudo-atoms first. This only needs to be called once. + setup_pseudoatom_pcs() + # Initialise. pcs = [] pcs_err = [] pcs_weight = [] temp = [] frq = [] + pseudo_flags = [] # The PCS data. for i in range(len(cdp.align_ids)): @@ -843,17 +848,25 @@ # Spin index. j = j + 1 + # Pseudo-atom. + for spin in spin_loop(): + if is_pseudoatom(spin): + pseudo_flags.append(1) + else: + pseudo_flags.append(0) + # Convert to numpy objects. pcs = array(pcs, float64) pcs_err = array(pcs_err, float64) pcs_weight = array(pcs_weight, float64) + pseudo_flags = array(pseudo_flags, int32) # Convert the PCS from ppm to no units. pcs = pcs * 1e-6 pcs_err = pcs_err * 1e-6 # Return the data structures. - return pcs, pcs_err, pcs_weight, temp, frq + return pcs, pcs_err, pcs_weight, temp, frq, pseudo_flags def set_errors(align_id=None, spin_id=None, sd=None): @@ -893,6 +906,26 @@ # Set the error. for id in align_ids: spin.pcs_err[id] = sd + + +def setup_pseudoatom_pcs(): + """Make sure that the spin systems are properly set up for pseudo-atoms and PCSs. + + All spin data containers which are a member of a pseudo-atom will be deselected. + """ + + # Loop over all spin data containers. + for pseudospin, pseudospin_id in spin_loop(return_id=True): + # No pseudo-atom, so do nothing. + if not is_pseudoatom(pseudospin): + return + + # Loop over the atoms of the pseudo-atom. + for spin, spin_id in pseudoatom_loop(pseudospin, return_id=True): + # Deselect if needed. + if spin.select: + warn(RelaxWarning("Deselecting the '%s' spin as it is a member of the '%s' pseudo-atom system." % (spin_id, pseudospin_id))) + spin.select = False def structural_noise(align_id=None, rmsd=0.2, sim_num=1000, file=None, dir=None, force=False): Modified: trunk/specific_analyses/n_state_model/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/n_state_model/__init__.py?rev=21450&r1=21449&r2=21450&view=diff ============================================================================== --- trunk/specific_analyses/n_state_model/__init__.py (original) +++ trunk/specific_analyses/n_state_model/__init__.py Thu Nov 14 15:00:49 2013 @@ -534,7 +534,7 @@ # Get the data structures for optimisation using PCSs as base data sets. pcs, pcs_err, pcs_weight, temp, frq = None, None, None, None, None if 'pcs' in data_types: - pcs, pcs_err, pcs_weight, temp, frq = return_pcs_data(sim_index=sim_index) + pcs, pcs_err, pcs_weight, temp, frq, pcs_pseudo_flags = return_pcs_data(sim_index=sim_index) # Get the data structures for optimisation using RDCs as base data sets. rdcs, rdc_err, rdc_weight, rdc_vector, rdc_dj, absolute_rdc, T_flags, j_couplings, rdc_pseudo_flags = None, None, None, None, None, None, None, None, None @@ -568,7 +568,7 @@ centre_fixed = cdp.paramag_centre_fixed # Set up the class instance containing the target function. - model = N_state_opt(model=cdp.model, N=cdp.N, init_params=param_vector, probs=probs, full_tensors=full_tensors, red_data=red_tensor_elem, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame, fixed_tensors=fixed_tensors, pcs=pcs, rdcs=rdcs, pcs_errors=pcs_err, rdc_errors=rdc_err, T_flags=T_flags, j_couplings=j_couplings, rdc_pseudo_flags=rdc_pseudo_flags, pcs_weights=pcs_weight, rdc_weights=rdc_weight, rdc_vect=rdc_vector, temp=temp, frq=frq, dip_const=rdc_dj, absolute_rdc=absolute_rdc, atomic_pos=atomic_pos, paramag_centre=paramag_centre, scaling_matrix=scaling_matrix, centre_fixed=centre_fixed) + model = N_state_opt(model=cdp.model, N=cdp.N, init_params=param_vector, probs=probs, full_tensors=full_tensors, red_data=red_tensor_elem, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame, fixed_tensors=fixed_tensors, pcs=pcs, rdcs=rdcs, pcs_errors=pcs_err, rdc_errors=rdc_err, T_flags=T_flags, j_couplings=j_couplings, rdc_pseudo_flags=rdc_pseudo_flags, pcs_pseudo_flags=pcs_pseudo_flags, pcs_weights=pcs_weight, rdc_weights=rdc_weight, rdc_vect=rdc_vector, temp=temp, frq=frq, dip_const=rdc_dj, absolute_rdc=absolute_rdc, atomic_pos=atomic_pos, paramag_centre=paramag_centre, scaling_matrix=scaling_matrix, centre_fixed=centre_fixed) # Return the data. return model, param_vector, data_types, scaling_matrix Modified: trunk/target_functions/n_state_model.py URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/n_state_model.py?rev=21450&r1=21449&r2=21450&view=diff ============================================================================== --- trunk/target_functions/n_state_model.py (original) +++ trunk/target_functions/n_state_model.py Thu Nov 14 15:00:49 2013 @@ -38,7 +38,7 @@ class N_state_opt: """Class containing the target function of the optimisation of the N-state model.""" - def __init__(self, model=None, N=None, init_params=None, probs=None, full_tensors=None, red_data=None, red_errors=None, full_in_ref_frame=None, fixed_tensors=None, pcs=None, pcs_errors=None, pcs_weights=None, rdcs=None, rdc_errors=None, rdc_weights=None, rdc_vect=None, T_flags=None, j_couplings=None, rdc_pseudo_flags=None, temp=None, frq=None, dip_const=None, absolute_rdc=None, atomic_pos=None, paramag_centre=None, scaling_matrix=None, centre_fixed=True): + def __init__(self, model=None, N=None, init_params=None, probs=None, full_tensors=None, red_data=None, red_errors=None, full_in_ref_frame=None, fixed_tensors=None, pcs=None, pcs_errors=None, pcs_weights=None, rdcs=None, rdc_errors=None, rdc_weights=None, rdc_vect=None, T_flags=None, j_couplings=None, rdc_pseudo_flags=None, pcs_pseudo_flags=None, temp=None, frq=None, dip_const=None, absolute_rdc=None, atomic_pos=None, paramag_centre=None, scaling_matrix=None, centre_fixed=True): """Set up the class instance for optimisation. The N-state models @@ -141,6 +141,8 @@ @type j_couplings: numpy rank-1 array @keyword rdc_pseudo_flags: The array of flags specifying if one of the atoms of the interatomic pair for the RDC are pseudo-atoms. The indices correspond to the interatomic pairs. @type rdc_pseudo_flags: numpy rank-1 int32 array + @keyword pcs_pseudo_flags: The array of flags specifying if one of the atoms of the interatomic pair for the PCS are pseudo-atoms. The indices correspond to the interatomic pairs. + @type pcs_pseudo_flags: numpy rank-1 int32 array @keyword temp: The temperature of each experiment, used for the PCS. @type temp: numpy rank-1 array @keyword frq: The frequency of each alignment, used for the PCS. @@ -171,6 +173,7 @@ self.T_flags = T_flags self.j_couplings = j_couplings self.rdc_pseudo_flags = rdc_pseudo_flags + self.pcs_pseudo_flags = pcs_pseudo_flags self.temp = temp self.frq = frq self.atomic_pos = atomic_pos