0 | ||| Functionality for counting the number of hydrogen bond acceptors
 1 | ||| in a molecule.
 2 | |||
 3 | ||| Like in the CDK, a H-acceptor is either
 4 | |||  * a non-positively charge oxygen that is not an aromatic ether
 5 | |||    nor adjacent to a nitrogen
 6 | |||  * a non-positively charge nitrogen that is not adjacent to an oxygen
 7 | module Chem.QSAR.HAcceptor
 8 |
 9 | import Chem
10 | import Chem.Aromaticity
11 | import Chem.QSAR.Util
12 |
13 | %default total
14 |
15 | parameters {0 b,e,p,r,h,t,c,l : Type}
16 |            {auto cst : Cast e Elem}
17 |            {k        : Nat}
18 |            (g        : IGraph k (AromBond b) (Atom e Charge p r h t c l))
19 |   
20 |   isAromEther : AssocList k (AromBond b) -> Bool
21 |   isAromEther bs = countNonHs g bs > 1 && any (isAromatic g) (keys bs)
22 |
23 |   ||| True, if the atom at the given node is a hydrogen bond acceptor.
24 |   |||
25 |   ||| Like in the CDK, an H-acceptor is either
26 |   |||  * a non-positively charge oxygen that is not an aromatic ether
27 |   |||    nor adjacent to a nitrogen
28 |   |||  * a non-positively charge nitrogen that is not adjacent to an oxygen
29 |   export
30 |   isHAcceptor : Fin k -> Bool
31 |   isHAcceptor n =
32 |     let A atm ns := adj g n
33 |      in case cast @{cst} (elem atm) of
34 |           N => charge atm <= 0 && not (hasElem g O ns)
35 |           O => charge atm <= 0 && not (hasElem g N ns || isAromEther ns)
36 |           _ => False
37 |
38 |   ||| Returns the number of H-acceptors counted in the graph.
39 |   |||
40 |   ||| See also `isHAcceptor` for the rules about what counts as an H-acceptor.
41 |   export %inline
42 |   hAcceptorCount : Nat
43 |   hAcceptorCount = count isHAcceptor $ nodes g
44 |