@@ -37,21 +37,22 @@ mutable struct MolState{T,F1,F2} <: AbstractState
3737 initialized:: Bool
3838 has_updates:: Bool
3939 has_new_edges:: Bool # as a SSSR recalculation flag
40+ force_calculate:: Bool # ignore cached descriptors (temporary set when running auto-preprocess)
4041 on_init:: F1
4142 on_update:: F2
4243end
4344
4445
4546function MolState{T}(
46- ; initialized= false , has_updates= true , has_new_edges= true ,
47+ ; initialized= false , has_updates= true , has_new_edges= true , force_calculate = false ,
4748 on_init= default_on_init!, on_update= default_on_update!) where T <: Integer
4849 return MolState{T,typeof(on_init),typeof(on_update)}(
49- initialized, has_updates, has_new_edges, on_init, on_update)
50+ initialized, has_updates, has_new_edges, force_calculate, on_init, on_update)
5051end
5152
5253
5354Base. copy(state:: T ) where T <: MolState = T(
54- state. initialized, state. has_updates, state. has_new_edges,
55+ state. initialized, state. has_updates, state. has_new_edges, state . force_calculate,
5556 state. on_init, state. on_update
5657)
5758
@@ -60,7 +61,12 @@ Base.copy(state::T) where T <: MolState = T(
6061
6162function get_descriptor(mol:: ReactiveMolGraph , field:: Symbol )
6263 dispatch_update!(mol)
63- return getproperty(mol. gprops. descriptors, field)
64+ return getproperty(mol[:descriptors], field)
65+ end
66+
67+ function has_descriptor(mol:: ReactiveMolGraph , field:: Symbol )
68+ mol. state. force_calculate && return false
69+ return hasproperty(mol[:descriptors], field)
6470end
6571
6672
@@ -103,8 +109,10 @@ to recalculate descriptors. If there are no changes, just return the stored desc
103109"""
104110function dispatch_update!(mol:: ReactiveMolGraph )
105111 mol. state. has_updates || return
106- mol. state. has_updates = false # call before update to avoid infinite roop
112+ mol. state. force_calculate = true # to avoid infinite roop
107113 mol. state. on_update(mol)
114+ mol. state. force_calculate = false
115+ mol. state. has_updates = false
108116 mol. state. has_new_edges = false
109117 return
110118end
@@ -151,7 +159,7 @@ Custom `on_init` function is called inside this method.
151159function initialize!(mol:: ReactiveMolGraph )
152160 mol. state. initialized || mol. state. on_init(mol)
153161 mol. state. initialized = true
154- dispatch_update!(mol) # just checking on-update callback errors
162+ dispatch_update!(mol) # check on-update callback errors
155163 return
156164end
157165
275283
276284
277285function Graphs. rem_vertex!(mol:: ReactiveMolGraph , v:: Integer )
278- dispatch_update!(mol)
279286 nv_ = nv(mol)
280287 old_edges = collect(edges(mol))
281288 rem_vertex!(mol. graph, v) || return false
301308
302309function Graphs. rem_vertices!(mol:: ReactiveMolGraph{T,V,E} , vs:: Vector{T} ) where {T,V,E}
303310 # TODO : if many vertices should be removed, induced_subgraph may be more efficient.
304- dispatch_update!(mol)
305311 old_edges = collect(edges(mol))
306312 vmap = rem_vertices!(mol. graph, vs)
307313 # remap vertex properties
330336
331337function _induced_subgraph(mol:: T , vlist_or_elist) where {T<: ReactiveMolGraph }
332338 # In many cases, induced_subgraph(mol.graph, vlist_or_elist) is sufficient
333- dispatch_update!(mol)
334339 subg, vmap = induced_subgraph(mol. graph, vlist_or_elist)
335340 vps = Dict{eltype(T),vproptype(T)}()
336341 for v in vertices(subg)
0 commit comments