0 | module Text.Molfile.AtomType
 1 |
 2 | import Chem
 3 | import Text.Molfile.Types
 4 |
 5 | %default total
 6 |
 7 | ||| Compute the atom type and implicit hydrogen count
 8 | ||| of an atom with charge and information about
 9 | ||| racicals set, that is bound to its neighbours by `MolBond`s.
10 | export
11 | calcMolAtomType :
12 |      {auto fld : Foldable f}
13 |   -> f MolBond
14 |   -> Atom Isotope Charge p Radical h t c l
15 |   -> Atom Isotope Charge p Radical HCount AtomType c l
16 | calcMolAtomType ns a =
17 |   let bs      := foldMap (toBonds . type) ns
18 |       (hy,at) := atomTypeAndHydrogens (cast a.elem) a.radical a.charge bs
19 |    in {type := at, hydrogen := hy} a
20 |
21 | ||| Perceive atom types and implicit hydrogens for a .mol-file graph
22 | export %inline
23 | perceiveMolAtomTypes : MolGraph -> MolGraphAT
24 | perceiveMolAtomTypes (G o g) =
25 |   G o $ mapWithCtxt (\_,(A a ns) => calcMolAtomType ns a) g
26 |