コード例 #1
0
def drawGroup(request, adjlist, format='png'):
    """
    Returns an image of the provided adjacency list `adjlist` for a molecular
    group.  urllib is used to quote/unquote the adjacency list.
    """
    from rmgpy.molecule.group import Group
    from rmgpy.molecule.adjlist import InvalidAdjacencyListError

    adjlist = str(urllib.unquote(adjlist))

    try:
        group = Group().fromAdjacencyList(adjlist)
    except (InvalidAdjacencyListError, ValueError):
        response = HttpResponseRedirect(static('img/invalid_icon.png'))
    else:
        if format == 'png':
            response = HttpResponse(content_type="image/png")
            response.write(group.draw('png'))
        elif format == 'svg':
            response = HttpResponse(content_type="image/svg+xml")
            svgdata = group.draw('svg')
            # Remove the scale and rotate transformations applied by pydot
            svgdata = re.sub(r'scale\(0\.722222 0\.722222\) rotate\(0\) ', '', svgdata)
            response.write(svgdata)
        else:
            response = HttpResponse('Image format not implemented.', status=501)

    return response
コード例 #2
0
ファイル: views.py プロジェクト: vishalvishw10/RMG-website
def drawGroup(request, adjlist, format='png'):
    """
    Returns an image of the provided adjacency list `adjlist` for a molecular
    group.  urllib is used to quote/unquote the adjacency list.
    """
    from rmgpy.molecule.group import Group
    from rmgpy.molecule.adjlist import InvalidAdjacencyListError

    adjlist = urllib.parse.unquote(adjlist)

    try:
        group = Group().from_adjacency_list(adjlist)
    except (InvalidAdjacencyListError, ValueError):
        response = HttpResponseRedirect(static('img/invalid_icon.png'))
    else:
        if format == 'png':
            response = HttpResponse(content_type="image/png")
            response.write(group.draw('png'))
        elif format == 'svg':
            response = HttpResponse(content_type="image/svg+xml")
            svg_data = group.draw('svg')
            # Remove the scale and rotate transformations applied by pydot
            svg_data = re.sub(r'scale\(0\.722222 0\.722222\) rotate\(0\) ', '',
                              svg_data)
            response.write(svg_data)
        else:
            response = HttpResponse('Image format not implemented.',
                                    status=501)

    return response
コード例 #3
0
def drawGroup(request, adjlist, format='png'):
    """
    Returns an image of the provided adjacency list `adjlist` for a molecular
    group.  urllib is used to quote/unquote the adjacency list.
    """
    from rmgpy.molecule.group import Group

    adjlist = str(urllib.unquote(adjlist))
    group = Group().fromAdjacencyList(adjlist)

    if format == 'png':
        response = HttpResponse(content_type="image/png")
        response.write(group.draw('png'))
    elif format == 'svg':
        response = HttpResponse(content_type="image/svg+xml")
        svgdata = group.draw('svg')
        # Remove the scale and rotate transformations applied by pydot
        svgdata = re.sub(r'scale\(0\.722222 0\.722222\) rotate\(0\) ', '',
                         svgdata)
        response.write(svgdata)
    else:
        response = HttpResponse('Image format not implemented.', status=501)

    return response
コード例 #4
0
ファイル: views.py プロジェクト: wangyuran/RMG-website
def drawGroup(request, adjlist):
    """
    Returns an image of the provided adjacency list `adjlist` for a molecular
    pattern.  urllib is used to quote/unquote the adjacency list.
    """
    from rmgpy.molecule.group import Group

    response = HttpResponse(content_type="image/svg+xml")

    adjlist = str(urllib.unquote(adjlist))
    pattern = Group().fromAdjacencyList(adjlist)

    # Create an svg drawing of the group
    svgdata = pattern.draw('svg')
    # Remove the scale and rotate transformations applied by pydot
    svgdata = re.sub(r'scale\(0\.722222 0\.722222\) rotate\(0\) ', '', svgdata)

    response.write(svgdata)

    return response
コード例 #5
0
ファイル: groupTest.py プロジェクト: bslakman/RMG-Py
    def testDrawGroup(self):
        """Test that the draw method returns the expected pydot graph."""
        adjlist = """
1 *1 [C,Cd,Ct,CO,CS,Cb] u1 {2,[S,D,T,B]}
2 *2 [C,Cd,Ct,CO,CS,Cb] u0 {1,[S,D,T,B]} {3,[S,D,T,B]}
3 *3 [C,Cd,Ct,CO,CS,Cb] u0 {2,[S,D,T,B]} {4,[S,D,T,B]}
4 *4 [C,Cd,Ct,CO,CS,Cb] u0 {3,[S,D,T,B]}
        """
        # Use of tabs in the expected string is intentional
        expected = """
graph G {
	graph [dpi=52];
	node [label="\N"];
	1	 [fontname=Helvetica,
		fontsize=16,
		label="*1 C,Cd,Ct,CO,CS,Cb"];
	2	 [fontname=Helvetica,
		fontsize=16,
		label="*2 C,Cd,Ct,CO,CS,Cb"];
	1 -- 2	 [fontname=Helvetica,
		fontsize=16,
		label="S,D,T,B"];
	3	 [fontname=Helvetica,
		fontsize=16,
		label="*3 C,Cd,Ct,CO,CS,Cb"];
	2 -- 3	 [fontname=Helvetica,
		fontsize=16,
		label="S,D,T,B"];
	4	 [fontname=Helvetica,
		fontsize=16,
		label="*4 C,Cd,Ct,CO,CS,Cb"];
	3 -- 4	 [fontname=Helvetica,
		fontsize=16,
		label="S,D,T,B"];
}
        """
        group = Group().fromAdjacencyList(adjlist)
        result = group.draw('canon')
        self.assertEqual(''.join(result.split()), ''.join(expected.split()))
コード例 #6
0
ファイル: groupTest.py プロジェクト: bslakman/RMG-Py
    def testDrawGroup(self):
        """Test that the draw method returns the expected pydot graph."""
        adjlist = """
1 *1 [C,Cd,Ct,CO,CS,Cb] u1 {2,[S,D,T,B]}
2 *2 [C,Cd,Ct,CO,CS,Cb] u0 {1,[S,D,T,B]} {3,[S,D,T,B]}
3 *3 [C,Cd,Ct,CO,CS,Cb] u0 {2,[S,D,T,B]} {4,[S,D,T,B]}
4 *4 [C,Cd,Ct,CO,CS,Cb] u0 {3,[S,D,T,B]}
        """
        # Use of tabs in the expected string is intentional
        expected = """
graph G {
	graph [dpi=52];
	node [label="\N"];
	1	 [fontname=Helvetica,
		fontsize=16,
		label="*1 C,Cd,Ct,CO,CS,Cb"];
	2	 [fontname=Helvetica,
		fontsize=16,
		label="*2 C,Cd,Ct,CO,CS,Cb"];
	1 -- 2	 [fontname=Helvetica,
		fontsize=16,
		label="S,D,T,B"];
	3	 [fontname=Helvetica,
		fontsize=16,
		label="*3 C,Cd,Ct,CO,CS,Cb"];
	2 -- 3	 [fontname=Helvetica,
		fontsize=16,
		label="S,D,T,B"];
	4	 [fontname=Helvetica,
		fontsize=16,
		label="*4 C,Cd,Ct,CO,CS,Cb"];
	3 -- 4	 [fontname=Helvetica,
		fontsize=16,
		label="S,D,T,B"];
}
        """
        group = Group().fromAdjacencyList(adjlist)
        result = group.draw('canon')
        self.assertEqual(''.join(result.split()), ''.join(expected.split()))