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