Exemple #1
0
    def reaction2svg(self, G_old, G_new, rid):
        font_size = 10
        scene = svg.Scene(800, 300)
        scene.add(G_old.svg(svg.Scene(300, 300)))
        scene.add(svg.Text((30, font_size), graph2compound(G_old, self.ignore_chirality), font_size, fill_color=magenta))
        scene.add(svg.Text((325, 120), self.reaction_templates[rid]['NAME'], font_size=font_size, fill_color=red))
        scene.add(svg.ChemicalArrow((380, 150), (420, 150), stroke_width=2))
        scene.add(G_new.svg(svg.Scene(300, 300)), (500, 0))
        scene.add(svg.Text((530, font_size), graph2compound(G_new, self.ignore_chirality), font_size, fill_color=magenta))
#        scene.justify()
        scene.border(True)
        return scene
Exemple #2
0
    def prepare_stage(self):
        self.scale_start = (SQR_SIDE, (17 + len(self.dp.matrix)) * SQR_SIDE)
        self.curve_start = (SQR_SIDE, (13 + len(self.dp.matrix)) * SQR_SIDE)
        self.matrix_start = (SQR_SIDE, (1 + len(self.dp.matrix)) * SQR_SIDE)

        self.scene = svg.Scene((17 + len(self.dp.matrix)) * SQR_SIDE,
                               (2 + len(self.dp.matrix)) * SQR_SIDE)
Exemple #3
0
def draw_layer(filename, layer):
    import svg
    scene = svg.Scene(filename, (pwidth, pheight))
    for a in layer:
        scene.add(
            svg.Rectangle((a['x'], a['y']), (a['width'], a['height']),
                          a['color']))
    scene.write()
Exemple #4
0
def get_svg():
    if (graph_list == []):
        error_stringvar.set("Not ready yet, please read a new graph")
        root.update()
        return None
    scene = svg.Scene(400, 400, font_size=24)
    graph_list[-1].svg(scene)
    return scene
Exemple #5
0
def build_scene():
    scene = svg.Scene((xsize*amp + 2*offset, ysize*amp + 2*offset + 40))
    # draw walls
    for wall in walls:
        p1 = wall[0] * amp + Point2(offset, offset)
        p2 = wall[1] * amp + Point2(offset, offset)
        scene.add(svg.Line(p1, p2))
    scene.add(svg.Rectangle(Point2(offset, offset), Point2(xsize*amp, ysize*amp)))
    return scene
Exemple #6
0
 def save_diagram(self, filename, size=1000):
     ''' Converts a collection of tiles to a scene of dimension size x size and saves it as a .svg file. '''
     s = size/2
     scene = svg.Scene('tiling', size, size)
     scene.add(svg.Circle((s,s),s,(255,255,255)))  # Boundary at infinity.
     
     # Draw each tile.
     for tile in self.tiles: scene.extend(tile.diagram(size))
     
     scene.write_svg(filename)
Exemple #7
0
def hash2svg(hash_string,
             width=400,
             height=400,
             node_color=None,
             bond_color=None):
    graph = hash2graph(hash_string)
    graph.width = width
    graph.height = height
    graph.initialize_pos()
    scene = svg.Scene(width, height)
    graph.svg(scene, node_color, bond_color)
    return scene
Exemple #8
0
def generate_image(genome, name="unnamed"):
    #creating an svg
    scene = svg.Scene(name, height=255, width=255)

    #iterating over each circle
    for i in range(len(genome) / CIRCLE_CODE_LENGTH):
        start = i * CIRCLE_CODE_LENGTH
        end = (i + 1) * CIRCLE_CODE_LENGTH

        circle_code = genome[start:end]

        xy = tuple(
            circle_code[:2])  #getting the location of the circle from the gene
        radius = circle_code[
            2]  #getting the radius of the circle from the gene #ALSO SCALING RAD DOWN A BIT
        rgba = tuple(circle_code[3:])  #getting the rgba values of the circle

        scene.add(svg.Circle(xy, radius, rgba))

    return scene.strarray()
Exemple #9
0
def test():
    util._mkdir("../results")
    f = open("../results/hash2compound.txt", "w")
    for (h, compound) in map_hash2compound.iteritems():
        f.write("compound = %s\n" % compound)
        f.write("hash = %s\n" % h)
        f.write("$$$$\n")
    f.close()

    import html_writer
    compound_list = sorted(map_compound2graph.keys())

    util._mkdir("../results/svg")
    html_writer = html_writer.HtmlWriter("../results/compounds.html")
    html_writer.write("<h1><center>Known Compounds</h1></center>")
    for i in range(len(compound_list)):
        G = map_compound2graph[compound_list[i].upper()]
        scene = G.svg(svg.Scene(300, 300, 10))
        scene.add(svg.Text((30, 10), compound_list[i], 10, fill_color=magenta))
        html_writer.write_svg(scene, "svg/%s" % G.hash())

    html_writer.display()
Exemple #10
0
def mol2svg(mol, width=200, height=200, font_size=7):
    G = ChemGraph()
    G.read_mol(mol.split("\n"))
    scene = svg.Scene(width, height, font_size)
    G.svg(scene)
    return scene
Exemple #11
0
    if (not os.path.isfile(mol_filename)):
        print >> sys.stderr, "File not found: " + mol_filename
        sys.exit(-2)

    #file = open(mol_filename)
    try:
        G = molfile2graph(mol_filename)
    except Exception, strerror:
        root.title("ERROR")
        Message(root, text=strerror, width=100).pack()
        Button(root, text="OK", command=root.destroy).pack()
        root.mainloop()
        sys.exit(-1)

    scene = svg.Scene(400, 400, 20)
    G.svg(scene)
    scene.set_attribute("height", 500)
    h = G.hash()
    scene.add(
        svg.Line((0, 400), (400, 400), stroke_width=3, stroke_color=black))
    scene.add(svg.Text((20, 450), h, font_size=20))
    print h
    #scene = mol2svg(file.read(), 500, 500, 20)

    if (svg_filename != None):
        scene.write_svg(svg_filename)
    else:
        scene.display()