Displaying an SVG without a notebook

I’m using the excellent MolecularGraph.jl package to generate a molecular graph representation of a SMILES string. The following code works in a notebook to display the molecule, but since I’m not using notebooks I get an error. How can I show this molecule in a regular plot window?

using MolecularGraph

# (R)-(-)-Apomorphine hydrochloride
mol = smilestomol("CN1CCc2cccc-3c2[C@H]1Cc1ccc(O)c(O)c-31")
molsvg = drawsvg(mol, 200, 200)
display("image/svg+xml", molsvg)

This produces: ERROR: MethodError: no method matching show(::Base.TTY, ::MIME{Symbol("image/svg+xml")}, ::String).

I tried saving the svg to a file and load it with Images.jl but this library does not support svg files.

open("mol.svg", "a") do io
    println(io, molsvg)
end

I’m sure this is really simple and I just am missing something obvious. :slight_smile:

GitHub - queryverse/ElectronDisplay.jl: An Electron.jl based figure and table display. should be a pretty easy solution.

2 Likes

That worked like a charm! Thanks @pfitzseb . The working code is given below.

using MolecularGraph
using ElectronDisplay

# (R)-(-)-Apomorphine hydrochloride
mol = smilestomol("CN1CCc2cccc-3c2[C@H]1Cc1ccc(O)c(O)c-31");
molsvg = drawsvg(mol, 500, 500);
display("image/svg+xml", molsvg)

This was also added to an issue I followed at MolecularGraphs.jl

1 Like