0 | module Text.Molfile.Writer.Util
 1 |
 2 | import Data.Linear.Traverse1
 3 | import Data.SortedMap
 4 | import Syntax.T1
 5 | import Data.String.Builder
 6 | import Text.Molfile.Types
 7 |
 8 | %default total
 9 |
10 | ||| Isotope pretty printer.
11 | export
12 | dispIso : Isotope -> String
13 | dispIso (MkI H (Just 2)) = "D"
14 | dispIso (MkI H (Just 3)) = "T"
15 | dispIso (MkI e _)        = symbol e
16 |
17 | ||| Radical pretty printer
18 | export
19 | dispRadical : Radical -> String
20 | dispRadical NoRadical = "0"
21 | dispRadical Singlet   = "1"
22 | dispRadical Doublet   = "2"
23 | dispRadical Triplet   = "3"
24 |
25 | parameters {auto b : Builder q}
26 |
27 |   writeV : SDValue -> F1' q
28 |   writeV "" = linebreak
29 |   writeV v  = T1.do
30 |     traverse1_ putCharsLn (grouped 200 $ unpack v.value)
31 |     linebreak
32 |
33 |   export
34 |   writeStructureData : StructureData -> F1' q
35 |   writeStructureData (SD h v) = putTextLn "> <\{h}>" >> writeV v
36 |
37 |   export %inline
38 |   sdfDelimiter : F1' q
39 |   sdfDelimiter = putTextLn "$$$$"
40 |
41 | public export
42 | 0 GroupMap : Type
43 | GroupMap = SortedMap Nat (String, SnocList Nat)
44 |
45 | export
46 | appendLbl : Fin k -> Adj k b (MolAtom' x y z) -> GroupMap -> GroupMap
47 | appendLbl x a m =
48 |   case a.label.label of
49 |     Nothing      => m
50 |     Just (G n l) => case lookup n m of
51 |       Just (l,sx) => insert n (l, sx :< S (cast x)) m
52 |       Nothing     => case trim l of
53 |         "" => m
54 |         l2 => insert n (l2, [<S (cast x)]) m
55 |