mojaie / MolecularGraph.jl

Graph-based molecule modeling toolkit for cheminformatics
MIT License
189 stars 27 forks source link

Implement the package in Pluto.jl #64

Closed Leticia-maria closed 1 year ago

Leticia-maria commented 2 years ago

I think one good alternative for more dynamic use of the package is to implement it on Pluto.jl, as a reactive tool.

mojaie commented 2 years ago

Thank you for your interest. Maybe you can use MolecularGraph.jl in Pluto.jl. Any problems? Or do you have any ideas about dynamic use?

Leticia-maria commented 2 years ago

Thank you for replying me :) I had problems running the example in Pluto.jl with the "display("image/svg+xml", molsvg)" called method. The error message is below.

` Screenshot from 2021-11-01 11-28-07

...

display(::TextDisplay, ::MIME{Symbol("image/svg+xml")}, ::Any)@multimedia.jl:249
display(::MIME{Symbol("image/svg+xml")}, ::Any)@multimedia.jl:342
display(::String, ::Any)@multimedia.jl:217
top-level scope@Local: 1[inlined]

`

Leticia-maria commented 2 years ago

And I have also ideias for interactive using. I am trying to integrate MolecularGraph and Gtk. And I would like to contribute to this package at this point, if you are interested.

SimonEnsemble commented 2 years ago

any word on whether we can display the svg's in Pluto somehow?

Leticia-maria commented 2 years ago

any word on whether we can display the svg's in Pluto somehow?

Hey, are you having problems by displaying a molecule svg image in Pluto? Could you show me the error?

SimonEnsemble commented 2 years ago

yes. have you found a way to make this display in Pluto.jl?

    mol2 = smilestomol("O=C3N2/C(=C(/C=C\\c1scnc1C)CS[C@@H]2[C@@H]3NC(=O)C(=N\\OC)/c4nc(sc4)N)C(=O)O")
    molsvg2 = drawsvg(mol2, 300, 300)
    display("image/svg+xml",  molsvg2)

for me gives:

MethodError: no method matching show(::IOContext{Base.PipeEndpoint}, ::MIME{Symbol("image/svg+xml")}, ::String)

Closest candidates are:

show(::IO, ::M, !Matched::PlutoUI.ExperimentalLayout.Show{M}) where M<:MIME at ~/.julia/packages/PlutoUI/WK1nR/src/Layout.jl:487

show(::IO, ::M, !Matched::PlutoUI.Show{M}) where M<:MIME at ~/.julia/packages/PlutoUI/WK1nR/src/DisplayTricks.jl:89

show(::IO, ::M, !Matched::PlutoUI.AsMIME{M}) where M<:MIME at ~/.julia/packages/PlutoUI/WK1nR/src/DisplayTricks.jl:12

...

    display(::TextDisplay, ::MIME{Symbol("image/svg+xml")}, ::Any)@multimedia.jl:249
    display(::MIME{Symbol("image/svg+xml")}, ::Any)@multimedia.jl:342
    display(::String, ::Any)@multimedia.jl:217
    top-level scope@Local: 5[inlined]
PingYang16 commented 2 years ago

Thank you for replying me :) I had problems running the example in Pluto.jl with the "display("image/svg+xml", molsvg)" called method. The error message is below.

` Screenshot from 2021-11-01 11-28-07

...

display(::TextDisplay, ::MIME{Symbol("image/svg+xml")}, ::Any)@multimedia.jl:249
display(::MIME{Symbol("image/svg+xml")}, ::Any)@multimedia.jl:342
display(::String, ::Any)@multimedia.jl:217
top-level scope@Local: 1[inlined]

`

Had the same issue, have you got some ways to display it in Pluto.jl?

mojaie commented 2 years ago

Sorry for very late response. I used Pluto.jl for the first time today, and looks really promissing...

Anyway, display may not work with Pluto.jl. MolecularGraph.jl does not have Base.Multimedia.display methods (see https://docs.julialang.org/en/v1/base/io-network/#Multimedia-I/O), so this is not a problem specific to this library, but to the Pluto.jl specification.

スクリーンショット 2022-02-24 0 03 31

HTML seems to work, but I don't know whether this is the intended way to do so.

SimonEnsemble commented 2 years ago

awesome, thanks, we are in business with Pluto now and MolecularGraph.jl now!

one thing I couldn't figure out is how to write the SVG to file.

SimonEnsemble commented 2 years ago
canvas = SvgCanvas()
draw2d!(canvas, mol)
drawatomindex!(canvas, mol, bgcolor=MolecularGraph.Color(255, 255, 255))
d = tosvg(canvas, 300, 300)

f = open("molecule.svg", "w")
write(f, d)
close(f)

for others looking for how to do this :)

mojaie commented 1 year ago

Base.multimedia.display(mol) implemented. See #77.