1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
29 from math import pi
30 from re import search
31 from types import FunctionType, MethodType
32
33
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
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
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
77 """A special object for handling global and spin parameters."""
78
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
87 self.spin_data = spin_data
88
89
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
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
123 self._uf_title = "Parameters"
124 self._uf_table_caption = "Parameters"
125 self._uf_docs = {}
126
127
128 self._initialised = True
129
130
132 """Replacement function for implementing the singleton design pattern."""
133
134
135 if cls._instance is None:
136
137 cls._instance = object.__new__(cls, *args, **kargs)
138
139
140 cls._instance._initialised = False
141
142
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
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
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
206 if string:
207 self._string[name] = string
208 else:
209 self._string[name] = name
210
211
212 if grace_string:
213 self._grace_string[name] = grace_string
214 else:
215 self._grace_string[name] = name
216
217
219 """Add the PCS and RDC data."""
220
221
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
241 """Add the alignment tensor parameters."""
242
243
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
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
339 """Add the Brownian rotational diffusion parameters to the list."""
340
341
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
552 self.min_stats_global = min_stats_global
553 self.min_stats_spin = min_stats_spin
554
555
556 if self.min_stats_global or self.min_stats_spin:
557
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
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
637 if model_flag:
638 self._add(
639 'model',
640 scope = scope,
641 desc = 'The model name',
642 py_type = str
643 )
644
645
646 if equation_flag:
647 self._add(
648 'equation',
649 scope = scope,
650 desc = 'The model equation',
651 py_type = str
652 )
653
654
655 self._add(
656 'params',
657 scope = scope,
658 desc = 'The parameters of the model',
659 py_type = list
660 )
661
662
664 """Add the peak intensity structure 'peak_intensity'."""
665
666
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
677 """Add the signal to noise ratio structure 'sn_ratio'."""
678
679
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
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
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
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
728 self._uf_docs[label] = Desc_container(self._uf_title)
729
730
731 table = uf_tables.add_table(label=label, caption=caption)
732
733
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
744 for set in sets:
745 for param in self.loop(set=set):
746
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
762 self._uf_docs[label].add_table(table.label)
763
764
765 return self._uf_docs[label]
766
767
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
778 if tables == None:
779 tables = sorted(self._uf_docs.keys())
780
781
782 for table in tables:
783 yield self._uf_docs[table]
784
785
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
798 for name in self._names:
799
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
808 if scope == 'global' and self._scope[name] == 'spin':
809 continue
810 if scope == 'spin' and self._scope[name] == 'global':
811 continue
812
813
814 yield name
815
816
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
826 if name not in self._names:
827 raise RelaxError("The parameter '%s' does not exist." % name)
828
829
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
840 if name in self._names:
841 return True
842
843
844 return False
845
846
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
857 self.check_param(name)
858
859
860 if self._conv_factor[name] == None:
861 return 1.0
862
863
864 if isinstance(self._conv_factor[name], FunctionType) or isinstance(self._conv_factor[name], MethodType):
865 return self._conv_factor[name]()
866
867
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
887 names = []
888
889
890 for name in self.loop(set=set, scope=scope, error_names=error_names, sim_names=sim_names):
891 names.append(name)
892
893
894 return names
895
896
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
907 self.check_param(name)
908
909
910 return self._defaults[name]
911
912
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
923 if name not in ['ri_data_err'] and (search('_err$', name) or search('_sim$', name)):
924 return None
925
926
927 self.check_param(name)
928
929
930 return self._desc[name]
931
932
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
943 self.check_param(name)
944
945
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
963 self.check_param(name)
964
965
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
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
987 self.check_param(name)
988
989
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
994 return self._grid_upper[name]
995
996
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
1007 self.check_param(name)
1008
1009
1010 return self._grace_string[name]
1011
1012
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
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
1045 for name in self.base_loop(set=set, scope=scope):
1046 yield name
1047
1048
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
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
1073 self.check_param(name)
1074
1075
1076 if isinstance(self._scaling[name], FunctionType) or isinstance(self._scaling[name], MethodType):
1077 return self._scaling[name](model_info)
1078
1079
1080 return self._scaling[name]
1081
1082
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
1093 self.check_param(name)
1094
1095
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
1109 self.check_param(name)
1110
1111
1112 return self._set[name]
1113
1114
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
1125 self.check_param(name)
1126
1127
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
1141 self.check_param(name)
1142
1143
1144 return self._py_types[name]
1145
1146
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
1157 self.check_param(name)
1158
1159
1160 text = repr(self._py_types[name])
1161
1162
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
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
1182 return self._uf_docs[label]
1183
1184
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
1195 self.check_param(name)
1196
1197
1198 if isinstance(self._units[name], FunctionType) or isinstance(self._units[name], MethodType):
1199 unit = self._units[name]()
1200
1201
1202 else:
1203 unit = self._units[name]
1204
1205
1206 if unit == None:
1207 unit = ''
1208
1209
1210 return unit
1211