def getBox(self):
     offset = np.array([self.offset_y.get(), self.offset_x.get()])
     box = fph.get_box(self.proj, self.width.get(), offset)
     return box
Beispiel #2
0
                             file, long, raw_input, reduce, reload,
                             unicode, xrange, StandardError)

__metaclass__ = type #New style classes in Python 2.x

import forgi.threedee.model.coarse_grain as ftmc
import forgi.projection.projection2d as fpp
import forgi.projection.hausdorff as fph

import sys, random
import numpy as np
import scipy.misc
import scipy.ndimage

WIDTH=350
if __name__=="__main__":
    for filename in sys.argv[1:]:
        cg=ftmc.CoarseGrainRNA(filename)
        try:
            proj=fpp.Projection2D(cg, project_virtual_atoms=True)
        except ValueError:
            a=random.random()
            b=random.random()
            c=random.random()
            proj=fpp.Projection2D(cg, project_virtual_atoms=True, proj_direction=[a,b,c])
        rot=random.randrange(0,3600)/10
        proj.rotate(rot)
        box=fph.get_box(proj, WIDTH)
        img, _= proj.rasterize(70, box)
        scipy.misc.imsave(filename+".rot{}.width{}.png".format(rot, WIDTH), img)
 def getBox(self):
     offset = np.array([self.offset_y.get(), self.offset_x.get()])
     box = fph.get_box(self.proj, self.width.get(), offset)
     return box
Beispiel #4
0
    else:
        res_nums = []
    for filename in args.cgfiles:
        for n in range(args.n):
            cg = ftmc.CoarseGrainRNA(filename)

            try:
                proj = fpp.Projection2D(cg,
                                        project_virtual_atoms=True,
                                        project_virtual_residues=res_nums)
            except ValueError:
                a = random.random()
                b = random.random()
                c = random.random()
                print("Projecting from {}, {}, {}".format(a, b, c))
                proj = fpp.Projection2D(cg,
                                        project_virtual_atoms=True,
                                        proj_direction=[a, b, c],
                                        project_virtual_residues=res_nums)
            if args.rotate == 99999999999:
                rot = random.randrange(0, 3600) / 10
            else:
                rot = args.rotate
            proj.rotate(rot)
            box = fph.get_box(proj, args.width)
            img, _ = proj.rasterize(args.dpi, box)
            outname = filename + ".dpi{}.width{}.{}.png".format(
                args.dpi, args.width, n)
            scipy.misc.imsave(outname, img, "png")
            print("File {} written".format(outname))
Beispiel #5
0
         s=args.scale/2
         ref_box=-s/2, s/2, -s/2, s/2
     else:
         parser.error("--scale is required if the reference is a png image")
     if args.show:
         fig, ax=plt.subplots()
         ax.imshow(ref_img, interpolation="none", cmap='gray')
         plt.show()
 else:
     ref_cg=ftmc.CoarseGrainRNA(args.reference)    
     try:
         ref_proj=ftmp.Projection2D(ref_cg, project_virtual_atoms=True)
     except ValueError:
           parser.error('The reference *.cg file needs a "project" line.')
     if args.scale:            
         ref_box=fph.get_box(ref_proj, args.scale)
     else:
         ref_box=ref_proj.get_bounding_square(margin=50)
         args.scale=ref_box[1]-ref_box[0]
     if args.dpi:
         ref_img, _=ref_proj.rasterize(args.dpi, bounding_square=ref_box)    
     else:
         parser.error("If the reference is not a png image, --dpi is required")
 ref_img=(ref_img>np.zeros_like(ref_img)) #Make it a boolean array
 for f in args.files:
     cg=ftmc.CoarseGrainRNA(f)
     if args.global_search or cg.project_from is None:
         distance, img, params = fph.globally_minimal_distance(ref_img, args.scale, cg)
         fname = os.path.basename(f)
         print ("{}:\t{} distance (projected from {}, rotated by {}, offset {}. Globally optimized)".format(fname, distance, params[0], params[1], params[2] ))
     else:
    args = parser.parse_args()
    if args.res_nums:
        res_nums = list(map(int, args.res_nums.split(",")))
    else:
        res_nums = []
    for filename in args.cgfiles:
        for n in range(args.n):
            cg = ftmc.CoarseGrainRNA(filename)

            try:
                proj = fpp.Projection2D(cg, project_virtual_atoms=True,
                                        project_virtual_residues=res_nums)
            except ValueError:
                a = random.random()
                b = random.random()
                c = random.random()
                print("Projecting from {}, {}, {}".format(a, b, c))
                proj = fpp.Projection2D(cg, project_virtual_atoms=True, proj_direction=[a, b, c],
                                        project_virtual_residues=res_nums)
            if args.rotate == 99999999999:
                rot = random.randrange(0, 3600) / 10
            else:
                rot = args.rotate
            proj.rotate(rot)
            box = fph.get_box(proj, args.width)
            img, _ = proj.rasterize(args.dpi, box)
            outname = filename + \
                ".dpi{}.width{}.{}.png".format(args.dpi, args.width, n)
            scipy.misc.imsave(outname, img, "png")
            print("File {} written".format(outname))
Beispiel #7
0
         s=args.scale/2
         ref_box=-s/2, s/2, -s/2, s/2
     else:
         parser.error("--scale is required if the reference is a png image")
     if args.show:
         fig, ax=plt.subplots()
         ax.imshow(ref_img, interpolation="none", cmap='gray')
         plt.show()
 else:
     ref_cg=ftmc.CoarseGrainRNA(args.reference)    
     try:
         ref_proj=ftmp.Projection2D(ref_cg, project_virtual_atoms=True)
     except ValueError:
           parser.error('The reference *.cg file needs a "project" line.')
     if args.scale:            
         ref_box=fph.get_box(ref_proj, args.scale)
     else:
         ref_box=ref_proj.get_bounding_square(margin=50)
         args.scale=ref_box[1]-ref_box[0]
     if args.dpi:
         ref_img, _=ref_proj.rasterize(args.dpi, bounding_square=ref_box)    
     else:
         parser.error("If the reference is not a png image, --dpi is required")
 ref_img=(ref_img>np.zeros_like(ref_img)) #Make it a boolean array
 for f in args.files:
     cg=ftmc.CoarseGrainRNA(f)
     if args.global_search or cg.project_from is None:
         distance, img, params = fph.globally_minimal_distance(ref_img, args.scale, cg)
         fname = os.path.basename(f)
         print ("{}:\t{} distance (projected from {}, rotated by {}, offset {}. Globally optimized)".format(fname, distance, params[0], params[1], params[2] ))
     else: