Skip to content

Commit 929358e

Browse files
committed
JSON 1.0 support
1 parent 6cd6c4e commit 929358e

27 files changed

+870
-909
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MolecularGraph"
22
uuid = "6c89ec66-9cd8-5372-9f91-fabc50dd27fd"
3-
version = "0.21.1"
43
authors = ["Seiji Matsuoka <[email protected]"]
4+
version = "0.21.1"
55

66
[deps]
77
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
@@ -15,6 +15,7 @@ MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
1515
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1616
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1717
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
18+
StructUtils = "ec057cc2-7a8d-4b58-b3b3-92acb9f63b42"
1819
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
1920
coordgenlibs_jll = "f6050b86-aaaf-512f-8549-0afff1b4d57f"
2021
libinchi_jll = "172afb32-8f1c-513b-968f-184fcd77af72"
@@ -33,11 +34,12 @@ Colors = "0.13"
3334
DelimitedFiles = "1"
3435
GeometryBasics = "0.5"
3536
Graphs = "1.12"
36-
JSON = "0.21"
37+
JSON = "1"
3738
MakieCore = "0.9,0.10"
3839
OrderedCollections = "1.8"
3940
RDKitMinimalLib = "1.2"
4041
Statistics = "1"
42+
StructUtils = "2.5.1"
4143
Test = "1"
4244
YAML = "0.4"
4345
coordgenlibs_jll = "3.0.2"

build/src/LibMolGraphJL.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ Base.@ccallable function smilestomol(smiles::Cstring, options::Cstring)::Cstring
2323
if haskey(op, "remove_all_hydrogens") && op["remove_all_hydrogens"]
2424
remove_all_hydrogens!(mol) # default remove_all_hydrogens=false
2525
end
26-
unsafe_convert(Cstring, JSON.json(to_dict(mol)))
26+
unsafe_convert(Cstring, JSON.json(mol))
2727
catch e
2828
mol = SMILESMolGraph()
2929
mol[:logs]["error_smiles"] = e.msg
30-
unsafe_convert(Cstring, JSON.json(to_dict(mol)))
30+
unsafe_convert(Cstring, JSON.json(mol))
3131
end
3232
end
3333

3434

3535
Base.@ccallable function smartstomol(smarts::Cstring)::Cstring
3636
try
3737
mol = MolecularGraph.smartstomol(unsafe_string(smarts))
38-
unsafe_convert(Cstring, JSON.json(to_dict(mol)))
38+
unsafe_convert(Cstring, JSON.json(mol))
3939
catch e
4040
mol = SMARTSMolGraph()
4141
mol[:logs]["error_smarts"] = e.msg
42-
unsafe_convert(Cstring, JSON.json(to_dict(mol)))
42+
unsafe_convert(Cstring, JSON.json(mol))
4343
end
4444
end
4545

@@ -55,18 +55,18 @@ Base.@ccallable function sdftomol(sdf::Cstring, options::Cstring)::Cstring
5555
if haskey(op, "remove_all_hydrogens") && op["remove_all_hydrogens"]
5656
remove_all_hydrogens!(mol) # default remove_all_hydrogens=false
5757
end
58-
unsafe_convert(Cstring, JSON.json(to_dict(mol)))
58+
unsafe_convert(Cstring, JSON.json(mol))
5959
catch e
6060
mol = SDFMolGraph()
6161
mol[:logs]["error_sdfile"] = e.msg
62-
unsafe_convert(Cstring, JSON.json(to_dict(mol)))
62+
unsafe_convert(Cstring, JSON.json(mol))
6363
end
6464
end
6565

6666

6767
Base.@ccallable function vertex_count(mol::Cstring)::Cint
6868
try
69-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
69+
molobj = mol_from_json(unsafe_string(mol))
7070
nv(molobj)
7171
catch
7272
Base.invokelatest(Base.display_error, Base.catch_stack())
@@ -76,7 +76,7 @@ end
7676

7777
Base.@ccallable function edge_count(mol::Cstring)::Cint
7878
try
79-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
79+
molobj = mol_from_json(unsafe_string(mol))
8080
ne(molobj)
8181
catch
8282
Base.invokelatest(Base.display_error, Base.catch_stack())
@@ -86,7 +86,7 @@ end
8686

8787
Base.@ccallable function inchikey(mol::Cstring)::Cstring
8888
try
89-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
89+
molobj = mol_from_json(unsafe_string(mol))
9090
ikey = MolecularGraph.inchikey(molobj)
9191
unsafe_convert(Cstring, something(ikey, ""))
9292
catch
@@ -97,7 +97,7 @@ end
9797

9898
Base.@ccallable function standard_weight(mol::Cstring)::Cdouble
9999
try
100-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
100+
molobj = mol_from_json(unsafe_string(mol))
101101
MolecularGraph.standard_weight(molobj, 2)
102102
catch
103103
Base.invokelatest(Base.display_error, Base.catch_stack())
@@ -107,7 +107,7 @@ end
107107

108108
Base.@ccallable function molblock(mol::Cstring)::Cstring
109109
try
110-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
110+
molobj = mol_from_json(unsafe_string(mol))
111111
unsafe_convert(Cstring, printv2mol(molobj; givebackhydrogen=false))
112112
catch
113113
Base.invokelatest(Base.display_error, Base.catch_stack())
@@ -117,7 +117,7 @@ end
117117

118118
Base.@ccallable function sdfmolblock(mol::Cstring)::Cstring
119119
try
120-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
120+
molobj = mol_from_json(unsafe_string(mol))
121121
buf = IOBuffer(write=true)
122122
printv2sdf(buf, molobj; givebackhydrogen=false)
123123
res = String(take!(buf))
@@ -131,7 +131,7 @@ end
131131

132132
Base.@ccallable function drawsvg(mol::Cstring, options::Cstring)::Cstring
133133
try
134-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
134+
molobj = mol_from_json(unsafe_string(mol))
135135
op = JSON.parse(unsafe_string(options))
136136
kwgs = Pair{Symbol,Any}[]
137137
haskey(op, "viewbox") && push!(kwgs, :viewbox => op["viewbox"])
@@ -149,7 +149,7 @@ end
149149
Base.@ccallable function drawpng(
150150
mol::Cstring, width::UInt32, height::UInt32, options::Cstring)::Cstring
151151
try
152-
molobj = MolGraph(JSON.parse(unsafe_string(mol)))
152+
molobj = mol_from_json(unsafe_string(mol))
153153
op = JSON.parse(unsafe_string(options))
154154
kwgs = Pair{Symbol,Any}[]
155155
haskey(op, "show_carbon") && push!(kwgs, :show_carbon => Symbol(op["show_carbon"]))
@@ -171,8 +171,8 @@ end
171171
Base.@ccallable function has_exact_match(
172172
mol1::Cstring, mol2::Cstring, kwargs::Cstring)::Cint
173173
try
174-
mol1 = mol_from_dict(JSON.parse(unsafe_string(mol1)))
175-
mol2 = mol_from_dict(JSON.parse(unsafe_string(mol2)))
174+
mol1 = mol_from_json(unsafe_string(mol1))
175+
mol2 = mol_from_json(unsafe_string(mol2))
176176
kwargs = JSON.parse(unsafe_string(kwargs))
177177
MolecularGraph.has_exact_match(mol1, mol2; kwargs...)
178178
catch
@@ -184,8 +184,8 @@ end
184184
Base.@ccallable function has_substruct_match(
185185
mol1::Cstring, mol2::Cstring, kwargs::Cstring)::Cint
186186
try
187-
mol1 = mol_from_dict(JSON.parse(unsafe_string(mol1)))
188-
mol2 = mol_from_dict(JSON.parse(unsafe_string(mol2)))
187+
mol1 = mol_from_json(unsafe_string(mol1))
188+
mol2 = mol_from_json(unsafe_string(mol2))
189189
kwargs = JSON.parse(unsafe_string(kwargs))
190190
MolecularGraph.has_substruct_match(mol1, mol2; kwargs...)
191191
catch
@@ -197,8 +197,8 @@ end
197197
Base.@ccallable function tdmcis_size(
198198
mol1::Cstring, mol2::Cstring, kwargs::Cstring)::Cint
199199
try
200-
mol1 = MolGraph(JSON.parse(unsafe_string(mol1)))
201-
mol2 = MolGraph(JSON.parse(unsafe_string(mol2)))
200+
mol1 = mol_from_json(unsafe_string(mol1))
201+
mol2 = mol_from_json(unsafe_string(mol2))
202202
kwargs = Dict(Symbol(k) => v for (k, v) in JSON.parse(unsafe_string(kwargs)))
203203
length(tdmcis(mol1, mol2; kwargs...)[1])
204204
catch
@@ -210,8 +210,8 @@ end
210210
Base.@ccallable function tdmces_size(
211211
mol1::Cstring, mol2::Cstring, kwargs::Cstring)::Cint
212212
try
213-
mol1 = MolGraph(JSON.parse(unsafe_string(mol1)))
214-
mol2 = MolGraph(JSON.parse(unsafe_string(mol2)))
213+
mol1 = mol_from_json(unsafe_string(mol1))
214+
mol2 = mol_from_json(unsafe_string(mol2))
215215
kwargs = Dict(Symbol(k) => v for (k, v) in JSON.parse(unsafe_string(kwargs)))
216216
length(tdmces(mol1, mol2; kwargs...)[1])
217217
catch
@@ -223,8 +223,8 @@ end
223223
Base.@ccallable function tdmcis_gls(
224224
mol1::Cstring, mol2::Cstring, kwargs::Cstring)::Cdouble
225225
try
226-
mol1 = MolGraph(JSON.parse(unsafe_string(mol1)))
227-
mol2 = MolGraph(JSON.parse(unsafe_string(mol2)))
226+
mol1 = mol_from_json(unsafe_string(mol1))
227+
mol2 = mol_from_json(unsafe_string(mol2))
228228
if nv(mol1) == 0 || nv(mol2) == 0
229229
return 0.0
230230
end
@@ -244,8 +244,8 @@ end
244244
Base.@ccallable function tdmces_gls(
245245
mol1::Cstring, mol2::Cstring, kwargs::Cstring)::Cdouble
246246
try
247-
mol1 = MolGraph(JSON.parse(unsafe_string(mol1)))
248-
mol2 = MolGraph(JSON.parse(unsafe_string(mol2)))
247+
mol1 = mol_from_json(unsafe_string(mol1))
248+
mol2 = mol_from_json(unsafe_string(mol2))
249249
if ne(mol1) == 0 || ne(mol2) == 0
250250
return 0.0
251251
end

src/MolecularGraph.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
module MolecularGraph
77

8+
import JSON
89
using OrderedCollections
910
using Printf: @sprintf
11+
using StructUtils
1012
import YAML
1113

1214

@@ -33,10 +35,13 @@ include("./property/interface.jl")
3335
include("./draw/interface.jl")
3436

3537
export
38+
VertexKey, EdgeKey,
3639
AbstractAtom, AbstractBond, Reaction, QueryTree,
3740
vproptype, eproptype,
3841
props, get_prop, has_prop, set_prop!,
39-
u_edge, ordered_neighbors, edge_neighbors, ordered_edge_neighbors
42+
u_edge, ordered_neighbors, edge_neighbors, ordered_edge_neighbors,
43+
Stereocenter, StereocenterMap, Stereobond, StereobondMap,
44+
Coords2d, Coords3d
4045

4146

4247
# Graph models and algorithms
@@ -90,10 +95,10 @@ export
9095

9196
# Basic molecular properties
9297

93-
include("property/topology.jl")
94-
include("property/valence.jl")
95-
include("property/hybridization.jl")
96-
include("property/wclogp.jl")
98+
include("./property/topology.jl")
99+
include("./property/valence.jl")
100+
include("./property/hybridization.jl")
101+
include("./property/wclogp.jl")
97102

98103
export
99104
sssr, sssr!,
@@ -114,10 +119,6 @@ export
114119

115120
# Preprocessing and molecule manipulation
116121

117-
using coordgenlibs_jll: libcoordgen
118-
119-
include("coords.jl")
120-
include("stereo.jl")
121122
include("preprocess.jl")
122123
include("virtualatom.jl")
123124

@@ -141,7 +142,6 @@ export
141142
# I/O
142143

143144
import Dates
144-
import JSON
145145

146146
include("json.jl")
147147
include("sdfilereader.jl")
@@ -153,7 +153,7 @@ include("./smarts/logicaloperator.jl")
153153
include("./smarts/molecule.jl")
154154

155155
export
156-
to_dict, to_json, mol_from_dict,
156+
to_dict, mol_from_json,
157157
SDFileReader,
158158
sdf_on_init!, sdf_on_update!,
159159
sdfilereader, rdfilereader, sdfilescanner,
@@ -167,7 +167,10 @@ export
167167
# Descriptors
168168

169169
using libinchi_jll: libinchi
170+
using coordgenlibs_jll: libcoordgen
170171

172+
include("stereo.jl")
173+
include("coords.jl")
171174
include("mass.jl")
172175
include("rdkit.jl")
173176
include("inchi.jl")

0 commit comments

Comments
 (0)