1 | module Chem.QSAR.Util
4 | import Chem.Aromaticity
9 | parameters {0 b,e,c,p,r,t,ch,l : Type}
10 | (g : IGraph k b (Atom e c p r h t ch l))
14 | elemAt : Cast e Elem => Fin k -> Elem
15 | elemAt = cast . elem . lab g
19 | isElem : Cast e Elem => Elem -> Fin k -> Bool
20 | isElem el = (el ==) . cast . elem . lab g
25 | hasElem : Cast e Elem => Elem -> AssocList k b -> Bool
26 | hasElem el = any (isElem el) . keys
32 | {auto ce : Cast e Elem}
33 | -> {auto cb : Cast b BondOrder}
39 | any (\(x,v) => cast v == o && isElem el x) . neighboursAsPairs g
44 | countElems : Cast e Elem => Elem -> AssocList k b -> Nat
45 | countElems el = count (isElem el) . keys
49 | countNonHs : Cast e Elem => AssocList k b -> Nat
50 | countNonHs = count (not . isElem H) . keys
54 | heavyDegree : Cast e Elem => Fin k -> Nat
55 | heavyDegree = countNonHs . neighboursAsAL g
59 | maxBondOrder : Cast b BondOrder => Fin k -> BondOrder
61 | foldl (\o,(_,vb) => max o $
cast vb) Single . neighboursAsPairs g
67 | isAmideBond : Cast e Elem => Cast b BondOrder => (x,y : Fin k) -> Bool
69 | (isElem N x && hasNeighbour O Dbl y) ||
70 | (isElem N y && hasNeighbour O Dbl x)
72 | parameters {auto cb : Cast b BondOrder}
77 | bonds : HCount -> AssocList k b -> Bonds
78 | bonds hc a = BS (cast hc.value) 0 0 <+> foldMap (toBonds . cast) a
82 | nonAromaticBonds : HCount -> AssocList k (AromBond b) -> Bonds
83 | nonAromaticBonds hc a = BS (cast hc.value) 0 0 <+> foldMap conv a
85 | conv : AromBond b -> Bonds
86 | conv ab = if ab.arom then neutral else toBonds (cast ab.type)
90 | numNeighbours : Atom e c p r HCount t ch l -> AssocList k b -> Nat
91 | numNeighbours a ns = cast a.hydrogen.value + length ns