0 | ||| Functionality for counting the number of hydrogen bond donors
 1 | ||| in a molecule.
 2 | |||
 3 | ||| Like in the CDK, a H-donor is either
 4 | |||  * a non-negatively charge oxygen bound to at least on hydrogen
 5 | |||  * a non-negatively charge nitrogen bound to at least on hydrogen
 6 | module Chem.QSAR.HDonor
 7 |
 8 | import Chem
 9 | import Chem.Aromaticity
10 | import Chem.QSAR.Util
11 |
12 | %default total
13 |
14 | parameters {0 b,e,p,r,t,c,l : Type}
15 |            {auto cst : Cast e Elem}
16 |            {k        : Nat}
17 |            (g        : IGraph k (AromBond b) (Atom e Charge p r HCount t c l))
18 |
19 |   ||| True, if the atom at the given node is a hydrogen bond donor.
20 |   |||
21 |   ||| Like in the CDK, a H-donor is either
22 |   |||  * a non-negatively charge oxygen bound to at least on hydrogen
23 |   |||  * a non-negatively charge nitrogen bound to at least on hydrogen
24 |   export
25 |   isHDonor : Fin k -> Bool
26 |   isHDonor n =
27 |     let A a ns := adj g n
28 |      in case cast @{cst} (elem a) of
29 |           N => charge a >= 0 && (hydrogen a > 0 || hasElem g H ns)
30 |           O => charge a >= 0 && (hydrogen a > 0 || hasElem g H ns)
31 |           _ => False
32 |
33 |   ||| Returns the number of H-donors counted in the graph.
34 |   |||
35 |   ||| See also `isHDonor` for the rules about what counts as an H-donor.
36 |   export %inline
37 |   hDonorCount : Nat
38 |   hDonorCount = count isHDonor $ nodes g
39 |