def drawMolecule(request, adjlist, format='png'): """ Returns an image of the provided adjacency list `adjlist` for a molecule. urllib is used to quote/unquote the adjacency list. """ from rmgpy.molecule import Molecule from rmgpy.molecule.draw import MoleculeDrawer from rmgpy.molecule.adjlist import InvalidAdjacencyListError adjlist = str(urllib.unquote(adjlist)) try: molecule = Molecule().fromAdjacencyList(adjlist) except (InvalidAdjacencyListError, ValueError): response = HttpResponseRedirect(static('img/invalid_icon.png')) else: if format == 'png': response = HttpResponse(content_type="image/png") surface, _, _ = MoleculeDrawer().draw(molecule, format='png') surface.write_to_png(response) elif format == 'svg': response = HttpResponse(content_type="image/svg+xml") MoleculeDrawer().draw(molecule, format='svg', target=response) else: response = HttpResponse('Image format not implemented.', status=501) return response
def drawMolecule(request, adjlist, format='png'): """ Returns an image of the provided adjacency list `adjlist` for a molecule. urllib is used to quote/unquote the adjacency list. """ from rmgpy.molecule import Molecule from rmgpy.molecule.draw import MoleculeDrawer from rmgpy.molecule.adjlist import InvalidAdjacencyListError from django.templatetags.static import static adjlist = str(urllib.unquote(adjlist)) try: molecule = Molecule().fromAdjacencyList(adjlist) except InvalidAdjacencyListError: response = HttpResponseRedirect(static('img/invalid_icon.png')) else: if format == 'png': response = HttpResponse(content_type="image/png") surface, _, _ = MoleculeDrawer().draw(molecule, format='png') surface.write_to_png(response) elif format == 'svg': response = HttpResponse(content_type="image/svg+xml") MoleculeDrawer().draw(molecule, format='svg', target=response) else: response = HttpResponse('Image format not implemented.', status=501) return response
def drawMolecule(request, adjlist): """ Returns an image of the provided adjacency list `adjlist` for a molecule. urllib is used to quote/unquote the adjacency list. """ from rmgpy.molecule import Molecule from rmgpy.molecule.draw import MoleculeDrawer adjlist = str(urllib.unquote(adjlist)) molecule = Molecule().fromAdjacencyList(adjlist) surface, cr, rect = MoleculeDrawer().draw(molecule, format='png') response = HttpResponse(content_type="image/png") surface.write_to_png(response) return response
def drawMolecule(request, adjlist, format='png'): """ Returns an image of the provided adjacency list `adjlist` for a molecule. urllib is used to quote/unquote the adjacency list. """ import io from rmgpy.molecule import Molecule from rmgpy.molecule.draw import MoleculeDrawer from rmgpy.molecule.adjlist import InvalidAdjacencyListError adjlist = urllib.parse.unquote(adjlist) try: molecule = Molecule().from_adjacency_list(adjlist) except (InvalidAdjacencyListError, ValueError): response = HttpResponseRedirect(static('img/invalid_icon.png')) else: if format == 'png': response = HttpResponse(content_type="image/png") surface, _, _ = MoleculeDrawer().draw(molecule, file_format='png') response.write(surface.write_to_png()) elif format == 'svg': response = HttpResponse(content_type="image/svg+xml") svg_data = io.BytesIO() MoleculeDrawer().draw(molecule, file_format='svg', target=svg_data) response.write(svg_data.getvalue()) else: response = HttpResponse('Image format not implemented.', status=501) return response
def drawMolecule(request, adjlist): """ Returns an image of the provided adjacency list `adjlist` for a molecule. Note that the newline character cannot be represented in a URL; semicolons should be used instead. """ from rmgpy.molecule import Molecule from rmgpy.molecule.draw import MoleculeDrawer adjlist = str(urllib.unquote(adjlist)) molecule = Molecule().fromAdjacencyList(adjlist) surface, cr, rect = MoleculeDrawer().draw(molecule, format='png') response = HttpResponse(content_type="image/png") surface.write_to_png(response) return response
def drawMolecule(request, adjlist): """ Returns an image of the provided adjacency list `adjlist` for a molecule. Note that the newline character cannot be represented in a URL; semicolons should be used instead. """ from rmgpy.molecule import Molecule from rmgpy.molecule.draw import MoleculeDrawer response = HttpResponse(mimetype="image/png") adjlist = str(adjlist.replace(';', '\n')) molecule = Molecule().fromAdjacencyList(adjlist) surface, cr, rect = MoleculeDrawer().draw(molecule, format='png') surface.write_to_png(response) return response