1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 """The main module for relax execution."""
35
36
37 import compat
38
39
40 import dep_check
41
42
43 import numpy
44 from optparse import Option, OptionParser
45 from os import F_OK, access, getpid, putenv
46 if dep_check.cprofile_module:
47 import cProfile as profile
48 elif dep_check.profile_module:
49 import profile
50 import pstats
51 from pydoc import pager
52 import sys
53
54
55 from info import Info_box
56 import lib.errors
57 from lib.io import io_streams_log, io_streams_tee
58 import lib.warnings
59 from multi import Application_callback, load_multiprocessor
60 from prompt import interpreter
61 from status import Status; status = Status()
62 import user_functions
63 import version
64
65
66
67 user_functions.initialise()
68
69
70 putenv('PDBVIEWER', 'vmd')
71
72
73 -def start(mode=None, profile_flag=False):
124
125
126 if not dep_check.profile_module:
127 sys.stderr.write("The profile module is not available, please install the Python development packages for profiling.\n\n")
128 sys.exit()
129
130
131 profile.Profile.print_stats = print_stats
132 profile.runctx('processor.run()', globals(), locals())
133
134
135
137 """The main relax class.
138
139 This contains information about the running state, for example the mode of operation of relax,
140 whether debugging is turned on, etc.
141 """
142
144 """The top level class for initialising the program.
145
146 @keyword mode: Force a relax mode, overriding the command line.
147 @type mode: str
148 """
149
150
151 self.pid = getpid()
152
153
268
269
271 """Process the command line arguments."""
272
273
274 parser = RelaxParser(self, usage="usage: %prog [options] [script_file]")
275
276
277 parser.add_option('-d', '--debug', action='store_true', dest='debug', default=0, help='enable debugging output')
278 parser.add_option('-l', '--log', action='store', type='string', dest='log', help='log relax output to the file LOG_FILE', metavar='LOG_FILE')
279 parser.add_option('--licence', action='store_true', dest='licence', default=0, help='display the licence')
280 parser.add_option('-t', '--tee', action='store', type='string', dest='tee', help='tee relax output to stdout and the file LOG_FILE', metavar='LOG_FILE')
281 parser.add_option('-g', '--gui', action='store_true', dest='gui', default=0, help='launch the relax GUI')
282 parser.add_option('-p', '--pedantic', action='store_true', dest='pedantic', default=0, help='escalate all warnings to errors')
283 parser.add_option('--test', action='store_true', dest='test', default=0, help='run relax in test mode')
284 parser.add_option('-x', '--test-suite', action='store_true', dest='test_suite', default=0, help='execute the relax test suite')
285 parser.add_option('-s', '--system-tests', action='store_true', dest='system_tests', default=0, help='execute the relax system/functional tests (part of the test suite)')
286 parser.add_option('-u', '--unit-tests', action='store_true', dest='unit_tests', default=0, help='execute the relax unit tests (part of the test suite)')
287 parser.add_option('--gui-tests', action='store_true', dest='gui_tests', default=0, help='execute the relax GUI tests (part of the test suite)')
288 parser.add_option('--time', action='store_true', dest='tt', default=0, help='enable the timing of individual tests in the test suite')
289 parser.add_option('-i', '--info', action='store_true', dest='info', default=0, help='display information about this version of relax')
290 parser.add_option('-v', '--version', action='store_true', dest='version', default=0, help='show the version number and exit')
291 parser.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method')
292 parser.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)')
293 parser.add_option('--numpy-raise', action='store_true', dest='numpy_raise', default=0, help='convert numpy warnings to errors')
294
295
296 (options, args) = parser.parse_args()
297
298
299 if options.debug:
300 status.debug = True
301 if options.numpy_raise:
302 numpy.seterr(all='raise')
303
304
305 if options.pedantic:
306 status.pedantic = True
307
308
309 if options.log:
310
311 if options.tee:
312 parser.error("the logging and tee options cannot be set simultaneously")
313
314
315 self.log_file = options.log
316
317
318 if access(self.log_file, F_OK):
319 parser.error("the log file " + repr(self.log_file) + " already exists")
320 else:
321 self.log_file = None
322
323
324 if options.tee:
325
326 if options.log:
327 parser.error("the tee and logging options cannot be set simultaneously")
328
329
330 self.tee_file = options.tee
331
332
333 if access(self.tee_file, F_OK):
334 parser.error("the tee file " + repr(self.tee_file) + " already exists")
335 else:
336 self.tee_file = None
337
338
339 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
340
341 self.tests = args
342
343
344 self.test_timings = False
345 if options.tt:
346 self.test_timings = True
347
348
349 else:
350
351 if len(args) > 1:
352 parser.error("incorrect number of arguments")
353
354
355 self.script_file = None
356 if len(args) == 1:
357 self.script_file = args[0]
358
359
360 if not access(self.script_file, F_OK):
361 parser.error("the script file " + repr(self.script_file) + " does not exist")
362
363
364 self.multiprocessor_type = options.multiprocessor
365 self.n_processors = options.n_processors
366
367
368 if self.multiprocessor_type == 'mpi4py' and not dep_check.mpi4py_module:
369 parser.error(dep_check.mpi4py_message)
370
371
372
373
374
375
376 if options.version:
377 self.mode = 'version'
378
379
380 elif options.info:
381 self.mode = 'info'
382
383
384 elif options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
385
386 if options.test:
387 parser.error("executing the relax test suite and running relax in test mode are mutually exclusive")
388 elif options.licence:
389 parser.error("executing the relax test suite and running relax in licence mode are mutually exclusive")
390
391
392 if options.test_suite:
393 self.mode = 'test suite'
394 elif options.system_tests:
395 self.mode = 'system tests'
396 elif options.unit_tests:
397 self.mode = 'unit tests'
398 elif options.gui_tests:
399 self.mode = 'GUI tests'
400
401
402 status.test_mode = True
403
404
405 elif options.test:
406
407 if self.script_file:
408 parser.error("a script should not be supplied in test mode")
409
410
411 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
412 parser.error("the relax test mode and executing the test suite are mutually exclusive")
413 elif options.licence:
414 parser.error("the relax modes test and licence are mutually exclusive")
415
416
417 self.mode = 'test'
418
419
420 elif options.licence:
421
422 if self.script_file:
423 parser.error("a script should not be supplied in test mode")
424
425
426 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
427 parser.error("the relax licence mode and executing the test suite are mutually exclusive")
428 elif options.test:
429 parser.error("the relax modes licence and test are mutually exclusive")
430
431
432 self.mode = 'licence'
433
434
435 elif options.gui:
436
437 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
438 parser.error("the relax GUI mode and testing modes are mutually exclusive")
439 elif options.licence:
440 parser.error("the relax GUI mode and licence mode are mutually exclusive")
441
442
443 if not dep_check.wx_module:
444 parser.error("To use the GUI, the wx python module must be installed.")
445
446
447 self.mode = 'gui'
448
449
450 elif self.script_file:
451 self.mode = 'script'
452
453
454 else:
455 self.mode = 'prompt'
456
457
459 """Function for displaying the licence."""
460
461
462 file = open('docs/COPYING')
463 pager(file.read())
464
465
467 """Relax test mode code."""
468
469
470 return
471
472
473
475 - def __init__(self, relax, usage=None, option_list=None, option_class=Option, version=None, conflict_handler="error", description=None, formatter=None, add_help_option=1, prog=None):
476 """Subclassed OptionParser class with a replacement error function."""
477
478
479 self.relax = relax
480
481
482 OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
483
484
485 - def error(self, message):
500
501
502
503 if __name__ == "__main__":
504 start()
505