segmentmodel.py 165 KB
Newer Older
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
            ## TODO: call oxdna
            cmd = [oxDNA, input_file]

            cmd = tuple(str(x) for x in cmd)

            print("Running oxDNA with: %s" % " ".join(cmd))
            process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
            for line in process.stdout:
                sys.stdout.write(line)
                sys.stdout.flush()

            return topology,last_conf_file
        finally:
            os.chdir(d_orig)

    """ Visualization """
cmaffeo2's avatar
cmaffeo2 committed
4017
4018
4019
    def vmd_tube_tcl(self, file_name="drawTubes.tcl"):
        with open(file_name, 'w') as tclFile:
            tclFile.write("## beginning TCL script \n")
4020

cmaffeo2's avatar
cmaffeo2 committed
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
            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)))

            ## 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()
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073

    def vmd_cylinder_tcl(self, file_name="drawCylinders.tcl"):
        #raise NotImplementedError
        with open(file_name, 'w') as tclFile:
            tclFile.write("## beginning TCL script \n")
            def draw_cylinder(segment,radius_value=10,color="cyan"):
                tclFile.write("## cylinder being drawn... \n")
                r0 = segment.contour_to_position(0)
                r1 = segment.contour_to_position(1)
                
                radius_value = str(radius_value)
                color = str(color)
                
                tclFile.write("graphics top color {} \n".format(color))
                tclFile.write("graphics top cylinder {{ {} {} {} }} {{ {} {} {} }} radius {} resolution 30 filled yes \n".format(r0[0], r0[1], r0[2], r1[0], r1[1], r1[2], radius_value))

            ## material
            tclFile.write("graphics top materials on \n")
            tclFile.write("graphics top material AOEdgy \n")
dwinogra's avatar
dwinogra committed
4074
4075
4076
4077
            
            ## iterate through the model segments
            for s in self.segments:
                if isinstance(s,DoubleStrandedSegment):
4078
                    tclFile.write("## dsDNA! \n")
dwinogra's avatar
dwinogra committed
4079
4080
                    draw_cylinder(s,10,"cyan")
                elif isinstance(s,SingleStrandedSegment):
4081
                    tclFile.write("## ssDNA! \n")
dwinogra's avatar
dwinogra committed
4082
4083
4084
4085
4086
                    draw_cylinder(s,3,"orange")
                else:
                    raise Exception ("your model includes beads that are neither ssDNA nor dsDNA")
            ## tclFile complete
            tclFile.close()
For faster browsing, not all history is shown. View entire blame