1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module implementing the mathematical modelling step of model elimination."""
25
26
27 from generic_fns import pipes
28 from relax_errors import RelaxError
29 from specific_fns.setup import get_specific_fn
30
31
32
34 """Model elimination.
35
36 @keyword function: A user supplied function for model elimination. This function should accept
37 five arguments, a string defining a certain parameter, the value of the
38 parameter, the minimisation instance (ie the residue index if the model
39 is residue specific), and the function arguments. If the model is rejected,
40 the function should return True, otherwise it should return False. The
41 function will be executed multiple times, once for each parameter of the model.
42 @type function: function
43 @param args: The arguments to be passed to the user supplied function.
44 @type args: tuple
45 """
46
47
48 pipes.test()
49
50
51 eliminate = get_specific_fn('eliminate', cdp.pipe_type)
52 model_loop = get_specific_fn('model_loop', cdp.pipe_type)
53 get_param_names = get_specific_fn('get_param_names', cdp.pipe_type)
54 get_param_values = get_specific_fn('get_param_values', cdp.pipe_type)
55 deselect = get_specific_fn('deselect', cdp.pipe_type)
56
57
58 if hasattr(cdp, 'sim_state') and cdp.sim_state == True:
59 sim_state = True
60 else:
61 sim_state = False
62
63
64
65 for model_info in model_loop():
66
67
68
69 if not sim_state:
70
71 names = get_param_names(model_info)
72 values = get_param_values(model_info)
73
74
75 if names == None or values == None:
76 continue
77
78
79 if len(names) != len(values):
80 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".")
81
82
83 flag = False
84 for j in xrange(len(names)):
85
86 if eliminate(names[j], values[j], model_info, args):
87 flag = True
88
89
90 if flag:
91 deselect(model_info)
92
93
94
95
96
97 else:
98
99 for j in xrange(cdp.sim_number):
100
101 names = get_param_names(model_info)
102 values = get_param_values(model_info, sim_index=j)
103
104
105 if names == None or values == None:
106 continue
107
108
109 if len(names) != len(values):
110 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".")
111
112
113 flag = False
114 for k in xrange(len(names)):
115
116 if eliminate(names[k], values[k], model_info, args, sim=j):
117 flag = True
118
119
120 if flag:
121 deselect(model_info, sim_index=j)
122