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 dep_check
38
39
40 import os
41 if 'TERM' in os.environ and os.environ['TERM'] == 'xterm':
42 os.environ['TERM'] = 'linux'
43
44
45 import lib.compat
46
47
48 import numpy
49 from optparse import Option, OptionGroup, OptionParser
50 from os import F_OK, access, getpid, putenv
51 if dep_check.cprofile_module:
52 import cProfile as profile
53 elif dep_check.profile_module:
54 import profile
55 import pstats
56 from pydoc import pager
57 import sys
58
59
60 from info import Info_box
61 import lib.errors
62 from lib.io import io_streams_log, io_streams_tee
63 import lib.warnings
64 from multi import Application_callback, load_multiprocessor
65 from prompt import interpreter
66 from status import Status; status = Status()
67 import user_functions
68 import version
69
70
71
72 user_functions.initialise()
73
74
75 putenv('PDBVIEWER', 'vmd')
76
77
78 -def start(mode=None, profile_flag=False):
129
130
131 if not dep_check.profile_module:
132 sys.stderr.write("The profile module is not available, please install the Python development packages for profiling.\n\n")
133 sys.exit()
134
135
136 profile.Profile.print_stats = print_stats
137 profile.runctx('processor.run()', globals(), locals())
138
139
140
142 """The main relax class.
143
144 This contains information about the running state, for example the mode of operation of relax,
145 whether debugging is turned on, etc.
146 """
147
149 """The top level class for initialising the program.
150
151 @keyword mode: Force a relax mode, overriding the command line.
152 @type mode: str
153 """
154
155
156 self.pid = getpid()
157
158
282
283
285 """Process the command line arguments."""
286
287
288 parser = RelaxParser(self, usage="usage: %prog [options] [script_file]")
289
290
291 group = OptionGroup(parser, 'UI options')
292 group.add_option('-p', '--prompt', action='store_true', dest='prompt', default=0, help='launch relax in prompt mode after running any optionally supplied scripts')
293 group.add_option('-g', '--gui', action='store_true', dest='gui', default=0, help='launch the relax GUI')
294 group.add_option('-i', '--info', action='store_true', dest='info', default=0, help='display information about this version of relax')
295 group.add_option('-v', '--version', action='store_true', dest='version', default=0, help='show the version number and exit')
296 group.add_option('--licence', action='store_true', dest='licence', default=0, help='display the licence')
297 group.add_option('--test', action='store_true', dest='test', default=0, help='run relax in test mode')
298 parser.add_option_group(group)
299
300
301 group = OptionGroup(parser, 'Multi-processor options')
302 group.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method')
303 group.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)')
304 parser.add_option_group(group)
305
306
307 group = OptionGroup(parser, 'IO redirection options')
308 group.add_option('-l', '--log', action='store', type='string', dest='log', help='log relax output to the file LOG_FILE', metavar='LOG_FILE')
309 group.add_option('-t', '--tee', action='store', type='string', dest='tee', help='tee relax output to both stdout and the file LOG_FILE', metavar='LOG_FILE')
310 parser.add_option_group(group)
311
312
313 group = OptionGroup(parser, 'Test suite options')
314 group.add_option('-x', '--test-suite', action='store_true', dest='test_suite', default=0, help='execute the full relax test suite')
315 group.add_option('-s', '--system-tests', action='store_true', dest='system_tests', default=0, help='execute the system/functional tests')
316 group.add_option('-u', '--unit-tests', action='store_true', dest='unit_tests', default=0, help='execute the unit tests')
317 group.add_option('--gui-tests', action='store_true', dest='gui_tests', default=0, help='execute the GUI tests')
318 group.add_option('--verification-tests', action='store_true', dest='verification_tests', default=0, help='execute the software verification tests')
319 group.add_option('--time', action='store_true', dest='tt', default=0, help='enable the timing of individual tests in the test suite')
320 parser.add_option_group(group)
321
322
323 group = OptionGroup(parser, 'Debugging options')
324 group.add_option('-d', '--debug', action='store_true', dest='debug', default=0, help='enable debugging output')
325 group.add_option('--error-state', action='store_true', dest='error_state', default=0, help='save a pickled state file when a RelaxError occurs')
326 group.add_option('--traceback', action='store_true', dest='traceback', default=0, help='show stack tracebacks on all RelaxErrors and RelaxWarnings')
327 group.add_option('-e', '--escalate', action='store_true', dest='escalate', default=0, help='escalate all warnings to errors')
328 group.add_option('--numpy-raise', action='store_true', dest='numpy_raise', default=0, help='convert numpy warnings to errors')
329 parser.add_option_group(group)
330
331
332 (options, args) = parser.parse_args()
333
334
335 if options.debug:
336 status.debug = True
337 if options.escalate:
338 lib.warnings.ESCALATE = True
339 if options.traceback:
340 status.traceback = True
341 lib.warnings.TRACEBACK = True
342 if options.numpy_raise:
343 numpy.seterr(all='raise')
344 if options.error_state:
345 lib.errors.SAVE_ERROR_STATE = True
346
347
348 if options.prompt:
349 status.prompt = True
350
351
352 if options.log:
353
354 if options.tee:
355 parser.error("the logging and tee options cannot be set simultaneously")
356
357
358 self.log_file = options.log
359
360
361 if access(self.log_file, F_OK):
362 parser.error("the log file " + repr(self.log_file) + " already exists")
363 else:
364 self.log_file = None
365
366
367 if options.tee:
368
369 if options.log:
370 parser.error("the tee and logging options cannot be set simultaneously")
371
372
373 self.tee_file = options.tee
374
375
376 if access(self.tee_file, F_OK):
377 parser.error("the tee file " + repr(self.tee_file) + " already exists")
378 else:
379 self.tee_file = None
380
381
382 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
383
384 self.tests = args
385
386
387 self.test_timings = False
388 if options.tt:
389 self.test_timings = True
390
391
392 else:
393
394 if len(args) > 1:
395 parser.error("incorrect number of arguments")
396
397
398 self.script_file = None
399 if len(args) == 1:
400 self.script_file = args[0]
401
402
403 if not access(self.script_file, F_OK):
404 parser.error("the script file " + repr(self.script_file) + " does not exist")
405
406
407 self.multiprocessor_type = options.multiprocessor
408 self.n_processors = options.n_processors
409
410
411 if self.multiprocessor_type == 'mpi4py' and not dep_check.mpi4py_module:
412 parser.error(dep_check.mpi4py_message)
413
414
415
416
417
418
419 if options.version:
420 self.mode = 'version'
421
422
423 elif options.info:
424 self.mode = 'info'
425
426
427 elif options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
428
429 if options.test:
430 parser.error("executing the relax test suite and running relax in test mode are mutually exclusive")
431 elif options.licence:
432 parser.error("executing the relax test suite and running relax in licence mode are mutually exclusive")
433
434
435 if options.test_suite:
436 self.mode = 'test suite'
437 elif options.system_tests:
438 self.mode = 'system tests'
439 elif options.unit_tests:
440 self.mode = 'unit tests'
441 elif options.gui_tests:
442 self.mode = 'GUI tests'
443 elif options.verification_tests:
444 self.mode = 'verification tests'
445
446
447 status.test_mode = True
448
449
450 elif options.test:
451
452 if self.script_file:
453 parser.error("a script should not be supplied in test mode")
454
455
456 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
457 parser.error("the relax test mode and executing the test suite are mutually exclusive")
458 elif options.licence:
459 parser.error("the relax modes test and licence are mutually exclusive")
460
461
462 self.mode = 'test'
463
464
465 elif options.licence:
466
467 if self.script_file:
468 parser.error("a script should not be supplied in test mode")
469
470
471 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
472 parser.error("the relax licence mode and executing the test suite are mutually exclusive")
473 elif options.test:
474 parser.error("the relax modes licence and test are mutually exclusive")
475
476
477 self.mode = 'licence'
478
479
480 elif options.gui:
481
482 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
483 parser.error("the relax GUI mode and testing modes are mutually exclusive")
484 elif options.licence:
485 parser.error("the relax GUI mode and licence mode are mutually exclusive")
486
487
488 if not dep_check.wx_module:
489
490 if dep_check.wx_module_message == "No module named 'wx'":
491 parser.error("To use the GUI, the wxPython module must be installed.")
492
493
494 else:
495 parser.error("The wxPython installation is broken:\n%s." % dep_check.wx_module_message)
496
497
498 self.mode = 'gui'
499
500
501 elif self.script_file:
502 self.mode = 'script'
503
504
505 else:
506 self.mode = 'prompt'
507
508
510 """Function for displaying the licence."""
511
512
513 file = open('docs/COPYING')
514 pager(file.read())
515
516
518 """Relax test mode code."""
519
520
521 return
522
523
524
526 - 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):
527 """Subclassed OptionParser class with a replacement error function."""
528
529
530 self.relax = relax
531
532
533 OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
534
535
536 - def error(self, message):
551
552
553
554 if __name__ == "__main__":
555 start()
556