mrdna 5.87 KB
Newer Older
1
2
3
4
5
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import re
6
import pathlib
cmaffeo2's avatar
cmaffeo2 committed
7
from mrdna import __version__ as __version__
cmaffeo2's avatar
cmaffeo2 committed
8
from mrdna.simulate import multiresolution_simulation as simulate
9

cmaffeo2's avatar
cmaffeo2 committed
10
parser = argparse.ArgumentParser(prog="mrdna",
11
12
13
14
15
16
17
18
				 description="""Easy multiresolution simulations of DNA nanotechnology objects using ARBD""")

parser.add_argument('-o','--output-prefix', type=str, default=None,
                    help="Name for your job's output")
parser.add_argument('-d','--directory', type=str,  default=None,
                    help='Directory for simulation; does not need to exist yet')
parser.add_argument('-g','--gpu', type=int, default=0,
                    help='GPU for simulation; check nvidia-smi for availability')
19
20
parser.add_argument('--output-period', type=float, default=1e4,
                    help='Simulation steps between DCD frames')
21
parser.add_argument('--coarse-steps', type=float, default=1e7,
22
                    help='Simulation steps for coarse model (200 fs/step)')
23
parser.add_argument('--fine-steps', type=float, default=1e7,
24
25
26
                    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')
27
28
parser.add_argument('--debug', action='store_true',
                    help='Run through the python debugger?')
29

30
parser.add_argument('--draw-cylinders', action='store_true',
cmaffeo2's avatar
cmaffeo2 committed
31
                    help='Whether or not to draw the cylinders')
32
parser.add_argument('--draw-tubes', action='store_true',
cmaffeo2's avatar
cmaffeo2 committed
33
                    help='Whether or not to draw the tubes')
34

cmaffeo2's avatar
cmaffeo2 committed
35
36
37
38
parser.add_argument('--version', action='version',
                    version='%(prog)s {}'.format(__version__),
                    help='Print the version of mrdna')

39
40
41
42
43
44
45
46
parser.add_argument('input_file', type=str,
                    help="""Any of the following:
                    (1) a cadnano JSON file;
                    (2) a vHelix Maya (.ma) file;
                    (3) an atomic PDB file""")

args = parser.parse_args()

47
def main():
48
    infile = pathlib.Path(args.input_file)
49
    try:
50
        prefix = infile.stem
51
        extension = infile.suffix
52
53
54
    except:
        raise Exception("Unrecognized input file '{}'".format(infile))
        
55
    if extension == '.json':
cmaffeo2's avatar
cmaffeo2 committed
56
        from mrdna.readers import read_cadnano as read_model
57
    elif extension == '.ma':
cmaffeo2's avatar
cmaffeo2 committed
58
        from mrdna.readers import read_vhelix as read_model
59
    elif extension == '.pdb':
cmaffeo2's avatar
cmaffeo2 committed
60
        from mrdna.readers import read_atomic_pdb as read_model
61
62
63
    else:
        raise Exception("Unrecognized input file '{}'".format(infile))
                    
64
    model = read_model( str(infile) )
65

66
67
    if args.output_prefix is not None:
        prefix = args.output_prefix
68
    
cmaffeo2's avatar
cmaffeo2 committed
69
70
71
72
73
74
75
76
    if args.draw_cylinders is True:
        output_name = prefix + ".cylinders.tcl"
        model.vmd_cylinder_tcl( output_name )
        if prefix == infile.stem and extension == ".pdb":
            print("Are you sure you want to overwrite '{}'? (you may provide '-o' option) [y/N]".format(infile))
            if input() not in ("y","Y","yes","Y","Yes","YES"):
                import sys
                sys.exit(1)
77
        model._clear_beads()
cmaffeo2's avatar
cmaffeo2 committed
78
79
80
81
82
83
84
85
86
87
88
89
90
        model._generate_atomic_model(scale=args.backbone_scale)            
        model.write_atomic_ENM( prefix )
        model.atomic_simulate( output_name = prefix )
    elif args.draw_tubes is True:
        output_name = prefix + ".tubes.tcl"
        model.vmd_tube_tcl( output_name )
        if prefix == infile.stem and extension == ".pdb":
            print("Are you sure you want to overwrite '{}'? (you may provide '-o' option) [y/N]".format(infile))
            if input() not in ("y","Y","yes","Y","Yes","YES"):
                import sys
                sys.exit(1)
        model._clear_beads()
        model._generate_atomic_model(scale=args.backbone_scale)            
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
        model.write_atomic_ENM( prefix )
        model.atomic_simulate( output_name = prefix )
    else:
        run_args = dict(
            model = model,
            output_name = prefix,
            job_id = "job-" + prefix,
            directory = args.directory,
            gpu = args.gpu,
            coarse_output_period = int(args.output_period),
            fine_output_period = int(args.output_period),
            coarse_steps = int(args.coarse_steps),
            fine_steps = int(args.fine_steps),
            backbone_scale = args.backbone_scale
        )
106
107


108
        simulate( **run_args )
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

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)
125
                self._user_requested_quit = False
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
                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()