0 | module Text.Molfile.Parser.V2000
2 | import Data.SortedMap
4 | import Text.Molfile.Parser.Stack
5 | import Text.Molfile.Parser.Util
16 | v2000 = repeat 34 sdigit >> oneof ['V','v'] >> "2000" >> newline
20 | sdigits : Nat -> RExp True
21 | sdigits n = orT $
atleast n sdigit >> newline
27 | smtExpr = repeat 3 sdigit >> ' ' >> star dot
33 | styExpr = repeat 3 sdigit >> star (repeat 4 sdigit >> ' ' >> repeat 3 upper)
37 | coordinatesV2 : RExp True
40 | (" " >> optmin >> digit >> rem)
41 | <|> (" " >> optmin >> repeat 2 digit >> rem)
42 | <|> (" " >> optmin >> repeat 3 digit >> rem)
43 | <|> ( optmin >> repeat 4 digit >> rem)
46 | optmin, rem : RExp True
47 | optmin = ' ' <|> '-' <|> digit
48 | rem = '.' >> repeat 4 digit
54 | parameters {auto sk : CSTCK q}
59 | countsV2 : ByteString -> F1 q CST
61 | case nat (substring 0 3 bs) of
62 | 0 => writeAs sk.isEmpty True Prop2
65 | write1 sk.count (nat $
substring 3 3 bs)
66 | writeAs sk.mgraph g Coords2
71 | coordsV2 : ByteString -> F1 q CST
73 | let x := substring 0 10 bs
74 | y := substring 10 10 bs
75 | z := substring 20 10 bs
76 | in modAtom {position := [coord x,coord y,coord z]} >> pure Sym2
83 | mg <- read1 sk.mgraph
85 | let x2 := finToNat $
FS x
87 | Just0 prf => writeAs mg.atom (natToFinLT x2) Coords2
88 | Nothing0 => countdown sk.count Bnd2 Prop2
94 | read blockcharge 3 >>= \case
96 | Right c => modAtom {charge := c} >> atomV2
102 | mg <- read1 sk.mgraph
103 | Right x <- read node 3 | Left x => failErr x
104 | Right e <- read (uedge x) 3 | Left x => failErr x
105 | Right o <- read bondOrder 3 | Left x => failErr x
106 | Right s <- read bondStereo 3 | Left x => failErr x
107 | linsEdge mg.graph ({label := MkBond (x == e.node1) o s} e)
108 | countdown sk.count Bnd2 Prop2
116 | repeat : CST -> F1' q -> Nat -> F1 q CST
117 | repeat res f 0 = pure res
118 | repeat res f (S k) = T1.do
120 | Nothing <- read1 sk.error_ | Just _ => pure CErr
125 | nx : CST -> F1' q -> F1 q CST
126 | nx res f = read nat 3 >>= repeat res f
130 | (ByteString -> Either ErrPair a)
131 | -> (a -> MolAtom -> MolAtom)
133 | prop rd adj = read1 sk.mgraph >>= nx Prop2 . act
135 | act : MGraph q -> F1' q
137 | Right x <- read node 4 | Left x => fail x
138 | Right v <- read rd 4 | Left x => fail x
139 | lupdNode mg.graph x (adj v)
141 | chg, iso, rad, sal, sty, smt : F1 q CST
142 | chg = prop charge $
\c => {charge := c}
143 | iso = prop massNr $
\m => {elem $= setMass m}
144 | rad = prop radical $
\r => {radical := r}
149 | mg <- read1 sk.mgraph
150 | Right n <- read node 4 | Left x => fail x
151 | lupdNode mg.graph n {label := Just $
G v ""}
153 | sty = nx Prop2 $ T1.do
155 | SUP <- read sgroupType 4 | _ => pure ()
156 | mod1 sk.groups (insert n "")
161 | mod1 sk.groups $
\m => case lookup n m of
162 | Just _ => insert n s m
167 | line : Nat -> a -> (CSTCK q => F1 q CST) -> (a, Step q CSz CSTCK)
168 | line n x f = (x, Rd $
\(sk # t) => (write1 sk.pos n >> f <* incline 1) t)
171 | prop2 : Steps q CSz CSTCK
173 | [ line 6 ("M CHG" >> star ('-' <|> sdigit) >> newline) chg
174 | , line 6 ("M ISO" >> star sdigit >> newline) iso
175 | , line 6 ("M RAD" >> star sdigit >> newline) rad
176 | , line 6 ("M SAL" >> star sdigit >> newline) sal
177 | , line 6 ("M STY" >> styExpr >> newline) sty
178 | , line 6 ("M SMT " >> smtExpr >> newline) smt
179 | , newline m_end (end >> pure CDone)
180 | , newline' (m_end >> newline) EndMol
181 | , newline' (oneof ['M','V','G','A'] >> " " >> star dot >> newline) Prop2