3 | import Chem.Aromaticity
4 | import Data.Graph.Indexed
5 | import Data.Graph.Indexed.Subgraph
6 | import Data.Graph.Indexed.Query.Subgraph
8 | import Text.Smiles.AtomType
9 | import Text.Smiles.Types
10 | import Text.Molfile.AtomType
11 | import Text.Molfile.Types
23 | TargetBond = AromBond BondOrder
29 | QueryBond = AromBond BondOrder
33 | matchBond : QueryBond -> TargetBond -> Bool
34 | matchBond (AB _ True) t = t.arom
35 | matchBond (AB Single _) t = True
36 | matchBond (AB q _) t = q == t.type
39 | qbond : Cast b BondOrder => AromBond b -> AromBond BondOrder
40 | qbond (AB t v) = AB (cast t) v
58 | TargetAtom = Atom Isotope Charge () () TotH () () ()
62 | record ExplicitH where
72 | QueryAtom = Atom Isotope Charge () () ExplicitH () () ()
74 | matchIso : Isotope -> Isotope -> Bool
75 | matchIso x y = x.elem == y.elem && (x.mass == Nothing || x.mass == y.mass)
79 | matchAtom : QueryAtom -> TargetAtom -> Bool
81 | matchIso q.elem t.elem &&
82 | (q.charge == 0 || q.charge == t.charge) &&
83 | q.hydrogen.count <= t.hydrogen.count
92 | QueryGraph = Graph QueryBond QueryAtom
96 | 0 TargetGraph : Type
97 | TargetGraph = Graph TargetBond TargetAtom
99 | isH : Cast e Isotope => Cast c Charge => Atom e c p r h t ch l -> Bool
100 | isH v = MkI H Nothing == cast v.elem && 0 == cast {to = Charge} v.charge
103 | removeHs : {k : _} -> IGraph k QueryBond QueryAtom -> QueryGraph
104 | removeHs g = snd <$> subgraphL g (filter (not . isH . lab g) (nodes g))
106 | parameters {0 e,c,p,r,h,t,ch,l,b : Type}
108 | {auto cb : Cast b BondOrder}
109 | {auto cel : Cast e Isotope}
110 | {auto cch : Cast c Charge}
111 | (g : IGraph k (AromBond b) (Atom e c p r h t ch l))
114 | Atm = Atom e c p r h t ch l
116 | explicitHs : AssocList k (AromBond b) -> Nat
117 | explicitHs ns = count (\(x,_) => isH $
lab g x) (pairs ns)
119 | qadj : Adj k (AromBond b) Atm -> Adj k QueryBond QueryAtom
121 | let bs2 := map qbond bs
122 | eh := explicitHs bs
123 | lbl2 := MkAtom (cast lbl.elem) (cast lbl.charge) () () (EH eh) () () ()
126 | tadj : Cast h HCount => Adj k (AromBond b) Atm -> Adj k TargetBond TargetAtom
128 | let bs2 := map qbond bs
129 | th := explicitHs bs + cast (value $
cast {to = HCount} lbl.hydrogen)
130 | lbl2 := MkAtom (cast lbl.elem) (cast lbl.charge) () () (TH th) () () ()
136 | toTarget : Cast h HCount => IGraph k TargetBond TargetAtom
137 | toTarget = mapAdj tadj g
142 | toQuery : Graph QueryBond QueryAtom
143 | toQuery = removeHs $
mapAdj qadj g
147 | smilesQuery : SmilesGraphAT -> QueryGraph
149 | let G o g := aromatize atomType sg
154 | smilesTarget : SmilesGraphAT -> TargetGraph
156 | let G o g := aromatize atomType sg
157 | in G o $
toTarget g
161 | molQuery : MolGraphAT -> QueryGraph
163 | let G o g := aromatize atomType sg
168 | molTarget : MolGraphAT -> TargetGraph
170 | let G o g := aromatize atomType sg
171 | in G o $
toTarget g
183 | -> IGraph q QueryBond QueryAtom
184 | -> IGraph t TargetBond TargetAtom
185 | -> Maybe (Vect q $
Fin t)
186 | substructureI = assert_total $
query matchBond matchAtom
194 | substructure : QueryGraph -> TargetGraph-> Maybe (List Nat)
195 | substructure (G _ qg) (G _ tg) = map finToNat . toList <$> substructureI qg tg