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, OptionGroup, 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 group = OptionGroup(parser, 'UI options')
278 group.add_option('-p', '--prompt', action='store_true', dest='prompt', default=0, help='launch relax in prompt mode after running any optionally supplied scripts')
279 group.add_option('-g', '--gui', action='store_true', dest='gui', default=0, help='launch the relax GUI')
280 group.add_option('-i', '--info', action='store_true', dest='info', default=0, help='display information about this version of relax')
281 group.add_option('-v', '--version', action='store_true', dest='version', default=0, help='show the version number and exit')
282 group.add_option('--licence', action='store_true', dest='licence', default=0, help='display the licence')
283 group.add_option('--test', action='store_true', dest='test', default=0, help='run relax in test mode')
284 parser.add_option_group(group)
285
286
287 group = OptionGroup(parser, 'Multi-processor options')
288 group.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method')
289 group.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)')
290 parser.add_option_group(group)
291
292
293 group = OptionGroup(parser, 'IO redirection options')
294 group.add_option('-l', '--log', action='store', type='string', dest='log', help='log relax output to the file LOG_FILE', metavar='LOG_FILE')
295 group.add_option('-t', '--tee', action='store', type='string', dest='tee', help='tee relax output to stdout and the file LOG_FILE', metavar='LOG_FILE')
296 parser.add_option_group(group)
297
298
299 group = OptionGroup(parser, 'Test suite options')
300 group.add_option('-x', '--test-suite', action='store_true', dest='test_suite', default=0, help='execute the relax test suite')
301 group.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)')
302 group.add_option('-u', '--unit-tests', action='store_true', dest='unit_tests', default=0, help='execute the relax unit tests (part of the test suite)')
303 group.add_option('--gui-tests', action='store_true', dest='gui_tests', default=0, help='execute the relax GUI tests (part of the test suite)')
304 group.add_option('--time', action='store_true', dest='tt', default=0, help='enable the timing of individual tests in the test suite')
305 parser.add_option_group(group)
306
307
308 group = OptionGroup(parser, 'Debugging options')
309 group.add_option('-d', '--debug', action='store_true', dest='debug', default=0, help='enable debugging output')
310 group.add_option('-e', '--escalate', action='store_true', dest='escalate', default=0, help='escalate all warnings to errors')
311 group.add_option('--numpy-raise', action='store_true', dest='numpy_raise', default=0, help='convert numpy warnings to errors')
312 parser.add_option_group(group)
313
314
315 (options, args) = parser.parse_args()
316
317
318 if options.debug:
319 status.debug = True
320 if options.numpy_raise:
321 numpy.seterr(all='raise')
322
323
324 if options.escalate:
325 status.escalate = True
326
327
328 if options.prompt:
329 status.prompt = True
330
331
332 if options.log:
333
334 if options.tee:
335 parser.error("the logging and tee options cannot be set simultaneously")
336
337
338 self.log_file = options.log
339
340
341 if access(self.log_file, F_OK):
342 parser.error("the log file " + repr(self.log_file) + " already exists")
343 else:
344 self.log_file = None
345
346
347 if options.tee:
348
349 if options.log:
350 parser.error("the tee and logging options cannot be set simultaneously")
351
352
353 self.tee_file = options.tee
354
355
356 if access(self.tee_file, F_OK):
357 parser.error("the tee file " + repr(self.tee_file) + " already exists")
358 else:
359 self.tee_file = None
360
361
362 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
363
364 self.tests = args
365
366
367 self.test_timings = False
368 if options.tt:
369 self.test_timings = True
370
371
372 else:
373
374 if len(args) > 1:
375 parser.error("incorrect number of arguments")
376
377
378 self.script_file = None
379 if len(args) == 1:
380 self.script_file = args[0]
381
382
383 if not access(self.script_file, F_OK):
384 parser.error("the script file " + repr(self.script_file) + " does not exist")
385
386
387 self.multiprocessor_type = options.multiprocessor
388 self.n_processors = options.n_processors
389
390
391 if self.multiprocessor_type == 'mpi4py' and not dep_check.mpi4py_module:
392 parser.error(dep_check.mpi4py_message)
393
394
395
396
397
398
399 if options.version:
400 self.mode = 'version'
401
402
403 elif options.info:
404 self.mode = 'info'
405
406
407 elif options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
408
409 if options.test:
410 parser.error("executing the relax test suite and running relax in test mode are mutually exclusive")
411 elif options.licence:
412 parser.error("executing the relax test suite and running relax in licence mode are mutually exclusive")
413
414
415 if options.test_suite:
416 self.mode = 'test suite'
417 elif options.system_tests:
418 self.mode = 'system tests'
419 elif options.unit_tests:
420 self.mode = 'unit tests'
421 elif options.gui_tests:
422 self.mode = 'GUI tests'
423
424
425 status.test_mode = True
426
427
428 elif options.test:
429
430 if self.script_file:
431 parser.error("a script should not be supplied in test mode")
432
433
434 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
435 parser.error("the relax test mode and executing the test suite are mutually exclusive")
436 elif options.licence:
437 parser.error("the relax modes test and licence are mutually exclusive")
438
439
440 self.mode = 'test'
441
442
443 elif options.licence:
444
445 if self.script_file:
446 parser.error("a script should not be supplied in test mode")
447
448
449 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
450 parser.error("the relax licence mode and executing the test suite are mutually exclusive")
451 elif options.test:
452 parser.error("the relax modes licence and test are mutually exclusive")
453
454
455 self.mode = 'licence'
456
457
458 elif options.gui:
459
460 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
461 parser.error("the relax GUI mode and testing modes are mutually exclusive")
462 elif options.licence:
463 parser.error("the relax GUI mode and licence mode are mutually exclusive")
464
465
466 if not dep_check.wx_module:
467 parser.error("To use the GUI, the wx python module must be installed.")
468
469
470 self.mode = 'gui'
471
472
473 elif self.script_file:
474 self.mode = 'script'
475
476
477 else:
478 self.mode = 'prompt'
479
480
482 """Function for displaying the licence."""
483
484
485 file = open('docs/COPYING')
486 pager(file.read())
487
488
490 """Relax test mode code."""
491
492
493 return
494
495
496
498 - 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):
499 """Subclassed OptionParser class with a replacement error function."""
500
501
502 self.relax = relax
503
504
505 OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
506
507
508 - def error(self, message):
523
524
525
526 if __name__ == "__main__":
527 start()
528