Author: michaelbieri Date: Tue Jul 13 01:35:11 2010 New Revision: 11297 URL: http://svn.gna.org/viewcvs/relax?rev=11297&view=rev Log: Merged revisions 11291-11296 via svnmerge from svn+ssh://michaelbieri@xxxxxxxxxxx/svn/relax/1.3 ........ r11291 | bugman | 2010-07-08 19:45:21 +1000 (Thu, 08 Jul 2010) | 3 lines Docstring improvements - the geometric info should be in Angstroms. ........ r11292 | bugman | 2010-07-08 19:49:35 +1000 (Thu, 08 Jul 2010) | 9 lines Better support for the optimisation and mapping of the Ln3+ position. The position is now treated in Angstrom, and is properly scaled. A few additional API methods have been added for the mapping of the optimisation space, and a few modified to support the Ln3+ position. ........ r11293 | bugman | 2010-07-08 19:56:42 +1000 (Thu, 08 Jul 2010) | 3 lines Fix for the Ln3+ position optimisation with no populations, the target function was overwritten. ........ r11294 | bugman | 2010-07-08 21:03:13 +1000 (Thu, 08 Jul 2010) | 5 lines Fix for the N-state model _assemble_scaling_matrix() method for the 2-domain model. This is a recently introduced bug. For the 2-domain model, no alignment parameters are optimised. ........ r11295 | bugman | 2010-07-08 21:49:04 +1000 (Thu, 08 Jul 2010) | 3 lines Changed the alignment tensor parameter scaling back to 1 as this was slowing down the optimisation. ........ r11296 | bugman | 2010-07-08 23:26:24 +1000 (Thu, 08 Jul 2010) | 3 lines Created the n_state_model.elim_no_prob() to remove structures with zero probability. ........ Modified: branches/bieri_gui/ (props changed) branches/bieri_gui/maths_fns/n_state_model.py branches/bieri_gui/maths_fns/paramag_centre.py branches/bieri_gui/prompt/n_state_model.py branches/bieri_gui/specific_fns/n_state_model.py Propchange: branches/bieri_gui/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Tue Jul 13 01:35:11 2010 @@ -1,1 +1,1 @@ -/1.3:1-11289 +/1.3:1-11296 Modified: branches/bieri_gui/maths_fns/n_state_model.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/maths_fns/n_state_model.py?rev=11297&r1=11296&r2=11297&view=diff ============================================================================== --- branches/bieri_gui/maths_fns/n_state_model.py (original) +++ branches/bieri_gui/maths_fns/n_state_model.py Tue Jul 13 01:35:11 2010 @@ -375,7 +375,7 @@ self.d2Dij_theta = zeros((self.total_num_params, self.total_num_params, self.num_align, self.num_spins), float64) # Set the target function, gradient, and Hessian (paramagnetic centre optimisation). - if not centre_fixed: + if not self.centre_fixed: self.func = self.func_population self.dfunc = None self.d2func = None @@ -387,7 +387,7 @@ self.d2func = self.d2func_population # Pure tensor optimisation overrides. - if model == 'fixed': + if model == 'fixed' and self.centre_fixed: # The probs are unpacked by self.func in the population model, so just override that function. self.func = self.func_tensor_opt self.dfunc = self.dfunc_tensor_opt Modified: branches/bieri_gui/maths_fns/paramag_centre.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/maths_fns/paramag_centre.py?rev=11297&r1=11296&r2=11297&view=diff ============================================================================== --- branches/bieri_gui/maths_fns/paramag_centre.py (original) +++ branches/bieri_gui/maths_fns/paramag_centre.py Tue Jul 13 01:35:11 2010 @@ -30,9 +30,9 @@ def paramag_data(atomic_pos, paramag_centre, unit_vector, r): """Calculate the electron spin to nuclear spin unit vectors and distances. - @param atomic_pos: The atomic positions. The first index is the spins, the second is the structures, and the third is the atomic coordinates. + @param atomic_pos: The atomic positions in Angstrom. The first index is the spins, the second is the structures, and the third is the atomic coordinates. @type atomic_pos: numpy rank-3 array - @param paramag_centre: The paramagnetic centre position. + @param paramag_centre: The paramagnetic centre position in Angstrom. @type paramag_centre: numpy rank-1, 3D array @param unit_vector: The structure to fill with the electron spin to nuclear spin unit vectors. @type unit_vector: numpy rank-3 array Modified: branches/bieri_gui/prompt/n_state_model.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/prompt/n_state_model.py?rev=11297&r1=11296&r2=11297&view=diff ============================================================================== --- branches/bieri_gui/prompt/n_state_model.py (original) +++ branches/bieri_gui/prompt/n_state_model.py Tue Jul 13 01:35:11 2010 @@ -163,6 +163,26 @@ n_state_model_obj._cone_pdb(cone_type=cone_type, scale=scale, file=file, dir=dir, force=force) + def elim_no_prob(self): + """Eliminate the structures or states with no probability. + + Examples + ~~~~~~~~ + + Simply type: + + relax> n_state_model.elim_no_prob(N=8) + """ + + # Function intro text. + if self._exec_info.intro: + text = self._exec_info.ps3 + "n_state_model.elim_no_prob()" + print(text) + + # Execute the functional code. + n_state_model_obj._elim_no_prob() + + def number_of_states(self, N=None): """Set the number of states in the N-state model. Modified: branches/bieri_gui/specific_fns/n_state_model.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/specific_fns/n_state_model.py?rev=11297&r1=11296&r2=11297&view=diff ============================================================================== --- branches/bieri_gui/specific_fns/n_state_model.py (original) +++ branches/bieri_gui/specific_fns/n_state_model.py Tue Jul 13 01:35:11 2010 @@ -61,6 +61,7 @@ # Place methods into the API. self.overfit_deselect = self._overfit_deselect_dummy + self.return_conversion_factor = self._return_no_conversion_factor self.test_grid_ops = self._test_grid_ops_general @@ -175,16 +176,20 @@ if ('rdc' in data_types or 'pcs' in data_types) and not (hasattr(cdp.align_tensors, 'fixed') and cdp.align_tensors.fixed): pop_start = pop_start + 5*len(cdp.align_ids) + # The alignment parameters. + for i in range(5*len(cdp.align_ids)): + scaling_matrix[i, i] = 1.0 + # Loop over the populations, and set the scaling factor. if cdp.model in ['2-domain', 'population']: - factor = 100.0 + factor = 0.1 for i in xrange(pop_start, pop_start + (cdp.N-1)): scaling_matrix[i, i] = factor # The paramagnetic centre. if hasattr(cdp, 'paramag_centre_fixed') and not cdp.paramag_centre_fixed: for i in range(-3, 0): - scaling_matrix[i, i] = 1e10 + scaling_matrix[i, i] = 1e2 # Return the matrix. return scaling_matrix @@ -537,6 +542,57 @@ cdp.paramagnetic_centre[0] = param_vector[-3] cdp.paramagnetic_centre[1] = param_vector[-2] cdp.paramagnetic_centre[2] = param_vector[-1] + + + def _elim_no_prob(self): + """Remove all structures or states which have no probability.""" + + # Test if the current data pipe exists. + pipes.test() + + # Test if the model is setup. + if not hasattr(cdp, 'model'): + raise RelaxNoModelError('N-state') + + # Test if there are populations. + if not hasattr(cdp, 'probs'): + raise RelaxError("The N-state model populations do not exist.") + + # Loop over the structures. + i = 0 + while 1: + # End condition. + if i == cdp.N - 1: + break + + # No probability. + if cdp.probs[i] < 1e-5: + # Remove the probability. + cdp.probs.pop(i) + + # Remove the structure. + cdp.structure.structural_data.pop(i) + + # Eliminate bond vectors. + for spin in spin_loop(): + # Position info. + if hasattr(spin, 'pos'): + spin.pos.pop(i) + + # Vector info. + if hasattr(spin, 'xh_vect'): + spin.xh_vect.pop(i) + if hasattr(spin, 'bond_vect'): + spin.bond_vect.pop(i) + + # Update N. + cdp.N -= 1 + + # Start the loop again without incrementing i. + continue + + # Increment i. + i += 1 def _linear_constraints(self, data_types=None, scaling_matrix=None): @@ -1674,8 +1730,8 @@ # The paramagnetic centre. elif hasattr(cdp, 'paramag_centre_fixed') and not cdp.paramag_centre_fixed and (n - i) <= 3: - lower.append(-100e-10) - upper.append(100e-10) + lower.append(-100) + upper.append(100) # Otherwise this must be an alignment tensor component. else: @@ -1683,7 +1739,7 @@ upper.append(1e-3) # Minimisation. - self.minimise(min_algor='grid', min_options=[inc, lower, upper], constraints=constraints, verbosity=verbosity, sim_index=sim_index) + self.minimise(min_algor='grid', lower=lower, upper=upper, inc=inc, constraints=constraints, verbosity=verbosity, sim_index=sim_index) def is_spin_param(self, name): @@ -1701,6 +1757,22 @@ # All other parameters are global. return False + + + def map_bounds(self, param, spin_id=None): + """Create bounds for the OpenDX mapping function. + + @param param: The name of the parameter to return the lower and upper bounds of. + @type param: str + @param spin_id: The spin identification string (unused). + @type spin_id: None + @return: The upper and lower bounds of the parameter. + @rtype: list of float + """ + + # Paramagnetic centre. + if search('^paramag_[xyz]$', param): + return [-100.0, 100.0] def minimise(self, min_algor=None, min_options=None, func_tol=None, grad_tol=None, max_iterations=None, constraints=False, scaling=True, verbosity=0, sim_index=None, lower=None, upper=None, inc=None): @@ -1767,7 +1839,14 @@ # Grid search. if search('^[Gg]rid', min_algor): - results = grid(func=model.func, args=(), num_incs=min_options[0], lower=min_options[1], upper=min_options[2], A=A, b=b, verbosity=verbosity) + # Scaling. + if scaling: + for i in xrange(len(param_vector)): + lower[i] = lower[i] / scaling_matrix[i, i] + upper[i] = upper[i] / scaling_matrix[i, i] + + # The search. + results = grid(func=model.func, args=(), num_incs=inc, lower=lower, upper=upper, A=A, b=b, verbosity=verbosity) # Unpack the results. param_vector, func, iter_count, warning = results @@ -2043,6 +2122,23 @@ obj = getattr(cdp, obj_name) obj[index] = value[i] + # The paramagnetic centre. + if search('^paramag_[xyz]$', obj_name): + # Init. + if not hasattr(cdp, 'paramagnetic_centre'): + cdp.paramagnetic_centre = zeros(3, float64) + + # Set the coordinate. + if obj_name == 'paramag_x': + index = 0 + elif obj_name == 'paramag_y': + index = 1 + else: + index = 2 + + # Set the value in Angstrom. + cdp.paramagnetic_centre[index] = value[i] + # Set the spin parameters. else: for spin in spin_loop(spin_id):