Commit 2eaf48d
Preserve R/S and E/Z stereochemistry in polymer converters
Extends PR #1's stereochemistry fix (previously molecule + markush only) to the
polymer path, which until now silently dropped chirality and double-bond
geometry on round-trip.
- polymer_to_mermaid: emit absolute CIP R/S (_CIPCode) in atom ids instead of
order-dependent CHI_TETRAHEDRAL_CW/CCW (same bug fixed in the molecule converter).
- mermaid_to_psmiles: parse _R/_S id suffixes and ===|E|/===|Z| markers, then
restore them after sanitize — chirality via brute-forced CIP matching, and
double-bond geometry via SetDoubleBondNeighborDirections so SMILES emits / and \.
- tests/test_polymer_stereochemistry.py: PLA R/S, cis/trans polybutadiene,
combined chiral+E/Z, and plain-polymer regression coverage.
Verified: chiral and E/Z PSMILES now round-trip to canonical-identical SMILES,
and cis is distinguished from trans.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 970d572 commit 2eaf48d
3 files changed
Lines changed: 148 additions & 9 deletions
File tree
- molecode/polymer
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
96 | 160 | | |
97 | 161 | | |
98 | 162 | | |
| |||
107 | 171 | | |
108 | 172 | | |
109 | 173 | | |
| 174 | + | |
110 | 175 | | |
111 | 176 | | |
112 | 177 | | |
| |||
117 | 182 | | |
118 | 183 | | |
119 | 184 | | |
120 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
121 | 189 | | |
122 | 190 | | |
123 | | - | |
| 191 | + | |
124 | 192 | | |
125 | 193 | | |
126 | 194 | | |
| |||
130 | 198 | | |
131 | 199 | | |
132 | 200 | | |
| 201 | + | |
133 | 202 | | |
134 | 203 | | |
135 | 204 | | |
| |||
141 | 210 | | |
142 | 211 | | |
143 | 212 | | |
144 | | - | |
| 213 | + | |
145 | 214 | | |
146 | 215 | | |
147 | 216 | | |
| |||
166 | 235 | | |
167 | 236 | | |
168 | 237 | | |
169 | | - | |
| 238 | + | |
| 239 | + | |
170 | 240 | | |
171 | 241 | | |
172 | 242 | | |
173 | 243 | | |
174 | 244 | | |
| 245 | + | |
| 246 | + | |
175 | 247 | | |
176 | 248 | | |
177 | 249 | | |
| |||
191 | 263 | | |
192 | 264 | | |
193 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
194 | 272 | | |
195 | 273 | | |
196 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
126 | 129 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
0 commit comments