Author: bugman Date: Tue Jul 29 16:41:17 2014 New Revision: 24814 URL: http://svn.gna.org/viewcvs/relax?rev=24814&view=rev Log: Better handling of unset parameters in the frame order optimisation functions. The specific_analyses.frame_order.optimisation.target_fn_data_setup() and specific_analyses.frame_order.parameters.assemble_param_vector() function both now accept the unset_fail argument. This is set in both the calculate() and minimise() API methods. When set, a RelaxError will be raised in the assemble_param_vector() function when a parameter has not been set yet. This together with previous changes will prevent the frame order analysis from using 0.0 as a starting value for unset parameters. Modified: branches/frame_order_cleanup/specific_analyses/frame_order/api.py branches/frame_order_cleanup/specific_analyses/frame_order/optimisation.py branches/frame_order_cleanup/specific_analyses/frame_order/parameters.py Modified: branches/frame_order_cleanup/specific_analyses/frame_order/api.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/specific_analyses/frame_order/api.py?rev=24814&r1=24813&r2=24814&view=diff ============================================================================== --- branches/frame_order_cleanup/specific_analyses/frame_order/api.py (original) +++ branches/frame_order_cleanup/specific_analyses/frame_order/api.py Tue Jul 29 16:41:17 2014 @@ -125,7 +125,7 @@ """ # Set up the data structures for the target function. - param_vector, full_tensors, full_in_ref_frame, rdcs, rdc_err, rdc_weight, rdc_vect, rdc_const, pcs, pcs_err, pcs_weight, atomic_pos, temp, frq, paramag_centre, com, ave_pos_pivot, pivot, pivot_opt = target_fn_data_setup(sim_index=sim_index, verbosity=verbosity) + param_vector, full_tensors, full_in_ref_frame, rdcs, rdc_err, rdc_weight, rdc_vect, rdc_const, pcs, pcs_err, pcs_weight, atomic_pos, temp, frq, paramag_centre, com, ave_pos_pivot, pivot, pivot_opt = target_fn_data_setup(sim_index=sim_index, verbosity=verbosity, unset_fail=True) # Set up the optimisation target function class. target_fn = 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, dip_const=rdc_const, pcs=pcs, pcs_errors=pcs_err, pcs_weights=pcs_weight, atomic_pos=atomic_pos, temp=temp, frq=frq, paramag_centre=paramag_centre, scaling_matrix=scaling_matrix[0], com=com, ave_pos_pivot=ave_pos_pivot, pivot=pivot, pivot_opt=pivot_opt, num_int_pts=cdp.num_int_pts) @@ -557,7 +557,7 @@ raise RelaxError("Only the 'simplex' minimisation algorithm is supported for the relaxation dispersion analysis as function gradients are not implemented.") # Set up the data structures for the target function. - param_vector, full_tensors, full_in_ref_frame, rdcs, rdc_err, rdc_weight, rdc_vect, rdc_const, pcs, pcs_err, pcs_weight, atomic_pos, temp, frq, paramag_centre, com, ave_pos_pivot, pivot, pivot_opt = target_fn_data_setup(sim_index=sim_index, verbosity=verbosity) + param_vector, full_tensors, full_in_ref_frame, rdcs, rdc_err, rdc_weight, rdc_vect, rdc_const, pcs, pcs_err, pcs_weight, atomic_pos, temp, frq, paramag_centre, com, ave_pos_pivot, pivot, pivot_opt = target_fn_data_setup(sim_index=sim_index, verbosity=verbosity, unset_fail=True) # Get the Processor box singleton (it contains the Processor instance) and alias the Processor. processor_box = Processor_box() Modified: branches/frame_order_cleanup/specific_analyses/frame_order/optimisation.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/specific_analyses/frame_order/optimisation.py?rev=24814&r1=24813&r2=24814&view=diff ============================================================================== --- branches/frame_order_cleanup/specific_analyses/frame_order/optimisation.py (original) +++ branches/frame_order_cleanup/specific_analyses/frame_order/optimisation.py Tue Jul 29 16:41:17 2014 @@ -624,7 +624,7 @@ rdc_index += 1 -def target_fn_data_setup(sim_index=None, verbosity=1, scaling_matrix=None): +def target_fn_data_setup(sim_index=None, verbosity=1, scaling_matrix=None, unset_fail=False): """Initialise the target function for optimisation or direct calculation. @keyword sim_index: The index of the simulation to optimise. This should be None if normal optimisation is desired. @@ -633,10 +633,12 @@ @type verbosity: int @keyword scaling_matrix: The diagonal and square scaling matrices. @type scaling_matrix: numpy rank-2, float64 array or None + @keyword unset_fail: A flag which if True will cause a RelaxError to be raised if the parameter is not set yet. + @type unset_fail: bool """ # Assemble the parameter vector. - param_vector = assemble_param_vector(sim_index=sim_index) + param_vector = assemble_param_vector(sim_index=sim_index, unset_fail=unset_fail) # Determine the base data types (RDCs and/or PCSs). data_types = base_data_types() Modified: branches/frame_order_cleanup/specific_analyses/frame_order/parameters.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/specific_analyses/frame_order/parameters.py?rev=24814&r1=24813&r2=24814&view=diff ============================================================================== --- branches/frame_order_cleanup/specific_analyses/frame_order/parameters.py (original) +++ branches/frame_order_cleanup/specific_analyses/frame_order/parameters.py Tue Jul 29 16:41:17 2014 @@ -27,17 +27,20 @@ from numpy import array, float64, zeros # relax module imports. +from lib.errors import RelaxError from specific_analyses.frame_order.data import pivot_fixed from specific_analyses.frame_order.variables import MODEL_DOUBLE_ROTOR, MODEL_FREE_ROTOR, MODEL_ISO_CONE, MODEL_ISO_CONE_FREE_ROTOR, MODEL_ISO_CONE_TORSIONLESS, MODEL_LIST_FREE_ROTORS, MODEL_LIST_ISO_CONE, MODEL_LIST_PSEUDO_ELLIPSE, MODEL_PSEUDO_ELLIPSE, MODEL_ROTOR -def assemble_param_vector(sim_index=None): +def assemble_param_vector(sim_index=None, unset_fail=False): """Assemble and return the parameter vector. - @return: The parameter vector. - @rtype: numpy rank-1 array - @keyword sim_index: The Monte Carlo simulation index. - @type sim_index: int + @keyword sim_index: The Monte Carlo simulation index. + @type sim_index: int + @keyword unset_fail: A flag which if True will cause a RelaxError to be raised if the parameter is not set yet. + @type unset_fail: bool + @return: The parameter vector. + @rtype: numpy rank-1 array """ # Initialise. @@ -50,13 +53,19 @@ # Loop over all model parameters. for param_name in cdp.params: + # Add the extension. + param_name += ext + # The parameter does not exist yet. - if not hasattr(cdp, param_name+ext): - param_vect.append(None) - continue + if not hasattr(cdp, param_name): + if unset_fail: + raise RelaxError("The parameter '%s' has not been set." % param_name) + else: + param_vect.append(None) + continue # Get the object. - obj = getattr(cdp, param_name+ext) + obj = getattr(cdp, param_name) # Add it to the parameter vector. if sim_index == None: