Skip to content

coordgen!() changes chirality from unspecified to specified #139

@hhaensel

Description

@hhaensel

Here's a demo with the demo molecule from tests

julia> txt = read("MolecularGraph/assets/test/demo.mol", String);

julia> mol = sdftomol(IOBuffer(txt));

julia> i1 = inchi(mol);

julia> coordgen!(mol);

julia> i2 = inchi(mol);

julia> compare_inchi(i1, i2)
Comparing InChI layers:
[6][b] ✗ different:
    1: b7-5+,8-6+,11-9?;
    2: b7-5+,8-6+,11-9+;
false

I tried to track it down to libcoordgen.setStereoCenter() and libcoordgen.setStereoBond(), but I couldn't find the definition in the coordgenlibs repo.
@mojaie Could you help me where that is defined? I already tried passing in 2 (unspecified) for undefined parity, but that didn't help.
Here's the helper function that I used above, we might add this to repo as well?

# utility function to compare inchi strings
function compare_inchi(i1::String, i2::String; verbose::Union{Symbol, Bool} = :fail)
    identical = true
    # strip "InChI=1S/" prefix if present
    strip_prefix(s) = startswith(s, "InChI=") ? split(s, "/", limit=2)[2] : s
    s1 = strip_prefix(i1)
    s2 = strip_prefix(i2)

    # split into layers
    layers1 = split(s1, "/")
    layers2 = split(s2, "/")

    maxlen = max(length(layers1), length(layers2))
    (verbose == false) || println("Comparing InChI layers:")
    for i in 1:maxlen
        l1 = i <= length(layers1) ? layers1[i] : "(none)"
        l2 = i <= length(layers2) ? layers2[i] : "(none)"
        tag = first(l1, 1)
        if l1 == l2
            (verbose == true || verbose == :all) && println("[$i][$tag] ✓ identical: $l1")
        else
            identical = false
            verbose == false || begin
                println("[$i][$tag] ✗ different:")
                println("    1: $l1")
                println("    2: $l2")
            end
        end
    end
    return identical
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions