0 | module Test.Text.Molfile.Generators
  1 |
  2 | import public Test.Chem.Generators
  3 | import public Test.Data.Graph.Generators
  4 | import public Text.Molfile
  5 |
  6 | import Data.Vect
  7 |
  8 | %default total
  9 |
 10 | export
 11 | molLine : Gen MolLine
 12 | molLine = MkMolLine <$> string (linear 0 80) printableAscii
 13 |
 14 | export
 15 | molVersion : Gen MolVersion
 16 | molVersion = element [V2000, V3000]
 17 |
 18 | export
 19 | chiralFlag : Gen ChiralFlag
 20 | chiralFlag = element [NonChiral, Chiral]
 21 |
 22 | export
 23 | stereoParity : Gen StereoParity
 24 | stereoParity = element [NoStereo, OddStereo, EvenStereo, AnyStereo]
 25 |
 26 | export
 27 | stereoCareBox : Gen StereoCareBox
 28 | stereoCareBox = element [IgnoreStereo, MatchStereo]
 29 |
 30 | export
 31 | valence : Gen Valence
 32 | valence = fromMaybe 0 . refineValence <$> bits8 (linear 0 15)
 33 |
 34 | export
 35 | h0Designator : Gen H0Designator
 36 | h0Designator = element [H0NotSpecified, NoHAllowed]
 37 |
 38 | export
 39 | hydrogenCount : Gen HydrogenCount
 40 | hydrogenCount = fromMaybe 0 . refineHydrogenCount <$> bits8 (linear 0 5)
 41 |
 42 | export
 43 | coordinate : Gen Coordinate
 44 | coordinate =
 45 |   fromMaybe 0 . refineCoordinate <$>
 46 |   integer (exponentialFrom 0 (-9999_9999) 99999_9999)
 47 |
 48 | export
 49 | coords : Gen (Vect 3 Coordinate)
 50 | coords = vect 3 coordinate
 51 |
 52 | u : Gen ()
 53 | u = pure ()
 54 |
 55 | export
 56 | atom : Gen (Maybe AtomGroup) -> Gen MolAtom
 57 | atom nr =
 58 |   [| MkAtom isotope charge coords radical u u u nr |]
 59 |
 60 | export
 61 | simpleAtom : Gen MolAtom
 62 | simpleAtom =
 63 |   [| MkAtom (map cast elem) (pure 0) coords (pure NoRadical) u u u (pure Nothing) |]
 64 |
 65 | export
 66 | bondStereo : Gen BondStereo
 67 | bondStereo = element [NoBondStereo,Up,Either,Down]
 68 |
 69 | export
 70 | bondTopo : Gen BondTopo
 71 | bondTopo = element [AnyTopology,Ring,Chain]
 72 |
 73 | export
 74 | bond : Gen MolBond
 75 | bond = [| MkBond bool bondOrder bondStereo |]
 76 |
 77 | export
 78 | bondEdge : Gen (Edge 999 MolBond)
 79 | bondEdge = edge bond
 80 |
 81 | lbl : Gen String
 82 | lbl = [| go alpha (string (linear 1 10) alphaNum) |]
 83 |   where
 84 |     go : Char -> String -> String
 85 |     go = (++) . singleton
 86 |
 87 | groups : Gen (List AtomGroup)
 88 | groups = withIndex [<] 1 <$> list (linear 0 4) lbl
 89 |   where
 90 |     withIndex : SnocList AtomGroup -> Nat -> List String -> List AtomGroup
 91 |     withIndex sa n []      = sa <>> []
 92 |     withIndex sa n (l::ls) = withIndex (sa :< G n l) (S n) ls
 93 |
 94 | group : List AtomGroup -> Gen (Maybe AtomGroup)
 95 | group []     = pure Nothing
 96 | group (h::t) = maybe (element $ h :: Vect.fromList t)
 97 |
 98 | export
 99 | sdHeader : Gen SDHeader
100 | sdHeader = fromMaybe "" . refineSDHeader <$> string (linear 0 70) alphaNum
101 |
102 | export
103 | sdValue : Gen SDValue
104 | sdValue = fromMaybe "" . refineSDValue <$> string (linear 0 300) printableAscii
105 |
106 | export
107 | structureData : Gen StructureData
108 | structureData = [| SD sdHeader sdValue |]
109 |
110 | export
111 | molFileGS : List AtomGroup -> Gen Molfile
112 | molFileGS gs = do
113 |   [| MkMolfile
114 |        molLine
115 |        molLine
116 |        molLine
117 |        (lgraph (linear 1 30) (linear 0 30) bond (atom $ group gs))
118 |        (pure [])
119 |   |]
120 |
121 | export
122 | molFile : Gen Molfile
123 | molFile = groups >>= molFileGS
124 |
125 | export
126 | sdFileGS : List AtomGroup -> Gen Molfile
127 | sdFileGS gs = do
128 |   [| MkMolfile
129 |        molLine
130 |        molLine
131 |        molLine
132 |        (lgraph (linear 1 30) (linear 0 30) bond (atom $ group gs))
133 |        (list (linear 0 5) structureData)
134 |   |]
135 |
136 | export
137 | sdFile : Gen Molfile
138 | sdFile = groups >>= sdFileGS
139 |