| Trees | Indices | Help |
|
|---|
|
|
1 ###############################################################################
2 # #
3 # relax #
4 # #
5 # Protein dynamics by NMR relaxation data analysis #
6 # #
7 # by Edward d'Auvergne #
8 # #
9 ###############################################################################
10 # #
11 # Licence #
12 # #
13 # relax, a program for relaxation data analysis. #
14 # #
15 # Copyright (C) 2001-2012 Edward d'Auvergne #
16 # Copyright (C) 2006-2012 the relax development team #
17 # #
18 # This program is free software; you can redistribute it and/or modify #
19 # it under the terms of the GNU General Public License as published by #
20 # the Free Software Foundation; either version 2 of the License, or #
21 # (at your option) any later version. #
22 # #
23 # This program is distributed in the hope that it will be useful, #
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
26 # GNU Library General Public License for more details. #
27 # #
28 # You should have received a copy of the GNU General Public License #
29 # along with this program; if not, write to the Free Software #
30 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
31 # #
32 ###############################################################################
33
34 # Dependency checks.
35 import dep_check
36
37 # Python modules.
38 from optparse import Option, OptionParser
39 from os import F_OK, access, getpid, putenv
40 if dep_check.profile_module:
41 import profile
42 import pstats
43 from re import match
44 from string import split, strip
45 import sys
46
47 # relax modules.
48 from info import Info_box
49 from multi import Application_callback, load_multiprocessor
50 from prompt.gpl import gpl
51 from prompt import interpreter
52 import relax_errors
53 from relax_io import io_streams_log, io_streams_tee
54 import relax_warnings
55 from status import Status; status = Status()
56 import version
57
58 # Modify the environmental variables.
59 putenv('PDBVIEWER', 'vmd')
60
61
63 """Execute relax.
64
65 @keyword mode: Force a relax mode, overriding the command line.
66 @type mode: str
67 @keyword profile_flag: Change this flag to True for code profiling.
68 @type profile_flag: bool
69 """
70
71 # Normal relax operation.
72 relax = Relax()
73
74 # Override normal operation.
75 if mode:
76 # Override the mode.
77 relax.mode = mode
78
79 # Some defaults.
80 relax.script_file = None
81 relax.log_file = None
82 relax.tee_file = None
83 relax.multiprocessor_type = 'uni'
84 relax.n_processors = 1
85
86 # Process the command line arguments.
87 else:
88 relax.arguments()
89
90 # Store some start up info in the status object.
91 status.relax_mode = relax.mode
92
93 # Set up the multi-processor elements.
94 callbacks = Application_callback(master=relax)
95 verbosity = 0
96 if status.debug:
97 verbosity = 1
98 processor = load_multiprocessor(relax.multiprocessor_type, callbacks, processor_size=relax.n_processors, verbosity=verbosity)
99
100 # Place the processor fabric intro string into the info box.
101 info = Info_box()
102 info.multi_processor_string = processor.get_intro_string()
103
104 # Normal relax operation.
105 if not profile_flag:
106 # Execute relax in multi-processor mode (this includes the uni-processor for normal operation).
107 processor.run()
108
109 # relax in profiling mode.
110 else:
111 def print_stats(stats, status=0):
112 pstats.Stats(stats).sort_stats('cumulative', 'name').print_stats()
113
114 # No profile module.
115 if not dep_check.profile_module:
116 sys.stderr.write("The profile module is not available, please install the Python development packages for profiling.\n\n")
117 sys.exit()
118
119 # Run relax in profiling mode.
120 profile.Profile.print_stats = print_stats
121 profile.runctx('processor.run()', globals(), locals())
122
123
124
126 """The main relax class.
127
128 This contains information about the running state, for example the mode of operation of relax,
129 whether debugging is turned on, etc.
130 """
131
133 """The top level class for initialising the program.
134
135 @keyword mode: Force a relax mode, overriding the command line.
136 @type mode: str
137 """
138
139 # Get and store the PID of this process.
140 self.pid = getpid()
141
142
144 """Execute relax.
145
146 This is the application callback method executed by the multi-processor framework.
147 """
148
149 # Set up the warning system.
150 relax_warnings.setup()
151
152 # Show the version number and exit.
153 if self.mode == 'version':
154 print(('relax ' + version.version_full()))
155 return
156
157 # Show the relax info and exit.
158 if self.mode == 'info':
159 # Initialise the information box.
160 info = Info_box()
161
162 # Print the program intro.
163 print(info.intro_text())
164
165 # Print the system info.
166 print(info.sys_info())
167
168 # Stop execution.
169 return
170
171 # Logging.
172 if self.log_file:
173 io_streams_log(self.log_file)
174
175 # Tee.
176 elif self.tee_file:
177 io_streams_tee(self.tee_file)
178
179 # Run the interpreter for the prompt or script modes.
180 if self.mode == 'prompt' or self.mode == 'script':
181 # Run the interpreter.
182 self.interpreter = interpreter.Interpreter()
183 self.interpreter.run(self.script_file)
184
185 # Execute the relax GUI.
186 elif self.mode == 'gui':
187 # Dependency check.
188 if not dep_check.wx_module:
189 sys.stderr.write("Please install the wx Python module to access the relax GUI.\n\n")
190 return
191
192 # Only import the module in this mode (to improve program start up speeds).
193 import gui
194
195 # Set the GUI flag in the status object.
196 status.show_gui = True
197
198 # Start the relax GUI wx application.
199 app = gui.App(script_file=self.script_file)
200 app.MainLoop()
201
202 # Execute the relax test suite
203 elif self.mode == 'test suite':
204 # Only import the module in the test modes (to improve program start up speeds).
205 from test_suite.test_suite_runner import Test_suite_runner
206
207 # Load the interpreter and turn intros on.
208 self.interpreter = interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True)
209 self.interpreter.on()
210
211 # Run the tests.
212 runner = Test_suite_runner(self.tests)
213 runner.run_all_tests()
214
215 # Execute the relax system tests.
216 elif self.mode == 'system tests':
217 # Only import the module in the test modes (to improve program start up speeds).
218 from test_suite.test_suite_runner import Test_suite_runner
219
220 # Load the interpreter and turn intros on.
221 self.interpreter = interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True)
222 self.interpreter.on()
223
224 # Run the tests.
225 runner = Test_suite_runner(self.tests)
226 runner.run_system_tests()
227
228 # Execute the relax unit tests.
229 elif self.mode == 'unit tests':
230 # Only import the module in the test modes (to improve program start up speeds).
231 from test_suite.test_suite_runner import Test_suite_runner
232
233 # Run the tests.
234 runner = Test_suite_runner(self.tests)
235 runner.run_unit_tests()
236
237 # Execute the relax GUI tests.
238 elif self.mode == 'GUI tests':
239 # Only import the module in the test modes (to improve program start up speeds).
240 from test_suite.test_suite_runner import Test_suite_runner
241
242 # Run the tests.
243 runner = Test_suite_runner(self.tests)
244 runner.run_gui_tests()
245
246 # Test mode.
247 elif self.mode == 'test':
248 self.test_mode()
249
250 # Licence mode.
251 elif self.mode == 'licence':
252 self.licence()
253
254 # Unknown mode.
255 else:
256 raise relax_errors.RelaxError("The '%s' mode is unknown." % self.mode)
257
258
260 """Process the command line arguments."""
261
262 # Parser object.
263 parser = RelaxParser(self, usage="usage: %prog [options] [script_file]")
264
265 # Recognised command line options.
266 parser.add_option('-d', '--debug', action='store_true', dest='debug', default=0, help='enable debugging output')
267 parser.add_option('-l', '--log', action='store', type='string', dest='log', help='log relax output to the file LOG_FILE', metavar='LOG_FILE')
268 parser.add_option('--licence', action='store_true', dest='licence', default=0, help='display the licence')
269 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')
270 parser.add_option('-g', '--gui', action='store_true', dest='gui', default=0, help='launch the relax GUI')
271 parser.add_option('-p', '--pedantic', action='store_true', dest='pedantic', default=0, help='escalate all warnings to errors')
272 parser.add_option('--test', action='store_true', dest='test', default=0, help='run relax in test mode')
273 parser.add_option('-x', '--test-suite', action='store_true', dest='test_suite', default=0, help='execute the relax test suite')
274 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)')
275 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)')
276 parser.add_option('--gui-tests', action='store_true', dest='gui_tests', default=0, help='execute the relax GUI tests (part of the test suite)')
277 parser.add_option('-i', '--info', action='store_true', dest='info', default=0, help='display information about this version of relax')
278 parser.add_option('-v', '--version', action='store_true', dest='version', default=0, help='show the version number and exit')
279 parser.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method')
280 parser.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)')
281
282 # Parse the options.
283 (options, args) = parser.parse_args()
284
285 # Debugging flag.
286 if options.debug:
287 status.debug = True
288
289 # Pedantic flag.
290 if options.pedantic:
291 status.pedantic = True
292
293 # Logging.
294 if options.log:
295 # Exclusive modes.
296 if options.tee:
297 parser.error("the logging and tee options cannot be set simultaneously")
298
299 # The log file.
300 self.log_file = options.log
301
302 # Fail if the file already exists.
303 if access(self.log_file, F_OK):
304 parser.error("the log file " + repr(self.log_file) + " already exists")
305 else:
306 self.log_file = None
307
308 # Tee.
309 if options.tee:
310 # Exclusive modes.
311 if options.log:
312 parser.error("the tee and logging options cannot be set simultaneously")
313
314 # The tee file.
315 self.tee_file = options.tee
316
317 # Fail if the file already exists.
318 if access(self.tee_file, F_OK):
319 parser.error("the tee file " + repr(self.tee_file) + " already exists")
320 else:
321 self.tee_file = None
322
323 # Test suite mode, therefore the args are the tests to run and not a script file.
324 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
325 self.tests = args
326
327 # The argument is a script.
328 else:
329 # Number of positional arguments should only be 0 or 1. 1 should be the script file.
330 if len(args) > 1:
331 parser.error("incorrect number of arguments")
332
333 # Script file.
334 self.script_file = None
335 if len(args) == 1:
336 self.script_file = args[0]
337
338 # Test if the script file exists.
339 if not access(self.script_file, F_OK):
340 parser.error("the script file " + repr(self.script_file) + " does not exist")
341
342 # Set the multi-processor type and number.
343 self.multiprocessor_type = options.multiprocessor
344 self.n_processors = options.n_processors
345
346 # Checks for the multiprocessor mode.
347 if self.multiprocessor_type == 'mpi4py' and not dep_check.mpi4py_module:
348 parser.error(dep_check.mpi4py_message)
349
350
351 # Determine the relax mode and test for mutually exclusive modes.
352 #################################################################
353
354 # Show the version number.
355 if options.version:
356 self.mode = 'version'
357
358 # Show the info about this relax version.
359 elif options.info:
360 self.mode = 'info'
361
362 # Run the relax tests.
363 elif options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
364 # Exclusive modes.
365 if options.test:
366 parser.error("executing the relax test suite and running relax in test mode are mutually exclusive")
367 elif options.licence:
368 parser.error("executing the relax test suite and running relax in licence mode are mutually exclusive")
369
370 # Set the mode.
371 if options.test_suite:
372 self.mode = 'test suite'
373 elif options.system_tests:
374 self.mode = 'system tests'
375 elif options.unit_tests:
376 self.mode = 'unit tests'
377 elif options.gui_tests:
378 self.mode = 'GUI tests'
379
380 # Set the status flag.
381 status.test_mode = True
382
383 # Test mode.
384 elif options.test:
385 # Make sure no script is supplied.
386 if self.script_file:
387 parser.error("a script should not be supplied in test mode")
388
389 # Exclusive modes.
390 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
391 parser.error("the relax test mode and executing the test suite are mutually exclusive")
392 elif options.licence:
393 parser.error("the relax modes test and licence are mutually exclusive")
394
395 # Set the mode.
396 self.mode = 'test'
397
398 # Licence mode.
399 elif options.licence:
400 # Make sure no script is supplied.
401 if self.script_file:
402 parser.error("a script should not be supplied in test mode")
403
404 # Exclusive modes.
405 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
406 parser.error("the relax licence mode and executing the test suite are mutually exclusive")
407 elif options.test:
408 parser.error("the relax modes licence and test are mutually exclusive")
409
410 # Set the mode.
411 self.mode = 'licence'
412
413 # GUI.
414 elif options.gui:
415 # Exclusive models.
416 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
417 parser.error("the relax GUI mode and testing modes are mutually exclusive")
418 elif options.licence:
419 parser.error("the relax GUI mode and licence mode are mutually exclusive")
420
421 # Missing wx module.
422 if not dep_check.wx_module:
423 parser.error("To use the GUI, the wx python module must be installed.")
424
425 # Set the mode.
426 self.mode = 'gui'
427
428 # Script mode.
429 elif self.script_file:
430 self.mode = 'script'
431
432 # Prompt mode (default).
433 else:
434 self.mode = 'prompt'
435
436
441
442
448
449
450
452 - 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):
453 """Subclassed OptionParser class with a replacement error function."""
454
455 # Relax base class.
456 self.relax = relax
457
458 # Run the __init__ method of the OptionParser class.
459 OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
460
461
463 """Replacement error function."""
464
465 # Usage message.
466 self.print_usage(sys.stderr)
467
468 # Raise a clean error.
469 try:
470 raise relax_errors.RelaxError(message)
471 except relax_errors.AllRelaxErrors, instance:
472 sys.stderr.write(instance.__str__())
473
474 # Exit.
475 sys.exit()
476
477
478 # Start relax if this file is passed to Python.
479 if __name__ == "__main__":
480 start()
481
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Wed Apr 10 14:16:39 2013 | http://epydoc.sourceforge.net |