diff --git a/bin/mrdna b/bin/mrdna index b16ac40f33e36f1eaa2b1272616cc3a0260e5cda..8c1fc0724aeb01cdfa32710bcd8069faf1b36770 100755 --- a/bin/mrdna +++ b/bin/mrdna @@ -23,6 +23,8 @@ parser.add_argument('--fine-steps', type=float, default=1e7, help='Simulation steps for fine model (50 fs/step)') parser.add_argument('--backbone-scale', type=float, default=1.0, help='Factor to scale DNA backbone in atomic model; try 0.25 to avoid clashes for atomistic simulations') +parser.add_argument('--debug', action='store_true', + help='Run through the python debugger?') parser.add_argument('--draw-cylinders', action='store_true', help='Whether or not to draw the cylinders') @@ -37,8 +39,7 @@ parser.add_argument('input_file', type=str, args = parser.parse_args() -if __name__ == '__main__': - +def main(): infile = pathlib.Path(args.input_file) try: prefix = infile.stem @@ -100,3 +101,43 @@ if __name__ == '__main__': simulate( **run_args ) + +if __name__ == '__main__': + if args.debug: + + class Restart(Exception): + """Causes a debugger to be restarted for the debugged python program.""" + pass + + import traceback + import sys + from pdb import Pdb + pdb = Pdb() + + while True: + try: + # pdb._runscript(mainpyfile) + pdb.runcall(main) + if pdb._user_requested_quit: + break + print("The program finished and will be restarted") + except Restart: + print("Restarting...") + print("\t" + " ".join(args)) + except SystemExit: + # In most cases SystemExit does not warrant a post-mortem session. + print("The program exited via sys.exit(). Exit status:", end=' ') + print(sys.exc_info()[1]) + except SyntaxError: + traceback.print_exc() + sys.exit(1) + except: + traceback.print_exc() + print("Uncaught exception. Entering post mortem debugging") + print("Running 'cont' or 'step' will restart the program") + t = sys.exc_info()[2] + pdb.interaction(None, t) + print("Post mortem debugger finished. mrdna will be restarted") + + else: + main()