1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import __builtin__
24 from code import InteractiveConsole, softspace
25 from os import F_OK, access
26 import readline
27
28 import sys
29
30
31 from math import pi
32 import Numeric
33 import Scientific
34
35
36 from help import _Helper, _Helper_python
37 from command import Ls, Lh, Ll, system
38 from tab_completion import Tab_completion
39
40
41 from angles import Angles
42 from dx import OpenDX
43 from eliminate import Eliminate
44 from fix import Fix
45 from gpl import GPL
46 from init_data import Init_data
47 from minimisation import Minimisation
48 from model_selection import Modsel
49 from nuclei import Nuclei
50 from pdb import PDB
51
52
53 from dasha import Dasha
54 from diffusion_tensor import Diffusion_tensor
55 from grace import Grace
56 from jw_mapping import Jw_mapping
57 from model_free import Model_free
58 from molmol import Molmol
59 from monte_carlo import Monte_carlo
60 from noe import Noe
61 from palmer import Palmer
62 from relax_data import Relax_data
63 from relax_fit import Relax_fit
64 from results import Results
65 from run import Run
66 from select import Select
67 from sequence import Sequence
68 from state import State
69 from thread import Threading
70 from unselect import Unselect
71 from value import Value
72 from vmd import Vmd
73
74
77 """The interpreter class."""
78
79
80 self.relax = relax
81
82
83 sys.ps1 = 'relax> '
84 sys.ps2 = 'relax| '
85 sys.ps3 = '\nrelax> '
86
87
88 self.intro = 0
89
90
91 self._pi = pi
92 self._Numeric = Numeric
93 self._Scientific = Scientific
94
95
96 self._Angles = Angles(relax)
97 self._Eliminate = Eliminate(relax)
98 self._Fix = Fix(relax)
99 self._GPL = GPL
100 self._Init_data = Init_data(relax)
101 self._Minimisation = Minimisation(relax)
102 self._Modsel = Modsel(relax)
103 self._Nuclei = Nuclei(relax)
104 self._OpenDX = OpenDX(relax)
105 self._PDB = PDB(relax)
106 self._system = system
107
108
109 self._Dasha = Dasha(relax)
110 self._Diffusion_tensor = Diffusion_tensor(relax)
111 self._OpenDX = OpenDX(relax)
112 self._Grace = Grace(relax)
113 self._Jw_mapping = Jw_mapping(relax)
114 self._Model_free = Model_free(relax)
115 self._Molmol = Molmol(relax)
116 self._Monte_carlo = Monte_carlo(relax)
117 self._Noe = Noe(relax)
118 self._Palmer = Palmer(relax)
119 self._Relax_data = Relax_data(relax)
120 self._Relax_fit = Relax_fit(relax)
121 self._Results = Results(relax)
122 self._Run = Run(relax)
123 self._Select = Select(relax)
124 self._Sequence = Sequence(relax)
125 self._State = State(relax)
126 self._Threading = Threading(relax)
127 self._Unselect = Unselect(relax)
128 self._Value = Value(relax)
129 self._Vmd = Vmd(relax)
130
131
133 """Run the python interpreter.
134
135 The namespace of this function is the namespace seen inside the interpreter. All user
136 accessible functions, classes, etc, should be placed in this namespace.
137 """
138
139
140 pi = self._pi
141 Numeric = self._Numeric
142 Scientific = self._Scientific
143
144
145 lh = Lh()
146 ll = Ll()
147 ls = Ls()
148 system = self._system
149
150
151 gpl = GPL = self._GPL()
152
153
154 angles = self._Angles.angles
155 calc = self._Minimisation.calc
156 eliminate = self._Eliminate.eliminate
157 fix = self._Fix.fix
158 grid_search = self._Minimisation.grid_search
159 init_data = self._Init_data.init
160 minimise = self._Minimisation.minimise
161 model_selection = self._Modsel.model_selection
162 nuclei = self._Nuclei.nuclei
163 pdb = self._PDB.pdb
164
165
166 dasha = self._Dasha
167 diffusion_tensor = self._Diffusion_tensor
168 dx = self._OpenDX
169 grace = self._Grace
170 jw_mapping = self._Jw_mapping
171 model_free = self._Model_free
172 molmol = self._Molmol
173 monte_carlo = self._Monte_carlo
174 noe = self._Noe
175 palmer = self._Palmer
176 relax_data = self._Relax_data
177 relax_fit = self._Relax_fit
178 results = self._Results
179 run = self._Run
180 select = self._Select
181 sequence = self._Sequence
182 state = self._State
183 thread = self._Threading
184 unselect = self._Unselect
185 vmd = self._Vmd
186 value = self._Value
187
188
189 intro_off = self._off
190 intro_on = self._on
191 exit = bye = quit = q = _Exit()
192 script = self.script
193
194
195 help_python = _Helper_python()
196 help = _Helper()
197
198
199 self.local = locals()
200
201
202 readline.set_completer(Tab_completion(name_space=self.local).finish)
203 readline.set_completer_delims(' \t\n`~!@#$%^&*()=+{}\\|;:",<>/?')
204
205 readline.parse_and_bind("tab: complete")
206
207
208 if self.relax.script_file:
209
210 self.intro = 1
211
212
213 run_script(intro=self.relax.intro_string, local=self.local, script_file=self.relax.script_file, quit=1)
214
215
216 elif hasattr(self.relax, 'dummy_mode'):
217
218 self.relax.local = self.local
219 return
220
221
222 else:
223 prompt(intro=self.relax.intro_string, local=self.local)
224
225
227 """Function for turning the function introductions off."""
228
229 self.intro = 0
230 print "Function intros have been disabled."
231
232
234 """Function for turning the function introductions on."""
235
236 self.intro = 1
237 print "Function intros have been enabled."
238
239
240 - def script(self, file=None, quit=0):
241 """Function for executing a script file."""
242
243
244 if file == None:
245 raise RelaxNoneError, 'file'
246 elif type(file) != str:
247 raise RelaxStrError, ('file', file)
248
249
250 if not access(file, F_OK):
251 raise RelaxError, "The script file '" + file + "' does not exist."
252
253
254 if type(quit) != int or (quit != 0 and quit != 1):
255 raise RelaxBinError, ('quit', quit)
256
257
258 self.intro = 1
259
260
261 run_script(local=self.local, script_file=file, quit=quit)
262
263
264 self.intro = 0
265
266
269 """Exit the program."""
270
271 print "Exiting the program."
272 sys.exit()
273
274
276 """Replacement function for 'code.InteractiveConsole.interact'.
277
278 This will enter into the prompt.
279 """
280
281
282 if intro:
283 self.write("%s\n" % intro)
284
285
286
287
288
289 more = 0
290 while 1:
291 try:
292 if more:
293 prompt = sys.ps2
294 else:
295 prompt = sys.ps1
296 try:
297 line = self.raw_input(prompt)
298 except EOFError:
299 self.write("\n")
300 break
301 else:
302 more = self.push(line)
303 except KeyboardInterrupt:
304 self.write("\nKeyboardInterrupt\n")
305 self.resetbuffer()
306 more = 0
307
308
310 """Replacement function for 'code.InteractiveConsole.interact'.
311
312 This will execute the script file.
313 """
314
315
316 if intro:
317 sys.stdout.write("%s\n" % intro)
318
319
320 local['self'].intro = 1
321
322
323 try:
324 file = open(script_file, 'r')
325 except IOError, warning:
326 try:
327 raise RelaxError, "The script file '" + script_file + "' does not exist."
328 except AllRelaxErrors, instance:
329 sys.stdout.write(instance.__str__())
330 sys.stdout.write("\n")
331 return
332 sys.stdout.write("script = " + `script_file` + "\n")
333 sys.stdout.write("----------------------------------------------------------------------------------------------------\n")
334 sys.stdout.write(file.read())
335 sys.stdout.write("----------------------------------------------------------------------------------------------------\n")
336 file.close()
337
338
339 try:
340 execfile(script_file, local)
341 except KeyboardInterrupt:
342 sys.stderr.write("\nScript execution cancelled.\n")
343 except AllRelaxErrors, instance:
344 if Debug:
345 self.showtraceback()
346 else:
347 sys.stderr.write(instance.__str__())
348 except:
349 raise
350
351 sys.stdout.write("\n")
352
353
354 if quit:
355 sys.exit()
356
357
358 -def prompt(intro=None, local=None):
359 """Python interpreter emulation.
360
361 This function replaces 'code.interact'.
362 """
363
364
365 InteractiveConsole.interact = interact_prompt
366 InteractiveConsole.runcode = runcode
367
368
369 console = InteractiveConsole(local)
370 console.interact(intro, local)
371
372
373 -def run_script(intro=None, local=None, script_file=None, quit=1):
374 """Python interpreter emulation.
375
376 This function replaces 'code.interact'.
377 """
378
379
380 InteractiveConsole.interact = interact_script
381 InteractiveConsole.runcode = runcode
382
383
384 console = InteractiveConsole(local)
385 console.interact(intro, local, script_file, quit)
386
387
389 """Replacement code for code.InteractiveInterpreter.runcode"""
390
391 try:
392 exec code in self.locals
393 except SystemExit:
394 raise
395 except AllRelaxErrors, instance:
396 self.write(instance.__str__())
397 self.write("\n")
398 except:
399 self.showtraceback()
400 else:
401 if softspace(sys.stdout, 0):
402 print
403