diff --git a/bin/enrgmd b/bin/enrgmd index 84d64893178a7b8921d64664fc53fae52796c47a..aa90fcf7459a37db0fc79f86d448aedc9dc165cd 100755 --- a/bin/enrgmd +++ b/bin/enrgmd @@ -42,13 +42,19 @@ if __name__ == '__main__': from mrdna.readers import read_atomic_pdb as read_model else: raise Exception("Unrecognized input file '{}'".format(infile)) - - model = read_model( str(infile) ) if args.output_prefix is not None: prefix = args.output_prefix directory = args.directory + 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 = read_model( str(infile) ) + d_orig = os.getcwd() try: if directory is None: diff --git a/bin/mrdna b/bin/mrdna index 4364474450fe9488b9f9f623f42d558e216d2b45..41f47a92b464f2e112900296d5abc87e4f1d4744 100755 --- a/bin/mrdna +++ b/bin/mrdna @@ -24,8 +24,10 @@ parser.add_argument('--fine-steps', type=float, default=1e7, 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('--draw-cylinders', type=bool, default=False, - help='whether or not to draw the cylinders') +parser.add_argument('--draw-cylinders', nargs='?', const=True, type=bool, default=False, + help='Whether or not to draw the cylinders') +parser.add_argument('--draw-tubes', nargs='?', const=True, type=bool, default=False, + help='Whether or not to draw the tubes') parser.add_argument('input_file', type=str, help="""Any of the following: @@ -58,15 +60,30 @@ if __name__ == '__main__': if args.output_prefix is not None: prefix = args.output_prefix - if args.draw_cylinders is not False: - model = model - model.vmd_cylinder_tcl() - output_name = prefix+ ".cylinders.tcl" + 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) model._clear_beads() - model._generate_atomic_model(scale=args.backbone_scale) + 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) model.write_atomic_ENM( prefix ) model.atomic_simulate( output_name = prefix ) - else: run_args = dict( model = model, diff --git a/mrdna/segmentmodel.py b/mrdna/segmentmodel.py index e3d400988f368d455d7c9131cb3c62d8af3b7af7..fa10c4d1840768371f9e6db03431d3f29d29e228 100644 --- a/mrdna/segmentmodel.py +++ b/mrdna/segmentmodel.py @@ -2874,27 +2874,44 @@ proc calcforces {} { print(angles[np.argmin(score)]) print(score) - def vmd_cylinder_tcl(self, file_handle): - raise NotImplementedError - - def draw_cylinder(segment): - r0 = segment.start_position - r1 = segment.end_position - - file_handle.write("") - file_handle.write("") + def vmd_tube_tcl(self, file_name="drawTubes.tcl"): + with open(file_name, 'w') as tclFile: + tclFile.write("## beginning TCL script \n") - ## material - for s in self.segments: - if isinstance(s,DoubleStrandedSegment): - ... - radius = 5 - elif isinstance(s,SingleStrandedSegment): - ... - else: - raise(Exception) + def draw_tube(segment,radius_value=10, color="cyan", resolution=5): + tclFile.write("## Tube being drawn... \n") + + contours = np.linspace(0,1, max(2,1+segment.num_nt//resolution) ) + rs = [segment.contour_to_position(c) for c in contours] + + radius_value = str(radius_value) + tclFile.write("graphics top color {} \n".format(str(color))) + for i in range(len(rs)-2): + r0 = rs[i] + r1 = rs[i+1] + filled = "yes" if i in (0,len(rs)-2) else "no" + tclFile.write("graphics top cylinder {{ {} {} {} }} {{ {} {} {} }} radius {} resolution 30 filled {} \n".format(r0[0], r0[1], r0[2], r1[0], r1[1], r1[2], str(radius_value), filled)) + tclFile.write("graphics top sphere {{ {} {} {} }} radius {} resolution 30\n".format(r1[0], r1[1], r1[2], str(radius_value))) + r0 = rs[-2] + r0 = rs[-1] + tclFile.write("graphics top cylinder {{ {} {} {} }} {{ {} {} {} }} radius {} resolution 30 filled yes \n".format(r0[0], r0[1], r0[2], r1[0], r1[1], r1[2], str(radius_value))) - file_handle.write("") + ## material + tclFile.write("graphics top materials on \n") + tclFile.write("graphics top material AOEdgy \n") + + ## iterate through the model segments + for s in self.segments: + if isinstance(s,DoubleStrandedSegment): + tclFile.write("## dsDNA! \n") + draw_tube(s,10,"cyan") + elif isinstance(s,SingleStrandedSegment): + tclFile.write("## ssDNA! \n") + draw_tube(s,3,"orange",resolution=1.5) + else: + raise Exception ("your model includes beads that are neither ssDNA nor dsDNA") + ## tclFile complete + tclFile.close() def vmd_cylinder_tcl(self, file_name="drawCylinders.tcl"): #raise NotImplementedError @@ -2905,9 +2922,6 @@ proc calcforces {} { r0 = segment.contour_to_position(0) r1 = segment.contour_to_position(1) - x0,y0,z0 = r0 - x1,y1,z1 = r1 - radius_value = str(radius_value) color = str(color)