Package specific_analyses :: Module parameter_object
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.parameter_object

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2012-2014 Edward d'Auvergne                                   # 
   4  #                                                                             # 
   5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   6  #                                                                             # 
   7  # This program is free software: you can redistribute it and/or modify        # 
   8  # it under the terms of the GNU General Public License as published by        # 
   9  # the Free Software Foundation, either version 3 of the License, or           # 
  10  # (at your option) any later version.                                         # 
  11  #                                                                             # 
  12  # This program is distributed in the hope that it will be useful,             # 
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  15  # GNU General Public License for more details.                                # 
  16  #                                                                             # 
  17  # You should have received a copy of the GNU General Public License           # 
  18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  19  #                                                                             # 
  20  ############################################################################### 
  21   
  22  # Module docstring. 
  23  """The parameter list object base class for the specific analyses. 
  24   
  25  This provides a uniform interface for defining and handling parameters - either optimised or fixed - of the specific analyses. 
  26  """ 
  27   
  28  # Python module imports. 
  29  from math import pi 
  30  from re import search 
  31  from types import FunctionType, MethodType 
  32   
  33  # relax module imports. 
  34  from lib.errors import RelaxError 
  35  from user_functions.data import Uf_tables; uf_tables = Uf_tables() 
  36  from user_functions.objects import Desc_container 
  37   
  38   
39 -def da_lower(incs=None, model_info=None):
40 """Determine the lower grid bound for the Da diffusion parameter. 41 42 @keyword incs: The number of grid search increments. 43 @type incs: int 44 @keyword model_info: The model information from model_loop(). 45 @type model_info: unknown 46 @return: The lower grid search bound for the Da diffusion parameter. 47 @rtype: float 48 """ 49 50 # Return the lower bound. 51 if (cdp.diff_tensor.type == 'spheroid' and cdp.diff_tensor.spheroid_type == 'prolate') or cdp.diff_tensor.type == 'ellipsoid': 52 return 0.0 53 else: 54 return -1e7
55 56
57 -def da_upper(incs=None, model_info=None):
58 """Determine the upper grid bound for the Da diffusion parameter. 59 60 @keyword incs: The number of grid search increments. 61 @type incs: int 62 @keyword model_info: The model information from model_loop(). 63 @type model_info: unknown 64 @return: The upper grid search bound for the Da diffusion parameter. 65 @rtype: float 66 """ 67 68 # Return the upper bound. 69 if cdp.diff_tensor.type == 'spheroid' and cdp.diff_tensor.spheroid_type == 'oblate': 70 return 0.0 71 else: 72 return 1e7
73 74 75
76 -class Param_list(object):
77 """A special object for handling global and spin parameters.""" 78
79 - def __init__(self, spin_data=True):
80 """Set up the class. 81 82 @keyword spin_data: A flag which if True indicates that the specific analysis operates with spins. 83 @type spin_data: bool 84 """ 85 86 # Store the flags. 87 self.spin_data = spin_data 88 89 # Initialise the lists and dictionaries for the parameter info. 90 self._names = [] 91 self._scope = {} 92 self._string = {} 93 self._defaults = {} 94 self._units = {} 95 self._desc = {} 96 self._py_types = {} 97 self._conv_factor = {} 98 self._grace_string = {} 99 self._grid_lower = {} 100 self._grid_upper = {} 101 self._set = {} 102 self._err = {} 103 self._scaling = {} 104 self._sim = {} 105 106 # Add some spin specific objects. 107 if self.spin_data: 108 self._add( 109 'select', 110 scope = 'spin', 111 desc = 'The spin selection flag', 112 py_type = bool, 113 sim = True 114 ) 115 self._add( 116 'fixed', 117 scope = 'spin', 118 desc = 'The fixed flag', 119 py_type = bool 120 ) 121 122 # Default user function documentation. 123 self._uf_title = "Parameters" 124 self._uf_table_caption = "Parameters" 125 self._uf_docs = {} 126 127 # Set the initialised flag. 128 self._initialised = True
129 130
131 - def __new__(cls, *args, **kargs):
132 """Replacement function for implementing the singleton design pattern.""" 133 134 # First initialisation. 135 if cls._instance is None: 136 # Create a new instance. 137 cls._instance = object.__new__(cls, *args, **kargs) 138 139 # Add an initialisation flag. 140 cls._instance._initialised = False 141 142 # Already initialised, so return the instance. 143 return cls._instance
144 145
146 - def _add(self, name, scope=None, string=None, default=None, units=None, desc=None, py_type=None, set='all', conv_factor=None, scaling=1.0, grid_lower=None, grid_upper=None, grace_string=None, err=False, sim=False):
147 """Add a parameter to the list. 148 149 @param name: The name of the parameter. This will be used as the variable name. 150 @type name: str 151 @keyword scope: The parameter scope. This can be set to 'global' for parameters located within the global scope of the current data pipe. Or set to 'spin' for spin specific parameters. Alternatively the value 'both' indicates that there are both global and specific versions of this parameter. 152 @type scope: str 153 @keyword string: The string representation of the parameter. 154 @type string: None or str 155 @keyword default: The default value of the parameter. 156 @type default: anything 157 @keyword units: A string representing the parameters units. 158 @type units: None or str 159 @keyword desc: The text description of the parameter. 160 @type desc: None or str 161 @keyword py_type: The Python type that this parameter should be. 162 @type py_type: Python type object 163 @keyword set: The set of object names. This can be set to 'all' for all names, to 'fixed' for parameter of the model which are permanently fixed, to 'params' for parameter of the model which are optimised or calculated, or to 'min' for minimisation specific object names. 164 @type set: str 165 @keyword conv_factor: The factor of conversion between different parameter units. 166 @type conv_factor: None, float or func 167 @keyword scaling: The diagonal scaling factor for optimisation. 168 @type scaling: float or function 169 @keyword grid_lower: The lower bound for the grid search. 170 @type grid_lower: int or function 171 @keyword grid_upper: The upper bound for the grid search. 172 @type grid_upper: int or function 173 @keyword grace_string: The string used for the axes in Grace plots of the data. 174 @type grace_string: None or str 175 @keyword err: A flag which if True indicates that the parameter name + '_err' error data structure can exist. 176 @type err: bool 177 @keyword sim: A flag which if True indicates that the parameter name + '_sim' Monte Carlo simulation data structure can exist. 178 @type sim: bool 179 """ 180 181 # Checks. 182 if scope == None: 183 raise RelaxError("The parameter scope must be set.") 184 if py_type == None: 185 raise RelaxError("The parameter type must be set.") 186 allowed_sets = ['all', 'fixed', 'params', 'min'] 187 if set not in allowed_sets: 188 raise RelaxError("The parameter set '%s' must be one of %s." % (set, allowed_sets)) 189 190 # Add the values. 191 self._names.append(name) 192 self._scope[name] = scope 193 self._defaults[name] = default 194 self._units[name] = units 195 self._desc[name] = desc 196 self._py_types[name] = py_type 197 self._set[name] = set 198 self._conv_factor[name] = conv_factor 199 self._err[name] = err 200 self._sim[name] = sim 201 self._grid_lower[name] = grid_lower 202 self._grid_upper[name] = grid_upper 203 self._scaling[name] = scaling 204 205 # The parameter string. 206 if string: 207 self._string[name] = string 208 else: 209 self._string[name] = name 210 211 # The Grace string. 212 if grace_string: 213 self._grace_string[name] = grace_string 214 else: 215 self._grace_string[name] = name
216 217
218 - def _add_align_data(self):
219 """Add the PCS and RDC data.""" 220 221 # Add the data. 222 self._add( 223 'pcs', 224 scope = 'spin', 225 grace_string = 'Pseudo-contact shift', 226 units = 'ppm', 227 desc = 'The pseudo-contact shift (PCS)', 228 py_type = float 229 ) 230 self._add( 231 'rdc', 232 scope = 'spin', 233 grace_string = 'Residual dipolar coupling', 234 units = 'Hz', 235 desc = 'The residual dipolar coupling (RDC)', 236 py_type = float 237 )
238 239
240 - def _add_align_tensor(self):
241 """Add the alignment tensor parameters.""" 242 243 # Add the parameters. 244 self._add( 245 'Axx', 246 scope = 'global', 247 desc = 'The Axx component of the alignment tensor', 248 py_type = float, 249 set = 'params', 250 grid_lower = -1e-3, 251 grid_upper = 1e-3, 252 grace_string = '\\qA\\sxx\\N', 253 err = True, 254 sim = True 255 ) 256 self._add( 257 'Ayy', 258 scope = 'global', 259 desc = 'The Ayy component of the alignment tensor', 260 py_type = float, 261 set = 'params', 262 grid_lower = -1e-3, 263 grid_upper = 1e-3, 264 grace_string = '\\qA\\syy\\N', 265 err = True, 266 sim = True 267 ) 268 self._add( 269 'Axy', 270 scope = 'global', 271 desc = 'The Axy component of the alignment tensor', 272 py_type = float, 273 set = 'params', 274 grid_lower = -1e-3, 275 grid_upper = 1e-3, 276 grace_string = '\\qA\\sxy\\N', 277 err = True, 278 sim = True 279 ) 280 self._add( 281 'Axz', 282 scope = 'global', 283 desc = 'The Axz component of the alignment tensor', 284 py_type = float, 285 set = 'params', 286 grid_lower = -1e-3, 287 grid_upper = 1e-3, 288 grace_string = '\\qA\\sxz\\N', 289 err = True, 290 sim = True 291 ) 292 self._add( 293 'Ayz', 294 scope = 'global', 295 desc = 'The Ayz component of the alignment tensor', 296 py_type = float, 297 set = 'params', 298 grid_lower = -1e-3, 299 grid_upper = 1e-3, 300 grace_string = '\\qA\\syz\\N', 301 err = True, 302 sim = True 303 )
304 305
306 - def _add_csa(self, default=None, set='fixed', err=False, sim=False):
307 """Add the CSA parameter 'csa'. 308 309 @keyword default: The default CSA value. 310 @type default: float 311 @keyword set: The set of object names. This can be set to 'all' for all names, to 'fixed' for parameter of the model which are permanently fixed, to 'params' for parameter of the model which are optimised or calculated, or to 'min' for minimisation specific object names. 312 @type set: str 313 @keyword err: A flag which if True indicates that the 'csa_err' error data structure can exist. 314 @type err: bool 315 @keyword sim: A flag which if True indicates that the 'csa_sim' Monte Carlo simulation data structure can exist. 316 @type sim: bool 317 """ 318 319 # Add the CSA structure. 320 self._add( 321 'csa', 322 scope = 'spin', 323 default = default, 324 units = 'ppm', 325 desc = 'Chemical shift anisotropy (unitless)', 326 py_type = float, 327 set = set, 328 scaling = 1e-4, 329 grid_lower = -120 * 1e-6, 330 grid_upper = -200 * 1e-6, 331 conv_factor = 1e-6, 332 grace_string = '\\qCSA\\Q', 333 err = err, 334 sim = sim 335 )
336 337
338 - def _add_diffusion_params(self):
339 """Add the Brownian rotational diffusion parameters to the list.""" 340 341 # Add the CSA structure. 342 self._add( 343 'tm', 344 scope = 'global', 345 default = 10.0 * 1e-9, 346 grace_string = '\\xt\\f{}\\sm', 347 units = 'ns', 348 desc = 'Global correlation time', 349 py_type = float, 350 set = 'params', 351 scaling = 1e-12, 352 grid_lower = 1.0 * 1e-9, 353 grid_upper = 12.0 * 1e-9, 354 conv_factor = 1e-9, 355 err = True, 356 sim = True 357 ) 358 self._add( 359 'Diso', 360 scope = 'global', 361 default = 1.666 * 1e7, 362 units = '1e6 1/s', 363 desc = 'Isotropic component of the diffusion tensor', 364 py_type = float, 365 set = 'params', 366 conv_factor = 1e6, 367 err = True, 368 sim = True 369 ) 370 self._add( 371 'Dx', 372 scope = 'global', 373 default = 1.666 * 1e7, 374 units = '1e6 1/s', 375 desc = 'Eigenvalue associated with the x-axis of the diffusion tensor', 376 py_type = float, 377 set = 'params', 378 conv_factor = 1e6, 379 err = True, 380 sim = True 381 ) 382 self._add( 383 'Dy', 384 scope = 'global', 385 default = 1.666 * 1e7, 386 units = '1e6 1/s', 387 desc = 'Eigenvalue associated with the y-axis of the diffusion tensor', 388 py_type = float, 389 set = 'params', 390 conv_factor = 1e6, 391 err = True, 392 sim = True 393 ) 394 self._add( 395 'Dz', 396 scope = 'global', 397 default = 1.666 * 1e7, 398 units = '1e6 1/s', 399 desc = 'Eigenvalue associated with the z-axis of the diffusion tensor', 400 py_type = float, 401 set = 'params', 402 conv_factor = 1e6, 403 err = True, 404 sim = True 405 ) 406 self._add( 407 'Dpar', 408 scope = 'global', 409 default = 1.666 * 1e7, 410 units = '1e6 1/s', 411 desc = 'Diffusion coefficient parallel to the major axis of the spheroid diffusion tensor', 412 py_type = float, 413 set = 'params', 414 conv_factor = 1e6, 415 err = True, 416 sim = True 417 ) 418 self._add( 419 'Dper', 420 scope = 'global', 421 default = 1.666 * 1e7, 422 units = '1e6 1/s', 423 desc = 'Diffusion coefficient perpendicular to the major axis of the spheroid diffusion tensor', 424 py_type = float, 425 set = 'params', 426 conv_factor = 1e6, 427 err = True, 428 sim = True 429 ) 430 self._add( 431 'Da', 432 scope = 'global', 433 default = 0.0, 434 units = '1e6 1/s', 435 desc = 'Anisotropic component of the diffusion tensor', 436 py_type = float, 437 set = 'params', 438 scaling = 1e7, 439 grid_lower = da_lower, 440 grid_upper = da_upper, 441 conv_factor = 1e6, 442 err = True, 443 sim = True 444 ) 445 self._add( 446 'Dr', 447 scope = 'global', 448 default = 0.0, 449 desc = 'Rhombic component of the diffusion tensor', 450 py_type = float, 451 set = 'params', 452 grid_lower = 0.0, 453 grid_upper = 1.0, 454 err = True, 455 sim = True 456 ) 457 self._add( 458 'Dratio', 459 scope = 'global', 460 default = 1.0, 461 desc = 'Ratio of the parallel and perpendicular components of the spheroid diffusion tensor', 462 py_type = float, 463 set = 'params', 464 err = True, 465 sim = True 466 ) 467 self._add( 468 'alpha', 469 scope = 'global', 470 default = 0.0, 471 units = 'deg', 472 desc = 'The first Euler angle of the ellipsoid diffusion tensor', 473 py_type = float, 474 set = 'params', 475 grid_lower = 0.0, 476 grid_upper = pi, 477 conv_factor = (2.0*pi) / 360.0, 478 err = True, 479 sim = True 480 ) 481 self._add( 482 'beta', 483 scope = 'global', 484 default = 0.0, 485 units = 'deg', 486 desc = 'The second Euler angle of the ellipsoid diffusion tensor', 487 py_type = float, 488 set = 'params', 489 grid_lower = 0.0, 490 grid_upper = pi, 491 conv_factor = (2.0*pi) / 360.0, 492 err = True, 493 sim = True 494 ) 495 self._add( 496 'gamma', 497 scope = 'global', 498 default = 0.0, 499 units = 'deg', 500 desc = 'The third Euler angle of the ellipsoid diffusion tensor', 501 py_type = float, 502 set = 'params', 503 grid_lower = 0.0, 504 grid_upper = pi, 505 conv_factor = (2.0*pi) / 360.0, 506 err = True, 507 sim = True 508 ) 509 self._add( 510 'theta', 511 scope = 'global', 512 default = 0.0, 513 units = 'deg', 514 desc = 'The polar angle defining the major axis of the spheroid diffusion tensor', 515 py_type = float, 516 set = 'params', 517 grid_lower = 0.0, 518 grid_upper = pi, 519 conv_factor = (2.0*pi) / 360.0, 520 err = True, 521 sim = True 522 ) 523 self._add( 524 'phi', 525 scope = 'global', 526 default = 0.0, 527 units = 'deg', 528 desc = 'The azimuthal angle defining the major axis of the spheroid diffusion tensor', 529 py_type = float, 530 set = 'params', 531 grid_lower = 0.0, 532 grid_upper = pi, 533 conv_factor = (2.0*pi) / 360.0, 534 err = True, 535 sim = True 536 )
537 538
539 - def _add_min_data(self, min_stats_global=False, min_stats_spin=False):
540 """Add minimisation specific objects. 541 542 The parameter scope is defined by the keyword arguments. 543 544 545 @keyword min_stats_global: A flag which if True will cause the parameters to be global. 546 @type min_stats_global: bool 547 @keyword min_stats_spin: A flag which if True will cause the parameters to be spin specific. 548 @type min_stats_spin: bool 549 """ 550 551 # Store the flags. 552 self.min_stats_global = min_stats_global 553 self.min_stats_spin = min_stats_spin 554 555 # Global minimisation data. 556 if self.min_stats_global or self.min_stats_spin: 557 # The scope. 558 if self.min_stats_global and self.min_stats_spin: 559 scope = 'both' 560 elif self.min_stats_global: 561 scope = 'global' 562 else: 563 scope = 'spin' 564 565 # The minimisation parameters. 566 self._add( 567 'chi2', 568 scope = scope, 569 desc = 'Chi-squared value', 570 py_type = float, 571 set = 'min', 572 grace_string = '\\xc\\S2', 573 err = False, 574 sim = True 575 ) 576 self._add( 577 'iter', 578 scope = scope, 579 desc = 'Optimisation iterations', 580 py_type = int, 581 set = 'min', 582 grace_string = 'Iteration count', 583 err = False, 584 sim = True 585 ) 586 self._add( 587 'f_count', 588 scope = scope, 589 desc = 'Number of function calls', 590 py_type = int, 591 set = 'min', 592 grace_string = 'Function call count', 593 err = False, 594 sim = True 595 ) 596 self._add( 597 'g_count', 598 scope = scope, 599 desc = 'Number of gradient calls', 600 py_type = int, 601 set = 'min', 602 grace_string = 'Gradient call count', 603 err = False, 604 sim = True 605 ) 606 self._add( 607 'h_count', 608 scope = scope, 609 desc = 'Number of Hessian calls', 610 py_type = int, 611 set = 'min', 612 grace_string = 'Hessian call count', 613 err = False, 614 sim = True 615 ) 616 self._add( 617 'warning', 618 scope = scope, 619 desc = 'Optimisation warning', 620 py_type = str, 621 set = 'min', 622 err = False, 623 sim = True 624 )
625 626
627 - def _add_model_info(self, scope='spin', model_flag=True, equation_flag=False):
628 """Add model specific objects 'model' and 'params'. 629 630 @keyword scope: The parameter scope. This can be set to 'global' for parameters located within the global scope of the current data pipe. Or set to 'spin' for spin specific parameters. Alternatively the value 'both' indicates that there are both global and specific versions of this parameter. 631 @type scope: str 632 @keyword model_flag: A flag which if True will cause the 'model' structure to be added. 633 @type model_flag: bool 634 """ 635 636 # Add the model structure. 637 if model_flag: 638 self._add( 639 'model', 640 scope = scope, 641 desc = 'The model name', 642 py_type = str 643 ) 644 645 # The equation information. 646 if equation_flag: 647 self._add( 648 'equation', 649 scope = scope, 650 desc = 'The model equation', 651 py_type = str 652 ) 653 654 # Add the parameter name list structure. 655 self._add( 656 'params', 657 scope = scope, 658 desc = 'The parameters of the model', 659 py_type = list 660 )
661 662
663 - def _add_peak_intensity(self):
664 """Add the peak intensity structure 'peak_intensity'.""" 665 666 # Add the peak intensity structure. 667 self._add( 668 'peak_intensity', 669 scope = 'spin', 670 desc = 'The peak intensities', 671 py_type = dict, 672 grace_string = '\\qPeak intensities\\Q' 673 )
674 675
676 - def _add_sn_ratio(self):
677 """Add the signal to noise ratio structure 'sn_ratio'.""" 678 679 # Add the peak intensity structure. 680 self._add( 681 'sn_ratio', 682 scope = 'spin', 683 desc = 'The signal to noise ratios', 684 py_type = dict, 685 grace_string = '\\qS/N ratio\\Q' 686 )
687 688
689 - def _set_uf_title(self, title):
690 """Set the title for the user function documentation. 691 692 @param title: The title to use in the user function docstrings. 693 @type title: str 694 """ 695 696 # Store the text. 697 self._uf_title = title
698 699
700 - def _uf_param_table(self, label=None, caption=None, scope='spin', sets=['params', 'fixed'], default=False, units=False, type=False):
701 """"Create the parameter documentation for the user function docstrings. 702 703 @keyword label: The label of the table. This is used to identify replicated tables, and is also used in the table referencing in the LaTeX compilation of the user manual. If this label is already used, the corresponding pre-constructed documentation object will be returned. 704 @type label: str 705 @keyword caption: The caption for the table. 706 @type caption: str 707 @keyword scope: The parameter scope to restrict the table to, defaulting to 'spin'. 708 @type scope: str or None 709 @keyword sets: The parameter sets to restrict the table to. If not given, then all parameters of the 'params' and 'fixed' sets will be added. This can be set to 'all' for all names, to 'fixed' for parameter of the model which are permanently fixed, to 'params' for parameter of the model which are optimised or calculated, or to 'min' for minimisation specific object names. 710 @type sets: list of str 711 @keyword default: A flag which if True will cause the default parameter value to be included in the table. 712 @type default: bool 713 @keyword units: A flag which if True will cause the units to be included in the table. 714 @type units: bool 715 @keyword type: A flag which if True will cause the parameter type to be included in the table. 716 @type type: bool 717 @return: The parameter documentation. 718 @rtype: Desc_container instance 719 """ 720 721 # Sanity checks. 722 if label == None: 723 raise RelaxError("The table identifying label must be supplied.") 724 if label in self._uf_docs: 725 raise RelaxError("The table identifying label '%s' already exists." % label) 726 727 # Initialise the documentation object. 728 self._uf_docs[label] = Desc_container(self._uf_title) 729 730 # The parameter table. 731 table = uf_tables.add_table(label=label, caption=caption) 732 733 # Add the headings. 734 headings = ["Name", "Description"] 735 if default: 736 headings.append("Default") 737 if units: 738 headings.append("Units") 739 if type: 740 headings.append("Type") 741 table.add_headings(headings) 742 743 # Add each parameter, first of the parameter set, then the 'generic' set. 744 for set in sets: 745 for param in self.loop(set=set): 746 # Limit the scope. 747 if scope and self.scope(param) != scope: 748 continue 749 750 row = [] 751 row.append(param) 752 row.append(self.description(param)) 753 if default: 754 row.append("%s" % self.default_value(param)) 755 if units: 756 row.append("%s" % self.units(param)) 757 if type: 758 row.append("%s" % self.type_string(param)) 759 table.add_row(row) 760 761 # Add the table to the documentation object. 762 self._uf_docs[label].add_table(table.label) 763 764 # Return the documentation object so that additional text can be added after the table. 765 return self._uf_docs[label]
766 767
768 - def _uf_doc_loop(self, tables=None):
769 """Generator method for looping over and yielding the user function parameter documentation. 770 771 @keyword tables: The list of tables to loop over. If None, then all tables will be yielded. 772 @type tables: list of str or None 773 @return: The user function documentation for each table. 774 @rtype: Desc_container instance 775 """ 776 777 # No tables supplied. 778 if tables == None: 779 tables = sorted(self._uf_docs.keys()) 780 781 # Loop over the tables, yielding the documentation objects. 782 for table in tables: 783 yield self._uf_docs[table]
784 785
786 - def base_loop(self, set=None, scope=None):
787 """An iterator method for looping over all the base parameters. 788 789 @keyword set: The set of object names. This can be set to 'all' for all names, to 'fixed' for parameter of the model which are permanently fixed, to 'params' for parameter of the model which are optimised or calculated, or to 'min' for minimisation specific object names. 790 @type set: str 791 @keyword scope: The scope of the parameter to return. If not set, then all will be returned. If set to 'global' or 'spin', then only the parameters within that scope will be returned. 792 @type scope: str or None 793 @returns: The parameter names. 794 @rtype: str 795 """ 796 797 # Loop over the parameters. 798 for name in self._names: 799 # Skip the parameter if the set does not match. 800 if set == 'fixed' and self._set[name] != 'fixed': 801 continue 802 if set == 'params' and self._set[name] != 'params': 803 continue 804 if set == 'min' and self._set[name] != 'min': 805 continue 806 807 # Skip the parameter is outside of the scope. 808 if scope == 'global' and self._scope[name] == 'spin': 809 continue 810 if scope == 'spin' and self._scope[name] == 'global': 811 continue 812 813 # Yield the parameter name. 814 yield name
815 816
817 - def check_param(self, name):
818 """Check if the parameter exists. 819 820 @param name: The name of the parameter to search for. 821 @type name: str 822 @raises RelaxError: If the parameter does not exist. 823 """ 824 825 # Check. 826 if name not in self._names: 827 raise RelaxError("The parameter '%s' does not exist." % name)
828 829
830 - def contains(self, name):
831 """Determine if the given name is within the parameter list. 832 833 @param name: The name of the parameter to search for. 834 @type name: str 835 @return: True if the parameter is within the list, False otherwise. 836 @rtype: bool 837 """ 838 839 # Check. 840 if name in self._names: 841 return True 842 843 # No match. 844 return False
845 846
847 - def conversion_factor(self, name):
848 """Return the conversion factor. 849 850 @param name: The name of the parameter. 851 @type name: str 852 @return: The conversion factor. 853 @rtype: float 854 """ 855 856 # Parameter check. 857 self.check_param(name) 858 859 # No factor. 860 if self._conv_factor[name] == None: 861 return 1.0 862 863 # Function. 864 if isinstance(self._conv_factor[name], FunctionType) or isinstance(self._conv_factor[name], MethodType): 865 return self._conv_factor[name]() 866 867 # Value. 868 return self._conv_factor[name]
869 870
871 - def data_names(self, set='all', scope=None, error_names=False, sim_names=False):
872 """Return a list of names of data structures. 873 874 @keyword set: The set of object names. This can be set to 'all' for all names, to 'fixed' for parameter of the model which are permanently fixed, to 'params' for parameter of the model which are optimised or calculated, or to 'min' for minimisation specific object names. 875 @type set: str 876 @keyword scope: The scope of the parameter to return. If not set, then all will be returned. If set to 'global' or 'spin', then only the parameters within that scope will be returned. 877 @type scope: str or None 878 @keyword error_names: A flag which if True will add the error object names as well. 879 @type error_names: bool 880 @keyword sim_names: A flag which if True will add the Monte Carlo simulation object names as well. 881 @type sim_names: bool 882 @return: The list of object names. 883 @rtype: list of str 884 """ 885 886 # Initialise. 887 names = [] 888 889 # Loop over the parameters. 890 for name in self.loop(set=set, scope=scope, error_names=error_names, sim_names=sim_names): 891 names.append(name) 892 893 # Return the names. 894 return names
895 896
897 - def default_value(self, name):
898 """Return the default value of the parameter. 899 900 @param name: The name of the parameter. 901 @type name: str 902 @return: The default value. 903 @rtype: None or str 904 """ 905 906 # Parameter check. 907 self.check_param(name) 908 909 # Return the default value. 910 return self._defaults[name]
911 912
913 - def description(self, name):
914 """Return the description of the parameter. 915 916 @param name: The name of the parameter. 917 @type name: str 918 @return: The description. 919 @rtype: None or str 920 """ 921 922 # Skip error and simulation structures. 923 if name not in ['ri_data_err'] and (search('_err$', name) or search('_sim$', name)): 924 return None 925 926 # Parameter check. 927 self.check_param(name) 928 929 # Return the description. 930 return self._desc[name]
931 932
933 - def error_flag(self, name):
934 """Return the error flag for the parameter. 935 936 @param name: The name of the parameter. 937 @type name: str 938 @return: The error flag for the parameter. 939 @rtype: bool 940 """ 941 942 # Parameter check. 943 self.check_param(name) 944 945 # Return the type. 946 return self._err[name]
947 948
949 - def grid_lower(self, name, incs=None, model_info=None):
950 """Return the default lower grid bound for the parameter. 951 952 @param name: The name of the parameter. 953 @type name: str 954 @keyword incs: The number of grid search increments. This is used by some of the bound determining functions. 955 @type incs: int 956 @keyword model_info: The model information from the model_loop() specific API method. If the lower bound is a function, this information is sent into it. 957 @type model_info: int 958 @return: The lower bound for the grid search. 959 @rtype: int 960 """ 961 962 # Parameter check. 963 self.check_param(name) 964 965 # Call any function or method. 966 if isinstance(self._grid_lower[name], FunctionType) or isinstance(self._grid_lower[name], MethodType): 967 return self._grid_lower[name](incs=incs, model_info=model_info) 968 969 # Return the value. 970 return self._grid_lower[name]
971 972
973 - def grid_upper(self, name, incs=None, model_info=None):
974 """Return the default upper grid bound for the parameter. 975 976 @param name: The name of the parameter. 977 @type name: str 978 @keyword incs: The number of grid search increments. This is used by some of the bound determining functions. 979 @type incs: int 980 @keyword model_info: The model information from the model_loop() specific API method. If the upper bound is a function, this information is sent into it. 981 @type model_info: int 982 @return: The upper bound for the grid search. 983 @rtype: int 984 """ 985 986 # Parameter check. 987 self.check_param(name) 988 989 # Call any function or method. 990 if isinstance(self._grid_upper[name], FunctionType) or isinstance(self._grid_upper[name], MethodType): 991 return self._grid_upper[name](incs=incs, model_info=model_info) 992 993 # Return the value. 994 return self._grid_upper[name]
995 996
997 - def grace_string(self, name):
998 """Return the Grace string for the parameter. 999 1000 @param name: The name of the parameter. 1001 @type name: str 1002 @return: The Grace string. 1003 @rtype: str 1004 """ 1005 1006 # Parameter check. 1007 self.check_param(name) 1008 1009 # Return the value. 1010 return self._grace_string[name]
1011 1012
1013 - def is_spin_param(self, name):
1014 """Determine whether the given parameter is spin specific. 1015 1016 @param name: The name of the parameter. 1017 @type name: str 1018 @return: True if the parameter is spin specific, False otherwise. 1019 @rtype: bool 1020 """ 1021 1022 # Use the scope. 1023 if self.scope(name) == 'spin': 1024 return True 1025 else: 1026 return False
1027 1028
1029 - def loop(self, set=None, scope=None, error_names=False, sim_names=False):
1030 """An iterator method for looping over all the parameters. 1031 1032 @keyword set: The set of object names. This can be set to 'all' for all names, to 'fixed' for parameter of the model which are permanently fixed, to 'params' for parameter of the model which are optimised or calculated, or to 'min' for minimisation specific object names. 1033 @type set: str 1034 @keyword scope: The scope of the parameter to return. If not set, then all will be returned. If set to 'global' or 'spin', then only the parameters within that scope will be returned. 1035 @type scope: str or None 1036 @keyword error_names: A flag which if True will add the error object names as well. 1037 @type error_names: bool 1038 @keyword sim_names: A flag which if True will add the Monte Carlo simulation object names as well. 1039 @type sim_names: bool 1040 @returns: The parameter names. 1041 @rtype: str 1042 """ 1043 1044 # Loop over and yield the parameters. 1045 for name in self.base_loop(set=set, scope=scope): 1046 yield name 1047 1048 # Error names. 1049 if error_names: 1050 for name in self.base_loop(set=set): 1051 if self.error_flag(name): 1052 yield name + '_err' 1053 1054 # Sim names. 1055 if sim_names: 1056 for name in self.base_loop(set=set): 1057 if self.simulation_flag(name): 1058 yield name + '_sim'
1059 1060
1061 - def scaling(self, name, model_info=None):
1062 """Return the scaling factor for the parameter. 1063 1064 @param model_info: The model information from the model_loop() specific API method. If the scaling factor is a function, this information is sent into it. 1065 @type model_info: int 1066 @param name: The name of the parameter. 1067 @type name: str 1068 @return: The scaling factor for optimisation. 1069 @rtype: int 1070 """ 1071 1072 # Parameter check. 1073 self.check_param(name) 1074 1075 # Call any function or method. 1076 if isinstance(self._scaling[name], FunctionType) or isinstance(self._scaling[name], MethodType): 1077 return self._scaling[name](model_info) 1078 1079 # Return the scaling factor. 1080 return self._scaling[name]
1081 1082
1083 - def scope(self, name):
1084 """Return the parameter scope. 1085 1086 @param name: The name of the parameter. 1087 @type name: str 1088 @return: The scope. This is 'global' for parameters located within the global scope of the current data pipe. Or 'spin' for spin specific parameters. Alternatively the value 'both' indicates that there are both global and specific versions of this parameter. 1089 @rtype: str 1090 """ 1091 1092 # Parameter check. 1093 self.check_param(name) 1094 1095 # Return the Python type. 1096 return self._scope[name]
1097 1098
1099 - def set(self, name):
1100 """Return the parameter set that the parameter belongs to. 1101 1102 @param name: The name of the parameter. 1103 @type name: str 1104 @return: The parameter set. 1105 @rtype: str 1106 """ 1107 1108 # Parameter check. 1109 self.check_param(name) 1110 1111 # Return the type. 1112 return self._set[name]
1113 1114
1115 - def simulation_flag(self, name):
1116 """Return the Monte Carlo simulation flag for the parameter. 1117 1118 @param name: The name of the parameter. 1119 @type name: str 1120 @return: The Monte Carlo simulation flag for the parameter. 1121 @rtype: bool 1122 """ 1123 1124 # Parameter check. 1125 self.check_param(name) 1126 1127 # Return the type. 1128 return self._sim[name]
1129 1130
1131 - def type(self, name):
1132 """Return the Python type for the parameter. 1133 1134 @param name: The name of the parameter. 1135 @type name: str 1136 @return: The Python type. 1137 @rtype: Python type object 1138 """ 1139 1140 # Parameter check. 1141 self.check_param(name) 1142 1143 # Return the Python type. 1144 return self._py_types[name]
1145 1146
1147 - def type_string(self, name):
1148 """Return the Python type for the parameter as a string representation. 1149 1150 @param name: The name of the parameter. 1151 @type name: str 1152 @return: The Python type. 1153 @rtype: Python type object 1154 """ 1155 1156 # Parameter check. 1157 self.check_param(name) 1158 1159 # The text representation. 1160 text = repr(self._py_types[name]) 1161 1162 # Return only the part in quotes. 1163 return text.split("'")[1]
1164 1165
1166 - def uf_doc(self, label=None, caption=None, scope='spin', default=False, units=False, type=False):
1167 """"Create the parameter documentation for the user function docstrings. 1168 1169 @keyword label: The label of the table to return. 1170 @type label: str 1171 @return: The parameter documentation. 1172 @rtype: Desc_container instance 1173 """ 1174 1175 # Sanity check. 1176 if label == None: 1177 raise RelaxError("The table identifying label must be supplied.") 1178 if label not in self._uf_docs: 1179 raise RelaxError("The table identifying label '%s' does not exist." % label) 1180 1181 # Return the documentation. 1182 return self._uf_docs[label]
1183 1184
1185 - def units(self, name):
1186 """Return the units string for the parameter. 1187 1188 @param name: The name of the parameter. 1189 @type name: str 1190 @return: The units string. If no unit is present, the empty string will be returned. 1191 @rtype: str 1192 """ 1193 1194 # Parameter check. 1195 self.check_param(name) 1196 1197 # Function. 1198 if isinstance(self._units[name], FunctionType) or isinstance(self._units[name], MethodType): 1199 unit = self._units[name]() 1200 1201 # The value. 1202 else: 1203 unit = self._units[name] 1204 1205 # Convert None to an empty string. 1206 if unit == None: 1207 unit = '' 1208 1209 # Return the units. 1210 return unit
1211