MolecularGraph.jl icon indicating copy to clipboard operation
MolecularGraph.jl copied to clipboard

Unable to assemble a molecule using the SMILESMolGraph ctor

Open Shredderroy opened this issue 2 months ago • 5 comments

I would like to assemble a simple SMILESMolGraph O=C=O molecule by hand, as it were, in the following manner:

import Graphs, MolecularGraph

mol = let
	edge_list = [Graphs.Edge(1, 2), Graphs.Edge(1, 3),];
	vprop_list = [
		MolecularGraph.SMILESAtom(:C, 0, 1, 0, false, :unspecified),
		MolecularGraph.SMILESAtom(:O, 0, 1, 0, false, :unspecified),
		MolecularGraph.SMILESAtom(:O, 0, 1, 0, false, :unspecified),
	];
	eprop_list = [
		MolecularGraph.SMILESBond(2, false, :unspecified),
		MolecularGraph.SMILESBond(2, false, :unspecified),
	];
	MolecularGraph.SMILESMolGraph(edge_list, vprop_list, eprop_list)
end

According to the MolGraph method listed at line 402 of ~/.julia/packages/MolecularGraph/isHa9/src/model/molgraph.jl, this is a valid signature:

MolGraph(
    edge_list::Vector{Edge{T}}, vprop_list::Vector{V}, eprop_list::Vector{E}; kwargs...
) where {T,V,E} = MolGraph{T,V,E}(edge_list, vprop_list, eprop_list; kwargs...)

.
.
.

const SMILESMolGraph = MolGraph{Int, SMILESAtom, SMILESBond}

But it leads to the following error in Pluto:

Error message from Main

Failed to show value:

KeyError: key :stereocenter not found Stack trace

Here is what happened, the most recent locations are first:

getindex(h::Dict{…}, key::Symbol) [...show types...](http://localhost:8888/edit?id=1135c318-adcf-11f0-117a-c9cb065cb7de#)
from 
[julia → dict.jl:477](https://github.com/JuliaLang/julia/tree/f2b3dbda30a314d042178ec70ae2115735176f7e/base/dict.jl#L475)

get_prop from interface.jl:107 coordgen(mol::MolecularGraph.SMILESMolGraph) from MolecularGraph → coords.jl:130

draw2d!(canvas::MolecularGraph.SvgCanvas, mol::MolecularGraph.SMILESMolGraph; kwargs::@Kwargs{}) from MolecularGraph → draw2d.jl:326

draw2d! from draw2d.jl:318 #drawsvg#455(mol::MolecularGraph.SMILESMolGraph; bgcolor::MolecularGraph.Color, bgopacity::Float64, atomhighlight::Vector{…}, bondhighlight::Vector{…}, highlightcolor::MolecularGraph.Color, atomindex::Bool, indexcolor::MolecularGraph.Color, indexbgcolor::MolecularGraph.Color, kwargs::@Kwargs{}) ...show types... from MolecularGraph → svg.jl:111

drawsvg from svg.jl:105 #html_fixed_size#458 from svg.jl:134 html_fixed_size from svg.jl:131 show(io::IOContext{…}, m::MIME{…}, mol::MolecularGraph.SMILESMolGraph) ...show types... from MolecularGraph → svg.jl:162

What am I doing incorrectly? Thanks in advance.

Shredderroy avatar Oct 28 '25 01:10 Shredderroy