Branch data Line data Source code
1 : : /*
2 : : * International Chemical Identifier (InChI)
3 : : * Version 1
4 : : * Software version 1.07
5 : : * April 30, 2024
6 : : *
7 : : * MIT License
8 : : *
9 : : * Copyright (c) 2024 IUPAC and InChI Trust
10 : : *
11 : : * Permission is hereby granted, free of charge, to any person obtaining a copy
12 : : * of this software and associated documentation files (the "Software"), to deal
13 : : * in the Software without restriction, including without limitation the rights
14 : : * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 : : * copies of the Software, and to permit persons to whom the Software is
16 : : * furnished to do so, subject to the following conditions:
17 : : *
18 : : * The above copyright notice and this permission notice shall be included in all
19 : : * copies or substantial portions of the Software.
20 : : *
21 : : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 : : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 : : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 : : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 : : * SOFTWARE.
28 : : *
29 : : * The InChI library and programs are free software developed under the
30 : : * auspices of the International Union of Pure and Applied Chemistry (IUPAC).
31 : : * Originally developed at NIST.
32 : : * Modifications and additions by IUPAC and the InChI Trust.
33 : : * Some portions of code were developed/changed by external contributors
34 : : * (either contractor or volunteer) which are listed in the file
35 : : * 'External-contributors' included in this distribution.
36 : : *
37 : : * info@inchi-trust.org
38 : : *
39 : : */
40 : :
41 : :
42 : : /*
43 : : Underivatization, ring-chain tautomerism, OriGAtData edits, etc.
44 : : */
45 : : #include <stdlib.h>
46 : : #include <string.h>
47 : :
48 : : #include "mode.h"
49 : : #include "ichinorm.h"
50 : : #include "aromaticity.h"
51 : : #include "ichierr.h"
52 : :
53 : : #include "bcf_s.h"
54 : :
55 : : #if ( FIND_RING_SYSTEMS == 1 ) /* { */
56 : :
57 : :
58 : :
59 : : /****************************************************************************/
60 : 211 : int MarkRingSystemsInp( inp_ATOM *at, int num_atoms, int start )
61 : : {
62 : 211 : AT_NUMB *nStackAtom = NULL;
63 : 211 : int nTopStackAtom = -1;
64 : 211 : AT_NUMB *nRingStack = NULL;
65 : 211 : int nTopRingStack = -1; /* was AT_NUMB */
66 : 211 : AT_NUMB *nDfsNumber = NULL;
67 : 211 : AT_NUMB *nLowNumber = NULL;
68 : 211 : S_CHAR *cNeighNumb = NULL;
69 : : AT_NUMB nDfs;
70 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
71 : : AT_NUMB nRs, *nRsConnect = NULL;
72 : : int k;
73 : : AT_NUMB *tree = NULL;
74 : : int nNumConnect, nMaxNumConnect, nLenConnect;
75 : : #endif
76 : : AT_NUMB nNumAtInRingSystem;
77 : : int i, j, u, /*start,*/ nNumRingSystems, nNumStartChildren;
78 : :
79 : : /* allocate arrays */
80 : 211 : nStackAtom = (AT_NUMB *) inchi_malloc( num_atoms * sizeof( nStackAtom[0] ) );
81 : 211 : nRingStack = (AT_NUMB *) inchi_malloc( num_atoms * sizeof( nRingStack[0] ) );
82 : 211 : nDfsNumber = (AT_NUMB *) inchi_malloc( num_atoms * sizeof( nDfsNumber[0] ) );
83 : 211 : nLowNumber = (AT_NUMB *) inchi_malloc( num_atoms * sizeof( nLowNumber[0] ) );
84 : 211 : cNeighNumb = (S_CHAR *) inchi_malloc( num_atoms * sizeof( cNeighNumb[0] ) );
85 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
86 : : nRsConnect = (AT_NUMB *) inchi_calloc( 3 * num_atoms + 3, sizeof( nRsConnect[0] ) );
87 : : #endif
88 : : /* check allocation */
89 [ + - + - : 211 : if (!nStackAtom || !nRingStack || !nDfsNumber || !nLowNumber || !cNeighNumb
+ - + - -
+ ]
90 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
91 : : || !nRsConnect
92 : : #endif
93 : : )
94 : : {
95 : 0 : nNumRingSystems = CT_OUT_OF_RAM; /* program error */ /* <BRKPT> */
96 : 0 : goto exit_function;
97 : : }
98 : :
99 : : /********************************************
100 : : *
101 : : * Find Cut-vertices & Blocks
102 : : *
103 : : ********************************************/
104 : :
105 : : /* initiation */
106 : : /*start = 0;*/
107 : 211 : nNumRingSystems = 0;
108 : 211 : u = start; /* start atom */
109 : 211 : nDfs = 0;
110 : 211 : nTopStackAtom = -1;
111 : 211 : nTopRingStack = -1;
112 : 211 : memset( nDfsNumber, 0, num_atoms * sizeof( nDfsNumber[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */
113 : 211 : memset( cNeighNumb, 0, num_atoms * sizeof( cNeighNumb[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */
114 : : /* push the start atom on the stack */
115 : : /* djb-rwth: fixing oss-fuzz issue #66720 */
116 [ + - ]: 211 : if (u <= num_atoms - 1)
117 : : {
118 : 211 : nLowNumber[u] = nDfsNumber[u] = ++nDfs;
119 : 211 : nStackAtom[++nTopStackAtom] = (AT_NUMB)u;
120 : 211 : nRingStack[++nTopRingStack] = (AT_NUMB)u;
121 : : }
122 : : else
123 : : {
124 : 0 : nNumRingSystems = CT_OVERFLOW; /* program error */ /* <BRKPT> */
125 : 0 : goto exit_function;
126 : : }
127 : :
128 : 211 : nNumStartChildren = 0;
129 : :
130 : : do
131 : : {
132 : :
133 : : /* advance */
134 : 2850 : advance_block:
135 : :
136 : : /*if ( (int)at[i=nStackAtom[nTopStackAtom]].valence > (j = (int)cNeighNumb[i]) )*/
137 : : /* replaced due to missing sequence point */
138 [ + + ]: 3061 : if (i = (int) nStackAtom[nTopStackAtom], j = (int) cNeighNumb[i], (int) at[i].valence > j)
139 : : {
140 : 1936 : cNeighNumb[i] ++;
141 : 1936 : u = (int) at[i].neighbor[j];
142 [ + + ]: 1936 : if (!nDfsNumber[u])
143 : : {
144 : : /* tree edge, 1st visit -- advance */
145 : 914 : nStackAtom[++nTopStackAtom] = (AT_NUMB) u;
146 : 914 : nRingStack[++nTopRingStack] = (AT_NUMB) u;
147 : 914 : nLowNumber[u] = nDfsNumber[u] = ++nDfs;
148 : 914 : nNumStartChildren += ( i == start );
149 : : }
150 : : else
151 : : {
152 [ + + + + ]: 1022 : if (!nTopStackAtom || u != (int) nStackAtom[nTopStackAtom - 1])
153 : : {
154 : : /* may comment out ? */
155 : : /* back edge: u is not a predecessor of i */
156 [ + + ]: 108 : if (nDfsNumber[u] < nDfsNumber[i])
157 : : {
158 : : /* Back edge, 1st visit: u is an ancestor of i. Compare */
159 [ + - ]: 54 : if (nLowNumber[i] > nDfsNumber[u])
160 : : {
161 : 54 : nLowNumber[i] = nDfsNumber[u];
162 : : }
163 : : }
164 : : } /* may comment out ? */
165 : : }
166 : 1936 : goto advance_block;
167 : : }
168 : : else
169 : : {
170 : 1125 : cNeighNumb[i] = 0;
171 : : }
172 : :
173 : : /* back up */
174 [ + + ]: 1125 : if (i != start)
175 : : {
176 : 914 : u = (int) nStackAtom[nTopStackAtom - 1]; /* predecessor of i */
177 [ + + ]: 914 : if (nLowNumber[i] >= nDfsNumber[u])
178 : : {
179 : : /* output the block */
180 : 724 : nNumRingSystems++;
181 : 724 : at[u].nBlockSystem = nNumRingSystems;
182 [ + + + + ]: 724 : if (u != start || nNumStartChildren > 1)
183 : : {
184 : 606 : at[u].bCutVertex += 1;
185 : : }
186 [ + - ]: 914 : while (nTopRingStack >= 0)
187 : : {
188 : 914 : j = nRingStack[nTopRingStack--];
189 : 914 : at[j].nBlockSystem = nNumRingSystems; /* mark the atom */
190 [ + + ]: 914 : if (i == j)
191 : : {
192 : 724 : break;
193 : : }
194 : : }
195 : : }
196 : : else
197 : : {
198 [ + + ]: 190 : if (nLowNumber[u] > nLowNumber[i])
199 : : {
200 : : /* inherit */
201 : 178 : nLowNumber[u] = nLowNumber[i];
202 : : }
203 : : }
204 : : }
205 [ + + ]: 1125 : } while (--nTopStackAtom >= 0);
206 : :
207 : : /****************************************************************************
208 : : *
209 : : * Find Ring Systems
210 : : * Including chain atoms X: A-X-B, where the bonds (of any kind) are bridges.
211 : : *
212 : : ****************************************************************************/
213 : :
214 : :
215 : : /* initiation */
216 : : /* start = 0;*/
217 : 211 : nNumRingSystems = 0;
218 : 211 : u = start; /* start atom */
219 : 211 : nDfs = 0;
220 : 211 : nTopStackAtom = -1;
221 : 211 : nTopRingStack = -1;
222 : 211 : memset( nDfsNumber, 0, num_atoms * sizeof( nDfsNumber[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */
223 : 211 : memset( cNeighNumb, 0, num_atoms * sizeof( cNeighNumb[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */
224 : : /* push the start atom on the stack */
225 : 211 : nLowNumber[u] = nDfsNumber[u] = ++nDfs;
226 : 211 : nStackAtom[++nTopStackAtom] = (AT_NUMB) u;
227 : 211 : nRingStack[++nTopRingStack] = (AT_NUMB) u;
228 : :
229 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
230 : : nNumConnect = nLenConnect = nMaxNumConnect = 0;
231 : : #endif
232 : :
233 : : do
234 : : {
235 : : /* advance */
236 : 2850 : advance_ring:
237 : : /*if ( (int)at[i=nStackAtom[nTopStackAtom]].valence > (j = (int)cNeighNumb[i]) )*/
238 : : /* replaced due to missing sequence point */
239 [ + + ]: 3061 : if (i = (int) nStackAtom[nTopStackAtom], j = (int) cNeighNumb[i], (int) at[i].valence > j)
240 : : {
241 : 1936 : cNeighNumb[i] ++;
242 : 1936 : u = (int) at[i].neighbor[j];
243 [ + + ]: 1936 : if (!nDfsNumber[u])
244 : : {
245 : : /* tree edge, 1st visit -- advance */
246 : 914 : nStackAtom[++nTopStackAtom] = (AT_NUMB) u;
247 : 914 : nRingStack[++nTopRingStack] = (AT_NUMB) u;
248 : 914 : nLowNumber[u] = nDfsNumber[u] = ++nDfs;
249 : : }
250 : : else
251 : : {
252 [ + + + + ]: 1022 : if (!nTopStackAtom || u != (int) nStackAtom[nTopStackAtom - 1])
253 : : {
254 : : /* back edge: u is not a predecessor of i */
255 [ + + ]: 108 : if (nDfsNumber[u] < nDfsNumber[i])
256 : : {
257 : : /* Back edge, 1st visit: u is ancestor of i. Compare */
258 [ + - ]: 54 : if (nLowNumber[i] > nDfsNumber[u])
259 : : {
260 : 54 : nLowNumber[i] = nDfsNumber[u];
261 : : }
262 : : }
263 : : }
264 : : }
265 : 1936 : goto advance_ring;
266 : : }
267 : : else
268 : : {
269 : 1125 : cNeighNumb[i] = 0;
270 : : }
271 : :
272 : : /* back up */
273 [ + + ]: 1125 : if (nDfsNumber[i] == nLowNumber[i])
274 : : {
275 : : /* found a ring system */
276 : 893 : nNumRingSystems++;
277 : : /* unwind nRingStack[] down to i */
278 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
279 : : nNumConnect = 2;
280 : : /* data structure: for each ring system nRsConnect[] contains:
281 : : * 1) nNumConnect+1 = (number of already discovered neighboring "ring systems" + 1)+1
282 : : * 2) nNumAtInRingSystem
283 : : * 3) (nNumConnect-1) numbers (IDs) of neighboring ring systems.
284 : : * BFS guarantees that each neighboring ring system is encountered only one time
285 : : * Number of all neighboring ring systems = (nNumConnect-1)+1 = nNumConnect
286 : : * (One additional ring system is where the BFS retracts from the vertex #i,
287 : : * except when i=DFS root node. In the latter case there is/are only (nNumConnect-1)
288 : : * neighboring ring system(s).
289 : : */
290 : : #endif
291 : : /* count atoms in a ring system */
292 [ + - ]: 1125 : for (nNumAtInRingSystem = 0, j = nTopRingStack; 0 <= j; j--)
293 : : {
294 : 1125 : nNumAtInRingSystem++;
295 [ + + ]: 1125 : if (i == (int) nRingStack[j])
296 : : {
297 : 893 : break;
298 : : }
299 : : }
300 [ + - ]: 1125 : while (nTopRingStack >= 0)
301 : : {
302 : 1125 : j = (int) nRingStack[nTopRingStack--];
303 : 1125 : at[j].nRingSystem = (AT_NUMB) nNumRingSystems; /* ring system id */
304 : 1125 : at[j].nNumAtInRingSystem = nNumAtInRingSystem;
305 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
306 : : for (k = 0; k < at[j].valence; k++)
307 : : {
308 : : if (( nRs = at[at[j].neighbor[k]].nRingSystem ) && (int) nRs != nNumRingSystems)
309 : : {
310 : : nRsConnect[nLenConnect + ( nNumConnect++ )] = nRs; /* adjacent ring system id */
311 : : }
312 : : }
313 : : #endif
314 [ + + ]: 1125 : if (i == j)
315 : : {
316 : : /* reached atom on the top of nStackAtom[] stack */
317 : 893 : break;
318 : : }
319 : : }
320 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
321 : : nRsConnect[nLenConnect] = nNumConnect;
322 : : nRsConnect[nLenConnect + 1] = nNumAtInRingSystem;
323 : : nLenConnect += nNumConnect;
324 : : if (nMaxNumConnect < nNumConnect)
325 : : {
326 : : /* max number of neighboring ring systems */
327 : : nMaxNumConnect = nNumConnect;
328 : : }
329 : : #endif
330 : : }
331 : : else
332 : : {
333 [ + - ]: 232 : if (nTopStackAtom > 0)
334 : : {
335 : 232 : j = (int) nStackAtom[nTopStackAtom - 1];
336 : : /* inherit nLowNumber */
337 [ + + ]: 232 : if (nLowNumber[j] > nLowNumber[i])
338 : : {
339 : 178 : nLowNumber[j] = nLowNumber[i];
340 : : }
341 : : }
342 : : }
343 [ + + ]: 1125 : } while (--nTopStackAtom >= 0);
344 : :
345 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 ) /* normally disabled */
346 : : nMaxNumConnect++;
347 : : if (nNumRingSystems > 1)
348 : : {
349 : : int nCol = nMaxNumConnect + 1;
350 : : int nNumInSyst = nMaxNumConnect;
351 : : int nMaxNeigh = nMaxNumConnect - 1;
352 : : #define T(a,b) tree[(a)*nCol+b]
353 : : if (tree = (AT_NUMB *) inchi_calloc( nCol * ( nNumRingSystems + 1 ), sizeof( tree[0] ) ))
354 : : {
355 : : int len, neigh;
356 : : /* reuse previous allocations */
357 : : AT_NUMB *nNumVisitedNeighbors = nStackAtom;
358 : : AT_NUMB *nDistanceFromTerminal = nRingStack;
359 : : AT_NUMB *nCurrActiveRingSystem = nDfsNumber;
360 : : AT_NUMB *nNextActiveRingSystem = nLowNumber;
361 : : int nNumCurrActiveRingSystems, nNumNextActiveRingSystems, pass;
362 : : /* build a "condensation graph (actually, a tree)" in which
363 : : * each vertex corresponds to a ring system T(row, col) = T(ring syst, neighbors)
364 : : * Number of rows = column length = max. number of ring system neighbors + 2
365 : : * Number of cols = row length = number of ring systems + 1
366 : : * Neighboring ring systems are contiguously stored in a row
367 : : * T(i,0) = number of neighbors, 1 <= i <= nNumRingSystems;
368 : : * T(i,k) = number of a neighboring ring system, 1 <= k <= T(i,0)
369 : : * T(i,nCol-1) = number of atoms in the system #i
370 : : */
371 : : for (i = 1, j = 0; len = nRsConnect[j]; i++)
372 : : {
373 : : T( i, nNumInSyst ) = nRsConnect[j + 1];
374 : : for (k = 2; k < len; k++)
375 : : {
376 : : neigh = nRsConnect[j + k];
377 : : if (T( i, 0 ) < nMaxNeigh && T( neigh, 0 ) < nMaxNeigh)
378 : : {
379 : : T( i, 0 )++;
380 : : T( neigh, 0 )++;
381 : : T( i, T( i, 0 ) ) = neigh;
382 : : T( neigh, T( neigh, 0 ) ) = i;
383 : : }
384 : : else
385 : : {
386 : : nNumRingSystems = CT_OVERFLOW; /* program error */ /* <BRKPT> */
387 : : goto exit_function;
388 : : }
389 : : }
390 : : j += len;
391 : : }
392 : : /* clear memory */
393 : : memset( nNumVisitedNeighbors, 0, nNumRingSystems * sizeof( nNumVisitedNeighbors[0] ) );
394 : : memset( nDistanceFromTerminal, 0, nNumRingSystems * sizeof( nDistanceFromTerminal[0] ) );
395 : : memset( nCurrActiveRingSystem, 0, nNumRingSystems * sizeof( nCurrActiveRingSystem[0] ) );
396 : : memset( nNextActiveRingSystem, 0, nNumRingSystems * sizeof( nNextActiveRingSystem[0] ) );
397 : : nNumNextActiveRingSystems = 0;
398 : : for (i = 0; i < nNumRingSystems; i++)
399 : : {
400 : : if (1 == T( i + 1, 0 ))
401 : : {
402 : : nNextActiveRingSystem[i] = 1; /* number of traversed neighbors + 1 */
403 : : nDistanceFromTerminal[i] = 1;
404 : : nNumNextActiveRingSystems++;
405 : : }
406 : : else
407 : : {
408 : : nNextActiveRingSystem[i] = 0;
409 : : nDistanceFromTerminal[i] = 0;
410 : : }
411 : : nNumVisitedNeighbors[i] = 0;
412 : : }
413 : :
414 : : /* nCurrActiveRingSystem[i] = a sum of:
415 : : * 1) +1 if it is or was active
416 : : * 2) +(number of neighbors from which it was reached)
417 : : * 3) +1 if it was left and not active anymore
418 : : */
419 : : pass = 0;
420 : : do
421 : : {
422 : : nNumCurrActiveRingSystems = nNumNextActiveRingSystems;
423 : : nNumNextActiveRingSystems = 0;
424 : : memcpy( nCurrActiveRingSystem, nNextActiveRingSystem,
425 : : nNumRingSystems * sizeof( nNextActiveRingSystem[0] ) );
426 : : for (i = 0; i < nNumRingSystems; i++)
427 : : {
428 : : if (T( i + 1, 0 ) == nCurrActiveRingSystem[i])
429 : : {
430 : : /* on the previous pass currently active ring system i+1 bas been reached
431 : : * from all neighbors except one;
432 : : * the neighbors from which it was reached have
433 : : * T(neigh,0)+1 == nCurrActiveRingSystem[i]
434 : : * this ring system has not been left yet
435 : : */
436 : : for (k = 1, len = T( i + 1, 0 ); k <= len; k++)
437 : : {
438 : : neigh = (int) T( i + 1, k );
439 : : if (T( neigh, 0 ) >= nCurrActiveRingSystem[neigh - 1])
440 : : {
441 : : if (0 == pass)
442 : : {
443 : : nDistanceFromTerminal[i] = 1;
444 : : }
445 : : break;
446 : : }
447 : : }
448 : : if (k <= len)
449 : : {
450 : : /* neigh was not reached from at least 2 neighbors
451 : : * walk along -R- chain (T(neigh,0)==2) up to
452 : : * 1) a terminal system, not including it or
453 : : * 2) a branching point.
454 : : *
455 : : * pass = 0: started from terminal systems:
456 : : * reach the branching point.
457 : : * If chain system next to a terminal system has already been reached
458 : : * then walk along it according to Note below
459 : : *
460 : : * pass > 0: started from branching points
461 : : * 2a) If the branching point has not been reached from 2 or more neighbors,
462 : : * then include it
463 : : * 2b) If the branching point has not been reached from 1 neighbor only,
464 : : * then do not include it: it will be a starting point later
465 : : * Note: if a chain atom already has nDistanceFromTerminal[i] > 0, then
466 : : * the last atom should be the one such that
467 : : * its nDistanceFromTerminal[]+1>= nDistanceFromTerminal[] of the
468 : : * next in the chain
469 : : */
470 : : int bOk = 0;
471 : : k = i + 1; /* starting point */
472 : : if (0 == pass && T( k, nNumInSyst ) > 1)
473 : : {
474 : : nNumNextActiveRingSystems++; /* request next pass */
475 : : continue; /* stop a the terminal ring system */
476 : : }
477 : : while (2 == T( neigh, 0 ))
478 : : {
479 : : /* walk along a chain */
480 : : if (!nNextActiveRingSystem[neigh - 1])
481 : : {
482 : : nNextActiveRingSystem[neigh - 1] = 1; /* make neighbor active */
483 : : }
484 : : else
485 : : if (nDistanceFromTerminal[k - 1] + 1 <= nDistanceFromTerminal[neigh - 1])
486 : : {
487 : : /* walking along the chain; already have had a walk */
488 : : /* in the opposite direction at this pass */
489 : : }
490 : : else
491 : : {
492 : : /* k is the last; neigh (it is a bridge -X-) has not been reached */
493 : : bOk = 1;
494 : : break;
495 : : }
496 : : nNextActiveRingSystem[k - 1] ++; /* leave system k */
497 : : if (nNextActiveRingSystem[neigh - 1] < T( neigh, 0 ))
498 : : {
499 : : nNextActiveRingSystem[neigh - 1] ++; /* add one connection to neigh */
500 : : }
501 : : nDistanceFromTerminal[neigh - 1] = nDistanceFromTerminal[k - 1] + 1;
502 : : j = ( T( neigh, 1 ) == k ) ? 2 : 1;
503 : : k = neigh;
504 : : neigh = T( k, j ); /* next in the chain */
505 : : nNumNextActiveRingSystems++;
506 : : if (T( k, nNumInSyst ) > 1)
507 : : {
508 : : bOk = 1;
509 : : break; /* stop on a ring system */
510 : : }
511 : : }
512 : : /* neigh is a terminal or a bridge or a branching point */
513 : : if (2 > T( neigh, 0 ))
514 : : {
515 : : /* neighbor is a terminal atom */
516 : : if (1 < pass)
517 : : {
518 : : nNumRingSystems = CT_UNKNOWN_ERR; /* error (debug only) */ /* <BRKPT> */
519 : : goto exit_function;
520 : : }
521 : : continue;
522 : : }
523 : : if (2 == T( neigh, 0 ))
524 : : {
525 : : /* neighbor is a bridge */
526 : : continue;
527 : : }
528 : : /* neighbor is a branching point */
529 : : if (T( neigh, 0 ) > nCurrActiveRingSystem[neigh - 1])
530 : : {
531 : : /* move to the neigh (make neigh active): on previous pass it */
532 : : /* has not been reached from 2 or more neighbors */
533 : : if (!nNextActiveRingSystem[neigh - 1])
534 : : {
535 : : nNextActiveRingSystem[neigh - 1] = 1;
536 : : }
537 : : if (nDistanceFromTerminal[neigh - 1] < nDistanceFromTerminal[k - 1] + 1)
538 : : {
539 : : nDistanceFromTerminal[neigh - 1] = nDistanceFromTerminal[k - 1] + 1;
540 : : }
541 : : nNextActiveRingSystem[k - 1] ++; /* leave system k */
542 : : if (nNextActiveRingSystem[neigh - 1] < T( neigh, 0 ))
543 : : {
544 : : nNextActiveRingSystem[neigh - 1] ++; /* add one connection to neigh */
545 : : }
546 : : nNumNextActiveRingSystems++;
547 : : }
548 : : }
549 : : }
550 : : }
551 : : pass++;
552 : : } while (nNumNextActiveRingSystems);
553 : :
554 : : for (i = 0; i < num_atoms; i++)
555 : : {
556 : : at[i].nDistanceFromTerminal = nDistanceFromTerminal[(int) at[i].nRingSystem - 1];
557 : : }
558 : :
559 : : inchi_free( tree );
560 : : tree = NULL;
561 : : #undef T
562 : : }
563 : : else
564 : : {
565 : : nNumRingSystems = CT_OUT_OF_RAM; /* error */ /* <BRKPT> */
566 : : goto exit_function;
567 : : }
568 : : }
569 : : #endif
570 : :
571 : 211 : exit_function:
572 : :
573 [ + - ]: 211 : if (nStackAtom)
574 : : {
575 [ + - ]: 211 : inchi_free( nStackAtom );
576 : : }
577 [ + - ]: 211 : if (nRingStack)
578 : : {
579 [ + - ]: 211 : inchi_free( nRingStack );
580 : : }
581 [ + - ]: 211 : if (nDfsNumber)
582 : : {
583 [ + - ]: 211 : inchi_free( nDfsNumber );
584 : : }
585 [ + - ]: 211 : if (nLowNumber)
586 : : {
587 [ + - ]: 211 : inchi_free( nLowNumber );
588 : : }
589 [ + - ]: 211 : if (cNeighNumb)
590 : : {
591 [ + - ]: 211 : inchi_free( cNeighNumb );
592 : : }
593 : :
594 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
595 : : if (nRsConnect)
596 : : inchi_free( nRsConnect );
597 : : if (tree)
598 : : inchi_free( tree );
599 : : #endif
600 : :
601 : 211 : return nNumRingSystems;
602 : : }
603 : :
604 : :
605 : : #endif /* } FIND_RING_SYSTEMS */
606 : :
607 : :
608 : : /****************************************************************************
609 : :
610 : : InChI post-version 1.01 features implementation
611 : : (v. 1.06+ : underivatize is still an experiment available in engineering mode)
612 : :
613 : : ****************************************************************************/
614 : :
615 : : #if ( RING2CHAIN == 1 || UNDERIVATIZE == 1 )
616 : :
617 : : typedef struct tagAtPair
618 : : {
619 : : AT_NUMB at[2]; /* at[0] < at[1] */
620 : : AT_NUMB atno; /* atom marked with derivative type */
621 : : } R2C_ATPAIR;
622 : :
623 : :
624 : : /* Local functions */
625 : : void set_R2C_el_numbers( void );
626 : : int subtract_DT_from_num_H( int num_atoms, inp_ATOM *at );
627 : : int add_inp_ATOM( inp_ATOM *at, int len_at, int len_cur,
628 : : inp_ATOM *add, int len_add );
629 : : int cmp_r2c_atpair( const void *p1, const void *p2 );
630 : : int has_atom_pair( R2C_ATPAIR *ap, int num_ap, AT_NUMB at1, AT_NUMB at2 );
631 : : int mark_atoms_ap( inp_ATOM *at, AT_NUMB start, R2C_ATPAIR *ap,
632 : : int num_ap, int num, AT_NUMB cFlags );
633 : :
634 : : int UnMarkDisconnectedComponents( ORIG_ATOM_DATA *orig_inp_data );
635 : : int UnMarkOtherIndicators( inp_ATOM *at, int num_atoms );
636 : : int UnMarkOneComponent( inp_ATOM *at, int num_atoms );
637 : :
638 : : /* Other functions */
639 : : int DisconnectInpAtBond( inp_ATOM *at, AT_NUMB *nOldCompNumber,
640 : : int iat, int neigh_ord );
641 : : int ExtractConnectedComponent( inp_ATOM *at, int num_at,
642 : : int component_number, inp_ATOM *component_at );
643 : : int UnMarkRingSystemsInp( inp_ATOM *at, int num_atoms );
644 : :
645 : :
646 : :
647 : : /****************************************************************************
648 : : Clear the (disconnected) components info in ORIG_ATOM_DATA
649 : : ****************************************************************************/
650 : 0 : int UnMarkDisconnectedComponents( ORIG_ATOM_DATA *orig_inp_data )
651 : : {
652 : : int i;
653 : :
654 [ # # ]: 0 : for (i = 0; i < orig_inp_data->num_inp_atoms; i++)
655 : : {
656 : 0 : orig_inp_data->at[i].orig_compt_at_numb = 0;
657 : 0 : orig_inp_data->at[i].component = 0;
658 : : }
659 : :
660 [ # # ]: 0 : if (orig_inp_data->nCurAtLen)
661 : : {
662 [ # # ]: 0 : inchi_free( orig_inp_data->nCurAtLen );
663 : 0 : orig_inp_data->nCurAtLen = NULL;
664 : : }
665 : :
666 [ # # ]: 0 : if (orig_inp_data->nOldCompNumber)
667 : : {
668 [ # # ]: 0 : inchi_free( orig_inp_data->nOldCompNumber );
669 : 0 : orig_inp_data->nOldCompNumber = NULL;
670 : : }
671 : :
672 : 0 : orig_inp_data->num_components = 0;
673 : :
674 : 0 : return 0;
675 : : }
676 : :
677 : :
678 : : /****************************************************************************/
679 : 0 : int UnMarkOtherIndicators( inp_ATOM *at, int num_atoms )
680 : : {
681 : : int i;
682 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
683 : : {
684 : 0 : at[i].at_type = 0;
685 : 0 : at[i].cFlags = 0;
686 : : }
687 : :
688 : 0 : return 0;
689 : : }
690 : :
691 : :
692 : : /****************************************************************************
693 : : Clear the (disconnected) component numbers in atoms of inp_ATOM structure
694 : : (which typicall came from INP_ATOM_DATA)
695 : : ****************************************************************************/
696 : 0 : int UnMarkOneComponent( inp_ATOM *at, int num_atoms )
697 : : {
698 : : int i;
699 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
700 : : {
701 : 0 : at[i].orig_compt_at_numb = 0;
702 : 0 : at[i].component = 0;
703 : : }
704 : :
705 : 0 : return 0;
706 : : }
707 : :
708 : :
709 : : /****************************************************************************/
710 : 0 : void set_R2C_el_numbers( void )
711 : : {
712 : : /*
713 : : if (!el_number_O)
714 : : {
715 : : el_number_O = EL_NUMBER_O;
716 : : el_number_C = EL_NUMBER_C;
717 : : el_number_N = EL_NUMBER_N;
718 : : el_number_P = EL_NUMBER_P;
719 : : el_number_S = EL_NUMBER_S;
720 : : el_number_Si = EL_NUMBER_SI;
721 : : el_number_F = EL_NUMBER_F;
722 : : el_number_Cl = EL_NUMBER_CL;
723 : : el_number_Br = EL_NUMBER_BR;
724 : : el_number_I = EL_NUMBER_I;
725 : : el_number_H = EL_NUMBER_H;
726 : : }
727 : : */
728 : 0 : }
729 : :
730 : :
731 : : /****************************************************************************/
732 : 0 : int subtract_DT_from_num_H( int num_atoms, inp_ATOM *at )
733 : : /* assume num_1H, num_D and num_T are included in num_H */
734 : : {
735 : : int i, j;
736 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
737 : : {
738 [ # # ]: 0 : for (j = 0; j < NUM_H_ISOTOPES; j++)
739 : 0 : at[i].num_H -= at[i].num_iso_H[j];
740 : : }
741 : :
742 : 0 : return 0;
743 : : }
744 : :
745 : :
746 : : /****************************************************************************/
747 : 0 : int add_inp_ATOM( inp_ATOM *at,
748 : : int len_at,
749 : : int len_cur,
750 : : inp_ATOM *add,
751 : : int len_add )
752 : : {
753 : : int i, j;
754 : : inp_ATOM *a;
755 : : /* chack correctness */
756 [ # # ]: 0 : if (len_cur < 0)
757 : 0 : return len_cur;
758 [ # # ]: 0 : if (len_add < 0)
759 : 0 : return len_add;
760 [ # # ]: 0 : if (len_cur + len_add > len_at)
761 : 0 : return -1;
762 : : /* copy */
763 : 0 : memcpy(at + len_cur, add, len_add * sizeof(at[0]));
764 : : /* modify */
765 [ # # ]: 0 : if (len_cur)
766 : : {
767 : 0 : a = at + len_cur;
768 [ # # ]: 0 : for (i = 0; i < len_add; i++)
769 : : {
770 [ # # ]: 0 : for (j = 0; j < a[i].valence; j++)
771 : : {
772 : 0 : a[i].neighbor[j] += len_cur;
773 : : }
774 : : }
775 : : }
776 : :
777 : 0 : return len_cur + len_add;
778 : : }
779 : :
780 : :
781 : : /****************************************************************************/
782 : 0 : int cmp_r2c_atpair( const void *p1, const void *p2 )
783 : : {
784 : 0 : const R2C_ATPAIR *ap1 = (const R2C_ATPAIR *) p1;
785 : 0 : const R2C_ATPAIR *ap2 = (const R2C_ATPAIR *) p2;
786 : 0 : int diff = (int) ap1->at[0] - (int) ap2->at[0];
787 [ # # ]: 0 : if (!diff)
788 : : {
789 : 0 : diff = (int) ap1->at[1] - (int) ap2->at[1];
790 : : }
791 : :
792 : 0 : return diff;
793 : : }
794 : :
795 : :
796 : : /****************************************************************************/
797 : 0 : int has_atom_pair_seq( R2C_ATPAIR *ap, int num_ap, AT_NUMB at1, AT_NUMB at2 )
798 : : {
799 : : R2C_ATPAIR ap1;
800 : : int i1;
801 : 0 : int n = at1 > at2;
802 : :
803 : 0 : ap1.at[n] = at1;
804 : 0 : ap1.at[1 - n] = at2;
805 [ # # ]: 0 : for (i1 = 0; i1 < num_ap; i1++)
806 : : {
807 [ # # ]: 0 : if (ap[i1].at[0] == ap1.at[0] &&
808 [ # # ]: 0 : ap[i1].at[1] == ap1.at[1])
809 : 0 : return i1 + 1;
810 : : }
811 : :
812 : 0 : return 0; /* not found */
813 : : }
814 : :
815 : :
816 : : /****************************************************************************/
817 : 0 : int has_atom_pair( R2C_ATPAIR *ap, int num_ap, AT_NUMB at1, AT_NUMB at2 )
818 : : {
819 : : R2C_ATPAIR ap1;
820 : : int i1, i2, i3, diff;
821 : 0 : int n = at1 > at2;
822 : :
823 : 0 : ap1.at[n] = at1;
824 : 0 : ap1.at[1 - n] = at2;
825 : 0 : i1 = 0;
826 : 0 : i2 = num_ap - 1;
827 : : /* search for ap1 by simple bisections */
828 : : do
829 : : {
830 : 0 : i3 = ( i1 + i2 ) / 2;
831 [ # # ]: 0 : if (!( diff = cmp_r2c_atpair( &ap1, ap + i3 ) ))
832 : : {
833 : 0 : return i3 + 1; /* found => positive number */
834 : : }
835 : : else
836 [ # # ]: 0 : if (diff > 0)
837 : : {
838 : 0 : i1 = i3 + 1;
839 : : }
840 : : else
841 : : {
842 : 0 : i2 = i3 - 1;
843 : : }
844 [ # # ]: 0 : } while (i2 >= i1);
845 : :
846 : 0 : return 0; /* not found */
847 : : }
848 : :
849 : :
850 : : /****************************************************************************
851 : : DFS search for atoms that do not have a flag
852 : : ****************************************************************************/
853 : 0 : int mark_atoms_ap( inp_ATOM *at,
854 : : AT_NUMB start,
855 : : R2C_ATPAIR *ap,
856 : : int num_ap, int num,
857 : : AT_NUMB cFlags )
858 : : {
859 [ # # ]: 0 : if (!at[start].at_type)
860 : : {
861 : : int i;
862 : : AT_NUMB neigh;
863 : 0 : at[start].at_type = cFlags;
864 : 0 : num++;
865 : :
866 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
867 : : {
868 : 0 : neigh = at[start].neighbor[i];
869 [ # # ]: 0 : if (has_atom_pair_seq( ap, num_ap, start, neigh ))
870 : : {
871 : 0 : continue;
872 : : }
873 : 0 : num = mark_atoms_ap( at, neigh, ap, num_ap, num, cFlags );
874 : : }
875 : : }
876 : :
877 : 0 : return num; /* number of atoms traversed forward from at[start] */
878 : : }
879 : :
880 : : #endif /* RING2CHAIN || UNDERIVATIZE */
881 : :
882 : :
883 : :
884 : : #if ( UNDERIVATIZE == 1 )
885 : :
886 : : /****************************************************************************/
887 : :
888 : : #ifdef NEVER
889 : : typedef struct tagAtTypeBitmap {
890 : : AT_NUMB ord1 : 5; /* up to 2^5-1 = 31 = 0x0037 */
891 : : AT_NUMB ord2 : 5;
892 : : AT_NUMB type : 6; /* up to 2^6-1 = 63 = 0x0077 */
893 : : } AtTypeBitmap;
894 : : typedef union tagAtTypeUnion {
895 : : AT_NUMB num;
896 : : AtTypeBitmap bits;
897 : : } AtTypeUnion;
898 : : #endif
899 : :
900 : :
901 : : /* Underivatize settings */
902 : : /* DERIV_AT::typ begin */
903 : : #define DERIV_BRIDGE_O 0x0001 /* R1-O-R2 => R1-OH + HO-R2 */
904 : : #define DERIV_BRIDGE_NH 0x0002 /* R1-NH-R2 amine */
905 : : #define DERIV_AMINE_tN 0x0004 /* R1-N(-R2)-R3 tertiary amine */
906 : : #define DERIV_RING_O_OUTSIDE_PRECURSOR 0x0008 /* -O- in a ring */
907 : : #define DERIV_RING_NH_OUTSIDE_PRECURSOR 0x0010 /* -NH- in a ring */
908 : : /* MOX_EtOX Underiv: R2-(R3-)C=N-O-R => >C=O (ketone, aldehide only);
909 : : -R: -CH3, -CH2-CH3, -Si(CH3)3, -CH2-Phenyl
910 : : DERIV_X_OXIME R3- may be H or any C, R2- is any C
911 : : precursor: R2-(R3-)C=O (note: N replaced with O)-- 2013-08-23 DT */
912 : : #define DERIV_X_OXIME 0x0020 /* comment out to disable */
913 : : /* */
914 : : #define DERIV_UNMARK 0x0040 /* unmark the cut */
915 : : #define DERIV_DUPLIC 0x0080 /* duplicated disconnection */
916 : : /* comment out to disable */
917 : : #define DERIV_RO_COX 0x0100 /* alcohol derivatives: R-O--C(=O)C[n]F[2n+1] 0<n<4, R-O--C(=O)CH3, R-O--C(=O)-Phenyl */
918 : : /* comment out next 2 to disable; DMOX=Dimethyloxazoline DEOX=Diethyloxazoline */
919 : : #define DERIV_RING_DMOX_DEOX_N 0x0200 /* =N- in a ring: /-O--CH2-\ DMOX, DEOX */
920 : : #define DERIV_RING_DMOX_DEOX_O 0x0400 /* -O- in a ring: R-C=N--------C<2Me or 2Et */
921 : :
922 : : #ifdef UNDERIV_PYRROLIDIDES
923 : : #define DERIV_RING2_PRRLDD_OUTSIDE_PRECUR 0x0800 /* alcohol derivatives: R(=O)-N<C4H4 5-memb ring Pyrrolidides; replace -N< with -OH */
924 : : #endif
925 : :
926 : : #define DERIV_RING2_PPRDN_OUTSIDE_PRECUR 0x1000 /* alcohol derivatives: R(=O)-N<C5H5 6-memb ring Piperidines; replace -N< with -OH */
927 : : #define DERIV_DANSYL 0x2000 /* alcohol derivatives: R-O--SO2-C10H5-N(CH3)2 => R-OH */
928 : : /* DERIV_AT::typ end */
929 : :
930 : : /* derivative types, which cannot be absorbed into greater derivatization agents */
931 : : static const int DERIV_UNEXPADABLE = 0
932 : : #ifdef DERIV_X_OXIME
933 : : | DERIV_X_OXIME
934 : : #endif
935 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
936 : : | ( DERIV_RING_DMOX_DEOX_O | DERIV_RING_DMOX_DEOX_N )
937 : : #endif
938 : : /*
939 : : #ifdef DERIV_RO_COX
940 : : |DERIV_RO_COX
941 : : #endif
942 : : */
943 : : #ifdef DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
944 : : | DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
945 : : #endif
946 : : #ifdef DERIV_RING2_PPRDN_OUTSIDE_PRECUR
947 : : | DERIV_RING2_PPRDN_OUTSIDE_PRECUR
948 : : #endif
949 : : #ifdef DERIV_DANSYL
950 : : | DERIV_DANSYL
951 : : #endif
952 : : ;
953 : : /* derivative precursor types in which Precur=N- is replaced with Precur=O */
954 : : static const int DERIV_REPL_N_WITH_O = 0
955 : : #ifdef DERIV_X_OXIME
956 : : | DERIV_X_OXIME
957 : : #endif
958 : : #ifdef DERIV_RING_DMOX_DEOX_N
959 : : | DERIV_RING_DMOX_DEOX_N
960 : : #endif
961 : : ;
962 : :
963 : : /* derivative precursor types in which Precur-N< is replaced with Precur-OH */
964 : : static const int DERIV_REPL_N_WITH_OH = 0
965 : : #ifdef DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
966 : : | DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
967 : : #endif
968 : : #ifdef DERIV_RING2_PPRDN_OUTSIDE_PRECUR
969 : : | DERIV_RING2_PPRDN_OUTSIDE_PRECUR
970 : : #endif
971 : : ;
972 : :
973 : : /* combined DERIV_AT::typ */
974 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
975 : : #define DERIV_RING_DMOX_DEOX (DERIV_RING_DMOX_DEOX_O | DERIV_RING_DMOX_DEOX_N)
976 : : #endif
977 : :
978 : : #if( defined(DERIV_RING_O_OUTSIDE_PRECURSOR) && defined(DERIV_RING_NH_OUTSIDE_PRECURSOR) )
979 : : #define DERIV_RING_OUTSIDE_PRECURSOR (DERIV_RING_O_OUTSIDE_PRECURSOR | DERIV_RING_NH_OUTSIDE_PRECURSOR)
980 : : #elif( defined(DERIV_RING_O_OUTSIDE_PRECURSOR) )
981 : : #define DERIV_RING_OUTSIDE_PRECURSOR DERIV_RING_O_OUTSIDE_PRECURSOR
982 : : #elif( defined(DERIV_RING_NH_OUTSIDE_PRECURSOR) )
983 : : #define DERIV_RING_OUTSIDE_PRECURSOR DERIV_RING_NH_OUTSIDE_PRECURSOR
984 : : #else
985 : : #define DERIV_RING_OUTSIDE_PRECURSOR 0
986 : : #endif
987 : :
988 : : #if( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) && defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
989 : : #define DERIV_RING2_OUTSIDE_PRECUR (DERIV_RING2_PRRLDD_OUTSIDE_PRECUR | DERIV_RING2_PPRDN_OUTSIDE_PRECUR)
990 : : #elif ( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) )
991 : : #define DERIV_RING2_OUTSIDE_PRECUR DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
992 : : #elif ( defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
993 : : #define DERIV_RING2_OUTSIDE_PRECUR DERIV_RING2_PPRDN_OUTSIDE_PRECUR
994 : : #endif
995 : : /* combined DERIV_AT::typ end */
996 : :
997 : : #define DERIV_AT_LEN 4
998 : : typedef struct tagDerivAttachment {
999 : : short typ[DERIV_AT_LEN]; /* changed from char to short on 2013-11-13 DT */
1000 : : char ord[DERIV_AT_LEN]; /* ring: neighbor in precursor; chain: neighbor in derivatizing agent */
1001 : : char num[DERIV_AT_LEN]; /* num. atoms to remove */
1002 : : #ifdef DERIV_RING_DMOX_DEOX
1003 : : AT_NUMB other_atom; /* other atno+1; for DERIV_RING_DMOX_DEOX */
1004 : : #endif
1005 : : } DERIV_AT;
1006 : :
1007 : : /* return value */
1008 : : #define DERIV_NOT 0x1000 /* cannot be a derivatization agent atom */
1009 : :
1010 : : #define MAX_AT_DERIV 13 /* max. num of heavy atoms in removed derivatizing agent: RO-C(O)PheF5 */
1011 : : #define NOT_AT_DERIV 99 /* DERIV_AT::num; rejected as > MAX_AT_DERIV */
1012 : : #define MIN_AT_LEFT_DERIV 2 /* was 3 before 2013-11-12; min num heavy atoms in derivative precursor = MIN_AT_LEFT_DERIV-1 */
1013 : :
1014 : : #define NO_ORD_VAL 0x0037 /* not used */
1015 : :
1016 : : #define CFLAG_MARK_BRANCH 1 /* for main derivative traversal */
1017 : : #define CFLAG_MARK_BLOCK 2 /* for block detection */
1018 : : #define CFLAG_MARK_BLOCK_INV ((char)~(CFLAG_MARK_BLOCK)) /* for block detection */
1019 : : #define COUNT_ALL_NOT_DERIV 1 /* 1=> count ALL atoms that are not in deriv. agents */
1020 : : /* 0=> only atoms that are not in DERIV_RING_OUTSIDE_PRECURSOR */
1021 : : #define IS_DA_NUM_LE(DA, I, MX) (((DA)->typ[I] && ((DA)->typ[I] & DERIV_UNEXPADABLE) == (DA)->typ[I]) || (DA)->num[I] <= (MX))
1022 : :
1023 : :
1024 : : /* derivative classes */
1025 : : typedef enum tagDerivId {
1026 : : DERIV_ID_Acentonate,
1027 : : DERIV_ID_Benzlidene,
1028 : : DERIV_ID_BenzOX,
1029 : : DERIV_ID_BuBorate,
1030 : : DERIV_ID_Dansyl,
1031 : : DERIV_ID_DEOX,
1032 : : DERIV_ID_DMOX,
1033 : : DERIV_ID_EtBorate,
1034 : : DERIV_ID_EtOX,
1035 : : DERIV_ID_HFB,
1036 : : DERIV_ID_MeBorate,
1037 : : DERIV_ID_MOX,
1038 : : DERIV_ID_PFB,
1039 : : DERIV_ID_PFP,
1040 : : DERIV_ID_Piperidine,
1041 : : DERIV_ID_Pyrrolidide,
1042 : : DERIV_ID_TBDMS,
1043 : : DERIV_ID_TFA,
1044 : : DERIV_ID_TMS,
1045 : : DERIV_ID_Unknown,
1046 : :
1047 : :
1048 : : #if defined(UNDERIV_RN_AcMe) || defined(UNDERIV_RNH_AcMe) || defined(UNDERIV_RO_COX_Me)
1049 : : DERIV_ID_Acetate,
1050 : : #endif
1051 : : #if defined(UNDERIV_RO_COX_BENZOATES)
1052 : : DERIV_ID_Benzoate,
1053 : : #endif
1054 : :
1055 : :
1056 : : #ifdef UNDERIV_ACETATE_Me
1057 : : DERIV_ID_Methylation,
1058 : : #endif
1059 : : #ifdef UNDERIV_ACETATE_Et
1060 : : DERIV_ID_Ethylation,
1061 : : #endif
1062 : : #if defined(UNDERIV_RN_AcEt) || defined(UNDERIV_RNH_AcEt) || defined(UNDERIV_RO_COX_Et)
1063 : : DERIV_ID_Propanoate,
1064 : : #endif
1065 : :
1066 : :
1067 : : } DerivId;
1068 : :
1069 : : #ifdef PTR_TO_DERIV_NAMES
1070 : : extern const char **pszDerivName;
1071 : : #else
1072 : : const char *pszDerivName[] = {
1073 : : "Acentonate", /* DERIV_ID_Acentonate, 00 */
1074 : : "Benzlidene", /* DERIV_ID_Benzlidene, 01 */
1075 : : "BenzOX", /* DERIV_ID_BenzOX, 02 */
1076 : : "BuBorate", /* DERIV_ID_BuBorate, 03 */
1077 : : "Dansyl", /* DERIV_ID_Dansyl, 04 */
1078 : : "DEOX", /* DERIV_ID_DEOX, 05 */
1079 : : "DMOX", /* DERIV_ID_DMOX, 06 */
1080 : : "EtBorate", /* DERIV_ID_EtBorate, 07 */
1081 : : "EtOX", /* DERIV_ID_EtOX, 08 */
1082 : : "HFB", /* DERIV_ID_HFB, 09 */
1083 : : "MeBorate", /* DERIV_ID_MeBorate, 10 */
1084 : : "MOX", /* DERIV_ID_MOX, 11 */
1085 : : "PFB", /* DERIV_ID_PFB, 12 */
1086 : : "PFP", /* DERIV_ID_PFP, 13 */
1087 : : "Piperidine", /* DERIV_ID_Piperidine, 14 */
1088 : : "Pyrrolidide", /* DERIV_ID_Pyrrolidide,15 */
1089 : : "TBDMS", /* DERIV_ID_TBDMS, 16 */
1090 : : "TFA", /* DERIV_ID_TFA, 17 */
1091 : : "TMS", /* DERIV_ID_TMS, 18 */
1092 : : "???", /* DERIV_ID_Unknown, 19 */
1093 : :
1094 : :
1095 : : #if defined(UNDERIV_RN_AcMe) || defined(UNDERIV_RNH_AcMe) || defined(UNDERIV_RO_COX_Me)
1096 : : "Acetate", /* DERIV_ID_Acetate, 20 */
1097 : : #endif
1098 : : #if defined(UNDERIV_RO_COX_BENZOATES)
1099 : : "Benzoate", /* DERIV_ID_Benzoate, 21 */
1100 : : #endif
1101 : :
1102 : : /************* disabled ***********************/
1103 : :
1104 : : #ifdef UNDERIV_ACETATE_Me
1105 : : "Methylation", /* DERIV_ID_Methylation */
1106 : : #endif
1107 : : #ifdef UNDERIV_ACETATE_Et
1108 : : "Ethylation", /* DERIV_ID_Ethylation */
1109 : : #endif
1110 : : #if defined(UNDERIV_RN_AcEt) || defined(UNDERIV_RNH_AcEt) || defined(UNDERIV_RO_COX_Et)
1111 : : "Propanoate", /* DERIV_ID_Propanoate */
1112 : : #endif
1113 : :
1114 : : "", /* for linear searching */
1115 : : };
1116 : : #endif /* PTR_TO_DERIV_NAMES */
1117 : :
1118 : : typedef enum tagDerivBit {
1119 : : DERIV_BIT_Acentonate = 1 << DERIV_ID_Acentonate,
1120 : : DERIV_BIT_Benzlidene = 1 << DERIV_ID_Benzlidene,
1121 : : DERIV_BIT_BenzOX = 1 << DERIV_ID_BenzOX,
1122 : : DERIV_BIT_BuBorate = 1 << DERIV_ID_BuBorate,
1123 : : DERIV_BIT_Dansyl = 1 << DERIV_ID_Dansyl,
1124 : : DERIV_BIT_DEOX = 1 << DERIV_ID_DEOX,
1125 : : DERIV_BIT_DMOX = 1 << DERIV_ID_DMOX,
1126 : : DERIV_BIT_EtBorate = 1 << DERIV_ID_EtBorate,
1127 : : DERIV_BIT_EtOX = 1 << DERIV_ID_EtOX,
1128 : : DERIV_BIT_HFB = 1 << DERIV_ID_HFB,
1129 : : DERIV_BIT_MeBorate = 1 << DERIV_ID_MeBorate,
1130 : : DERIV_BIT_MOX = 1 << DERIV_ID_MOX,
1131 : : DERIV_BIT_PFB = 1 << DERIV_ID_PFB,
1132 : : DERIV_BIT_PFP = 1 << DERIV_ID_PFP,
1133 : : DERIV_BIT_Piperidine = 1 << DERIV_ID_Piperidine,
1134 : : DERIV_BIT_Pyrrolidide = 1 << DERIV_ID_Pyrrolidide,
1135 : : DERIV_BIT_TBDMS = 1 << DERIV_ID_TBDMS,
1136 : : DERIV_BIT_TFA = 1 << DERIV_ID_TFA,
1137 : : DERIV_BIT_TMS = 1 << DERIV_ID_TMS,
1138 : : DERIV_BIT_Unknown = 1 << DERIV_ID_Unknown,
1139 : :
1140 : : #if defined(UNDERIV_RN_AcMe) || defined(UNDERIV_RNH_AcMe) || defined(UNDERIV_RO_COX_Me)
1141 : : DERIV_BIT_Acetate = 1 << DERIV_ID_Acetate,
1142 : : #endif
1143 : : #if defined(UNDERIV_RO_COX_BENZOATES)
1144 : : DERIV_BIT_Benzoate = 1 << DERIV_ID_Benzoate,
1145 : : #endif
1146 : :
1147 : :
1148 : : #ifdef UNDERIV_ACETATE_Me
1149 : : DERIV_BIT_Methylation = 1 << DERIV_ID_Methylation,
1150 : : #endif
1151 : : #ifdef UNDERIV_ACETATE_Et
1152 : : DERIV_BIT_Ethylation = 1 << DERIV_ID_Ethylation,
1153 : : #endif
1154 : : #if defined(UNDERIV_RN_AcEt) || defined(UNDERIV_RNH_AcEt) || defined(UNDERIV_RO_COX_Et)
1155 : : DERIV_BIT_Propanoate = 1 << DERIV_ID_Propanoate,
1156 : : #endif
1157 : :
1158 : :
1159 : : DERIV_ID_NUMBER,
1160 : : } DerivBit;
1161 : :
1162 : : typedef int BIT_UNDERIV;
1163 : :
1164 : : int mark_atoms_cFlags( inp_ATOM *at,
1165 : : int start,
1166 : : int num,
1167 : : char cFlags );
1168 : : int unmark_atoms_cFlags( inp_ATOM *at,
1169 : : int start,
1170 : : int num,
1171 : : char cFlags,
1172 : : char cInvFlags );
1173 : :
1174 : : int is_C_or_S_DB_O( inp_ATOM *at, int i );
1175 : : int is_C_DB_O( inp_ATOM *at, int i );
1176 : : int is_Saturated_C( inp_ATOM *at, int attachment_pont );
1177 : : int is_C_Alk( inp_ATOM *at, int i, char cFlags );
1178 : :
1179 : : #ifdef DERIV_X_OXIME
1180 : : int is_Phenyl( inp_ATOM *at,
1181 : : int outside_point,
1182 : : int attachment_point );
1183 : : int is_PentaFluoroPhenyl( inp_ATOM *at,
1184 : : int outside_point,
1185 : : int attachment_point );
1186 : : #endif
1187 : :
1188 : : int is_Methyl( inp_ATOM *at,
1189 : : int attachment_point );
1190 : : int is_Ethyl( inp_ATOM *at,
1191 : : int outside_point,
1192 : : int attachment_point );
1193 : : int is_Methyl_or_Etyl( inp_ATOM *at,
1194 : : int outside_point,
1195 : : int attachment_point );
1196 : : int is_Si_IV( inp_ATOM *at, int i );
1197 : : int is_P_TB_N( inp_ATOM *at, int i );
1198 : :
1199 : : #if( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) || defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
1200 : : int is_DERIV_RING2_PRRLDD_PPRDN( inp_ATOM *at,
1201 : : int cur_atom,
1202 : : int from_ord,
1203 : : DERIV_AT *da,
1204 : : DERIV_AT *da1 );
1205 : : #endif
1206 : : int is_Dansyl( inp_ATOM *at,
1207 : : int cur_atom,
1208 : : int from_ord,
1209 : : DERIV_AT *da,
1210 : : DERIV_AT *da1 );
1211 : : int is_possibly_deriv_neigh( inp_ATOM *at,
1212 : : int iat,
1213 : : int iord,
1214 : : int type,
1215 : : char cFlags );
1216 : : int get_traversed_deriv_type( inp_ATOM *at,
1217 : : DERIV_AT *da,
1218 : : int k, DERIV_AT *da1,
1219 : : char cFlags );
1220 : : int add_to_da( DERIV_AT *da, DERIV_AT *add );
1221 : : int mark_atoms_deriv( inp_ATOM *at,
1222 : : DERIV_AT *da,
1223 : : int start,
1224 : : int num,
1225 : : char cFlags,
1226 : : int *pbFound );
1227 : : int count_one_bond_atoms( inp_ATOM *at,
1228 : : DERIV_AT *da,
1229 : : int start,
1230 : : int ord,
1231 : : char cFlags,
1232 : : int *bFound );
1233 : : int is_silyl( inp_ATOM *at, int start, int ord_prev );
1234 : : int is_silyl2( inp_ATOM *at, int start, int from_at );
1235 : : int is_Me_or_Et( inp_ATOM *at, int start, int ord_prev );
1236 : : int is_nButyl( inp_ATOM *at, int start, int ord_prev );
1237 : : int is_CF3_or_linC3F7a( inp_ATOM *at, int start, int iat_prev );
1238 : : int is_CF3_or_linC3F7( inp_ATOM *at, int start, int ord_prev );
1239 : : int is_phenyl( inp_ATOM *at, int start, int ord_prev );
1240 : : int is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR( inp_ATOM *at,
1241 : : int start,
1242 : : int num_atoms,
1243 : : DERIV_AT *da1,
1244 : : int idrv,
1245 : : char *szUnderiv,
1246 : : int lenUnderiv,
1247 : : char *szUnderiv2,
1248 : : int lenUnderiv2,
1249 : : BIT_UNDERIV *bitUnderiv );
1250 : : int is_deriv_chain( inp_ATOM *at,
1251 : : int start,
1252 : : int num_atoms,
1253 : : DERIV_AT *da1,
1254 : : int idrv,
1255 : : char *szUnderiv,
1256 : : int lenUnderiv,
1257 : : char *szUnderiv2,
1258 : : int lenUnderiv2,
1259 : : BIT_UNDERIV *bitUnderiv );
1260 : : int is_deriv_chain2( inp_ATOM *at,
1261 : : int start,
1262 : : int type,
1263 : : int num,
1264 : : int ord,
1265 : : int idrv,
1266 : : char *szUnderiv,
1267 : : int lenUnderiv,
1268 : : char *szUnderiv2,
1269 : : int lenUnderiv2,
1270 : : BIT_UNDERIV *bitUnderiv );
1271 : : int is_deriv_chain_or_ring( inp_ATOM *at,
1272 : : int start,
1273 : : int num_atoms,
1274 : : DERIV_AT *da1,
1275 : : int *idrv );
1276 : :
1277 : : int remove_deriv( DERIV_AT *da1, int idrv );
1278 : : int remove_deriv_mark( DERIV_AT *da1, int idrv );
1279 : : int underiv_compare( const void *p1, const void *p2 );
1280 : : int underiv_list_add_two_cuts( char *szUnderivList,
1281 : : int lenUnderivList,
1282 : : char *szUnderiv,
1283 : : const char cDelim );
1284 : : int sort_merge_underiv( char *pSdfValue,
1285 : : int bOutputSdf,
1286 : : char *szUnderivList,
1287 : : char cDerivSeparator,
1288 : : const char *pszUnderivPrefix,
1289 : : const char *pszUnderivPostfix );
1290 : : int eliminate_deriv_not_in_list( inp_ATOM *at,
1291 : : DERIV_AT *da,
1292 : : int num_atoms,
1293 : : char *szUnderivList,
1294 : : int lenUnderivList,
1295 : : char *szUnderivList2,
1296 : : int lenUnderivList2,
1297 : : BIT_UNDERIV *bitUnderivList );
1298 : : void underiv_buf_clear( char *szUnderiv );
1299 : : int underiv_list_add( char *szUnderivList,
1300 : : int lenUnderivList,
1301 : : const char *szUnderiv,
1302 : : char cDelimiter );
1303 : : const char* underiv_list_get_last( const char *szUnderivList,
1304 : : char cDelimiter );
1305 : : int make_single_cut( inp_ATOM *at,
1306 : : DERIV_AT *da,
1307 : : int iat,
1308 : : int icut );
1309 : : int fill_out_bond_cuts( inp_ATOM *at,
1310 : : DERIV_AT *da,
1311 : : int num_atoms,
1312 : : R2C_ATPAIR *ap,
1313 : : int num_cuts_to_check );
1314 : : int mark_deriv_agents( inp_ATOM *at,
1315 : : DERIV_AT *da,
1316 : : int num_atoms,
1317 : : R2C_ATPAIR *ap,
1318 : : int num_cuts_to_check,
1319 : : AT_NUMB *pnum_comp,
1320 : : int *pcur_num_at );
1321 : : int add_explicit_H( INP_ATOM_DATA *inp_cur_data );
1322 : : void free_underiv_temp_data( R2C_ATPAIR *ap,
1323 : : DERIV_AT *da,
1324 : : inp_ATOM *at2,
1325 : : INP_ATOM_DATA *inp_cur_data,
1326 : : int num_components );
1327 : : void remove_cut_derivs( int num_atoms,
1328 : : inp_ATOM *at,
1329 : : INP_ATOM_DATA *inp_cur_data,
1330 : : int i_component,
1331 : : int *errcode );
1332 : :
1333 : :
1334 : : /****************************************************************************
1335 : : DFS search for atoms that do not have a flag
1336 : : ****************************************************************************/
1337 : 0 : int mark_atoms_cFlags( inp_ATOM *at, int start, int num, char cFlags )
1338 : : {
1339 [ # # ]: 0 : if (!( at[start].cFlags & cFlags ))
1340 : : {
1341 : : int i;
1342 : 0 : at[start].cFlags |= cFlags;
1343 : 0 : num++;
1344 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
1345 : : {
1346 : 0 : num = mark_atoms_cFlags( at, at[start].neighbor[i], num, cFlags );
1347 : : }
1348 : : }
1349 : :
1350 : 0 : return num; /* number of atoms traversed forward from at[start] */
1351 : : }
1352 : :
1353 : :
1354 : : /****************************************************************************
1355 : : DFS search for atoms that do have a flag
1356 : : ****************************************************************************/
1357 : 0 : int unmark_atoms_cFlags( inp_ATOM *at,
1358 : : int start,
1359 : : int num,
1360 : : char cFlags,
1361 : : char cInvFlags )
1362 : : {
1363 [ # # ]: 0 : if (at[start].cFlags & cFlags)
1364 : : {
1365 : : int i;
1366 : 0 : at[start].cFlags &= cInvFlags;
1367 : 0 : num++;
1368 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
1369 : : {
1370 : 0 : num = unmark_atoms_cFlags( at, at[start].neighbor[i], num, cFlags, cInvFlags );
1371 : : }
1372 : : }
1373 : :
1374 : 0 : return num; /* number of atoms traversed forward from at[start] */
1375 : : }
1376 : :
1377 : :
1378 : : /****************************************************************************/
1379 : 0 : int is_C_or_S_DB_O( inp_ATOM *at, int i )
1380 : : {
1381 : : int j, neigh;
1382 [ # # ]: 0 : if ((at[i].el_number != EL_NUMBER_C &&
1383 [ # # ]: 0 : at[i].el_number != EL_NUMBER_S) ||
1384 [ # # # # ]: 0 : at[i].charge || at[i].radical) /* djb-rwth: addressing LLVM warning */
1385 : 0 : return 0;
1386 [ # # ]: 0 : for (j = 0; j < at[i].valence; j++)
1387 : : {
1388 : 0 : neigh = at[i].neighbor[j];
1389 [ # # ]: 0 : if (( at[neigh].el_number == EL_NUMBER_O ||
1390 [ # # ]: 0 : at[neigh].el_number == EL_NUMBER_S ) &&
1391 [ # # # # ]: 0 : !at[neigh].num_H && 1 == at[neigh].valence &&
1392 [ # # ]: 0 : 2 == at[neigh].chem_bonds_valence)
1393 : : {
1394 : 0 : return 1;
1395 : : }
1396 : : }
1397 : :
1398 : 0 : return 0;
1399 : : }
1400 : :
1401 : :
1402 : : /****************************************************************************/
1403 : 0 : int is_C_DB_O( inp_ATOM *at, int i )
1404 : : {
1405 : : int j, neigh;
1406 [ # # ]: 0 : if (at[i].el_number != EL_NUMBER_C ||
1407 [ # # # # ]: 0 : at[i].charge || at[i].radical ||
1408 [ # # # # ]: 0 : at[i].valence != 3 || at[i].chem_bonds_valence != 4)
1409 : 0 : return 0;
1410 [ # # ]: 0 : for (j = 0; j < at[i].valence; j++)
1411 : : {
1412 : 0 : neigh = at[i].neighbor[j];
1413 [ # # ]: 0 : if (( at[neigh].el_number == EL_NUMBER_O ) &&
1414 [ # # # # ]: 0 : !at[neigh].num_H && 1 == at[neigh].valence &&
1415 [ # # ]: 0 : 2 == at[neigh].chem_bonds_valence)
1416 : : {
1417 : 0 : return j + 1; /* =O ord */
1418 : : }
1419 : : }
1420 : :
1421 : 0 : return 0;
1422 : : }
1423 : :
1424 : :
1425 : : /****************************************************************************/
1426 : 0 : int is_Saturated_C( inp_ATOM *at, int attachment_pont )
1427 : : {
1428 [ # # ]: 0 : return ( at[attachment_pont].el_number == EL_NUMBER_C &&
1429 [ # # ]: 0 : at[attachment_pont].valence == at[attachment_pont].chem_bonds_valence );
1430 : : }
1431 : :
1432 : :
1433 : : /****************************************************************************/
1434 : 0 : int is_C_Alk( inp_ATOM *at, int i, char cFlags )
1435 : : {
1436 [ # # ]: 0 : if (at[i].el_number == EL_NUMBER_C &&
1437 [ # # ]: 0 : at[i].valence == at[i].chem_bonds_valence)
1438 : : {
1439 : : int j, k;
1440 : : U_CHAR el;
1441 [ # # ]: 0 : for (j = 0; j < at[i].valence; j++)
1442 : : {
1443 : 0 : k = at[i].neighbor[j];
1444 [ # # ]: 0 : if (at[k].cFlags & cFlags)
1445 : 0 : continue;
1446 : 0 : el = at[k].el_number;
1447 [ # # # # ]: 0 : if (el != EL_NUMBER_C &&
1448 [ # # ]: 0 : el != EL_NUMBER_F &&
1449 [ # # ]: 0 : el != EL_NUMBER_CL &&
1450 [ # # ]: 0 : el != EL_NUMBER_BR &&
1451 : : el != EL_NUMBER_I)
1452 : : {
1453 : 0 : return 0;
1454 : : }
1455 : : }
1456 : 0 : return 1;
1457 : : }
1458 : :
1459 : 0 : return 0;
1460 : : }
1461 : :
1462 : :
1463 : : #if( defined(DERIV_X_OXIME) || defined(DERIV_RO_COX) || defined(DERIV_DANSYL) )
1464 : :
1465 : :
1466 : : /****************************************************************************
1467 : : CH -- CH
1468 : : / \
1469 : : (outside point)-(attachment point, C) CH
1470 : : \ /
1471 : : CH -- CH
1472 : : note: bond types in the ring are not checked,
1473 : : we check num_H, valence, charge, radical, RingSystem,
1474 : : nNumAtInRingSystem, bCutVertex
1475 : : ****************************************************************************/
1476 : 0 : int is_Phenyl( inp_ATOM *at, int outside_point, int attachment_point )
1477 : : {
1478 : : int iNext, iCur, iNewNext, k;
1479 : :
1480 [ # # ]: 0 : if (at[attachment_point].el_number == EL_NUMBER_C &&
1481 [ # # ]: 0 : at[attachment_point].valence == 3 && /*at[attachment_point].chem_bonds_valence == 4 &&*/
1482 [ # # # # : 0 : !at[attachment_point].num_H && !at[attachment_point].charge && !at[attachment_point].radical &&
# # ]
1483 [ # # ]: 0 : at[attachment_point].nRingSystem != at[outside_point].nRingSystem &&
1484 [ # # # # ]: 0 : at[attachment_point].bCutVertex && at[attachment_point].nNumAtInRingSystem == 6)
1485 : : {
1486 : :
1487 [ # # ]: 0 : for (iNext = 0; iNext < at[attachment_point].valence; iNext++)
1488 : : {
1489 [ # # ]: 0 : if (at[attachment_point].neighbor[iNext] != outside_point)
1490 : : {
1491 : 0 : break;
1492 : : }
1493 : : }
1494 [ # # ]: 0 : if (iNext == at[attachment_point].valence)
1495 : : {
1496 : 0 : return 0; /* program error*/
1497 : : }
1498 : 0 : iCur = attachment_point;
1499 : 0 : iNext = at[attachment_point].neighbor[iNext];
1500 [ # # ]: 0 : for (k = 0; k < 5; k++)
1501 : : {
1502 : : /* here we do not check bond type in the aromatic ring */
1503 [ # # # # : 0 : if (at[iNext].el_number != EL_NUMBER_C || at[iNext].valence != 2 || at[iNext].num_H != 1 || at[iNext].charge || at[iNext].radical)
# # # # #
# ]
1504 : : {
1505 : 0 : return 0;
1506 : : }
1507 : 0 : iNewNext = at[iNext].neighbor[at[iNext].neighbor[0] == iCur];
1508 : 0 : iCur = iNext;
1509 : 0 : iNext = iNewNext;
1510 : : }
1511 : 0 : return ( iNext == attachment_point );
1512 : : }
1513 : :
1514 : 0 : return 0;
1515 : : }
1516 : :
1517 : :
1518 : : /****************************************************************************
1519 : : F F
1520 : : | |
1521 : : C --- C
1522 : : / \
1523 : : (outside point)-(attachment point, C) C---F
1524 : : \ /
1525 : : C --- C
1526 : : | |
1527 : : F F
1528 : : note: bond types in the ring are not checked,
1529 : : we check num_H, valence, charge, radical, RingSystem,
1530 : : nNumAtInRingSystem, bCutVertex
1531 : : ****************************************************************************/
1532 : 0 : int is_PentaFluoroPhenyl( inp_ATOM *at,
1533 : : int outside_point,
1534 : : int attachment_point )
1535 : : {
1536 : : int iNext, iCur, iNewNext, nF, k, i, neigh;
1537 : :
1538 [ # # ]: 0 : if (at[attachment_point].el_number == EL_NUMBER_C &&
1539 [ # # ]: 0 : at[attachment_point].valence == 3 && /*at[attachment_point].chem_bonds_valence == 4 &&*/
1540 [ # # # # : 0 : !at[attachment_point].num_H && !at[attachment_point].charge && !at[attachment_point].radical &&
# # ]
1541 [ # # ]: 0 : at[attachment_point].nRingSystem != at[outside_point].nRingSystem &&
1542 [ # # # # ]: 0 : at[attachment_point].bCutVertex && at[attachment_point].nNumAtInRingSystem == 6)
1543 : : {
1544 : :
1545 [ # # ]: 0 : for (iNext = 0; iNext < at[attachment_point].valence; iNext++)
1546 : : {
1547 [ # # ]: 0 : if (at[attachment_point].neighbor[iNext] != outside_point)
1548 : 0 : break;
1549 : : }
1550 [ # # ]: 0 : if (iNext == at[attachment_point].valence)
1551 : 0 : return 0; /* program error*/
1552 : 0 : iCur = attachment_point;
1553 : 0 : iNext = at[attachment_point].neighbor[iNext];
1554 [ # # ]: 0 : for (k = 0; k < 5; k++)
1555 : : {
1556 : : /* here we do not check bond type in the aromatic ring */
1557 [ # # # # : 0 : if (at[iNext].el_number != EL_NUMBER_C || at[iNext].valence != 3 || at[iNext].num_H != 0 || at[iNext].charge || at[iNext].radical)
# # # # #
# ]
1558 : 0 : return 0;
1559 [ # # ]: 0 : for (i = 0, nF = 0, iNewNext = -1; i < at[iNext].valence; i++)
1560 : : {
1561 : 0 : neigh = at[iNext].neighbor[i];
1562 [ # # ]: 0 : if (neigh == iCur)
1563 : : {
1564 : : ;
1565 : : }
1566 : : else
1567 [ # # # # : 0 : if (at[neigh].el_number == EL_NUMBER_F && at[neigh].chem_bonds_valence == 1 && !at[neigh].charge && !at[neigh].radical && !at[neigh].num_H)
# # # # #
# ]
1568 : : {
1569 : 0 : nF++; /* terminal flourine */
1570 : : }
1571 : : else
1572 [ # # ]: 0 : if (iNewNext == -1)
1573 : : {
1574 : 0 : iNewNext = neigh; /* Carbon will be checked on the next pass */
1575 : : }
1576 : : else
1577 : : {
1578 : 0 : return 0;
1579 : : }
1580 : : }
1581 [ # # # # ]: 0 : if (iNewNext == -1 || nF != 1)
1582 : : {
1583 : 0 : return 0;
1584 : : }
1585 : 0 : iCur = iNext;
1586 : 0 : iNext = iNewNext;
1587 : : }
1588 : 0 : return ( iNext == attachment_point );
1589 : : }
1590 : :
1591 : 0 : return 0;
1592 : : }
1593 : :
1594 : :
1595 : : /****************************************************************************/
1596 : 0 : int is_Methyl( inp_ATOM *at, int attachment_point )
1597 : : {
1598 [ # # # # ]: 0 : if (at[attachment_point].valence == 1 && at[attachment_point].chem_bonds_valence == 1 &&
1599 [ # # # # ]: 0 : at[attachment_point].el_number == EL_NUMBER_C && at[attachment_point].num_H == 3 &&
1600 [ # # # # ]: 0 : !at[attachment_point].charge && !at[attachment_point].radical)
1601 : : {
1602 : : /* methyl */
1603 : 0 : return 1;
1604 : : }
1605 : :
1606 : 0 : return 0;
1607 : : }
1608 : :
1609 : :
1610 : : /****************************************************************************/
1611 : 0 : int is_Ethyl( inp_ATOM *at, int outside_point, int attachment_point )
1612 : : {
1613 [ # # # # ]: 0 : if (at[attachment_point].valence == 2 && at[attachment_point].chem_bonds_valence == 2 &&
1614 [ # # # # ]: 0 : at[attachment_point].el_number == EL_NUMBER_C && at[attachment_point].num_H == 2 &&
1615 [ # # # # ]: 0 : !at[attachment_point].charge && !at[attachment_point].radical)
1616 : : {
1617 : : /* methanediyl */
1618 : 0 : int iat_methyl = at[attachment_point].neighbor[( at[attachment_point].neighbor[0] == outside_point )];
1619 : 0 : return is_Methyl( at, iat_methyl );
1620 : : }
1621 : :
1622 : 0 : return 0;
1623 : : }
1624 : :
1625 : : /*****************************************************************************/
1626 : 0 : int is_Methyl_or_Etyl( inp_ATOM *at, int outside_point, int attachment_point )
1627 : : {
1628 [ # # ]: 0 : if (is_Methyl( at, attachment_point ))
1629 : : {
1630 : 0 : return 1;
1631 : : }
1632 [ # # ]: 0 : if (is_Ethyl( at, outside_point, attachment_point ))
1633 : : {
1634 : 0 : return 2;
1635 : : }
1636 : :
1637 : 0 : return 0;
1638 : : }
1639 : :
1640 : : #endif /* ( defined(DERIV_X_OXIME) || defined(DERIV_RO_COX) || defined(DERIV_DANSYL) ) */
1641 : :
1642 : :
1643 : : /****************************************************************************/
1644 : 0 : int is_Si_IV( inp_ATOM *at, int i )
1645 : : {
1646 [ # # ]: 0 : if (at[i].el_number != EL_NUMBER_SI ||
1647 [ # # # # : 0 : at[i].charge || at[i].radical || at[i].valence != 4 || at[i].chem_bonds_valence != 4)
# # # # ]
1648 : : {
1649 : 0 : return 0;
1650 : : }
1651 : :
1652 : 0 : return 1;
1653 : : }
1654 : :
1655 : :
1656 : : /****************************************************************************/
1657 : 0 : int is_P_TB_N( inp_ATOM *at, int i )
1658 : : {
1659 : : int j, k;
1660 [ # # # # ]: 0 : if (at[i].el_number != EL_NUMBER_P || at[i].chem_bonds_valence - at[i].valence != 2)
1661 : 0 : return 0;
1662 [ # # ]: 0 : for (j = 0; j < at[i].valence; j++)
1663 : : {
1664 : 0 : k = at[i].neighbor[j];
1665 [ # # # # : 0 : if (at[k].el_number == EL_NUMBER_N && at[k].valence == 1 && at[k].chem_bonds_valence == 3)
# # ]
1666 : : {
1667 : 0 : return 1;
1668 : : }
1669 : : }
1670 : :
1671 : 0 : return 0;
1672 : : }
1673 : :
1674 : :
1675 : : /****************************************************************************
1676 : : X
1677 : : ||
1678 : : [iat](iord)--C--(iord_opposite)[iat_oppposite]
1679 : : ****************************************************************************/
1680 : 0 : int get_CO_opposite( inp_ATOM *at,
1681 : : int iat,
1682 : : int iord,
1683 : : int *iat_opposite,
1684 : : int *iord_opposite )
1685 : : {
1686 : 0 : int i, iOpp, iC = at[iat].neighbor[iord];
1687 [ # # # # : 0 : if (at[iat].bond_type[iord] == BOND_SINGLE && 3 == at[iC].valence && 4 == at[iC].chem_bonds_valence)
# # ]
1688 : : {
1689 : : /* scan neighbors of iC */
1690 [ # # ]: 0 : for (i = 0; i < at[iC].valence; i++)
1691 : : {
1692 [ # # # # ]: 0 : if (iat != at[iC].neighbor[i] && BOND_SINGLE == at[iC].bond_type[i])
1693 : : {
1694 : 0 : iOpp = *iat_opposite = at[iC].neighbor[i];
1695 : 0 : goto scan_opposite_atom;
1696 : : }
1697 : : }
1698 : 0 : return 0; /* failed */
1699 : 0 : scan_opposite_atom:
1700 [ # # ]: 0 : for (i = 0; i < at[iOpp].valence; i++)
1701 : : {
1702 [ # # ]: 0 : if (iC == at[iOpp].neighbor[i])
1703 : : {
1704 : 0 : *iord_opposite = i;
1705 : 0 : return 1; /* success */
1706 : : }
1707 : : }
1708 : : }
1709 : :
1710 : 0 : return 0; /* failed */
1711 : : }
1712 : :
1713 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
1714 : :
1715 : : #define OX_RING_SIZE 5
1716 : :
1717 : :
1718 : : /****************************************************************************/
1719 : 0 : int is_DERIV_RING_DMOX_DEOX_O( inp_ATOM *at,
1720 : : int cur_atom,
1721 : : int from_ord,
1722 : : DERIV_AT *da,
1723 : : DERIV_AT *da1 )
1724 : : {
1725 : : /*-----------------------
1726 : : <-
1727 : : #4 #3
1728 : : R--C==N Me or Et
1729 : : | \ /
1730 : : | C #2
1731 : : | / \
1732 : : at[k]:O--CH2 Me or ET
1733 : : #0 #1
1734 : : ->
1735 : : --------------------------*/
1736 : : /* #0 #1 #2 #3 #4 */
1737 : : static const U_CHAR bond_type[OX_RING_SIZE] = { BOND_SINGLE, BOND_SINGLE, BOND_SINGLE, BOND_DOUBLE, BOND_SINGLE };
1738 : : static const S_CHAR valence[OX_RING_SIZE] = { 2, 2, 4, 2, 3 };
1739 : : static const S_CHAR bonds_valence[OX_RING_SIZE] = { 2, 2, 4, 3, 4 };
1740 : : static const S_CHAR num_H[OX_RING_SIZE] = { 0, 2, 0, 0, 0 };
1741 : :
1742 : : AT_NUMB from, curr, next, nRingSystem, at_no[OX_RING_SIZE];
1743 : : S_CHAR bond_no[OX_RING_SIZE];
1744 : : int i, n0, n1, attach1, attach2, neigh;
1745 : :
1746 [ # # # # ]: 0 : if (at[cur_atom].el_number == EL_NUMBER_O && at[cur_atom].nNumAtInRingSystem == OX_RING_SIZE)
1747 : : {
1748 : 0 : AT_NUMB attype[OX_RING_SIZE] = { (AT_NUMB) EL_NUMBER_O, (AT_NUMB) EL_NUMBER_C, (AT_NUMB) EL_NUMBER_C, (AT_NUMB) EL_NUMBER_N, (AT_NUMB) EL_NUMBER_C };
1749 : :
1750 : 0 : curr = cur_atom;
1751 : 0 : from = at[curr].neighbor[from_ord];
1752 : 0 : nRingSystem = at[curr].nRingSystem;
1753 : 0 : n0 = 0;
1754 : :
1755 : : do
1756 : : {
1757 : : /* find next atom in a simple ring */
1758 [ # # ]: 0 : for (i = 0; i < at[curr].valence &&
1759 [ # # ]: 0 : ( from == ( next = at[curr].neighbor[i] ) ||
1760 [ # # ]: 0 : nRingSystem != at[next].nRingSystem ); i++)
1761 : : {
1762 : : ;
1763 : : }
1764 [ # # ]: 0 : if (i == at[curr].valence)
1765 : : {
1766 : 0 : goto check_next_derivative2;
1767 : : }
1768 : : /* check curr atom */
1769 [ # # # # ]: 0 : if (at[curr].charge || at[curr].radical)
1770 : : {
1771 : 0 : goto check_next_derivative2;
1772 : : }
1773 [ # # ]: 0 : if (at[curr].bond_type[i] != bond_type[n0] ||
1774 [ # # ]: 0 : at[curr].valence != valence[n0] ||
1775 [ # # ]: 0 : at[curr].chem_bonds_valence != bonds_valence[n0] ||
1776 [ # # ]: 0 : at[curr].num_H != num_H[n0] ||
1777 [ # # ]: 0 : at[curr].el_number != (U_CHAR) attype[n0])
1778 : : {
1779 : 0 : goto check_next_derivative2;
1780 : : }
1781 : : /* save current atom */
1782 : 0 : at_no[n0] = curr;
1783 : 0 : bond_no[n0] = i;
1784 : : /* prepare for the next */
1785 : 0 : from = curr;
1786 : 0 : curr = next;
1787 : 0 : n0++;
1788 [ # # # # ]: 0 : } while (n0 < OX_RING_SIZE && curr != cur_atom);
1789 : : /* check completion */
1790 [ # # # # ]: 0 : if (OX_RING_SIZE != n0 || curr != cur_atom)
1791 : : {
1792 : 0 : goto check_next_derivative2;
1793 : : }
1794 : : /* check if R is C */
1795 : 0 : n1 = at_no[4];
1796 [ # # ]: 0 : for (i = 0; i < at[n1].valence; i++)
1797 : : {
1798 : 0 : neigh = at[n1].neighbor[i];
1799 [ # # # # ]: 0 : if (neigh != at_no[0] && neigh != at_no[3])
1800 : : {
1801 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C)
1802 : : {
1803 : 0 : goto check_next_derivative2;
1804 : : }
1805 : : else
1806 : : {
1807 : 0 : break; /* checked */
1808 : : }
1809 : : }
1810 : : }
1811 : : /* check >C< attachments */
1812 : 0 : n1 = at_no[2];
1813 : 0 : attach1 = attach2 = 0;
1814 [ # # ]: 0 : for (i = 0; i < at[n1].valence; i++)
1815 : : {
1816 [ # # ]: 0 : if (at[n1].neighbor[i] != at_no[1] &&
1817 [ # # ]: 0 : at[n1].neighbor[i] != at_no[3])
1818 : : {
1819 [ # # ]: 0 : if (!attach1)
1820 : : {
1821 : 0 : attach1 = is_Methyl_or_Etyl( at, n1, at[n1].neighbor[i] );
1822 : : }
1823 : : else
1824 : : {
1825 [ # # ]: 0 : if (!attach2)
1826 : : {
1827 : 0 : attach2 = is_Methyl_or_Etyl( at, n1, at[n1].neighbor[i] );
1828 : : }
1829 : : else
1830 : : {
1831 : 0 : goto check_next_derivative2;
1832 : : }
1833 : : }
1834 : : }
1835 : : }
1836 [ # # # # ]: 0 : if (!attach2 || attach2 != attach1)
1837 : : {
1838 : 0 : goto check_next_derivative2;
1839 : : }
1840 : : /* all checks are done */
1841 [ # # ]: 0 : if ( /*da &&*/ da1)
1842 : : {
1843 : 0 : short ord_O = bond_no[0];
1844 : : /*short ord_N = !bond_no[3];*/
1845 : 0 : AT_NUMB iN = at_no[3];
1846 : : /*AT_NUMB iO = at_no[0];*/
1847 : 0 : char num_2remove = 2 + attach1 + attach2;
1848 : 0 : da1->typ[0] /* = da1->typ[1] */ = DERIV_RING_DMOX_DEOX_O;
1849 : 0 : da1->ord[0] /* = da1->ord[1] */ = ord_O;
1850 : 0 : da1->num[0] /* = da1->num[1] */ = num_2remove;
1851 : 0 : da1->other_atom = iN + 1;
1852 : : /*
1853 : : if ( da1->typ[0] ) {
1854 : : if ( da1->typ[0] != DERIV_RING_DMOX_DEOX_O ||
1855 : : da1->ord[0] != ord_O ||
1856 : : da1->num[0] != num_2remove ||
1857 : : da1->other_atom != iN ) {
1858 : : goto check_next_derivative2;
1859 : : }
1860 : : } else {
1861 : : da1->typ[0] = DERIV_RING_DMOX_DEOX_O;
1862 : : da1->ord[0] = ord_O;
1863 : : da1->num[0] = num_2remove;
1864 : : da1->other_atom = iN;
1865 : : }
1866 : : */
1867 : : }
1868 : :
1869 : 0 : return DERIV_RING_DMOX_DEOX_O;
1870 : : }
1871 : :
1872 : 0 : check_next_derivative2:;
1873 : :
1874 : 0 : return 0;
1875 : : }
1876 : :
1877 : :
1878 : : /****************************************************************************/
1879 : 0 : int is_DERIV_RING_DMOX_DEOX_N( inp_ATOM *at,
1880 : : int cur_atom,
1881 : : int from_ord,
1882 : : DERIV_AT *da,
1883 : : DERIV_AT *da1 )
1884 : : {
1885 : : /*-----------------------
1886 : : ->
1887 : : #4 #0
1888 : : R--C==N Me or Et
1889 : : | \ /
1890 : : | C #1
1891 : : | / \
1892 : : at[k]:O--CH2 Me or ET
1893 : : #3 #2
1894 : : <-
1895 : : --------------------------*/
1896 : : /* #0 #1 #2 #3 #4 */
1897 : : static const U_CHAR bond_type[OX_RING_SIZE] = { BOND_SINGLE, BOND_SINGLE, BOND_SINGLE, BOND_SINGLE, BOND_DOUBLE };
1898 : : static const S_CHAR valence[OX_RING_SIZE] = { 2, 4, 2, 2, 3 };
1899 : : static const S_CHAR bonds_valence[OX_RING_SIZE] = { 3, 4, 2, 2, 4 };
1900 : : static const S_CHAR num_H[OX_RING_SIZE] = { 0, 0, 2, 0, 0 };
1901 : :
1902 : : AT_NUMB from, curr, next, nRingSystem, at_no[OX_RING_SIZE];
1903 : : S_CHAR bond_no[OX_RING_SIZE];
1904 : : int i, n0, n1, attach1, attach2, neigh;
1905 : :
1906 [ # # # # ]: 0 : if (at[cur_atom].el_number == EL_NUMBER_N && at[cur_atom].nNumAtInRingSystem == OX_RING_SIZE &&
1907 [ # # # # ]: 0 : at[cur_atom].valence == 2 && at[cur_atom].chem_bonds_valence == 3)
1908 : : {
1909 : 0 : AT_NUMB attype[OX_RING_SIZE] = { (AT_NUMB) EL_NUMBER_N, (AT_NUMB) EL_NUMBER_C, (AT_NUMB) EL_NUMBER_C, (AT_NUMB) EL_NUMBER_O, (AT_NUMB) EL_NUMBER_C };
1910 : :
1911 : 0 : curr = cur_atom;
1912 : 0 : from = at[curr].neighbor[from_ord];
1913 : 0 : nRingSystem = at[curr].nRingSystem;
1914 : 0 : n0 = 0;
1915 : :
1916 : : do
1917 : : {
1918 : : /* find next atom in a simple ring */
1919 [ # # ]: 0 : for (i = 0; i < at[curr].valence &&
1920 [ # # ]: 0 : ( from == ( next = at[curr].neighbor[i] ) ||
1921 [ # # ]: 0 : nRingSystem != at[next].nRingSystem ); i++)
1922 : : {
1923 : : ;
1924 : : }
1925 [ # # ]: 0 : if (i == at[curr].valence)
1926 : : {
1927 : 0 : goto check_next_derivative2;
1928 : : }
1929 : : /* check curr atom */
1930 [ # # # # ]: 0 : if (at[curr].charge || at[curr].radical)
1931 : : {
1932 : 0 : goto check_next_derivative2;
1933 : : }
1934 [ # # ]: 0 : if (at[curr].bond_type[i] != bond_type[n0] ||
1935 [ # # ]: 0 : at[curr].valence != valence[n0] ||
1936 [ # # ]: 0 : at[curr].chem_bonds_valence != bonds_valence[n0] ||
1937 [ # # ]: 0 : at[curr].num_H != num_H[n0] ||
1938 [ # # ]: 0 : at[curr].el_number != (U_CHAR) attype[n0])
1939 : : {
1940 : 0 : goto check_next_derivative2;
1941 : : }
1942 : : /* save current atom */
1943 : 0 : at_no[n0] = curr;
1944 : 0 : bond_no[n0] = i;
1945 : : /* prepare for the next */
1946 : 0 : from = curr;
1947 : 0 : curr = next;
1948 : 0 : n0++;
1949 [ # # # # ]: 0 : } while (n0 < OX_RING_SIZE && curr != cur_atom);
1950 : :
1951 : : /* check completion */
1952 [ # # # # ]: 0 : if (OX_RING_SIZE != n0 || curr != cur_atom)
1953 : : {
1954 : 0 : goto check_next_derivative2;
1955 : : }
1956 : :
1957 : : /* check if R is C */
1958 : 0 : n1 = at_no[4];
1959 [ # # ]: 0 : for (i = 0; i < at[n1].valence; i++)
1960 : : {
1961 : 0 : neigh = at[n1].neighbor[i];
1962 [ # # # # ]: 0 : if (neigh != at_no[0] && neigh != at_no[3])
1963 : : {
1964 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C)
1965 : : {
1966 : 0 : goto check_next_derivative2;
1967 : : }
1968 : : else
1969 : : {
1970 : 0 : break; /* checked */
1971 : : }
1972 : : }
1973 : : }
1974 : :
1975 : : /* check >C< attachments */
1976 : 0 : n1 = at_no[1];
1977 : 0 : attach1 = attach2 = 0;
1978 [ # # ]: 0 : for (i = 0; i < at[n1].valence; i++)
1979 : : {
1980 [ # # ]: 0 : if (at[n1].neighbor[i] != at_no[0] &&
1981 [ # # ]: 0 : at[n1].neighbor[i] != at_no[2])
1982 : : {
1983 [ # # ]: 0 : if (!attach1)
1984 : : {
1985 : 0 : attach1 = is_Methyl_or_Etyl( at, n1, at[n1].neighbor[i] );
1986 : : }
1987 : : else
1988 : : {
1989 [ # # ]: 0 : if (!attach2)
1990 : : {
1991 : 0 : attach2 = is_Methyl_or_Etyl( at, n1, at[n1].neighbor[i] );
1992 : : }
1993 : : else
1994 : : {
1995 : 0 : goto check_next_derivative2;
1996 : : }
1997 : : }
1998 : : }
1999 : : }
2000 [ # # # # ]: 0 : if (!attach2 || attach2 != attach1)
2001 : : {
2002 : 0 : goto check_next_derivative2;
2003 : : }
2004 : :
2005 : : /* all checks are done */
2006 [ # # ]: 0 : if ( /*da &&*/ da1)
2007 : : {
2008 : : /*short ord_O = !bond_no[3];*/
2009 : 0 : short ord_N = bond_no[0];
2010 : : /*AT_NUMB iN = at_no[0];*/
2011 : 0 : AT_NUMB iO = at_no[3];
2012 : 0 : char num_2remove = 2 + attach1 + attach2;
2013 : 0 : da1->typ[0] /* = da1->typ[1] */ = DERIV_RING_DMOX_DEOX_N;
2014 : 0 : da1->ord[0] /* = da1->ord[1] */ = ord_N;
2015 : 0 : da1->num[0] /* = da1->num[1] */ = num_2remove;
2016 : 0 : da1->other_atom = iO + 1;
2017 : : /*
2018 : : if ( da1->typ[0] ) {
2019 : : if ( da1->typ[0] != DERIV_RING_DMOX_DEOX_O ||
2020 : : da1->ord[0] != ord_O ||
2021 : : da1->num[0] != num_2remove ||
2022 : : da1->other_atom != iN ) {
2023 : : goto check_next_derivative2;
2024 : : }
2025 : : } else {
2026 : : da1->typ[0] = DERIV_RING_DMOX_DEOX_O;
2027 : : da1->ord[0] = ord_O;
2028 : : da1->num[0] = num_2remove;
2029 : : da1->other_atom = iN;
2030 : : }
2031 : : */
2032 : : }
2033 : :
2034 : 0 : return DERIV_RING_DMOX_DEOX_N;
2035 : : }
2036 : :
2037 : 0 : check_next_derivative2:;
2038 : 0 : return 0;
2039 : : }
2040 : :
2041 : :
2042 : : #endif /* defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) */
2043 : :
2044 : : #if( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) || defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
2045 : :
2046 : : #define PRRLDD_RING_SIZE 5
2047 : : #define PPRDN_RING_SIZE 6
2048 : : #if( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) && defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
2049 : : #define MIN_PRRLDD_PPRDN_RING_SIZE PRRLDD_RING_SIZE
2050 : : #define MAX_PRRLDD_PPRDN_RING_SIZE PPRDN_RING_SIZE
2051 : : #elif ( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) )
2052 : : #define MIN_PRRLDD_PPRDN_RING_SIZE PRRLDD_RING_SIZE
2053 : : #define MAX_PRRLDD_PPRDN_RING_SIZE PRRLDD_RING_SIZE
2054 : : #elif ( defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
2055 : : #define MIN_PRRLDD_PPRDN_RING_SIZE PPRDN_RING_SIZE
2056 : : #define MAX_PRRLDD_PPRDN_RING_SIZE PPRDN_RING_SIZE
2057 : : #else
2058 : : #define MIN_PRRLDD_PPRDN_RING_SIZE (-1)
2059 : : #define MAX_PRRLDD_PPRDN_RING_SIZE (-1)
2060 : : #endif
2061 : :
2062 : :
2063 : : /****************************************************************************/
2064 : 0 : int is_DERIV_RING2_PRRLDD_PPRDN( inp_ATOM *at,
2065 : : int cur_atom,
2066 : : int from_ord,
2067 : : DERIV_AT *da,
2068 : : DERIV_AT *da1 )
2069 : : {
2070 : : /*
2071 : : #1 #2 #1 #2
2072 : : O CH2--CH2 O CH2--CH2 O
2073 : : || / | || / | ||
2074 : : R--C--N #0 | N is cur_atom R--C--N #0 CH2 #3 => R--C--OH
2075 : : from \ | C(IV) is from atom from \ |
2076 : : CH2--CH2 CH2--CH2
2077 : : #4 #3 #5 #4
2078 : :
2079 : : Pyrrolidides: Replace -N< with -OH Piperidines: Replace -N< with -OH
2080 : : DERIV_RING2_PRRLDD_OUTSIDE_PRECUR DERIV_RING2_PPRDN_OUTSIDE_PRECUR
2081 : : */
2082 : : int iat_from, i, neigh, k;
2083 : : char ord[2];
2084 : :
2085 : : /* check cur atom */
2086 : 0 : if (
2087 [ # # ]: 0 : at[cur_atom].el_number == EL_NUMBER_N &&
2088 [ # # ]: 0 : MIN_PRRLDD_PPRDN_RING_SIZE <= at[cur_atom].nNumAtInRingSystem &&
2089 [ # # ]: 0 : at[cur_atom].nNumAtInRingSystem <= MAX_PRRLDD_PPRDN_RING_SIZE &&
2090 [ # # # # ]: 0 : at[cur_atom].valence == 3 && at[cur_atom].chem_bonds_valence == 3 &&
2091 [ # # # # : 0 : !at[cur_atom].charge && !at[cur_atom].radical && !at[cur_atom].num_H &&
# # ]
2092 : : /* check the "from" atom (on the left from cur atom) */
2093 [ # # ]: 0 : at[iat_from = at[cur_atom].neighbor[from_ord]].el_number == EL_NUMBER_C &&
2094 [ # # ]: 0 : at[iat_from].nNumAtInRingSystem == 1 &&
2095 [ # # ]: 0 : at[iat_from].valence == 3 &&
2096 [ # # ]: 0 : at[iat_from].chem_bonds_valence == 4 &&
2097 [ # # # # : 0 : !at[iat_from].charge && !at[iat_from].radical && !at[iat_from].num_H)
# # ]
2098 : : {
2099 : : /* check neighbors of the "from" atom (on the left from cur atom) */
2100 [ # # ]: 0 : for (i = 0; i < at[iat_from].valence; i++)
2101 : : {
2102 : 0 : neigh = at[iat_from].neighbor[i];
2103 [ # # ]: 0 : if (neigh == cur_atom)
2104 : : {
2105 : : ;
2106 : : }
2107 : : else
2108 : : {
2109 [ # # ]: 0 : if (at[iat_from].bond_type[i] == BOND_SINGLE)
2110 : : {
2111 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C)
2112 : : {
2113 : 0 : goto check_next_derivative;
2114 : : }
2115 : : }
2116 : : else
2117 : : {
2118 [ # # ]: 0 : if (at[iat_from].bond_type[i] == BOND_DOUBLE)
2119 : : {
2120 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_O ||
2121 [ # # # # ]: 0 : at[neigh].valence != 1 || at[neigh].chem_bonds_valence != 2 ||
2122 [ # # # # : 0 : at[neigh].charge || at[neigh].radical || at[neigh].num_H)
# # ]
2123 : : {
2124 : 0 : goto check_next_derivative;
2125 : : }
2126 : : }
2127 : : else
2128 : : {
2129 : 0 : goto check_next_derivative;
2130 : : }
2131 : : }
2132 : : }
2133 : : }
2134 : :
2135 : : /* check the ring */
2136 : 0 : iat_from = cur_atom;
2137 : 0 : neigh = at[cur_atom].neighbor[!from_ord]; /* any except "from" atom */
2138 : 0 : i = 1;
2139 [ # # ]: 0 : if (at[cur_atom].nRingSystem != at[neigh].nRingSystem)
2140 : : {
2141 : 0 : goto check_next_derivative;
2142 : : }
2143 : : do
2144 : : {
2145 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C ||
2146 [ # # ]: 0 : at[neigh].valence != 2 ||
2147 [ # # ]: 0 : at[neigh].chem_bonds_valence != 2 ||
2148 [ # # ]: 0 : at[neigh].num_H != 2 ||
2149 [ # # # # ]: 0 : at[neigh].charge || at[neigh].radical)
2150 : : {
2151 : 0 : goto check_next_derivative;
2152 : : }
2153 : 0 : i++; /* at[neigh] satisfied the conditions */
2154 : 0 : k = at[neigh].neighbor[at[neigh].neighbor[0] == iat_from];
2155 : 0 : iat_from = neigh;
2156 : 0 : neigh = k;
2157 [ # # # # ]: 0 : } while (neigh != cur_atom && i <= MAX_PRRLDD_PPRDN_RING_SIZE);
2158 : :
2159 [ # # # # ]: 0 : if (neigh == cur_atom &&
2160 [ # # ]: 0 : MIN_PRRLDD_PPRDN_RING_SIZE <= i && i <= MAX_PRRLDD_PPRDN_RING_SIZE)
2161 : : {
2162 [ # # ]: 0 : if (da1)
2163 : : {
2164 : : #ifdef DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
2165 [ # # ]: 0 : if (i == PRRLDD_RING_SIZE)
2166 : : {
2167 : 0 : da1->typ[0] = da1->typ[1] = DERIV_RING2_PRRLDD_OUTSIDE_PRECUR;
2168 : : }
2169 : : #endif
2170 : : #ifdef DERIV_RING2_PPRDN_OUTSIDE_PRECUR
2171 [ # # ]: 0 : if (i == PPRDN_RING_SIZE)
2172 : : {
2173 : 0 : da1->typ[0] = da1->typ[1] = DERIV_RING2_PPRDN_OUTSIDE_PRECUR;
2174 : : }
2175 : : #endif
2176 : 0 : ord[0] = !from_ord;
2177 [ # # ]: 0 : ord[1] = ( ( !from_ord + 1 ) ^ ( from_ord + 1 ) ) - 1; /* the 3rd possible index out of (0,1,2) */
2178 : 0 : k = ( ord[1] < ord[0] );
2179 : 0 : da1->ord[0] = ord[k]; /* smaller */
2180 : 0 : da1->ord[1] = ord[!k]; /* greater */
2181 : 0 : /*da1->num[0] = */da1->num[0] = i - 1; /* djb-rwth: unresolved issue -- revision required? / da1->num[1] = i-1? */
2182 : : }
2183 : 0 : return i;
2184 : : }
2185 : : }
2186 : :
2187 : 0 : check_next_derivative:
2188 : :
2189 : 0 : return 0;
2190 : : }
2191 : : #endif /* defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) || defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) */
2192 : :
2193 : :
2194 : : #ifdef DERIV_DANSYL
2195 : :
2196 : :
2197 : : /****************************************************************************
2198 : :
2199 : : O CH--CH
2200 : : || // \\
2201 : : R--O[cur]--S[iS]--C[a] CH => R--OH
2202 : : || \ /cj bond from c
2203 : : O [b]C====C[c] CH3
2204 : : / \ /
2205 : : CH [d]C--N[iN]-CH3
2206 : : \\ //dj bond from d
2207 : : CH--CH
2208 : :
2209 : : -O[cur]= -O- or -S- or -NH-
2210 : :
2211 : : ****************************************************************************/
2212 : 0 : int is_Dansyl( inp_ATOM *at,
2213 : : int cur_atom,
2214 : : int to_ord, DERIV_AT *da,
2215 : : DERIV_AT *da1 )
2216 : : {
2217 : 0 : int i, a, b, c, d, cj = -1, dj = -1, neigh, k, iS /* S */, iN /* N */;
2218 [ # # # # : 0 : if (( (( at[cur_atom].el_number == EL_NUMBER_O || at[cur_atom].el_number == EL_NUMBER_S || at[cur_atom].el_number == EL_NUMBER_N ) &&
# # ]
2219 [ # # # # ]: 0 : at[cur_atom].valence == 2 && at[cur_atom].num_H == ( at[cur_atom].el_number == EL_NUMBER_N ) &&
2220 [ # # ]: 0 : at[cur_atom].nNumAtInRingSystem == 1) ||
2221 [ # # # # : 0 : (at[cur_atom].el_number == EL_NUMBER_N && at[cur_atom].valence == 3 && at[cur_atom].num_H == 0) ) &&
# # ]
2222 [ # # ]: 0 : at[cur_atom].valence == at[cur_atom].chem_bonds_valence &&
2223 [ # # ]: 0 : at[iS /* S */ = at[cur_atom].neighbor[to_ord]].el_number == EL_NUMBER_S &&
2224 [ # # # # ]: 0 : at[iS].valence == 4 && at[iS].chem_bonds_valence == 6) /* djb-rwth: addressing LLVM warning */
2225 : : {
2226 : : /* neighbors of S; 6=1+1+2+2, 1+1+1+3 only. Therefore, we do not need to count (=O) neighbors */
2227 [ # # ]: 0 : for (i = 0, a = -1; i < at[iS].valence; i++)
2228 : : {
2229 [ # # ]: 0 : if (cur_atom == ( neigh = at[iS].neighbor[i] ))
2230 : : {
2231 : : ;
2232 : : }
2233 : : else
2234 : : {
2235 [ # # ]: 0 : if (at[iS].bond_type[i] == BOND_DOUBLE)
2236 : : {
2237 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_O ||
2238 [ # # ]: 0 : at[neigh].valence != 1 ||
2239 [ # # ]: 0 : at[neigh].chem_bonds_valence != 2 ||
2240 [ # # # # : 0 : at[neigh].num_H || at[neigh].charge || at[neigh].radical)
# # ]
2241 : : {
2242 : 0 : goto check_next_derivative;
2243 : : }
2244 : : }
2245 : : else
2246 : : {
2247 [ # # # # ]: 0 : if (at[iS].bond_type[i] == BOND_SINGLE && a == -1)
2248 : : {
2249 [ # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C ||
2250 [ # # ]: 0 : at[neigh].nNumAtInRingSystem != 10 ||
2251 [ # # ]: 0 : at[neigh].valence != 3 ||
2252 [ # # ]: 0 : at[neigh].chem_bonds_valence != 4 ||
2253 [ # # # # : 0 : at[neigh].num_H || at[neigh].charge || at[neigh].radical ||
# # ]
2254 [ # # ]: 0 : at[neigh].bond_type[at[neigh].neighbor[0] == iS] != BOND_ALTERN)
2255 : : {
2256 : 0 : goto check_next_derivative;
2257 : : }
2258 : 0 : a = neigh;
2259 : : }
2260 : : else
2261 : : {
2262 : 0 : goto check_next_derivative;
2263 : : }
2264 : : }
2265 : : }
2266 : : }
2267 : :
2268 [ # # ]: 0 : if (a < 0)
2269 : : {
2270 : 0 : goto check_next_derivative;
2271 : : }
2272 : :
2273 : : /* at[a] - aromatic, j1 - index of its bond to its aromatic neighbor */
2274 : : /* find at[b] */
2275 [ # # ]: 0 : for (i = k = 0, b = -1; i < at[a].valence; i++)
2276 : : {
2277 : 0 : neigh = at[a].neighbor[i];
2278 [ # # ]: 0 : if (neigh == iS)
2279 : : {
2280 : 0 : k += 1;
2281 : : }
2282 : : else
2283 : : {
2284 [ # # ]: 0 : if (at[a].bond_type[i] != BOND_ALTERN)
2285 : : {
2286 : 0 : goto check_next_derivative; /* not Dansyl */
2287 : : }
2288 [ # # # # ]: 0 : if (at[neigh].valence == 3 && b == -1)
2289 : : {
2290 : 0 : b = neigh;
2291 : 0 : k += 10;
2292 : : }
2293 : : else
2294 : : {
2295 [ # # # # ]: 0 : if (at[neigh].valence == 2 && at[neigh].chem_bonds_valence == 3)
2296 : : {
2297 : 0 : k += 100;
2298 : : }
2299 : : else
2300 : : {
2301 : 0 : goto check_next_derivative; /* not Dansyl */
2302 : : }
2303 : : }
2304 : : }
2305 : : }
2306 : :
2307 : : /* structure check: C[b] */
2308 [ # # ]: 0 : if (k != 111)
2309 : : {
2310 : 0 : goto check_next_derivative; /* not Dansyl */
2311 : : }
2312 [ # # ]: 0 : if (at[b].el_number != EL_NUMBER_C ||
2313 [ # # ]: 0 : at[b].valence != 3 ||
2314 [ # # ]: 0 : at[b].chem_bonds_valence != 4 ||
2315 [ # # # # : 0 : at[b].charge || at[b].radical || at[b].num_H)
# # ]
2316 : : {
2317 : 0 : goto check_next_derivative; /* not Dansyl */
2318 : : }
2319 : :
2320 : : /* find at[c] */
2321 [ # # ]: 0 : for (i = k = 0, c = -1; i < at[b].valence; i++)
2322 : : {
2323 [ # # ]: 0 : if (at[b].bond_type[i] != BOND_ALTERN)
2324 : : {
2325 : 0 : goto check_next_derivative; /* not Dansyl */
2326 : : }
2327 : 0 : neigh = at[b].neighbor[i];
2328 [ # # ]: 0 : if (neigh == a)
2329 : : {
2330 : 0 : k += 1;
2331 : : }
2332 : : else
2333 : : {
2334 [ # # # # ]: 0 : if (at[neigh].valence == 3 && c == -1)
2335 : : {
2336 : 0 : c = neigh;
2337 : 0 : k += 10;
2338 : : }
2339 : : else
2340 : : {
2341 [ # # # # ]: 0 : if (at[neigh].valence == 2 && at[neigh].chem_bonds_valence == 3)
2342 : : {
2343 : 0 : k += 100;
2344 : : }
2345 : : else
2346 : : {
2347 : 0 : goto check_next_derivative; /* not Dansyl */
2348 : : }
2349 : : }
2350 : : }
2351 : : }
2352 : :
2353 [ # # ]: 0 : if (k != 111)
2354 : : {
2355 : 0 : goto check_next_derivative; /* not Dansyl */
2356 : : }
2357 : :
2358 : : /* structure check: C[c] */
2359 [ # # ]: 0 : if (at[c].el_number != EL_NUMBER_C ||
2360 [ # # ]: 0 : at[c].valence != 3 ||
2361 [ # # ]: 0 : at[c].chem_bonds_valence != 4 ||
2362 [ # # # # : 0 : at[c].charge || at[c].radical || at[c].num_H)
# # ]
2363 : : {
2364 : 0 : goto check_next_derivative; /* not Dansyl */
2365 : : }
2366 : :
2367 : : /* find at[d] */
2368 [ # # ]: 0 : for (i = k = 0, d = -1; i < at[c].valence; i++)
2369 : : {
2370 [ # # ]: 0 : if (at[c].bond_type[i] != BOND_ALTERN)
2371 : : {
2372 : 0 : goto check_next_derivative; /* not Dansyl */
2373 : : }
2374 : 0 : neigh = at[c].neighbor[i];
2375 [ # # ]: 0 : if (neigh == b)
2376 : : {
2377 : 0 : k += 1;
2378 : : }
2379 : : else
2380 : : {
2381 [ # # # # ]: 0 : if (at[neigh].valence == 3 && d == -1)
2382 : : {
2383 : 0 : d = neigh;
2384 : 0 : k += 10;
2385 : : }
2386 : : else
2387 : : {
2388 [ # # ]: 0 : if (at[neigh].valence == 2)
2389 : : {
2390 : 0 : cj = i;
2391 : 0 : k += 100;
2392 : : }
2393 : : else
2394 : : {
2395 : 0 : goto check_next_derivative; /* not Dansyl */
2396 : : }
2397 : : }
2398 : : }
2399 : : }
2400 [ # # ]: 0 : if (k != 111)
2401 : : {
2402 : 0 : goto check_next_derivative; /* not Dansyl */
2403 : : }
2404 : :
2405 : : /* structure check: C[d] */
2406 [ # # ]: 0 : if (at[d].el_number != EL_NUMBER_C ||
2407 [ # # ]: 0 : at[d].valence != 3 ||
2408 [ # # ]: 0 : at[d].chem_bonds_valence != 4 ||
2409 [ # # # # : 0 : at[d].charge || at[d].radical || at[d].num_H)
# # ]
2410 : : {
2411 : 0 : goto check_next_derivative; /* not Dansyl */
2412 : : }
2413 : : /* find at[iN] */
2414 [ # # ]: 0 : for (i = k = 0, iN = -1; i < at[d].valence; i++)
2415 : : {
2416 : 0 : neigh = at[d].neighbor[i];
2417 [ # # ]: 0 : if (neigh == c)
2418 : : {
2419 : 0 : k += 1;
2420 : : }
2421 : : else
2422 : : {
2423 [ # # # # ]: 0 : if (at[neigh].valence == 3 && iN == -1)
2424 : : {
2425 : 0 : iN = neigh;
2426 : 0 : k += 10;
2427 : : }
2428 : : else
2429 : : {
2430 [ # # # # : 0 : if (at[neigh].valence == 2 && at[neigh].chem_bonds_valence == 3 && at[d].bond_type[i] == BOND_ALTERN)
# # ]
2431 : : {
2432 : 0 : dj = i;
2433 : 0 : k += 100;
2434 : : }
2435 : : else
2436 : : {
2437 : 0 : goto check_next_derivative; /* not Dansyl */
2438 : : }
2439 : : }
2440 : : }
2441 : : }
2442 : :
2443 : : /* structure check: at[iN] */
2444 [ # # ]: 0 : if (k != 111)
2445 : : {
2446 : 0 : goto check_next_derivative; /* not Dansyl */
2447 : : }
2448 [ # # ]: 0 : if (at[iN].el_number != EL_NUMBER_N ||
2449 [ # # ]: 0 : at[iN].valence != 3 ||
2450 [ # # ]: 0 : at[iN].chem_bonds_valence != 3 ||
2451 [ # # # # : 0 : at[iN].charge || at[d].radical || at[d].num_H)
# # ]
2452 : : {
2453 : 0 : goto check_next_derivative; /* not Dansyl */
2454 : : }
2455 : :
2456 : : /* find attached to N 2 methyls */
2457 [ # # ]: 0 : for (i = 0; i < at[iN].valence; i++)
2458 : : {
2459 [ # # # # ]: 0 : if (( neigh = at[iN].neighbor[i] ) != d &&
2460 : 0 : !is_Methyl( at, neigh ))
2461 : : {
2462 : 0 : goto check_next_derivative; /* not Dansyl */
2463 : : }
2464 : : }
2465 : :
2466 : : /* check aromatic chain d-dj-...b and c-cj-...a */
2467 [ # # # # ]: 0 : if (check_arom_chain( at, at[d].neighbor[dj] /* first*/, d /*from*/, b /*to*/, 4 ) &&
2468 : 0 : check_arom_chain( at, at[c].neighbor[cj] /* first*/, c /*from*/, a /*to*/, 4 ))
2469 : : {
2470 [ # # ]: 0 : if (da1)
2471 : : {
2472 : 0 : da1->typ[0] = DERIV_DANSYL;
2473 : 0 : da1->ord[0] = to_ord;
2474 : 0 : da1->num[0] = 16;
2475 : : }
2476 : 0 : return DERIV_DANSYL;
2477 : : }
2478 : : }
2479 : :
2480 : 0 : check_next_derivative:
2481 : :
2482 : 0 : return 0;
2483 : : }
2484 : : #endif /* DERIV_DANSYL */
2485 : :
2486 : :
2487 : : /****************************************************************************/
2488 : 0 : int is_possibly_deriv_neigh( inp_ATOM *at,
2489 : : int iat,
2490 : : int iord,
2491 : : int type,
2492 : : char cFlags )
2493 : : {
2494 : 0 : int neigh = at[iat].neighbor[iord]; /* inside derivatizing agent */
2495 : 0 : int neigh_from = -1;
2496 : 0 : U_CHAR el = at[neigh].el_number;
2497 : 0 : int bOk = 0;
2498 [ # # # # : 0 : switch (type)
# ]
2499 : : {
2500 : 0 : case DERIV_BRIDGE_O:
2501 : 0 : neigh_from = at[iat].neighbor[!iord]; /* inside precursor
2502 : : neigh_from iat
2503 : : -> A--O--B -> traversing from A(neigh_from) to B(neigh); may we cut O--B bond? */
2504 : : /* do not cut bond "---" in A=Si(IV), B(=O), B=C: Si(IV)-O---B(=O) */
2505 [ # # # # : 0 : if (!( is_C_or_S_DB_O( at, neigh ) && is_Si_IV( at, neigh_from ) ) &&
# # ]
2506 : 0 : !is_C_unsat_not_arom( at, neigh ))
2507 : : {
2508 [ # # ]: 0 : bOk = ( el == EL_NUMBER_C ||
2509 [ # # ]: 0 : el == EL_NUMBER_SI ||
2510 [ # # ]: 0 : el == EL_NUMBER_S ||
2511 [ # # # # ]: 0 : el == EL_NUMBER_P ) &&
2512 : 0 : is_deriv_chain2( at, iat, DERIV_BRIDGE_O, -1, iord, 0, NULL, 0, NULL, 0, NULL );
2513 : : }
2514 : 0 : break;
2515 : :
2516 : : #ifdef DERIV_RO_COX
2517 : 0 : case DERIV_RO_COX:
2518 : : /* iord
2519 : : -> R-O--[C(=O)-B]; -B: -CH3, C[n]F[2n+1] 0 < n < 4; may we cut O--C bond? */
2520 : 0 : neigh_from = at[iat].neighbor[!iord];
2521 [ # # ]: 0 : if (at[neigh_from].el_number == EL_NUMBER_C &&
2522 [ # # ]: 0 : at[iat].el_number == EL_NUMBER_O &&
2523 [ # # # # ]: 0 : at[neigh].el_number == EL_NUMBER_C &&
2524 : 0 : is_C_or_S_DB_O( at, neigh ))
2525 : : {
2526 : 0 : bOk = 1; /*is_deriv_chain2( at, iat, DERIV_RO_COX, iord, 0 ); does nothing */
2527 : : }
2528 : 0 : break;
2529 : : #endif
2530 : :
2531 : 0 : case DERIV_BRIDGE_NH:
2532 : : /* -> A--NH--B -> traversing from A(neigh_from) to B(neigh); may we cut NH--B bond? */
2533 [ # # ]: 0 : bOk = ( is_C_or_S_DB_O( at, neigh ) ||
2534 : : /*is_C_Alk( at, neigh, cFlags ) ||*/
2535 : 0 : is_Si_IV( at, neigh ) /*||
2536 [ # # # # : 0 : is_P_TB_N( at, neigh )*/ ) && !( is_C_unsat_not_arom( at, neigh ) ) &&
# # ]
2537 : 0 : is_deriv_chain2( at, iat, DERIV_BRIDGE_NH, -1, iord, 0, NULL, 0, NULL, 0, NULL );
2538 : 0 : break;
2539 : 0 : case DERIV_AMINE_tN:
2540 [ # # ]: 0 : bOk = ( is_C_or_S_DB_O( at, neigh ) ||
2541 : : /*is_C_Alk( at, neigh, cFlags ) ||*/
2542 : 0 : is_Si_IV( at, neigh ) /*||
2543 [ # # # # : 0 : is_P_TB_N( at, neigh )*/ ) && !( is_C_unsat_not_arom( at, neigh ) ) &&
# # ]
2544 : 0 : is_deriv_chain2( at, iat, DERIV_AMINE_tN, -1, iord, 0, NULL, 0, NULL, 0, NULL );
2545 : 0 : break;
2546 : : }
2547 : :
2548 : 0 : return bOk;
2549 : : }
2550 : :
2551 : :
2552 : : /****************************************************************************
2553 : : Determines derivative type on the forward step of the DFS
2554 : : ****************************************************************************/
2555 : 0 : int get_traversed_deriv_type( inp_ATOM *at,
2556 : : DERIV_AT *da,
2557 : : int k,
2558 : : DERIV_AT *da1,
2559 : : char cFlags )
2560 : : {
2561 : : /* at[k] is attachment point of the precursor */
2562 : : /* at[(int)at[k].neighbor[m]] is inside precursor */
2563 : : /* at[(int)at[k].neighbor[!m]] is inside derivatizing agent */
2564 : : /* !!! Except DERIV_RING_O_OUTSIDE_PRECURSOR, DERIV_RING_NH_OUTSIDE_PRECURSOR !!! */
2565 : : /* when at[k] is B or C attached to two atoms of the precursor */
2566 : : int i, j, m, n1, nBlockSystemFrom, nOrdBack1, nOrdBack2, nOrdBack3, nBackType1, nBackType2;
2567 : :
2568 : : #if( defined(DERIV_X_OXIME) || defined(DERIV_RO_COX) || defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
2569 : : int n0, n2, n3;
2570 : : #endif
2571 : :
2572 : 0 : memset( da1, 0, sizeof( *da1 ) ); /* djb-rwth: memset_s C11/Annex K variant? */
2573 [ # # ]: 0 : if (at[k].cFlags & cFlags)
2574 : : {
2575 : 0 : return 0;
2576 : : }
2577 : :
2578 [ # # # # ]: 0 : for (m = 0; m < at[k].valence && !( at[(int) at[k].neighbor[m]].cFlags & cFlags ); m++)
2579 : : {
2580 : : ;
2581 : : }
2582 [ # # ]: 0 : if (m == at[k].valence)
2583 : : {
2584 : 0 : return -1; /* error: at least one neighbor must have cFlags */
2585 : : /* traversing at[k] from at[(int)at[k].neighbor[m]] */
2586 : : }
2587 [ # # # # ]: 0 : if (at[k].valence == 1 && at[k].num_H && (
2588 [ # # ]: 0 : at[k].el_number == EL_NUMBER_O ||
2589 [ # # ]: 0 : at[k].el_number == EL_NUMBER_N ||
2590 [ # # ]: 0 : at[k].el_number == EL_NUMBER_S ||
2591 [ # # ]: 0 : at[k].el_number == EL_NUMBER_P ))
2592 : : {
2593 : 0 : return DERIV_NOT;
2594 : : }
2595 [ # # ]: 0 : if (is_el_a_metal( at[k].el_number ))
2596 : : {
2597 : 0 : return DERIV_NOT;
2598 : : }
2599 : : #ifdef NEVER
2600 : : if (at[k].el_number == EL_NUMBER_N && at[k].valence >= 2 && at[k].chem_bonds_valence <= 3)
2601 : : {
2602 : : return DERIV_NOT; /* prohibit -N-, -N=, allow -N# as in isocyano -N#C or NO2 */
2603 : : }
2604 : : #endif
2605 : : /* m is the ord of the bond from which at[k] was reached first time */
2606 [ # # # # ]: 0 : if (da[k].typ[0] && ( da[k].typ[0] & DERIV_UNEXPADABLE ) == da[k].typ[0])
2607 : : {
2608 : 0 : return 0;
2609 : : }
2610 : : #ifdef DERIV_X_OXIME
2611 [ # # # # ]: 0 : if (at[k].nNumAtInRingSystem == 1 && at[k].el_number == EL_NUMBER_N &&
2612 [ # # # # ]: 0 : at[k].valence == 2 && at[k].chem_bonds_valence == 3 &&
2613 [ # # # # : 0 : !at[k].num_H && !at[k].charge && !at[k].radical &&
# # ]
2614 [ # # ]: 0 : at[n0 = at[k].neighbor[m]].el_number == EL_NUMBER_C && /* inside precursor */
2615 [ # # ]: 0 : at[n1 = at[k].neighbor[!m]].el_number == EL_NUMBER_O && /* inside derivatizing agent */
2616 [ # # # # ]: 0 : at[k].bond_type[m] == BOND_DOUBLE && at[k].bond_type[!m] == BOND_SINGLE &&
2617 [ # # # # : 0 : at[n0].valence == 3 - at[n0].num_H && at[n0].chem_bonds_valence == 4 - at[n0].num_H && !at[n0].charge && !at[n0].radical && /* C */
# # # # ]
2618 [ # # # # : 0 : at[n1].valence == 2 && at[n1].chem_bonds_valence == 2 && !at[n1].charge && !at[n1].radical /* O */
# # # # ]
2619 : : )
2620 : : {
2621 : : /* found C==N--O */
2622 : : /* traversing from C to O; C(at[neighbor[m]]) has cFlag; N is at[k]; N-O bond is to be broken */
2623 : : /* m !m
2624 : : n0 k n1 n2 n2 n2 n3 n2 n3 n2 n3...
2625 : : C==N--O--R; -R: -CH3, -CH2-CH3, -Si(CH3)3, -CH2-C6H5; cut N-O and replace =N- with =O 2013-08-22 DT */
2626 : : /* check other neighbors of C: they should be C,H or C,C */
2627 [ # # ]: 0 : for (i = 0; i < at[n0].valence; i++)
2628 : : {
2629 [ # # # # ]: 0 : if (at[n0].neighbor[i] != k && at[at[n0].neighbor[i]].el_number != EL_NUMBER_C)
2630 : : {
2631 : 0 : goto check_next_derivative; /* wrong neighbor */
2632 : : }
2633 : : }
2634 : : /* found C
2635 : : |
2636 : : C==N==O
2637 : : |
2638 : : C
2639 : : */
2640 : : /* find other neighbor of O */
2641 : 0 : n2 = at[n1].neighbor[at[n1].neighbor[0] == k];
2642 [ # # ]: 0 : if (is_Si_IV( at, n2 ))
2643 : : {
2644 : 0 : int n4 = -1;
2645 [ # # ]: 0 : for (i = 0; i < at[n2].valence; i++)
2646 : : {
2647 : 0 : int n3 = at[n2].neighbor[i];
2648 [ # # ]: 0 : if (n3 == n1)
2649 : : {
2650 : 0 : continue; /* atom O */
2651 : : }
2652 [ # # # # ]: 0 : if (at[n3].el_number != EL_NUMBER_C || at[n3].charge ||
2653 [ # # # # ]: 0 : at[n3].radical || at[n3].chem_bonds_valence != at[n3].valence)
2654 : 0 : goto check_next_derivative; /* wrong neighbor */
2655 [ # # # # : 0 : if (n4 == -1 && at[n3].valence == 4 && !at[n3].num_H)
# # ]
2656 : : {
2657 : 0 : n4 = n3; /* possibly tret-butyl */
2658 : : }
2659 : : else
2660 : : {
2661 [ # # # # ]: 0 : if (at[n3].chem_bonds_valence != 1 || at[n3].num_H != 3)
2662 : : {
2663 : 0 : goto check_next_derivative; /* wrong neighbor */
2664 : : /* methyl identified */
2665 : : }
2666 : : }
2667 : : }
2668 [ # # ]: 0 : if (n4 == -1)
2669 : : {
2670 : : #ifdef UNDERIV_X_OXIME_TMS
2671 : : /* found C
2672 : : | n2
2673 : : C==N==O--Si(CH3)3
2674 : : |
2675 : : C
2676 : : */
2677 : 0 : da1->ord[0] = !m; /* ord of neighbor O, already checked */
2678 : 0 : da1->typ[0] = DERIV_X_OXIME; /* type */
2679 : 0 : da1->num[0] = 5; /* 5 atoms: -O-Si(CH3)3 -O-TMS*/
2680 : 0 : return DERIV_X_OXIME; /* >C=N-O-Si(CH3)3 */
2681 : : #else
2682 : : goto check_next_derivative; /* wrong neighbor */
2683 : : #endif
2684 : : }
2685 : : #ifndef UNDERIV_X_OXIME_TBDMS
2686 : : goto check_next_derivative; /* do not include TBDMS */
2687 : : #endif
2688 : :
2689 [ # # ]: 0 : for (i = 0; i < at[n4].valence; i++)
2690 : : {
2691 : 0 : int n3 = at[n4].neighbor[i];
2692 [ # # ]: 0 : if (n3 == n2)
2693 : : {
2694 : 0 : continue; /* atom Si */
2695 : : }
2696 [ # # # # ]: 0 : if (at[n3].el_number != EL_NUMBER_C || at[n3].charge ||
2697 [ # # # # ]: 0 : at[n3].radical || at[n3].chem_bonds_valence != at[n3].valence)
2698 : : {
2699 : 0 : goto check_next_derivative; /* wrong neighbor */
2700 : : }
2701 [ # # # # ]: 0 : if (at[n3].chem_bonds_valence != 1 || at[n3].num_H != 3)
2702 : : {
2703 : 0 : goto check_next_derivative; /* wrong neighbor */
2704 : : /* methyl identified */
2705 : : }
2706 : : }
2707 : 0 : da1->ord[0] = !m; /* ord of neighbor O, already checked */
2708 : 0 : da1->typ[0] = DERIV_X_OXIME; /* type */
2709 : 0 : da1->num[0] = 8; /* 8 atoms: -O-Si(CH3)2-C(CH3)3 -O-TBDMS */
2710 : 0 : return DERIV_X_OXIME; /* >C=N-O-Si(CH3)2-C(CH3)3 */
2711 : :
2712 : : }
2713 [ # # ]: 0 : if (at[n2].el_number != EL_NUMBER_C)
2714 : : {
2715 : 0 : goto check_next_derivative; /* wrong neighbor */
2716 : : }
2717 [ # # # # : 0 : if (at[n2].chem_bonds_valence == 1 && at[n2].num_H == 3 && !at[n2].charge && !at[n2].radical)
# # # # ]
2718 : : {
2719 : 0 : da1->ord[0] = !m; /* ord of neighbor O, already checked */
2720 : 0 : da1->typ[0] = DERIV_X_OXIME; /* type */
2721 : 0 : da1->num[0] = 2; /* 2 atoms: -O-CH3 */
2722 : 0 : return DERIV_X_OXIME; /* >C=N-O-CH3 */
2723 : : }
2724 [ # # # # : 0 : if (at[n2].valence != 2 || at[n2].chem_bonds_valence != 2 || at[n2].num_H != 2 || at[n2].charge || at[n2].radical)
# # # # #
# ]
2725 : : {
2726 : 0 : goto check_next_derivative; /* wrong neighbor */
2727 : : }
2728 : 0 : n3 = at[n2].neighbor[at[n2].neighbor[0] == n1];
2729 [ # # # # : 0 : if (at[n3].chem_bonds_valence == 1 && at[n3].num_H == 3 && !at[n3].charge && !at[n3].radical)
# # # # ]
2730 : : {
2731 : 0 : da1->ord[0] = !m; /* ord of neighbor O, already checked */
2732 : 0 : da1->typ[0] = DERIV_X_OXIME; /* type */
2733 : 0 : da1->num[0] = 3; /* 3 atoms: -O-CH2-CH3 */
2734 : 0 : return DERIV_X_OXIME; /* >C=N-O-CH2-CH3 */
2735 : : }
2736 [ # # # # : 0 : if (at[n3].valence == 3 && at[n3].chem_bonds_valence == 4 && !at[n3].num_H && !at[n3].charge && !at[n3].radical &&
# # # # #
# ]
2737 [ # # # # : 0 : at[n3].nRingSystem != at[n2].nRingSystem && at[n3].bCutVertex && at[n3].nNumAtInRingSystem == 6)
# # ]
2738 : : {
2739 [ # # ]: 0 : if (is_Phenyl( at, n2, n3 ))
2740 : : {
2741 : 0 : da1->ord[0] = !m; /* ord of neighbor O, already checked */
2742 : 0 : da1->typ[0] = DERIV_X_OXIME; /* type */
2743 : 0 : da1->num[0] = 8; /* 8 atoms: O--CH2-C6H5 */
2744 : 0 : return DERIV_X_OXIME; /* >C=N-O-CH2-C6H5 */
2745 : : }
2746 : : }
2747 : : }
2748 : :
2749 : 0 : check_next_derivative:
2750 : : #endif /* DERIV_X_OXIME */
2751 : : #ifdef DERIV_DANSYL
2752 [ # # ]: 0 : if (at[k].nNumAtInRingSystem == 1 &&
2753 [ # # # # : 0 : ( (( at[k].el_number == EL_NUMBER_O || at[k].el_number == EL_NUMBER_S ) && at[k].valence == 2) ||
# # ]
2754 [ # # # # : 0 : (at[k].el_number == EL_NUMBER_N && at[k].valence == 2 && at[k].num_H == 1) || (at[k].valence == 3 && at[k].num_H == 2) )) /* djb-rwth: addressing LLVM warnings */
# # # # #
# ]
2755 : : {
2756 : : DERIV_AT da2;
2757 : 0 : memset( &da2, 0, sizeof( da2 ) ); /* djb-rwth: memset_s C11/Annex K variant? */
2758 [ # # ]: 0 : for (j = 0, n1 = 0; j < at[k].valence; j++)
2759 : : {
2760 [ # # ]: 0 : if (j == m)
2761 : : {
2762 : 0 : continue;
2763 : : }
2764 [ # # ]: 0 : if (at[i = at[k].neighbor[j]].el_number == EL_NUMBER_S &&
2765 [ # # # # : 0 : at[i].valence == 4 && at[i].chem_bonds_valence == 6 &&
# # ]
2766 : 0 : is_Dansyl( at, k, j, da, &da2 ))
2767 : : {
2768 : 0 : n1++;
2769 : : }
2770 : : }
2771 [ # # ]: 0 : if (n1 == 1)
2772 : : {
2773 : 0 : *da1 = da2;
2774 : 0 : return DERIV_DANSYL;
2775 : : }
2776 : : }
2777 : : #endif
2778 : :
2779 [ # # # # : 0 : if (at[k].nNumAtInRingSystem == 1 && ( at[k].el_number == EL_NUMBER_O || at[k].el_number == EL_NUMBER_S ) &&
# # ]
2780 [ # # # # ]: 0 : at[k].valence == 2 && at[k].chem_bonds_valence == 2 &&
2781 [ # # # # : 0 : !at[k].num_H && !at[k].charge && !at[k].radical)
# # ]
2782 : : {
2783 : : /* at[k].neighbor[m] k n1==at[k].neighbor[!m] */
2784 : : /* -> A--O--B -> traversing from A to B; cut O--B */
2785 : : /* check for carboxy A(=O)-O-B and A--O--B(=O) */
2786 : : /*int has_A_CO = is_C_or_S_DB_O( at, at[k].neighbor[m] );*/
2787 : 0 : int has_B_CO = is_C_or_S_DB_O( at, n1 = at[k].neighbor[!m] );/* B is C(=o) or S(=O) */
2788 : 0 : int is_A_Si_IV = is_Si_IV( at, at[k].neighbor[m] ); /* A is >Si< */
2789 : : /* int is_B_Si_IV = is_Si_IV( at, at[k].neighbor[!m] );*/
2790 : :
2791 : : #ifdef DERIV_RO_COX
2792 : : /* n3
2793 : : at[k].neighbor[m] k n1 n2
2794 : : R--O--C--X; -X = -CH3, -Phenyl, -C[n]F[2n+1] 0 < n < 4
2795 : : || (acetate)(benzoate)
2796 : : O
2797 : : */
2798 : 0 : n3 = at[k].neighbor[m]; /* R */
2799 [ # # # # : 0 : if (has_B_CO && is_C_DB_O( at, n1 ) && /* B:n1 is >C=O */
# # ]
2800 [ # # ]: 0 : !is_silyl2( at, n3, k ) &&
2801 : 0 : !is_el_a_metal( at[n3].el_number ))
2802 : : {
2803 [ # # ]: 0 : for (j = 0; j < at[n1].valence; j++)
2804 : : {
2805 [ # # # # ]: 0 : if (at[n1].neighbor[j] != k && at[n1].bond_type[j] == BOND_SINGLE)
2806 : : {
2807 : : /* the only suspected neighbor */
2808 : 0 : n2 = at[n1].neighbor[j]; /* X */
2809 : 0 : n0 = is_CF3_or_linC3F7a(at, n2, n1); /* djb-rwth: addressing LLVM warning */
2810 [ # # ]: 0 : if (n0)
2811 : : {
2812 : 0 : n0 = 2 + 3 * n0 + 1; /* (6,9,12 atoms) -C(=O)C[n]F[2n+1]; is_CF3_or_linC3F7a returns n */
2813 : : }
2814 : : #ifdef UNDERIV_RO_COX_Me
2815 : : else
2816 [ # # ]: 0 : if (is_Methyl( at, n2 ))
2817 : : {
2818 : : /* methyl */
2819 [ # # # # ]: 0 : if (!is_Methyl( at, n3 ) && !is_Ethyl( at, k, n3 ))
2820 : : {
2821 : 0 : n0 = 3; /* 3 atoms: -C(=O)-CH3 */
2822 : : }
2823 : : }
2824 : : #endif /* UNDERIV_RO_COX_Me */
2825 : : #ifdef UNDERIV_RO_COX_Et
2826 : : else
2827 : : if (is_Ethyl( at, n1, n2 ))
2828 : : { /* ethyl */
2829 : : if (!is_Methyl( at, n3 ) && !is_Ethyl( at, k, n3 ))
2830 : : {
2831 : : n0 = 4; /* 4 atoms: -C(=O)-CH2-CH3 */
2832 : : }
2833 : : }
2834 : : #endif /* UNDERIV_RO_COX_Et */
2835 : : #ifdef UNDERIV_RO_COX_BENZOATES
2836 : : else
2837 [ # # ]: 0 : if (is_Phenyl( at, n1, n2 ))
2838 : : {
2839 [ # # # # ]: 0 : if (!is_Methyl( at, n3 ) && !is_Ethyl( at, k, n3 ))
2840 : : {
2841 : 0 : n0 = 2 + 6; /* 8 atoms -C(=O)-C6H5 */
2842 : : }
2843 : : }
2844 : : #endif /* UNDERIV_RO_COX_BENZOATES */
2845 : : #ifdef UNDERIV_RO_COX_PENTAFLOUROBENZOATES
2846 : : else
2847 [ # # ]: 0 : if (is_PentaFluoroPhenyl( at, n1, n2 ))
2848 : : {
2849 [ # # # # ]: 0 : if (!is_Methyl( at, n3 ) && !is_Ethyl( at, k, n3 ))
2850 : : {
2851 : 0 : n0 = 13; /* 13 atoms -C(=O)-C6F5 */
2852 : : }
2853 : : }
2854 : : #endif /* UNDERIV_RO_COX_PENTAFLOUROBENZOATES */
2855 [ # # ]: 0 : if (n0)
2856 : : {
2857 : 0 : da1->ord[0] = !m; /* ord of at[k]'s, that is, -O-'s neighbor X in C(=O)-X */
2858 : 0 : da1->typ[0] = DERIV_RO_COX; /* type */
2859 : 0 : da1->num[0] = n0; /* num atoms in derivatizing attachement */
2860 : 0 : return DERIV_RO_COX; /* R--O--C(=O)--X; -X = -CH3, -C[n]F[2n+1] 0 < n < 4, -Phenyl, -C6F5 */
2861 : : }
2862 : 0 : break;
2863 : : }
2864 : : }
2865 : : }
2866 : : #endif /* DERIV_RO_COX */
2867 : :
2868 [ # # # # ]: 0 : if (is_A_Si_IV && has_B_CO)
2869 : : {
2870 : : /* precursor | deriv.agent */
2871 : : ; /* do not cut bond --- in A=>Si<, B(=O), B=C,S: Si(IV)-O---B(=O) */
2872 : : }
2873 : : else
2874 : : {
2875 : : /* at[k] is precursor's attachment point;
2876 : : at[at[k].neighbor[!m]] belongs to drivatizing agent,
2877 : : at[at[k].neighbor[m]] was marked (from_atom) */
2878 [ # # ]: 0 : if (is_possibly_deriv_neigh( at, k, !m, DERIV_BRIDGE_O, cFlags ))
2879 : : {
2880 : 0 : da1->ord[0] = !m; /* ord of neighbor B, not traversed yet */
2881 : 0 : da1->typ[0] = DERIV_BRIDGE_O; /* type */
2882 : 0 : return DERIV_BRIDGE_O; /* Representative: R-C(=O)-O(!m)--[D] */
2883 : : }
2884 : : }
2885 : : }
2886 : :
2887 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
2888 : : /*
2889 : : R--C==N Me or Et
2890 : : | \ /
2891 : : | C
2892 : : | / \
2893 : : O--CH2 Me or ET
2894 : : */
2895 [ # # # # : 0 : if (at[k].el_number == EL_NUMBER_O && at[k].nNumAtInRingSystem == 5 &&
# # ]
2896 : 0 : is_DERIV_RING_DMOX_DEOX_O( at, k, m, da, da1 ))
2897 : : {
2898 : 0 : return DERIV_RING_DMOX_DEOX_O;
2899 : : }
2900 [ # # # # ]: 0 : if (at[k].el_number == EL_NUMBER_N && at[k].nNumAtInRingSystem == 5 &&
2901 [ # # # # : 0 : at[k].valence == 2 && at[k].chem_bonds_valence == 3 &&
# # ]
2902 : 0 : is_DERIV_RING_DMOX_DEOX_N( at, k, m, da, da1 ))
2903 : : {
2904 : 0 : return DERIV_RING_DMOX_DEOX_N;
2905 : : }
2906 : : #endif
2907 : :
2908 : : /* R1--NH--R2 */
2909 [ # # # # ]: 0 : if (at[k].bCutVertex && at[k].el_number == EL_NUMBER_N &&
2910 [ # # # # ]: 0 : at[k].valence == 2 && at[k].chem_bonds_valence == at[k].valence &&
2911 [ # # # # : 0 : at[k].valence + at[k].num_H == 3 && !at[k].charge && !at[k].radical)
# # ]
2912 : : {
2913 : 0 : da1->ord[0] = !m; /* ord of neighbor B, not traversed yet */
2914 : 0 : da1->typ[0] = DERIV_BRIDGE_NH; /* type */
2915 : 0 : return DERIV_BRIDGE_NH; /* R1-NH-R2 amine */
2916 : : }
2917 : : /*
2918 : : R2
2919 : : /
2920 : : R1----N
2921 : : \
2922 : : R3
2923 : : */
2924 : :
2925 : :
2926 [ # # # # ]: 0 : if (at[k].bCutVertex && at[k].el_number == EL_NUMBER_N &&
2927 [ # # # # ]: 0 : at[k].valence == 3 && at[k].chem_bonds_valence == at[k].valence &&
2928 [ # # # # : 0 : at[k].valence + at[k].num_H == 3 && !at[k].charge && !at[k].radical)
# # ]
2929 : : {
2930 : : #if( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) || defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) )
2931 [ # # ]: 0 : if (at[j = at[k].neighbor[m]].el_number == EL_NUMBER_C &&
2932 [ # # # # : 0 : at[j].valence == 3 && at[j].chem_bonds_valence == 4 &&
# # ]
2933 : 0 : ( i = is_DERIV_RING2_PRRLDD_PPRDN( at, k, m, da, da1 ) ))
2934 : : {
2935 : 0 : return i;
2936 : : }
2937 : : else
2938 : : #endif
2939 : : {
2940 : 0 : int rm1 = ( at[at[k].neighbor[m]].nRingSystem == at[at[k].neighbor[( m + 1 ) % 3]].nRingSystem );
2941 : 0 : int rm2 = ( at[at[k].neighbor[m]].nRingSystem == at[at[k].neighbor[( m + 2 ) % 3]].nRingSystem );
2942 : 0 : int r12 = ( at[at[k].neighbor[( m + 1 ) % 3]].nRingSystem == at[at[k].neighbor[( m + 2 ) % 3]].nRingSystem );
2943 : 0 : int ord[2] = { -1, -1 };
2944 : 0 : i = 0; /* type: tertriary amine: DERIV_AMINE_tN */
2945 [ # # # ]: 0 : switch (rm1 + rm2 + r12)
2946 : : {
2947 : 0 : case 0:
2948 : : /* -N< has no ring bonds */
2949 [ # # ]: 0 : if (is_possibly_deriv_neigh( at, k, ( m + 1 ) % 3, DERIV_AMINE_tN, cFlags ))
2950 : : {
2951 : 0 : ord[i++] = ( m + 1 ) % 3; /* ord of a non-ring neighbor, not traversed yet */
2952 : : }
2953 [ # # ]: 0 : if (is_possibly_deriv_neigh( at, k, ( m + 2 ) % 3, DERIV_AMINE_tN, cFlags ))
2954 : : {
2955 : 0 : ord[i++] = ( m + 2 ) % 3; /* ord of another non-ring neighbor, not traversed yet */
2956 : : }
2957 [ # # # # ]: 0 : if (i == 2 && ord[0] > ord[1])
2958 : : {
2959 : 0 : int tmp = ord[0];
2960 : 0 : ord[0] = ord[1];
2961 : 0 : ord[1] = tmp;
2962 : : }
2963 : 0 : break;
2964 : :
2965 : 0 : case 1:
2966 : : /* -N< has one non-ring bond; do not consider [m] because it is "from" bond */
2967 [ # # # # ]: 0 : if (rm1 && is_possibly_deriv_neigh( at, k, ( m + 2 ) % 3, DERIV_AMINE_tN, cFlags ))
2968 : : {
2969 : 0 : ord[i++] = ( m + 2 ) % 3; /* ord of a single non-ring neighbor, not traversed yet */
2970 : : }
2971 : : else
2972 [ # # # # ]: 0 : if (rm2 && is_possibly_deriv_neigh( at, k, ( m + 1 ) % 3, DERIV_AMINE_tN, cFlags ))
2973 : : {
2974 : 0 : ord[i++] = ( m + 1 ) % 3; /* ord of a single non-ring neighbor, not traversed yet */
2975 : : }
2976 : : /* r12 != 0 <=> at[k]neighbor[m] is the only non-ring bond; ignore it because it is "from" bond */
2977 : : }
2978 [ # # ]: 0 : for (j = 0; j < i; j++)
2979 : : {
2980 : 0 : da1->ord[j] = ord[j];
2981 : 0 : da1->typ[j] = DERIV_AMINE_tN;
2982 : : }
2983 [ # # ]: 0 : if (i)
2984 : : {
2985 : 0 : return DERIV_AMINE_tN;
2986 : : }
2987 : 0 : return 0; /* all neighbors or two untraversed edges are in one ring system */
2988 : : }
2989 : : }
2990 : :
2991 : : /*-----------------------------------------------------------------*/
2992 : : /* DERIV_RING_O_OUTSIDE_PRECURSOR, DERIV_RING_NH_OUTSIDE_PRECURSOR */
2993 [ # # ]: 0 : if (at[k].bCutVertex && /* DD */
2994 [ # # ]: 0 : at[k].valence == at[k].chem_bonds_valence &&
2995 [ # # # # : 0 : ( !at[k].num_H || (at[k].el_number == EL_NUMBER_C && 1 == at[k].num_H) ) &&
# # ]
2996 [ # # # # ]: 0 : !at[k].charge && !at[k].radical &&
2997 [ # # # # ]: 0 : ( (at[k].el_number == EL_NUMBER_C && at[k].valence + at[k].num_H == 4) ||
2998 [ # # # # ]: 0 : (at[k].el_number == EL_NUMBER_SI && at[k].valence == 4) ||
2999 [ # # # # ]: 0 : (at[k].el_number == EL_NUMBER_B && at[k].valence == 3) )) /* djb-rwth: addressing LLVM warning */
3000 : : {
3001 : :
3002 : : /*--> j \ entering path: ->X--O--DD
3003 : : --X--O v
3004 : : | \ k / DD = C, CH, Si, B
3005 : : | DD
3006 : : | / \ O = O, S, NH = at[j], going from DD
3007 : : --Y--O
3008 : : X, Y -- must be C
3009 : : */
3010 : 0 : nBlockSystemFrom = 0;
3011 : 0 : nBackType1 = nBackType2 = 0;
3012 : 0 : nOrdBack1 = nOrdBack2 = nOrdBack3 = -1;
3013 : 0 : j = (int) at[k].neighbor[m];
3014 : : ; /* X */
3015 [ # # # # : 0 : if (( at[j].el_number == EL_NUMBER_O || at[j].el_number == EL_NUMBER_S ) && at[j].valence == 2 &&
# # ]
3016 [ # # ]: 0 : at[j].chem_bonds_valence == at[j].valence &&
3017 [ # # ]: 0 : at[j].nNumAtInRingSystem >= 5 &&
3018 [ # # ]: 0 : at[n1 = at[j].neighbor[at[j].neighbor[0] == k]].el_number == EL_NUMBER_C && /* X is C */
3019 [ # # # # : 0 : !at[j].num_H && !at[j].charge && !at[j].radical) /* djb-rwth: ignoring LLVM warning: variable used */
# # ]
3020 : : {
3021 : 0 : nBackType1 = DERIV_RING_O_OUTSIDE_PRECURSOR;
3022 : 0 : nBlockSystemFrom = at[j].nBlockSystem;
3023 : 0 : nOrdBack1 = m; /* predecessor */
3024 : : }
3025 : : else
3026 [ # # # # ]: 0 : if (at[j].el_number == EL_NUMBER_N && at[j].valence == 2 &&
3027 [ # # ]: 0 : at[j].chem_bonds_valence == at[j].valence &&
3028 [ # # ]: 0 : at[j].nNumAtInRingSystem >= 5 &&
3029 [ # # ]: 0 : at[n1 = at[j].neighbor[at[j].neighbor[0] == k]].el_number == EL_NUMBER_C && /* X is C */
3030 [ # # # # : 0 : 1 == at[j].num_H && !at[j].charge && !at[j].radical) /* djb-rwth: ignoring LLVM warning: variable used */
# # ]
3031 : : {
3032 : 0 : nBackType1 = DERIV_RING_NH_OUTSIDE_PRECURSOR;
3033 : 0 : nBlockSystemFrom = at[j].nBlockSystem;
3034 : 0 : nOrdBack1 = m; /* predecessor */
3035 : : }
3036 [ # # ]: 0 : if (nBlockSystemFrom)
3037 : : {
3038 : : int num1, num2, bFound;
3039 : 0 : at[k].cFlags |= CFLAG_MARK_BLOCK;
3040 : : /* mark precursor atoms + at[k] */
3041 : 0 : num1 = mark_atoms_cFlags( at, at[k].neighbor[nOrdBack1], 1, CFLAG_MARK_BLOCK );
3042 [ # # ]: 0 : for (i = 0; i < at[k].valence; i++)
3043 : : {
3044 [ # # ]: 0 : if (i == nOrdBack1)
3045 : 0 : continue;
3046 : 0 : j = (int) at[k].neighbor[i];
3047 : 0 : bFound = 0;
3048 [ # # ]: 0 : if (at[j].cFlags & CFLAG_MARK_BLOCK)
3049 : : {
3050 [ # # # # : 0 : if (( at[j].el_number == EL_NUMBER_O || at[j].el_number == EL_NUMBER_S ) && at[j].valence == 2 &&
# # ]
3051 [ # # ]: 0 : at[j].chem_bonds_valence == at[j].valence &&
3052 [ # # ]: 0 : at[j].nNumAtInRingSystem >= 5 &&
3053 [ # # ]: 0 : at[n1 = at[j].neighbor[at[j].neighbor[0] == k]].el_number == EL_NUMBER_C && /* Y is C */
3054 [ # # # # : 0 : !at[j].num_H && !at[j].charge && !at[j].radical) /* djb-rwth: ignoring LLVM warning: variable used */
# # ]
3055 : : {
3056 : 0 : bFound = 1;
3057 [ # # ]: 0 : if (nOrdBack2 < 0)
3058 : : {
3059 : 0 : nOrdBack2 = i; /* predecessor #2 */
3060 : 0 : nBackType2 = DERIV_RING_O_OUTSIDE_PRECURSOR;
3061 : : }
3062 : : else
3063 : : {
3064 : 0 : nOrdBack3 = i; /* predecessor #3 -- should not happen */
3065 : : }
3066 : : }
3067 [ # # # # ]: 0 : if (at[j].el_number == EL_NUMBER_N && at[j].valence == 2 &&
3068 [ # # ]: 0 : at[j].chem_bonds_valence == at[j].valence &&
3069 [ # # ]: 0 : at[j].nNumAtInRingSystem >= 5 &&
3070 [ # # ]: 0 : at[n1 = at[j].neighbor[at[j].neighbor[0] == k]].el_number == EL_NUMBER_C && /* Y is C */
3071 [ # # # # : 0 : 1 == at[j].num_H && !at[j].charge && !at[j].radical) /* djb-rwth: ignoring LLVM warning: variable used */
# # ]
3072 : : {
3073 : 0 : bFound = 1;
3074 [ # # ]: 0 : if (nOrdBack2 < 0)
3075 : : {
3076 : 0 : nOrdBack2 = i; /* predecessor #2 */
3077 : 0 : nBackType2 = DERIV_RING_NH_OUTSIDE_PRECURSOR;
3078 : : }
3079 : : else
3080 : : {
3081 : 0 : nOrdBack3 = i; /* predecessor #3 -- should not happen */
3082 : : }
3083 : : }
3084 [ # # ]: 0 : if (!bFound)
3085 : : {
3086 : 0 : nOrdBack3 = 99; /* reject: wrong neighboring atom in the same block */
3087 : 0 : break;
3088 : : }
3089 : : }
3090 : : }
3091 : 0 : num2 = unmark_atoms_cFlags( at, k, 0, CFLAG_MARK_BLOCK, CFLAG_MARK_BLOCK_INV );
3092 [ # # ]: 0 : if (num1 != num2)
3093 : : {
3094 : 0 : return -1; /* mark_atoms_cFlags() program error */
3095 : : }
3096 [ # # # # ]: 0 : if (nOrdBack2 >= 0 && nOrdBack3 < 0)
3097 : : {
3098 : : /* note: da1 refers to DD, which is a neighbor of 2 precursor atoms; ord point to precursor attachment points, O */
3099 [ # # ]: 0 : if (nOrdBack1 < nOrdBack2)
3100 : : {
3101 : 0 : da1->ord[0] = nOrdBack1; /* ord of a ring neighbor, traversed */
3102 : 0 : da1->typ[0] = nBackType1;
3103 : 0 : da1->ord[1] = nOrdBack2; /* ord of another ring neighbor, not traversed yet */
3104 : 0 : da1->typ[1] = nBackType2;
3105 : : }
3106 : : else
3107 : : {
3108 : 0 : da1->ord[0] = nOrdBack2; /* ord of a ring neighbor, traversed */
3109 : 0 : da1->typ[0] = nBackType2;
3110 : 0 : da1->ord[1] = nOrdBack1; /* ord of another ring neighbor, not traversed yet */
3111 : 0 : da1->typ[1] = nBackType1;
3112 : : }
3113 : 0 : return nBackType1 | nBackType2;
3114 : : }
3115 : : }
3116 : : }
3117 : :
3118 : 0 : return 0;
3119 : : }
3120 : :
3121 : :
3122 : : /****************************************************************************/
3123 : 0 : int add_to_da( DERIV_AT *da, DERIV_AT *add )
3124 : : {
3125 : : /* if add has more than 1 element the elements are in ascending add.ord[] order */
3126 : : int i, j, len_da, len_add, numAddHiPri, numDaHiPri;
3127 : :
3128 [ # # # # ]: 0 : for (len_da = 0, numDaHiPri = 0; len_da < DERIV_AT_LEN && da->typ[len_da]; len_da++)
3129 : : {
3130 : 0 : numDaHiPri += ( 0 != ( da->typ[len_da] & DERIV_UNEXPADABLE ) );
3131 : : }
3132 [ # # # # ]: 0 : for (len_add = 0, numAddHiPri = 0; len_add < DERIV_AT_LEN && da->typ[len_add]; len_add++) /* djb-rwth: addressing coverity ID #499516 -- definitely not a copy-paste error */
3133 : : {
3134 : 0 : numAddHiPri += ( 0 != ( add->typ[len_add] & DERIV_UNEXPADABLE ) );
3135 : : }
3136 : :
3137 : : /* HiPri replaces non-HiPri derivatives */
3138 [ # # # # ]: 0 : if (numAddHiPri && !numDaHiPri)
3139 : : {
3140 : : /* no harm if already len_da=0 */
3141 : 0 : memset( da, 0, sizeof( *da ) ); /* djb-rwth: memset_s C11/Annex K variant? */
3142 : 0 : len_da = 0;
3143 : : }
3144 : : else
3145 : : {
3146 : : /* non-HiPri derivatives cannot be added to HiPri */
3147 [ # # # # ]: 0 : if (!numAddHiPri && numDaHiPri)
3148 : : {
3149 : 0 : return 0;
3150 : : }
3151 : : }
3152 : :
3153 [ # # # # ]: 0 : for (j = 0; j < DERIV_AT_LEN && add->typ[j]; j++)
3154 : : {
3155 [ # # ]: 0 : for (i = 0; i < len_da; i++)
3156 : : {
3157 [ # # ]: 0 : if (add->ord[j] == da->ord[i])
3158 : : {
3159 [ # # ]: 0 : if (add->typ[j] != da->typ[i])
3160 : : {
3161 : 0 : return -1; /* error, should not happen */
3162 : : }
3163 [ # # ]: 0 : if (add->num[j] != da->num[i])
3164 : : {
3165 : 0 : return -2; /* error, should not happen */
3166 : : }
3167 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3168 [ # # # # : 0 : if ((( len_da>1 || j ) && ( add->other_atom || da->other_atom )) || (1 == len_da && add->other_atom != da->other_atom)) /* djb-rwth: addressing LLVM warning */
# # # # #
# # # ]
3169 : : {
3170 : 0 : return -3; /* other_atom implies single bond to cut */
3171 : : }
3172 : : #endif
3173 : 0 : break;
3174 : : }
3175 : : }
3176 : :
3177 [ # # ]: 0 : if (i == len_da)
3178 : : {
3179 : : /* add->ord[j] has different ord values from all da->ord[]; add or replace */
3180 [ # # ]: 0 : if (len_da < DERIV_AT_LEN)
3181 : : {
3182 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3183 [ # # # # : 0 : if (( i || j ) && add->other_atom)
# # ]
3184 : : {
3185 : 0 : return -3; /* other_atom implies single bond to cut */
3186 : : }
3187 : : #endif
3188 : 0 : da->ord[i] = add->ord[j];
3189 : 0 : da->typ[i] = add->typ[j];
3190 : 0 : da->num[i] = add->num[j];
3191 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3192 : 0 : da->other_atom = add->other_atom;
3193 : : #endif
3194 : 0 : len_da++;
3195 : : }
3196 : : else
3197 : : {
3198 : 0 : return -4; /* overflow, should not happen */
3199 : : }
3200 : : }
3201 : : }
3202 : :
3203 : 0 : return 0;
3204 : : }
3205 : :
3206 : :
3207 : : /****************************************************************************
3208 : : DFS search for atoms that do not have a flag
3209 : : ****************************************************************************/
3210 : 0 : int mark_atoms_deriv( inp_ATOM *at,
3211 : : DERIV_AT *da,
3212 : : int start,
3213 : : int num,
3214 : : char cFlags,
3215 : : int *pbFound )
3216 : : {
3217 : 0 : int i, nFound = 0, ret; /* djb-rwth: removing redundant variables */
3218 : : DERIV_AT da1;
3219 : : int ret2; /* moved from below 2024-09-01 DT */
3220 : : DERIV_AT da2; /* moved from below 2024-09-01 DT */
3221 : 0 : da1.other_atom = 0; /* djb-rwth: initialisation needed for if conditons */
3222 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3223 : : /* djb-rwth: initialisation needed to avoid garbage values in add_to_da function call; fixing coverity ID #499492 */
3224 : 0 : memset(da2.typ, 0, DERIV_AT_LEN * sizeof(da2.typ[0]));
3225 : 0 : memset(da2.ord, '\0', DERIV_AT_LEN * sizeof(da2.ord[0]));
3226 : 0 : memset(da2.num, '\0', DERIV_AT_LEN * sizeof(da2.num[0]));
3227 : 0 : da2.other_atom = 0; /* djb-rwth: initialisation needed for if conditons */
3228 : : #endif
3229 [ # # ]: 0 : if (!( at[start].cFlags & cFlags ))
3230 : : {
3231 [ # # ]: 0 : if (DERIV_NOT == ( ret = get_traversed_deriv_type( at, da, start, &da1, cFlags ) ))
3232 : : {
3233 : 0 : nFound++; /* at[start] cannot belong to a derivatizing agent */
3234 : : }
3235 : 0 : num++;
3236 : 0 : at[start].cFlags |= cFlags;
3237 [ # # ]: 0 : if (da1.typ[0])
3238 : : {
3239 : : /* possibly a derivatization agent attachment point. */
3240 : : /* check neighbors that have not been traversed yet */
3241 : 0 : int n1 = 0, n2 = 0, i1 = -1, i2 = -1, nFound1 = 0, nFound2 = 0;
3242 [ # # # # : 0 : switch (da1.typ[0])
# # # # ]
3243 : : {
3244 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3245 : 0 : case DERIV_RING_DMOX_DEOX_N:
3246 : : case DERIV_RING_DMOX_DEOX_O:
3247 : 0 : ret2 = get_traversed_deriv_type( at, da, da1.other_atom - 1, &da2, cFlags );
3248 [ # # ]: 0 : if (ret != ( ret2 ^ DERIV_RING_DMOX_DEOX ))
3249 : : {
3250 : : /* bug */
3251 : 0 : nFound++; /* at[start] cannot belong to a derivatizing agent */
3252 : 0 : goto check_neighbors; /* bypass add_to_da( da+start, &da1 ) */
3253 : : }
3254 : : /*at[da1.other_atom-1].cFlags |= cFlags;*/
3255 : 0 : n1 = da1.num[0]; /* terminal fragment has been identified; don't search subfragments */
3256 : 0 : nFound++;
3257 : 0 : break;
3258 : : #endif
3259 : : #ifdef DERIV_X_OXIME
3260 : 0 : case DERIV_X_OXIME:
3261 : 0 : n1 = da1.num[0]; /* terminal fragment has been identified; don't search subfragments */
3262 : 0 : nFound++;
3263 : 0 : break;
3264 : : #endif
3265 : : #ifdef DERIV_RO_COX
3266 : 0 : case DERIV_RO_COX:
3267 : 0 : n1 = da1.num[0]; /* terminal fragment has been identified; don't search subfragments */
3268 : 0 : nFound++;
3269 : 0 : break;
3270 : : #endif
3271 : : #if( defined(DERIV_RING2_PRRLDD_OUTSIDE_PRECUR) || defined(DERIV_RING2_PPRDN_OUTSIDE_PRECUR) || defined(DERIV_DANSYL) )
3272 : : #ifdef DERIV_RING2_PRRLDD_OUTSIDE_PRECUR
3273 : 0 : case DERIV_RING2_PRRLDD_OUTSIDE_PRECUR:
3274 : : #endif
3275 : : #ifdef DERIV_RING2_PPRDN_OUTSIDE_PRECUR
3276 : : case DERIV_RING2_PPRDN_OUTSIDE_PRECUR:
3277 : : #endif
3278 : : #ifdef DERIV_DANSYL
3279 : : case DERIV_DANSYL:
3280 : : #endif
3281 : 0 : n1 = da1.num[0]; /* terminal fragment has been identified; don't search subfragments */
3282 : 0 : nFound++;
3283 : 0 : break;
3284 : : #endif
3285 : :
3286 : 0 : case DERIV_BRIDGE_O:
3287 : : case DERIV_BRIDGE_NH:
3288 : 0 : n1 = mark_atoms_deriv( at, da, at[start].neighbor[(int) da1.ord[0]], 0, cFlags, &nFound1 );
3289 [ # # # # ]: 0 : if (n1 > MAX_AT_DERIV || nFound1)
3290 : : {
3291 : 0 : da1.typ[0] = 0;
3292 : : }
3293 : : else
3294 : : {
3295 : 0 : da1.num[0] = n1;
3296 : 0 : nFound++;
3297 : : }
3298 : 0 : break;
3299 : 0 : case DERIV_AMINE_tN:
3300 : 0 : n1 = mark_atoms_deriv( at, da, at[start].neighbor[i1 = da1.ord[0]], 0, cFlags, &nFound1 ); /* djb-rwth: ignoring LLVM warning: variable used */
3301 [ # # ]: 0 : if (da1.typ[1])
3302 : : {
3303 : 0 : n2 = mark_atoms_deriv( at, da, at[start].neighbor[i2 = da1.ord[1]], 0, cFlags, &nFound2 ); /* djb-rwth: ignoring LLVM warning: variable used */
3304 : : }
3305 [ # # # # : 0 : if (0 < n1 && n1 <= MAX_AT_DERIV && !nFound1)
# # ]
3306 : : {
3307 : 0 : da1.num[0] = n1;
3308 : 0 : i = 1;
3309 : 0 : nFound++;
3310 : : }
3311 : : else
3312 : : {
3313 : 0 : da1.ord[0] = da1.ord[1];
3314 : 0 : da1.num[0] = da1.num[1];
3315 : 0 : da1.typ[0] = da1.typ[1];
3316 : 0 : da1.typ[1] = 0;
3317 : 0 : i = 0;
3318 : : }
3319 [ # # # # : 0 : if (0 < n2 && n2 <= MAX_AT_DERIV && !nFound2)
# # ]
3320 : : {
3321 : 0 : da1.num[i] = n2;
3322 : 0 : nFound++;
3323 : : }
3324 : : else
3325 : : {
3326 : 0 : da1.typ[i] = 0;
3327 : : }
3328 : 0 : break;
3329 : 0 : case DERIV_RING_O_OUTSIDE_PRECURSOR:
3330 : : case DERIV_RING_NH_OUTSIDE_PRECURSOR:
3331 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
3332 : : {
3333 [ # # # # : 0 : if (i != da1.ord[0] && i != da1.ord[1] && !( at[at[start].neighbor[i]].cFlags & cFlags ))
# # ]
3334 : : {
3335 [ # # ]: 0 : if (!n1)
3336 : : {
3337 : 0 : n1 = mark_atoms_deriv( at, da, at[start].neighbor[i1 = i], 0, cFlags, &nFound1 ); /* djb-rwth: ignoring LLVM warning: variable used */
3338 : : }
3339 : : else
3340 : : {
3341 : 0 : n2 = mark_atoms_deriv( at, da, at[start].neighbor[i2 = i], 0, cFlags, &nFound2 ); /* djb-rwth: ignoring LLVM warning: variable used */
3342 : : }
3343 : : }
3344 : : }
3345 [ # # # # : 0 : if (n1 + n2 + 1 > MAX_AT_DERIV || nFound1 || nFound2)
# # ]
3346 : : {
3347 : 0 : da1.typ[1] = da1.typ[0] = 0;
3348 : : }
3349 : : else
3350 : : {
3351 : 0 : da1.num[0] = n1;
3352 : 0 : da1.num[1] = n2;
3353 : 0 : nFound++;
3354 : : }
3355 : 0 : break;
3356 : : }
3357 : :
3358 : : /* --------- end of switch( da1.typ[0] ) ------- */
3359 [ # # ]: 0 : if (n1 < 0)
3360 : : {
3361 : 0 : return n1;
3362 : : }
3363 [ # # ]: 0 : if (n2 < 0)
3364 : : {
3365 : 0 : return n2; /* errors */
3366 : : }
3367 : :
3368 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3369 [ # # ]: 0 : if (da1.other_atom)
3370 : : {
3371 [ # # ]: 0 : if (da2.other_atom == start + 1)
3372 : : {
3373 [ # # ]: 0 : if ((i = add_to_da( da + da1.other_atom - 1, &da2 ))) /* djb-rwth: addressing LLVM warning */
3374 : : {
3375 : 0 : return i; /* error */
3376 : : }
3377 : : }
3378 : : else
3379 : : {
3380 : 0 : return -4; /* error */
3381 : : }
3382 : : }
3383 : : #endif
3384 [ # # ]: 0 : if ((i = add_to_da( da + start, &da1 ))) /* djb-rwth: addressing LLVM warning */
3385 : : {
3386 : 0 : return i; /* error */
3387 : : }
3388 : 0 : *pbFound += nFound1 + nFound2 + nFound;
3389 : 0 : num += n1 + n2;
3390 : : }
3391 : : else
3392 : : {
3393 : 0 : *pbFound += nFound;
3394 : : }
3395 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
3396 : 0 : check_neighbors:
3397 : : #endif
3398 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
3399 : : {
3400 : 0 : num = mark_atoms_deriv( at, da, at[start].neighbor[i], num, cFlags, pbFound );
3401 [ # # ]: 0 : if (num < 0)
3402 : : {
3403 : 0 : return num;
3404 : : }
3405 : : }
3406 : : }
3407 : : /* *pbFound = number of derivatizer attachment points traversed forward from at[start] */
3408 : :
3409 : 0 : return num; /* number of atoms traversed forward from at[start] */
3410 : : }
3411 : :
3412 : :
3413 : : /****************************************************************************/
3414 : 0 : int count_one_bond_atoms( inp_ATOM *at,
3415 : : DERIV_AT *da,
3416 : : int start,
3417 : : int ord,
3418 : : char cFlags,
3419 : : int *bFound )
3420 : : {
3421 : 0 : int num = 0;
3422 [ # # ]: 0 : if (!( at[at[start].neighbor[ord]].cFlags & cFlags ))
3423 : : {
3424 : 0 : at[at[start].neighbor[ord]].cFlags |= cFlags;
3425 : 0 : num++;
3426 : 0 : num = mark_atoms_deriv( at, da, start, num, cFlags, bFound );
3427 : : }
3428 : :
3429 : 0 : return num;
3430 : : }
3431 : :
3432 : :
3433 : : /****************************************************************************
3434 : : List of allowed derivatives
3435 : :
3436 : : Legend:
3437 : :
3438 : : ->- marks the bond to be disconnexted: X->-Y => XD + TY
3439 : : where TY is a derivatizing agent eventually to be discarded
3440 : :
3441 : : Allowed Derivative Types List
3442 : : =============================
3443 : :
3444 : : DERIV_BRIDGE_O, DERIV_BRIDGE_NH, DERIV_AMINE_tN
3445 : : -----------------------------------------------
3446 : : CH3 CH3 CH3 CH3 CH3
3447 : : | | | | |
3448 : : X->-Si--CH3 X->-Si---Si--CH3 X->-Si----C--CH3 X= O, NH, N
3449 : : | | | | |
3450 : : CH3 CH3 CH3 CH3 CH3
3451 : :
3452 : : 4 atoms 7 atoms 7 atoms is_silyl()
3453 : : - eliminated
3454 : :
3455 : :
3456 : :
3457 : : O O O F O O
3458 : : || || || | || ||
3459 : : R--C--O->-CH3 R--C--O->-CH2--CH3 R--C--O->-C--F R--C--O->-CF2-CF3 R--C--O->-CF2-CF2-CF3
3460 : : |
3461 : : F
3462 : :
3463 : :
3464 : :
3465 : : 1 atom 2 atoms 4 atoms 7 atoms 10 atoms
3466 : : is_Me_or_Et() is_Me_or_Et() is_CF3_or_linC3F7()
3467 : :
3468 : :
3469 : : A. DERIV_BRIDGE_NH, DERIV_AMINE_tN
3470 : : -----------------------------------
3471 : :
3472 : :
3473 : : O O O F O O
3474 : : || || || | || ||
3475 : : N->-C--CH3 N->-C--CH2--CH3 N->-C---C--F N->-C--CF2-CF3 N->-C--CF2-CF2-CF3
3476 : : |
3477 : : F
3478 : :
3479 : :
3480 : :
3481 : : 3 atoms 5 atoms 8 atoms 7 atoms 12 atoms
3482 : : is_Me_or_Et() is_Me_or_Et() is_CF3_or_linC3F7()
3483 : :
3484 : : DERIV_RING_O_OUTSIDE_PRECURSOR (da contains >B- or >C< or >CH- atom)
3485 : : ------------
3486 : :
3487 : : C----O R----O R----O
3488 : : | \ | \ CH3 | \
3489 : : | > | > / | >
3490 : : | \ | \ / | \
3491 : : | B--X | C | CH--Ph
3492 : : | / | / \ | /
3493 : : | > | > \ | >
3494 : : | / | / CH3 | /
3495 : : C----O R----O R----O
3496 : :
3497 : : 5-member 5 or 6-member 5 or 6-member
3498 : : X=Me,Et, n-Butyl
3499 : :
3500 : : 2 atoms 3 atoms 7 atoms
3501 : :
3502 : : DERIV_RING_NH_OUTSIDE_PRECURSOR
3503 : : ------------
3504 : :
3505 : : None in the list
3506 : :
3507 : : ****************************************************************************/
3508 : :
3509 : :
3510 : : /****************************************************************************/
3511 : 0 : int is_silyl( inp_ATOM *at, int start, int ord_prev )
3512 : : {
3513 : 0 : int i, neigh, num_Me = 0, iC_IV = -1, iSi_IV = -1, i_C_or_Si_IV;
3514 : :
3515 [ # # # # ]: 0 : if (at[start].el_number != EL_NUMBER_SI || at[start].valence != 4 ||
3516 [ # # ]: 0 : at[start].valence != at[start].chem_bonds_valence ||
3517 [ # # # # ]: 0 : at[start].charge || at[start].radical)
3518 : : {
3519 : 0 : return 0;
3520 : : }
3521 : :
3522 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
3523 : : {
3524 [ # # ]: 0 : if (i == ord_prev)
3525 : : {
3526 : 0 : continue;
3527 : : }
3528 : 0 : neigh = at[start].neighbor[i];
3529 [ # # # # ]: 0 : if (at[neigh].charge || at[neigh].radical ||
3530 [ # # ]: 0 : at[neigh].valence != at[neigh].chem_bonds_valence)
3531 : : {
3532 : 0 : return 0;
3533 : : }
3534 [ # # ]: 0 : if (at[neigh].valence == 4)
3535 : : {
3536 [ # # # # : 0 : if (at[neigh].el_number == EL_NUMBER_C && iC_IV < 0 && iSi_IV < 0)
# # ]
3537 : : {
3538 : 0 : iC_IV = neigh;
3539 : : }
3540 : : else
3541 : : {
3542 [ # # # # : 0 : if (at[neigh].el_number == EL_NUMBER_SI && iC_IV < 0 && iSi_IV < 0)
# # ]
3543 : : {
3544 : 0 : iSi_IV = neigh;
3545 : : }
3546 : : else
3547 : : {
3548 : 0 : return 0;
3549 : : }
3550 : : }
3551 : : }
3552 : : else
3553 : : {
3554 [ # # ]: 0 : if (at[neigh].valence == 1 &&
3555 [ # # ]: 0 : at[neigh].valence == at[neigh].chem_bonds_valence &&
3556 [ # # # # ]: 0 : at[neigh].el_number == EL_NUMBER_C && at[neigh].num_H == 3)
3557 : : {
3558 : 0 : num_Me++;
3559 : : }
3560 : : else
3561 : : {
3562 : 0 : return 0;
3563 : : }
3564 : : }
3565 : : }
3566 : :
3567 [ # # # # : 0 : if (num_Me == 3 && iC_IV < 0 && iSi_IV < 0)
# # ]
3568 : : {
3569 : 0 : return 1; /* Si(CH3)3 */
3570 : : }
3571 : :
3572 : : /* next C(IV) or Si(IV) */
3573 : : /* this is a fix requested by Anz. and suggested by Gary 09/21/2011
3574 : : it rejects -Si(CH3)2-Si(CH3)3 and allows only -Si(CH3)2-C(CH3)3
3575 : : */
3576 : 0 : i_C_or_Si_IV = iC_IV >= 0 ? iC_IV : -1;
3577 [ # # # # ]: 0 : if (num_Me != 2 || i_C_or_Si_IV < 0)
3578 : : {
3579 : 0 : return 0;
3580 : : }
3581 : :
3582 : 0 : num_Me = 0;
3583 [ # # ]: 0 : for (i = 0; i < at[i_C_or_Si_IV].valence; i++)
3584 : : {
3585 : 0 : neigh = at[i_C_or_Si_IV].neighbor[i];
3586 [ # # ]: 0 : if (neigh == start)
3587 : : {
3588 : 0 : continue;
3589 : : }
3590 [ # # # # ]: 0 : if (at[neigh].charge || at[neigh].radical ||
3591 [ # # ]: 0 : at[neigh].valence != at[neigh].chem_bonds_valence)
3592 : : {
3593 : 0 : return 0;
3594 : : }
3595 [ # # ]: 0 : if (at[neigh].valence == 1 &&
3596 [ # # ]: 0 : at[neigh].valence == at[neigh].chem_bonds_valence &&
3597 [ # # # # ]: 0 : at[neigh].el_number == EL_NUMBER_C && at[neigh].num_H == 3)
3598 : : {
3599 : 0 : num_Me++;
3600 : : }
3601 : : else
3602 : : {
3603 : 0 : return 0;
3604 : : }
3605 : : }
3606 [ # # ]: 0 : if (num_Me == 3)
3607 : : {
3608 : 0 : return 2; /* Si(CH3)2Si/C(CH3)3 */
3609 : : }
3610 : :
3611 : 0 : return 0;
3612 : : }
3613 : :
3614 : :
3615 : : /****************************************************************************/
3616 : 0 : int is_silyl2( inp_ATOM *at, int start, int from_at )
3617 : : {
3618 : 0 : int i, neigh, num_Me = 0, iC_IV = -1;
3619 : :
3620 [ # # # # ]: 0 : if (at[start].el_number != EL_NUMBER_SI || at[start].valence != 4 ||
3621 [ # # ]: 0 : at[start].valence != at[start].chem_bonds_valence ||
3622 [ # # # # ]: 0 : at[start].charge || at[start].radical)
3623 : : {
3624 : 0 : return 0;
3625 : : }
3626 : :
3627 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
3628 : : {
3629 : 0 : neigh = at[start].neighbor[i];
3630 [ # # ]: 0 : if (neigh == from_at)
3631 : : {
3632 : 0 : continue;
3633 : : }
3634 [ # # # # ]: 0 : if (at[neigh].charge || at[neigh].radical ||
3635 [ # # ]: 0 : at[neigh].valence != at[neigh].chem_bonds_valence)
3636 : : {
3637 : 0 : return 0;
3638 : : }
3639 [ # # ]: 0 : if (at[neigh].valence == 4)
3640 : : {
3641 [ # # # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_C && iC_IV < 0)
3642 : : {
3643 : 0 : iC_IV = neigh;
3644 : : }
3645 : : else
3646 : : {
3647 : 0 : return 0;
3648 : : }
3649 : : }
3650 : : else
3651 : : {
3652 [ # # ]: 0 : if (at[neigh].valence == 1 &&
3653 [ # # ]: 0 : at[neigh].valence == at[neigh].chem_bonds_valence &&
3654 [ # # # # ]: 0 : at[neigh].el_number == EL_NUMBER_C && at[neigh].num_H == 3)
3655 : : {
3656 : 0 : num_Me++;
3657 : : }
3658 : : else
3659 : : {
3660 : 0 : return 0;
3661 : : }
3662 : : }
3663 : : }
3664 [ # # # # ]: 0 : if (num_Me == 3 && iC_IV < 0)
3665 : : {
3666 : 0 : return 1; /* Si(CH3)3 */
3667 : : }
3668 : :
3669 : : /* next C(IV) */
3670 [ # # # # ]: 0 : if (num_Me != 2 || iC_IV < 0)
3671 : : {
3672 : 0 : return 0;
3673 : : }
3674 : :
3675 : 0 : num_Me = 0;
3676 [ # # ]: 0 : for (i = 0; i < at[iC_IV].valence; i++)
3677 : : {
3678 : 0 : neigh = at[iC_IV].neighbor[i];
3679 [ # # ]: 0 : if (neigh == start)
3680 : : {
3681 : 0 : continue;
3682 : : }
3683 [ # # # # ]: 0 : if (at[neigh].charge || at[neigh].radical ||
3684 [ # # ]: 0 : at[neigh].valence != at[neigh].chem_bonds_valence)
3685 : : {
3686 : 0 : return 0;
3687 : : }
3688 [ # # ]: 0 : if (at[neigh].valence == 1 &&
3689 [ # # ]: 0 : at[neigh].valence == at[neigh].chem_bonds_valence &&
3690 [ # # # # ]: 0 : at[neigh].el_number == EL_NUMBER_C && at[neigh].num_H == 3)
3691 : : {
3692 : 0 : num_Me++;
3693 : : }
3694 : : else
3695 : : {
3696 : 0 : return 0;
3697 : : }
3698 : : }
3699 [ # # ]: 0 : if (num_Me == 3)
3700 : : {
3701 : 0 : return 2; /* Si(CH3)2-Si/C(CH3)3, not Si(CH3)2-Si(CH3)3 */
3702 : : }
3703 : :
3704 : 0 : return 0;
3705 : : }
3706 : :
3707 : :
3708 : : /****************************************************************************/
3709 : 0 : int is_nButyl( inp_ATOM *at, int start, int ord_prev )
3710 : : {
3711 : 0 : int i, next, curr = start;
3712 : 0 : int prev = at[curr].neighbor[ord_prev];
3713 : 0 : const int len = 4;
3714 [ # # ]: 0 : for (i = 0; i < len; i++)
3715 : : {
3716 [ # # # # ]: 0 : if (at[curr].el_number != EL_NUMBER_C || at[curr].valence > 2 ||
3717 [ # # ]: 0 : at[curr].valence != at[curr].chem_bonds_valence ||
3718 [ # # ]: 0 : at[curr].chem_bonds_valence + at[curr].num_H != 4 ||
3719 [ # # # # ]: 0 : at[curr].charge || at[curr].radical)
3720 : : {
3721 : 0 : return 0;
3722 : : }
3723 [ # # ]: 0 : if (at[curr].valence == 2)
3724 : : {
3725 : 0 : next = at[curr].neighbor[prev == at[curr].neighbor[0]];
3726 : 0 : prev = curr;
3727 : 0 : curr = next;
3728 : : }
3729 : : else
3730 : : {
3731 : 0 : return i + 1 == len;
3732 : : }
3733 : : }
3734 : :
3735 : 0 : return 0;
3736 : : }
3737 : :
3738 : :
3739 : : /****************************************************************************/
3740 : 0 : int is_Me_or_Et( inp_ATOM *at, int start, int ord_prev )
3741 : : {
3742 : 0 : int i, neigh = -1;
3743 [ # # # # ]: 0 : if (at[start].el_number != EL_NUMBER_C || at[start].valence > 2 ||
3744 [ # # ]: 0 : at[start].valence != at[start].chem_bonds_valence ||
3745 [ # # ]: 0 : at[start].chem_bonds_valence + at[start].num_H != 4 ||
3746 [ # # # # ]: 0 : at[start].charge || at[start].radical)
3747 : 0 : return 0;
3748 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
3749 : : {
3750 [ # # ]: 0 : if (i == ord_prev)
3751 : : {
3752 : 0 : continue;
3753 : : }
3754 [ # # ]: 0 : if (neigh >= 0)
3755 : : {
3756 : 0 : return 0;
3757 : : }
3758 : :
3759 : 0 : neigh = at[start].neighbor[i];
3760 [ # # # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C || at[neigh].valence > 1 ||
3761 [ # # ]: 0 : at[neigh].valence != at[neigh].chem_bonds_valence ||
3762 [ # # ]: 0 : at[neigh].chem_bonds_valence + at[neigh].num_H != 4 ||
3763 [ # # # # ]: 0 : at[neigh].charge || at[neigh].radical)
3764 : : {
3765 : 0 : return 0;
3766 : : }
3767 : : }
3768 : :
3769 [ # # ]: 0 : return 1 + ( neigh >= 0 );
3770 : : }
3771 : :
3772 : :
3773 : : #ifdef NEVER
3774 : :
3775 : : /****************************************************************************
3776 : : CF3
3777 : : -CF3 or -CF<
3778 : : CF3
3779 : : ****************************************************************************/
3780 : :
3781 : : /****************************************************************************/
3782 : : int is_CF3_or_isoC3F7( inp_ATOM *at, int start, int ord_prev )
3783 : : {
3784 : : int i, k, num_C_IV, iC_IV[2], neigh, num_F, iC;
3785 : : if (at[start].el_number != EL_NUMBER_C || at[start].valence != 4 ||
3786 : : at[start].valence != at[start].chem_bonds_valence ||
3787 : : at[start].chem_bonds_valence + at[start].num_H != 4 ||
3788 : : at[start].charge || at[start].radical)
3789 : : return 0;
3790 : :
3791 : : iC_IV[0] = iC_IV[1] = num_F = 0;
3792 : :
3793 : : for (i = num_C_IV = 0; i < at[start].valence; i++)
3794 : : {
3795 : : if (i == ord_prev)
3796 : : {
3797 : : continue;
3798 : : }
3799 : :
3800 : : neigh = at[start].neighbor[i];
3801 : : if (at[neigh].valence != at[neigh].chem_bonds_valence ||
3802 : : at[neigh].charge || at[neigh].radical)
3803 : : return 0;
3804 : : if (at[neigh].el_number == EL_NUMBER_F)
3805 : : {
3806 : : if (at[neigh].chem_bonds_valence + at[neigh].num_H != 1)
3807 : : {
3808 : : return 0;
3809 : : }
3810 : : num_F++;
3811 : : }
3812 : : else
3813 : : {
3814 : : if (at[neigh].el_number == EL_NUMBER_C &&
3815 : : at[neigh].valence == 4 &&
3816 : : !at[neigh].num_H && !at[neigh].charge && !at[neigh].radical && num_C_IV < 2)
3817 : : {
3818 : :
3819 : : if (num_C_IV > 1)
3820 : : return 0;
3821 : :
3822 : : iC_IV[num_C_IV++] = neigh;
3823 : : }
3824 : : }
3825 : : }
3826 : : if (!num_C_IV && 3 == num_F)
3827 : : {
3828 : : return 1; /* -CF3 */
3829 : : }
3830 : : if (2 != num_C_IV || 1 != num_F)
3831 : : {
3832 : : return 0;
3833 : : }
3834 : :
3835 : : /* detect iso-C3F7 */
3836 : : for (k = 0; k < num_C_IV; k++)
3837 : : {
3838 : : iC = iC_IV[k];
3839 : : num_F = 0;
3840 : : for (i = 0; i < at[iC].valence; i++)
3841 : : {
3842 : : neigh = at[iC].neighbor[i];
3843 : : if (neigh == start)
3844 : : {
3845 : : continue;
3846 : : }
3847 : : if (at[neigh].valence != at[neigh].chem_bonds_valence ||
3848 : : at[neigh].charge || at[neigh].radical)
3849 : : {
3850 : : return 0;
3851 : : }
3852 : : if (at[neigh].el_number == EL_NUMBER_F)
3853 : : {
3854 : : if (at[neigh].chem_bonds_valence + at[neigh].num_H != 1)
3855 : : {
3856 : : return 0;
3857 : : }
3858 : : num_F++;
3859 : : }
3860 : : else
3861 : : {
3862 : : return 0;
3863 : : }
3864 : : }
3865 : : if (num_F != 3)
3866 : : {
3867 : : return 0;
3868 : : }
3869 : : }
3870 : :
3871 : : return 2; /* iso-C3F7 */
3872 : : }
3873 : :
3874 : : #endif
3875 : :
3876 : :
3877 : : /****************************************************************************/
3878 : 0 : int is_CF3_or_linC3F7a( inp_ATOM *at, int start, int iat_prev )
3879 : : {
3880 : : int i;
3881 : :
3882 [ # # ]: 0 : for (i = 0; i < at[start].valence; i++)
3883 : : {
3884 [ # # ]: 0 : if (iat_prev == at[start].neighbor[i])
3885 : : {
3886 : 0 : return is_CF3_or_linC3F7( at, start, i );
3887 : : }
3888 : : }
3889 : :
3890 : 0 : return 0;
3891 : : }
3892 : :
3893 : :
3894 : : /****************************************************************************/
3895 : 0 : int is_CF3_or_linC3F7( inp_ATOM *at, int start, int ord_prev )
3896 : : {
3897 : 0 : int i, num_C_IV, iC_IV, neigh, num_F, num_C = 0;
3898 : : AT_NUMB *p;
3899 : :
3900 [ # # ]: 0 : while (num_C < 4)
3901 : : {
3902 : :
3903 [ # # # # ]: 0 : if (at[start].el_number != EL_NUMBER_C || at[start].valence != 4 ||
3904 [ # # ]: 0 : at[start].valence != at[start].chem_bonds_valence ||
3905 [ # # ]: 0 : at[start].chem_bonds_valence + at[start].num_H != 4 ||
3906 [ # # # # ]: 0 : at[start].charge || at[start].radical)
3907 : : {
3908 : 0 : return 0;
3909 : : }
3910 : :
3911 : 0 : iC_IV = num_F = 0;
3912 : :
3913 [ # # ]: 0 : for (i = num_C_IV = 0; i < at[start].valence; i++)
3914 : : {
3915 [ # # ]: 0 : if (i == ord_prev)
3916 : : {
3917 : 0 : continue;
3918 : : }
3919 : :
3920 : 0 : neigh = at[start].neighbor[i];
3921 [ # # ]: 0 : if (at[neigh].valence != at[neigh].chem_bonds_valence ||
3922 [ # # # # ]: 0 : at[neigh].charge || at[neigh].radical)
3923 : : {
3924 : 0 : return 0;
3925 : : }
3926 [ # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_F)
3927 : : {
3928 [ # # ]: 0 : if (at[neigh].chem_bonds_valence + at[neigh].num_H != 1)
3929 : : {
3930 : 0 : return 0;
3931 : : }
3932 : 0 : num_F++;
3933 : : }
3934 : : else
3935 : : {
3936 [ # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_C &&
3937 [ # # ]: 0 : at[neigh].valence == 4 &&
3938 [ # # # # : 0 : !at[neigh].num_H && !at[neigh].charge && !at[neigh].radical && num_C_IV < 2)
# # # # ]
3939 : : {
3940 : :
3941 [ # # ]: 0 : if (num_C_IV)
3942 : : {
3943 : 0 : return 0;
3944 : : }
3945 : :
3946 : 0 : iC_IV = neigh;
3947 : 0 : num_C_IV++;
3948 : : }
3949 : : }
3950 : : }
3951 : :
3952 [ # # ]: 0 : if (num_C_IV + num_F != 3)
3953 : : {
3954 : 0 : return 0;
3955 : : }
3956 : :
3957 : 0 : num_C++; /* found -CF2-C or -CF3 */
3958 [ # # ]: 0 : if (!num_C_IV)
3959 : : {
3960 : 0 : break; /* -CF3 */
3961 : : }
3962 : :
3963 : : /* treat next C(IV) as a new start atom */
3964 [ # # ]: 0 : if ((p = is_in_the_list( at[iC_IV].neighbor, (AT_NUMB) start, at[iC_IV].valence ))) /* djb-rwth: addressing LLVM warning */
3965 : : {
3966 : 0 : start = iC_IV;
3967 : 0 : ord_prev = p - at[iC_IV].neighbor;
3968 : : }
3969 : : else
3970 : : {
3971 : 0 : return -1; /* program error */
3972 : : }
3973 : : }
3974 : :
3975 : : /* Corrected by DT below - ? was - return num_C == 1 ? 1 : num_C == 3 ? 2 : 0;*/
3976 [ # # # # : 0 : return num_C == 1 ? 1 : num_C == 2 ? 2 : num_C == 3 ? 3 : 0;
# # ]
3977 : : }
3978 : :
3979 : :
3980 : : /****************************************************************************/
3981 : 0 : int is_phenyl( inp_ATOM *at, int start, int ord_prev )
3982 : : {
3983 : : int k, neigh, cur_at, ord;
3984 [ # # # # ]: 0 : if (at[start].el_number != EL_NUMBER_C || at[start].valence != 3 ||
3985 [ # # ]: 0 : at[start].valence + 1 != at[start].chem_bonds_valence ||
3986 [ # # ]: 0 : at[start].chem_bonds_valence + at[start].num_H != 4 ||
3987 [ # # # # ]: 0 : at[start].charge || at[start].radical)
3988 : : {
3989 : 0 : return 0;
3990 : : }
3991 : :
3992 : 0 : ord = ( ord_prev + 1 ) % 3;
3993 : 0 : cur_at = start;
3994 : :
3995 [ # # ]: 0 : for (k = 0; k < 5; k++)
3996 : : {
3997 : 0 : neigh = at[cur_at].neighbor[ord];
3998 [ # # # # ]: 0 : if (at[neigh].el_number != EL_NUMBER_C || at[neigh].valence != 2 ||
3999 [ # # ]: 0 : at[neigh].valence + 1 != at[neigh].chem_bonds_valence ||
4000 [ # # ]: 0 : at[neigh].chem_bonds_valence + at[neigh].num_H != 4 ||
4001 [ # # # # ]: 0 : at[neigh].charge || at[neigh].radical)
4002 : : {
4003 : 0 : return 0;
4004 : : }
4005 : 0 : ord = ( at[neigh].neighbor[0] == cur_at );
4006 : 0 : cur_at = neigh;
4007 : : }
4008 : :
4009 : 0 : return ( at[cur_at].neighbor[ord] == start );
4010 : : }
4011 : :
4012 : :
4013 : : /****************************************************************************/
4014 : 0 : int is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR( inp_ATOM *at,
4015 : : int start,
4016 : : int num_atoms,
4017 : : DERIV_AT *da1,
4018 : : int idrv,
4019 : : char *szUnderiv,
4020 : : int lenUnderiv,
4021 : : char *szUnderiv2,
4022 : : int lenUnderiv2,
4023 : : BIT_UNDERIV *bitUnderiv )
4024 : : {
4025 : 0 : int i, j, k, neigh_at[2], prev_ord[2], neigh, is_B = 0, is_C = 0, n0, n1, n2, n3, n[4] = {0}, nFound, ind1, ind2; /* djb-rwth: adding variables for char -> int conversion of subscripts */
4026 : : AT_NUMB *p;
4027 : : const char *pUnk;
4028 : 0 : char str[16] = { '\0' };
4029 : : #if( defined(DERIV_RING_O_OUTSIDE_PRECURSOR) )
4030 : 0 : char strO[8] = { '\0' };
4031 : : #endif
4032 : : #if( defined(DERIV_RING_NH_OUTSIDE_PRECURSOR) )
4033 : 0 : char strN[8] = { '\0' };
4034 : : #endif
4035 : :
4036 [ # # # # ]: 0 : if (da1->typ[idrv] && ( da1->typ[idrv] & DERIV_RING_OUTSIDE_PRECURSOR ) == da1->typ[idrv] &&
4037 [ # # # # ]: 0 : da1->typ[idrv + 1] && ( da1->typ[idrv + 1] & DERIV_RING_OUTSIDE_PRECURSOR ) == da1->typ[idrv + 1])
4038 : : {
4039 : : ;
4040 : : }
4041 : : else
4042 : : {
4043 : 0 : return 0;
4044 : : }
4045 : :
4046 : : /*
4047 : : if ( (da1->typ[idrv] & DERIV_RING_O_OUTSIDE_PRECURSOR || da1->typ[idrv+1] != DERIV_RING_O_OUTSIDE_PRECURSOR) &&
4048 : : (da1->typ[idrv] != DERIV_RING_NH_OUTSIDE_PRECURSOR || da1->typ[idrv+1] != DERIV_RING_NH_OUTSIDE_PRECURSOR) )
4049 : : return 0;
4050 : : */
4051 [ # # # # : 0 : if (at[start].charge || at[start].radical || at[start].valence != at[start].chem_bonds_valence)
# # ]
4052 : : {
4053 : 0 : return 0; /* check bond types start-n0 and start-n3 */
4054 : : }
4055 : :
4056 : : /* check
4057 : : n1 n0
4058 : : R1---O
4059 : : | \
4060 : : | B [start]
4061 : : | /
4062 : : R2---O
4063 : : n2 n3
4064 : :
4065 : : All bond are single except n1-n2 (R1-R2), which may be either single or aromatic
4066 : :
4067 : : */
4068 : 0 : nFound = 0;
4069 : 0 : ind1 = da1->ord[0] - '0'; /* djb-rwth: converting char to int for subscript use */
4070 : 0 : ind2 = da1->ord[1] - '0'; /* djb-rwth: converting char to int for subscript use */
4071 : 0 : n0 = at[start].neighbor[ind1];
4072 : 0 : n3 = at[start].neighbor[ind2];
4073 : : /* search for i, j, k such that at[at[n1]neighbor[i]].neighbor[k]= at[n2]neighbor[j] */
4074 [ # # ]: 0 : for (i = 0; i < at[n0].valence; i++)
4075 : : {
4076 [ # # ]: 0 : if (( n1 = at[n0].neighbor[i] ) == start)
4077 : : {
4078 : 0 : continue; /* don't go back */
4079 : : }
4080 [ # # ]: 0 : if (BOND_SINGLE != at[n0].bond_type[i])
4081 : : {
4082 : : /* check bond type n0-n1 */
4083 : 0 : continue;
4084 : : }
4085 [ # # ]: 0 : for (j = 0; j < at[n1].valence; j++)
4086 : : {
4087 [ # # ]: 0 : if (( n2 = at[n1].neighbor[j] ) == n0)
4088 : : {
4089 : 0 : continue; /* don't go back */
4090 : : }
4091 [ # # ]: 0 : if ((p = is_in_the_list( at[n3].neighbor, (AT_NUMB) n2, at[n3].valence ))) /* djb-rwth: addressing LLVM warning */
4092 : : {
4093 [ # # # # ]: 0 : if (( BOND_SINGLE == at[n1].bond_type[j] || BOND_ALTERN == at[n1].bond_type[j] ) && /* check bond type n1-n2 */
4094 [ # # ]: 0 : BOND_SINGLE == at[n3].bond_type[p - at[n3].neighbor] && /* check bond type n3-n2 */
4095 [ # # ]: 0 : !nFound++)
4096 : : {
4097 : 0 : n[0] = n0;
4098 : 0 : n[1] = n1;
4099 : 0 : n[2] = n2;
4100 : 0 : n[3] = n3;
4101 : : }
4102 : : }
4103 : : }
4104 : : }
4105 : :
4106 [ # # # # : 0 : if (nFound != 1 || at[n[1]].el_number != EL_NUMBER_C || at[n[2]].el_number != EL_NUMBER_C)
# # ]
4107 : : {
4108 : 0 : return 0;
4109 : : }
4110 : :
4111 : : /* n[1] and n[2] cannot have 3 neighboring heteroatoms */
4112 [ # # ]: 0 : for (i = 1; i <= 2; i++)
4113 : : {
4114 [ # # ]: 0 : if (at[n1 = n[i]].valence > 3)
4115 : : {
4116 [ # # ]: 0 : for (k = 0, j = 0; j < at[n1].valence; j++)
4117 : : {
4118 : 0 : k += ( at[at[n1].neighbor[j]].el_number != EL_NUMBER_C );
4119 : : }
4120 [ # # ]: 0 : if (k >= 3)
4121 : : {
4122 : 0 : return 0;
4123 : : }
4124 : : }
4125 : : }
4126 : :
4127 : 0 : n0 = n[0];
4128 : 0 : n3 = n[3];
4129 : :
4130 [ # # ]: 0 : if (NULL != szUnderiv)
4131 : : {
4132 : : #if( defined(DERIV_RING_O_OUTSIDE_PRECURSOR) )
4133 [ # # # # ]: 0 : if (da1->typ[idrv] == DERIV_RING_O_OUTSIDE_PRECURSOR && da1->typ[idrv + 1] == DERIV_RING_O_OUTSIDE_PRECURSOR)
4134 : : {
4135 [ # # ]: 0 : if (at[n0].el_number <= at[n3].el_number)
4136 : : {
4137 : 0 : strcat(strO, at[n0].elname);
4138 : 0 : strcat(strO, at[n3].elname);
4139 : : }
4140 : : else
4141 : : {
4142 : 0 : strcat(strO, at[n3].elname);
4143 : 0 : strcat(strO, at[n0].elname);
4144 : : }
4145 : : }
4146 : : else
4147 : : {
4148 [ # # ]: 0 : if (da1->typ[idrv] == DERIV_RING_O_OUTSIDE_PRECURSOR)
4149 : : {
4150 : 0 : strcat(strO, at[n0].elname);
4151 : : }
4152 : : else
4153 : : {
4154 [ # # ]: 0 : if (da1->typ[idrv + 1] == DERIV_RING_O_OUTSIDE_PRECURSOR)
4155 : : {
4156 : 0 : strcat(strO, at[n3].elname);
4157 : : }
4158 : : }
4159 : : }
4160 : : #endif
4161 : :
4162 : : #if( defined(DERIV_RING_NH_OUTSIDE_PRECURSOR) )
4163 [ # # # # ]: 0 : if (da1->typ[idrv] == DERIV_RING_NH_OUTSIDE_PRECURSOR && da1->typ[idrv + 1] == DERIV_RING_NH_OUTSIDE_PRECURSOR)
4164 : : {
4165 [ # # # # ]: 0 : if (1 == at[n0].num_H && 1 == at[n3].num_H)
4166 : : {
4167 : 0 : strcat(strN, "(NH)2");
4168 : : }
4169 : : else
4170 : : {
4171 [ # # # # ]: 0 : if (1 == at[n0].num_H || 1 == at[n3].num_H)
4172 : : {
4173 : 0 : strcat(strN, "(NH)N");
4174 : : }
4175 : : else
4176 : : {
4177 : 0 : strcat(strN, "NN");
4178 : : }
4179 : : }
4180 : : }
4181 : : else
4182 : : {
4183 [ # # ]: 0 : if (da1->typ[idrv] == DERIV_RING_NH_OUTSIDE_PRECURSOR)
4184 : : {
4185 [ # # ]: 0 : strcat(strN, 1 == at[n0].num_H ? "(NH)" : "N");
4186 : : }
4187 : : else
4188 : : {
4189 [ # # ]: 0 : if (da1->typ[idrv + 1] == DERIV_RING_NH_OUTSIDE_PRECURSOR)
4190 : : {
4191 [ # # ]: 0 : strcat(strN, 1 == at[n3].num_H ? "(NH)" : "N");
4192 : : }
4193 : : }
4194 : : }
4195 : : #endif
4196 : :
4197 : :
4198 [ # # # # ]: 0 : switch (da1->typ[idrv] | da1->typ[idrv + 1])
4199 : : {
4200 : : #if( defined(DERIV_RING_O_OUTSIDE_PRECURSOR) && defined(DERIV_RING_NH_OUTSIDE_PRECURSOR) )
4201 : 0 : case ( DERIV_RING_O_OUTSIDE_PRECURSOR | DERIV_RING_NH_OUTSIDE_PRECURSOR ):
4202 : 0 : strcat(str, strN);
4203 : 0 : strcat(str, strO); /* "(NH)O" or "(NH)S" */
4204 : 0 : break;
4205 : : #endif
4206 : : #if( defined(DERIV_RING_O_OUTSIDE_PRECURSOR) )
4207 : 0 : case ( DERIV_RING_O_OUTSIDE_PRECURSOR ):
4208 : 0 : strcat(str, strO); /* "OO" or "OS" or "SS" */
4209 : 0 : break;
4210 : : #endif
4211 : : #if( defined(DERIV_RING_NH_OUTSIDE_PRECURSOR) )
4212 : 0 : case ( DERIV_RING_NH_OUTSIDE_PRECURSOR ):
4213 : 0 : strcat(str, strN);
4214 : 0 : break;
4215 : : #endif
4216 : 0 : default:
4217 : 0 : strcat(str, "???");
4218 : 0 : break;
4219 : : }
4220 : 0 : strcat(str, "-");
4221 : : }
4222 : 0 : underiv_list_add( szUnderiv, lenUnderiv, str, 0 );
4223 : :
4224 : : /*underiv_list_add( szUnderiv, lenUnderiv, da1->typ[idrv] == DERIV_RING_O_OUTSIDE_PRECURSOR? "OO-" : "(NH)2-", 0 );*/
4225 [ # # # # ]: 0 : if (at[start].el_number == EL_NUMBER_B && at[start].valence == 3)
4226 : : {
4227 : 0 : is_B = 1;
4228 : 0 : underiv_list_add( szUnderiv, lenUnderiv, "B", 0 );
4229 : : }
4230 : : else
4231 : : {
4232 [ # # # # : 0 : if (at[start].el_number == EL_NUMBER_C && ( at[start].valence == 3 || at[start].valence == 4 ) &&
# # ]
4233 [ # # ]: 0 : at[start].chem_bonds_valence == at[start].valence &&
4234 [ # # ]: 0 : at[start].num_H + at[start].chem_bonds_valence == 4)
4235 : : {
4236 : 0 : is_C = 1;
4237 [ # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv, at[start].valence == 3 ? "CH" : "C", 0 );
4238 : : }
4239 : : else
4240 : : {
4241 : 0 : return 0;
4242 : : }
4243 : : }
4244 : :
4245 : : /* locate bonds connecting >B- or >C< or >C- to the rest of the derivative */
4246 [ # # ]: 0 : for (i = k = 0; i < at[start].valence; i++)
4247 : : {
4248 [ # # # # ]: 0 : if (i != da1->ord[idrv] && i != da1->ord[idrv + 1])
4249 : : {
4250 : 0 : neigh = at[start].neighbor[i];
4251 [ # # # # ]: 0 : if (k < 2 && ( p = is_in_the_list( at[neigh].neighbor, (AT_NUMB) start, at[neigh].valence ) ))
4252 : : {
4253 : 0 : neigh_at[k] = neigh;
4254 : 0 : prev_ord[k] = p - at[neigh].neighbor;
4255 : 0 : k++;
4256 : : }
4257 : : else
4258 : : {
4259 : 0 : return -1; /* program error */
4260 : : }
4261 : : }
4262 : : }
4263 : :
4264 : 0 : n1 = n2 = 0; /* djb-rwth: ignoring LLVM warning: variables used */
4265 [ # # # # : 0 : if (is_B && k == 1 && da1->typ[idrv] == DERIV_RING_O_OUTSIDE_PRECURSOR)
# # ]
4266 : : {
4267 [ # # ]: 0 : if (0 < ( n1 = is_Me_or_Et( at, neigh_at[0], prev_ord[0] ) )
4268 : : #ifdef UNDERIV_OOB_nButyl
4269 [ # # ]: 0 : || 0 < ( n2 = is_nButyl( at, neigh_at[0], prev_ord[0] ) )
4270 : : #endif
4271 : : )
4272 : : {
4273 [ # # # # : 0 : underiv_list_add( szUnderiv, lenUnderiv, n1 == 1 ? "Me" : n1 == 2 ? "Et" : n2 ? "nButyl" : "???", 0 );
# # ]
4274 : : /* is_B */
4275 [ # # ]: 0 : underiv_list_add( szUnderiv2, lenUnderiv2, n1 == 1 ? pszDerivName[DERIV_ID_MeBorate] :
4276 [ # # ]: 0 : n1 == 2 ? pszDerivName[DERIV_ID_EtBorate] :
4277 [ # # ]: 0 : n2 ? pszDerivName[DERIV_ID_BuBorate] : "???", ' ' );
4278 [ # # ]: 0 : *bitUnderiv |= n1 == 1 ? DERIV_BIT_MeBorate :
4279 [ # # ]: 0 : n1 == 2 ? DERIV_BIT_EtBorate :
4280 [ # # ]: 0 : n2 ? DERIV_BIT_BuBorate : DERIV_BIT_Unknown;
4281 : 0 : return 1;
4282 : : }
4283 : : }
4284 : : else
4285 : : {
4286 [ # # ]: 0 : if (is_C)
4287 : : {
4288 [ # # # # : 0 : if (k == 1 && at[start].num_H == 1 && is_phenyl( at, neigh_at[0], prev_ord[0] ))
# # ]
4289 : : {
4290 : 0 : underiv_list_add( szUnderiv, lenUnderiv, "Phe", 0 );
4291 [ # # ]: 0 : if (strN[0])
4292 : : {
4293 [ # # ]: 0 : if ((pUnk = underiv_list_get_last( szUnderiv, ' ' ))) /* djb-rwth: addressing LLVM warning */
4294 : : {
4295 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pUnk, ' ' );
4296 : 0 : *bitUnderiv |= DERIV_BIT_Unknown;
4297 : : }
4298 : : }
4299 : : else
4300 : : {
4301 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[DERIV_ID_Benzlidene], ' ' );
4302 : 0 : *bitUnderiv |= DERIV_BIT_Benzlidene;
4303 : : }
4304 : 0 : return 1;
4305 : : }
4306 [ # # # # : 0 : if (k == 2 && 0 < ( n1 = is_Me_or_Et( at, neigh_at[0], prev_ord[0] ) ) &&
# # ]
4307 : 0 : 0 < ( n2 = is_Me_or_Et( at, neigh_at[1], prev_ord[1] ) ))
4308 : : {
4309 [ # # ]: 0 : if (n1 != n2)
4310 : : {
4311 : 0 : underiv_list_add( szUnderiv, lenUnderiv, "MeEt", 0 );
4312 [ # # ]: 0 : if ((pUnk = underiv_list_get_last( szUnderiv, ' ' ))) /* djb-rwth: addressing LLVM warning */
4313 : : {
4314 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pUnk, ' ' );
4315 : 0 : *bitUnderiv |= DERIV_BIT_Unknown;
4316 : : }
4317 : : }
4318 : : else
4319 : : {
4320 [ # # # # ]: 0 : if (n1 == 1 || n1 == 2)
4321 : : {
4322 [ # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv, n1 == 1 ? "Me2" : "Et2", 0 );
4323 [ # # # # ]: 0 : if (strN[0] || n1 != 1)
4324 : : {
4325 [ # # ]: 0 : if ((pUnk = underiv_list_get_last( szUnderiv, ' ' ))) /* djb-rwth: addressing LLVM warning */
4326 : : {
4327 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pUnk, ' ' );
4328 : 0 : *bitUnderiv |= DERIV_BIT_Unknown;
4329 : : }
4330 : : }
4331 : : else
4332 : : {
4333 [ # # ]: 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[n1 == 1 ? DERIV_ID_Acentonate : DERIV_ID_Unknown], ' ' );
4334 [ # # ]: 0 : *bitUnderiv |= ( n1 == 1 ? DERIV_BIT_Acentonate : DERIV_BIT_Unknown );
4335 : : }
4336 : : }
4337 : : }
4338 : :
4339 : 0 : return 1;
4340 : : }
4341 : : }
4342 : : }
4343 : :
4344 : : /*
4345 : : if ( is_B && k == 1 && is_Me_or_Et( at, neigh_at[0], prev_ord[0]) )
4346 : : return 1;
4347 : : if ( is_B && k == 1 && is_nButyl( at, neigh_at[0], prev_ord[0]) )
4348 : : return 1;
4349 : : if ( is_C && k == 1 && at[start].num_H == 1 && is_phenyl( at, neigh_at[0], prev_ord[0]) )
4350 : : return 1;
4351 : : if ( is_C && k == 2 && is_Me_or_Et( at, neigh_at[0], prev_ord[0]) &&
4352 : : is_Me_or_Et( at, neigh_at[1], prev_ord[1]) )
4353 : : return 1;
4354 : : */
4355 : :
4356 : 0 : return 0;
4357 : : }
4358 : :
4359 : :
4360 : : /****************************************************************************/
4361 : 0 : int is_deriv_chain2( inp_ATOM *at,
4362 : : int start,
4363 : : int type,
4364 : : int num,
4365 : : int ord,
4366 : : int idrv,
4367 : : char *szUnderiv,
4368 : : int lenUnderiv,
4369 : : char *szUnderiv2,
4370 : : int lenUnderiv2,
4371 : : BIT_UNDERIV *bitUnderiv )
4372 : : {
4373 : 0 : int i, k, prev_ord, neigh, iC, iO /* O or N */, iNxt, n1 = 0, n2 = 0;
4374 : : AT_NUMB *p;
4375 : :
4376 [ # # # # ]: 0 : if (!type || ( type & DERIV_RING_OUTSIDE_PRECURSOR ))
4377 : : {
4378 : 0 : return 0;
4379 : : }
4380 : : /*
4381 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
4382 : : if (type & DERIV_RING2_OUTSIDE_PRECUR)
4383 : : {
4384 : : return 1;
4385 : : }
4386 : : #endif
4387 : : */
4388 : : /* reject unexpected unsaturated */
4389 [ # # # # : 0 : if (at[start].charge || at[start].radical || (at[start].valence != at[start].chem_bonds_valence
# # ]
4390 : : #ifdef DERIV_X_OXIME
4391 [ # # ]: 0 : && type != DERIV_X_OXIME
4392 : : #endif
4393 : : #ifdef DERIV_RO_COX
4394 [ # # ]: 0 : && type != DERIV_RO_COX
4395 : : #endif
4396 : : #ifdef DERIV_RING_DMOX_DEOX_N
4397 [ # # ]: 0 : && type != DERIV_RING_DMOX_DEOX_N
4398 : : #endif
4399 : : )) /* djb-rwth: addressing LLVM warning */
4400 : : {
4401 : 0 : return 0;
4402 : : }
4403 : :
4404 : 0 : neigh = at[start].neighbor[(int) ord];
4405 : 0 : p = is_in_the_list( at[neigh].neighbor, (AT_NUMB) start, at[neigh].valence );
4406 [ # # ]: 0 : if (!p)
4407 : : {
4408 : 0 : return -1; /* program error */
4409 : : }
4410 : :
4411 : 0 : prev_ord = p - at[neigh].neighbor;
4412 : :
4413 : : /* eliminate silyl possibility */
4414 [ # # # # : 0 : if (type == DERIV_BRIDGE_O || type == DERIV_BRIDGE_NH || type == DERIV_AMINE_tN)
# # ]
4415 : : {
4416 [ # # ]: 0 : if ((n1 = is_silyl( at, neigh, prev_ord ))) /* djb-rwth: addressing LLVM warning */
4417 : : {
4418 [ # # ]: 0 : if (at[start].valence != 2 || /* amine ? */
4419 : : /*at[start].el_number == EL_NUMBER_O && */
4420 [ # # ]: 0 : at[at[start].neighbor[!ord]].el_number != EL_NUMBER_SI)
4421 : : {
4422 : : /* Gari's request: disconnect only from C-O->-Si..., not Si-O->-Si... (e.g. CASr.n.= 141-63-9 ). */
4423 : : /* ???? in case of type == DERIV_AMINE_tN why don't we check more neighbors ???? */
4424 [ # # # # ]: 0 : if (NULL != szUnderiv && 0 < lenUnderiv)
4425 : : {
4426 : 0 : char szPrecur[16] = "R";
4427 [ # # # # ]: 0 : switch (type)
4428 : : {
4429 : 0 : case DERIV_BRIDGE_O:
4430 : 0 : strcat(szPrecur, at[start].elname);
4431 : 0 : break;
4432 : 0 : case DERIV_BRIDGE_NH:
4433 : 0 : strcat(szPrecur, "NH");
4434 : 0 : break;
4435 : 0 : case DERIV_AMINE_tN:
4436 : 0 : strcat(szPrecur, "N");
4437 : 0 : break;
4438 : 0 : default:
4439 : 0 : strcat(szPrecur, "??");
4440 : 0 : break;
4441 : : }
4442 : 0 : strcat(szPrecur, "-");
4443 [ # # # ]: 0 : switch (n1)
4444 : : {
4445 : 0 : case 1:
4446 : 0 : strcat(szPrecur, "TMS");
4447 : 0 : break;
4448 : 0 : case 2:
4449 : 0 : strcat(szPrecur, "TBDMS");
4450 : 0 : break;
4451 : 0 : default:
4452 : 0 : strcat(szPrecur, "???");
4453 : 0 : break;
4454 : : }
4455 : 0 : underiv_list_add( szUnderiv, lenUnderiv, szPrecur, ' ' );
4456 [ # # # # ]: 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[n1 == 1 ? DERIV_ID_TMS : n1 == 2 ? DERIV_ID_TBDMS : DERIV_ID_Unknown], ' ' );
4457 [ # # # # ]: 0 : *bitUnderiv |= n1 == 1 ? DERIV_BIT_TMS : n1 == 2 ? DERIV_BIT_TBDMS : DERIV_BIT_Unknown;
4458 : :
4459 : : /*
4460 : : underiv_list_add( szUnderiv, lenUnderiv, type == DERIV_BRIDGE_O? "RO-" : type == DERIV_BRIDGE_NH? "RNH-" : "RN-", ' ' );
4461 : : underiv_list_add( szUnderiv, lenUnderiv, n1==1?"TMS" : n1==2? "TBDMS" : "???", 0 );
4462 : : */
4463 : : }
4464 : 0 : return 1;
4465 : : }
4466 : : else
4467 : : {
4468 : 0 : return 0;
4469 : : }
4470 : : }
4471 : : }
4472 : : #ifdef UNDERIV_SYLYL_ONLY
4473 : : return 0; /* if it is not Sylyl then it is not a derivative */
4474 : : #endif
4475 : :
4476 : 0 : n1 = n2 = 0; /* djb-rwth: ignoring LLVM warning: variables used */
4477 [ # # ]: 0 : if (type == DERIV_BRIDGE_O)
4478 : : {
4479 : : /* check acetyl */
4480 : : #if ( !defined(UNDERIV_ACETATE_Me) && !defined(UNDERIV_ACETATE_Et) && !defined(UNDERIV_ACETATE_CnF2np1) )
4481 : 0 : return 0;
4482 : : #else
4483 : : iC = at[start].neighbor[!ord];
4484 : : if (at[iC].charge || at[iC].radical || at[iC].num_H ||
4485 : : at[iC].el_number != EL_NUMBER_C || at[iC].valence != 3 ||
4486 : : at[iC].valence + 1 != at[iC].chem_bonds_valence)
4487 : : return 0;
4488 : : for (i = k = 0; i < at[iC].valence; i++)
4489 : : {
4490 : : iO = at[iC].neighbor[i];
4491 : : if (at[iO].charge || at[iO].radical || at[iO].num_H ||
4492 : : at[iO].el_number != EL_NUMBER_O || at[iO].valence != 1 ||
4493 : : at[iO].valence + 1 != at[iO].chem_bonds_valence)
4494 : : continue;
4495 : : k++; /* number of =O */
4496 : : }
4497 : : if (k != 1)
4498 : : return 0;
4499 : : /* check derivative */
4500 : : #if defined(UNDERIV_ACETATE_Et) || defined(UNDERIV_ACETATE_Me)
4501 : : n1 = is_Me_or_Et( at, neigh, prev_ord );
4502 : : if (
4503 : : #if defined(UNDERIV_ACETATE_Et) && defined(UNDERIV_ACETATE_Me)
4504 : : 0 !=
4505 : : #elif defined(UNDERIV_ACETATE_Et)
4506 : : 2 ==
4507 : : #elif defined(UNDERIV_ACETATE_Me)
4508 : : 1 ==
4509 : : #endif
4510 : : n1)
4511 : : ;
4512 : : else
4513 : : n1 = 0;
4514 : : #endif /* defined(UNDERIV_ACETATE_Et) || defined(UNDERIV_ACETATE_Me) */
4515 : : #ifdef UNDERIV_ACETATE_CnF2np1
4516 : : if (n1 <= 0)
4517 : : n2 = is_CF3_or_linC3F7( at, neigh, prev_ord );
4518 : : #endif
4519 : : if (n1 || n2)
4520 : : {
4521 : : if (szUnderiv)
4522 : : {
4523 : : underiv_list_add( szUnderiv, lenUnderiv, "RCOO-", ' ' );
4524 : : underiv_list_add( szUnderiv, lenUnderiv,
4525 : : n1 == 1 ? "Me" :
4526 : : n1 == 2 ? "Et" :
4527 : : n2 == 1 ? "CF3" :
4528 : : n2 == 2 ? "C2F5" :
4529 : : n2 == 3 ? "C3F7" :
4530 : : "C?F?", 0 );
4531 : : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[
4532 : : #if defined(UNDERIV_ACETATE_Me)
4533 : : n1 == 1 ? DERIV_ID_Methylation :
4534 : : #endif
4535 : : #if defined(UNDERIV_ACETATE_Et)
4536 : : n1 == 2 ? DERIV_ID_Ethylation :
4537 : : #endif
4538 : : n2 == 1 ? DERIV_ID_TFA :
4539 : : n2 == 2 ? DERIV_ID_PFP :
4540 : : n2 == 3 ? DERIV_ID_HFB :
4541 : : DERIV_ID_Unknown], ' ' );
4542 : : *bitUnderiv |=
4543 : : #if defined(UNDERIV_ACETATE_Me)
4544 : : n1 == 1 ? DERIV_BIT_Methylation :
4545 : : #endif
4546 : : #if defined(UNDERIV_ACETATE_Et)
4547 : : n1 == 2 ? DERIV_BIT_Ethylation :
4548 : : #endif
4549 : : n2 == 1 ? DERIV_BIT_TFA :
4550 : : n2 == 2 ? DERIV_BIT_PFP :
4551 : : n2 == 3 ? DERIV_BIT_HFB :
4552 : : DERIV_BIT_Unknown;
4553 : : }
4554 : : return 1;
4555 : : }
4556 : : return 0;
4557 : : #endif /* !defined(UNDERIV_ACETATE_Me) && !defined(UNDERIV_ACETATE_Et) && !defined(UNDERIV_ACETATE_CnF2np1) */
4558 : : }
4559 : :
4560 : 0 : n1 = n2 = 0;
4561 [ # # # # ]: 0 : if (type == DERIV_BRIDGE_NH || type == DERIV_AMINE_tN)
4562 : : {
4563 : : /* check acetyl */
4564 : 0 : iNxt = -1;
4565 : 0 : iC = at[start].neighbor[(int) ord];
4566 [ # # # # : 0 : if (at[iC].charge || at[iC].radical || at[iC].num_H ||
# # ]
4567 [ # # # # ]: 0 : at[iC].el_number != EL_NUMBER_C || at[iC].valence != 3 ||
4568 [ # # ]: 0 : at[iC].valence + 1 != at[iC].chem_bonds_valence)
4569 : : {
4570 : 0 : return 0;
4571 : : }
4572 [ # # ]: 0 : for (i = k = 0; i < at[iC].valence; i++)
4573 : : {
4574 : 0 : iO = at[iC].neighbor[i];
4575 [ # # # # : 0 : if (at[iO].charge || at[iO].radical || at[iO].num_H ||
# # ]
4576 [ # # # # ]: 0 : at[iO].el_number != EL_NUMBER_O || at[iO].valence != 1 ||
4577 [ # # ]: 0 : at[iO].valence + 1 != at[iO].chem_bonds_valence)
4578 : : {
4579 [ # # ]: 0 : if (iO != start)
4580 : : {
4581 [ # # ]: 0 : if (iNxt < 0)
4582 : : {
4583 : 0 : iNxt = iO;
4584 : : }
4585 : : else
4586 : : {
4587 : 0 : return 0;
4588 : : }
4589 : : }
4590 : 0 : continue;
4591 : : }
4592 : 0 : k++; /* number of =O */
4593 : : }
4594 [ # # # # ]: 0 : if (k != 1 || iNxt < 0)
4595 : : {
4596 : 0 : return 0;
4597 : : }
4598 : : /* find bond from iNxt to iC */
4599 : 0 : p = is_in_the_list( at[iNxt].neighbor, (AT_NUMB) iC, at[iNxt].valence );
4600 [ # # ]: 0 : if (!p)
4601 : : {
4602 : 0 : return -1; /* program error */
4603 : : }
4604 : 0 : prev_ord = p - at[iNxt].neighbor;
4605 : : /* check derivative */
4606 : : #if ( defined( UNDERIV_RN_AcEt ) || defined( UNDERIV_RNH_AcEt ) )
4607 : : n1 = is_Me_or_Et( at, iNxt, prev_ord );
4608 : : #endif
4609 [ # # ]: 0 : if (!n1)
4610 : : {
4611 : 0 : n2 = is_CF3_or_linC3F7( at, iNxt, prev_ord );
4612 : : }
4613 : : else
4614 : : {
4615 [ # # ]: 0 : if (n1 == 1)
4616 : : {
4617 : : #if ( !defined(UNDERIV_RN_AcMe) && defined(DERIV_BRIDGE_tN) )
4618 : : if (type == DERIV_BRIDGE_tN) n1 = 0;
4619 : : #elif ( !defined(UNDERIV_RNH_AcMe) && defined(DERIV_BRIDGE_NH) )
4620 : : if (type == DERIV_BRIDGE_NH) n1 = 0;
4621 : : #endif
4622 : : ; /* keep C-compiler happy */
4623 : : }
4624 : : else
4625 : : {
4626 [ # # ]: 0 : if (n1 == 2)
4627 : : {
4628 : : #if ( !defined(UNDERIV_RN_AcEt) && defined(DERIV_BRIDGE_tN) )
4629 : : if (type == DERIV_BRIDGE_tN) n1 = 0;
4630 : : #elif ( !defined(UNDERIV_RNH_AcEt) && defined(DERIV_BRIDGE_NH) )
4631 [ # # ]: 0 : if (type == DERIV_BRIDGE_NH) n1 = 0;
4632 : : #endif
4633 : : ; /* keep C-compiler happy */
4634 : : }
4635 : : else
4636 : : {
4637 : 0 : n1 = 0;
4638 : : }
4639 : : }
4640 : : }
4641 : :
4642 [ # # # # ]: 0 : if (n1 || n2)
4643 : : {
4644 [ # # ]: 0 : if (szUnderiv)
4645 : : {
4646 [ # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv, type == DERIV_AMINE_tN ? "RN-C(O)" : "RNH-C(O)", ' ' );
4647 [ # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv,
4648 [ # # # # : 0 : n1 == 1 ? "Me" :
# # # # ]
4649 : : n1 == 2 ? "Et" :
4650 : : n2 == 1 ? "CF3" :
4651 : : n2 == 2 ? "C2F5" :
4652 : : n2 == 3 ? "C3F7" :
4653 : : "C?F?", 0 );
4654 : : /* djb-rwth: addressing coverity ID #499506 -- condition is correct for n1 != 1 */
4655 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[
4656 : : #if defined(UNDERIV_RN_AcMe) || defined(UNDERIV_RNH_AcMe)
4657 [ # # ]: 0 : n1 == 1 ? DERIV_ID_Acetate :
4658 : : #endif
4659 : : #if defined(UNDERIV_RN_AcEt) || defined(UNDERIV_RNH_AcEt)
4660 : : n1 == 2 ? DERIV_ID_Propanoate :
4661 : : #endif
4662 [ # # ]: 0 : n2 == 1 ? DERIV_ID_TFA :
4663 [ # # ]: 0 : n2 == 2 ? DERIV_ID_PFP :
4664 [ # # ]: 0 : n2 == 3 ? DERIV_ID_HFB :
4665 : : DERIV_ID_Unknown], ' ' );
4666 : 0 : *bitUnderiv |=
4667 : : #if defined(UNDERIV_RN_AcMe) || defined(UNDERIV_RNH_AcMe)
4668 [ # # ]: 0 : n1 == 1 ? DERIV_BIT_Acetate :
4669 : : #endif
4670 : : #if defined(UNDERIV_RN_AcEt) || defined(UNDERIV_RNH_AcEt)
4671 : : n1 == 2 ? DERIV_BIT_Propanoate :
4672 : : #endif
4673 [ # # ]: 0 : n2 == 1 ? DERIV_BIT_TFA :
4674 [ # # ]: 0 : n2 == 2 ? DERIV_BIT_PFP :
4675 [ # # ]: 0 : n2 == 3 ? DERIV_BIT_HFB :
4676 : : DERIV_BIT_Unknown;
4677 : : }
4678 : 0 : return 1;
4679 : : }
4680 : :
4681 : 0 : return 0;
4682 : : }
4683 : :
4684 : : /*underiv_buf_clear( szUnderiv );*/
4685 : : #ifdef DERIV_X_OXIME
4686 [ # # ]: 0 : if (type == DERIV_X_OXIME)
4687 : : {
4688 [ # # ]: 0 : if (szUnderiv)
4689 : : {
4690 : 0 : iO = 0;
4691 [ # # ]: 0 : if (num == 2)
4692 : : {
4693 : 0 : underiv_list_add( szUnderiv, lenUnderiv, "MOX", ' ' );
4694 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[DERIV_ID_MOX], ' ' );
4695 : 0 : *bitUnderiv |= DERIV_BIT_MOX;
4696 : : }
4697 : : else
4698 : : {
4699 [ # # ]: 0 : if (num == 3)
4700 : : {
4701 : 0 : underiv_list_add( szUnderiv, lenUnderiv, "EtOX", ' ' );
4702 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[DERIV_ID_EtOX], ' ' );
4703 : 0 : *bitUnderiv |= DERIV_BIT_EtOX;
4704 : : }
4705 : : else
4706 : : {
4707 [ # # ]: 0 : if (num == 8)
4708 : : {
4709 : 0 : neigh = at[start].neighbor[ord];
4710 : 0 : iC = at[neigh].neighbor[start == at[neigh].neighbor[0]];
4711 : 0 : iO = at[iC].el_number == EL_NUMBER_SI;
4712 : : }
4713 : 0 : underiv_list_add( szUnderiv, lenUnderiv, "OX-", ' ' );
4714 [ # # # # : 0 : underiv_list_add( szUnderiv, lenUnderiv, num == 5 ? "TMS" : num == 8 && iO ? "TBDMS" : num == 8 && !iO ? "CH2Phe" : "???", 0 );
# # # # #
# ]
4715 [ # # # # : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[num == 5 ? DERIV_ID_TMS : num == 8 && iO ? DERIV_ID_TBDMS : num == 8 && !iO ? DERIV_ID_BenzOX : DERIV_ID_Unknown], ' ' );
# # # # #
# ]
4716 [ # # # # : 0 : *bitUnderiv |= num == 5 ? DERIV_BIT_TMS : num == 8 && iO ? DERIV_BIT_TBDMS : num == 8 && !iO ? DERIV_BIT_BenzOX : DERIV_BIT_Unknown;
# # # # #
# ]
4717 : : }
4718 : : }
4719 : : }
4720 : :
4721 : 0 : return 1;
4722 : : }
4723 : : #endif
4724 : :
4725 : : #ifdef DERIV_RO_COX
4726 [ # # ]: 0 : if (type == DERIV_RO_COX)
4727 : : {
4728 [ # # ]: 0 : if (szUnderiv)
4729 : : {
4730 [ # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv, at[start].el_number == EL_NUMBER_O ? "RO-C(O)" :
4731 [ # # ]: 0 : at[start].el_number == EL_NUMBER_S ? "RS-C(O)" : "R?-C(O)", ' ' );
4732 [ # # # # : 0 : underiv_list_add( szUnderiv, lenUnderiv, num == 3 ? "Me" :
# # # # #
# # # #
# ]
4733 : : num == 4 ? "Et" :
4734 : : num == 6 ? "CF3" :
4735 : : num == 8 ? "Phe" :
4736 : : num == 9 ? "C2F5" :
4737 : : num == 12 ? "C3F7" :
4738 : : num == 13 ? "PheF5" :
4739 : : "???", 0 );
4740 [ # # ]: 0 : if (num == 13)
4741 : : {
4742 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, underiv_list_get_last( szUnderiv, ' ' ), ' ' );
4743 : 0 : *bitUnderiv |= DERIV_BIT_Unknown;
4744 : : }
4745 : : else
4746 : : {
4747 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[
4748 : : #if defined(UNDERIV_RO_COX_Me)
4749 [ # # ]: 0 : num == 3 ? DERIV_ID_Acetate :
4750 : : #endif
4751 : : #if defined(UNDERIV_RO_COX_Et)
4752 : : num == 4 ? DERIV_ID_Propanoate :
4753 : : #endif
4754 [ # # ]: 0 : num == 6 ? DERIV_ID_TFA :
4755 : : #if defined(UNDERIV_RO_COX_BENZOATES)
4756 [ # # ]: 0 : num == 8 ? DERIV_ID_Benzoate :
4757 : : #endif
4758 [ # # ]: 0 : num == 9 ? DERIV_ID_PFP :
4759 [ # # ]: 0 : num == 12 ? DERIV_ID_HFB :
4760 [ # # ]: 0 : num == 13 ? DERIV_ID_PFB :
4761 : : DERIV_ID_Unknown], ' ' );
4762 : 0 : *bitUnderiv |=
4763 : : #if defined(UNDERIV_RO_COX_Me)
4764 [ # # ]: 0 : num == 3 ? DERIV_BIT_Acetate :
4765 : : #endif
4766 : : #if defined(UNDERIV_RO_COX_Et)
4767 : : num == 4 ? DERIV_BIT_Propanoate :
4768 : : #endif
4769 [ # # ]: 0 : num == 6 ? DERIV_BIT_TFA :
4770 : : #if defined(UNDERIV_RO_COX_BENZOATES)
4771 [ # # ]: 0 : num == 8 ? DERIV_BIT_Benzoate :
4772 : : #endif
4773 [ # # ]: 0 : num == 9 ? DERIV_BIT_PFP :
4774 [ # # ]: 0 : num == 12 ? DERIV_BIT_HFB :
4775 [ # # ]: 0 : num == 13 ? DERIV_BIT_PFB :
4776 : : DERIV_ID_Unknown;
4777 : : }
4778 : : }
4779 : :
4780 : 0 : return 1;
4781 : : }
4782 : : #endif
4783 : :
4784 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
4785 [ # # # # : 0 : if (!idrv && ( type == DERIV_RING_DMOX_DEOX_N ||
# # ]
4786 : : type == DERIV_RING_DMOX_DEOX_O ))
4787 : : {
4788 [ # # # # ]: 0 : if (szUnderiv && type == DERIV_RING_DMOX_DEOX_N)
4789 : : {
4790 : : /* add only once; do not add upon DERIV_RING_DMOX_DEOX_O */
4791 [ # # # # : 0 : underiv_list_add( szUnderiv, lenUnderiv, num == 4 ? "DMOX" : num == 6 ? "DEOX" : num ? "D?OX" : "???", ' ' );
# # ]
4792 [ # # # # ]: 0 : if (num == 4 || num == 6)
4793 : : {
4794 [ # # # # ]: 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[num == 4 ? DERIV_ID_DMOX : num == 6 ? DERIV_ID_DEOX : DERIV_ID_Unknown], ' ' );
4795 [ # # # # ]: 0 : *bitUnderiv |= num == 4 ? DERIV_BIT_DMOX : num == 6 ? DERIV_BIT_DEOX : DERIV_BIT_Unknown;
4796 : : }
4797 : : else
4798 : : {
4799 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, underiv_list_get_last( szUnderiv, ' ' ), ' ' );
4800 : 0 : *bitUnderiv |= DERIV_BIT_Unknown;
4801 : : }
4802 : : }
4803 : :
4804 : 0 : return 1;
4805 : : }
4806 : : #endif
4807 : :
4808 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
4809 [ # # # # ]: 0 : if (type && ( type & DERIV_RING2_OUTSIDE_PRECUR ) == type)
4810 : : {
4811 [ # # # # ]: 0 : if (szUnderiv && !idrv)
4812 : : {
4813 [ # # # # ]: 0 : if (num == 4 || num == 5)
4814 : : {
4815 [ # # # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv, num == 4 ? "Pyrrolidide" : num == 5 ? "Piperidine" : "???", ' ' );
4816 [ # # # # ]: 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[num == 4 ? DERIV_ID_Pyrrolidide : num == 5 ? DERIV_ID_Piperidine : DERIV_ID_Unknown], ' ' ); /* djb-rwth: addressing coverity ID #499491 -- working correctly for num == 5 */
4817 [ # # # # ]: 0 : *bitUnderiv |= num == 4 ? DERIV_BIT_Pyrrolidide : num == 5 ? DERIV_BIT_Piperidine : DERIV_BIT_Unknown;
4818 : : }
4819 : : else
4820 : : {
4821 : : #ifdef _DEBUG
4822 : : int stop_DERIV_RING2_OUTSIDE_PRECUR = 1; /* debug only */
4823 : : #endif
4824 [ # # ]: 0 : underiv_list_add( szUnderiv, lenUnderiv, num ? "Pyrrol?Piper?" : "???", ' ' );
4825 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[DERIV_ID_Unknown], ' ' );
4826 : 0 : *bitUnderiv |= DERIV_BIT_Unknown;
4827 : : }
4828 : : }
4829 : 0 : return 1;
4830 : : }
4831 : : #endif
4832 : :
4833 : : #ifdef DERIV_DANSYL
4834 [ # # # # : 0 : if (!idrv && type && ( type & DERIV_DANSYL ) == type)
# # ]
4835 : : {
4836 [ # # ]: 0 : if (szUnderiv)
4837 : : {
4838 : 0 : char szRO[16] = "R";
4839 : 0 : strcat(szRO, at[start].elname);
4840 [ # # ]: 0 : if (at[start].num_H == 1)
4841 : : {
4842 : 0 : strcat(szRO, "H");
4843 : : }
4844 : 0 : strcat(szRO, "-Dansyl");
4845 : 0 : underiv_list_add( szUnderiv, lenUnderiv, szRO, ' ' );
4846 : 0 : underiv_list_add( szUnderiv2, lenUnderiv2, pszDerivName[DERIV_ID_Dansyl], ' ' );
4847 : 0 : *bitUnderiv |= DERIV_BIT_Dansyl;
4848 : : }
4849 : 0 : return 1;
4850 : : }
4851 : : #endif
4852 : :
4853 : 0 : return 0;
4854 : : }
4855 : :
4856 : :
4857 : : /****************************************************************************/
4858 : 0 : int is_deriv_chain( inp_ATOM *at,
4859 : : int start,
4860 : : int num_atoms,
4861 : : DERIV_AT *da1,
4862 : : int idrv,
4863 : : char *szUnderiv,
4864 : : int lenUnderiv,
4865 : : char *szUnderiv2,
4866 : : int lenUnderiv2,
4867 : : BIT_UNDERIV *bitUnderiv )
4868 : : {
4869 : 0 : return is_deriv_chain2( at, start, da1->typ[idrv], da1->num[idrv], da1->ord[idrv], idrv, szUnderiv, lenUnderiv, szUnderiv2, lenUnderiv2, bitUnderiv );
4870 : : }
4871 : :
4872 : :
4873 : : /****************************************************************************/
4874 : 0 : int is_deriv_chain_or_ring( inp_ATOM *at,
4875 : : int start,
4876 : : int num_atoms,
4877 : : DERIV_AT *da1,
4878 : : int *idrv )
4879 : : {
4880 : 0 : int i, ret = -1;
4881 [ # # ]: 0 : if (da1->typ[*idrv] & DERIV_RING_OUTSIDE_PRECURSOR)
4882 : : {
4883 : : /* find the first ord of this derivative; ord of ring derivatives are in pairs */
4884 : 0 : int j = -1;
4885 [ # # # # ]: 0 : for (i = 0; i < DERIV_AT_LEN && da1->typ[i]; i++)
4886 : : {
4887 [ # # ]: 0 : if (da1->typ[i] & DERIV_RING_OUTSIDE_PRECURSOR)
4888 : : {
4889 [ # # # # ]: 0 : if (i == *idrv || i + 1 == *idrv)
4890 : : {
4891 : 0 : *idrv = j = i;
4892 : 0 : break;
4893 : : }
4894 : 0 : i++; /* bypass the second bond to the same derivatization agent */
4895 : : }
4896 : : }
4897 : : /* check consistency */
4898 [ # # # # ]: 0 : if (j == -1 || j + 1 >= DERIV_AT_LEN ||
4899 [ # # # # ]: 0 : !( da1->typ[j] & DERIV_RING_OUTSIDE_PRECURSOR ) || !( da1->typ[j + 1] & DERIV_RING_OUTSIDE_PRECURSOR ))
4900 : : {
4901 : 0 : ret = -1; /* program error */
4902 : : }
4903 : : else
4904 : : {
4905 : 0 : ret = is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR( at, start, num_atoms, da1, j, NULL, 0, NULL, 0, NULL );
4906 : : }
4907 : : }
4908 : : else
4909 : : {
4910 [ # # ]: 0 : if (da1->typ[*idrv])
4911 : : {
4912 : 0 : ret = is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR( at, start, num_atoms, da1, *idrv, NULL, 0, NULL, 0, NULL );
4913 : : }
4914 : : }
4915 : :
4916 : 0 : return ret;
4917 : : }
4918 : :
4919 : :
4920 : : #define DERIV_RING DERIV_RING_OUTSIDE_PRECURSOR
4921 : :
4922 : :
4923 : : /****************************************************************************/
4924 : 0 : int remove_deriv( DERIV_AT *da1, int idrv )
4925 : : {
4926 : 0 : int i, j, ret = -1;
4927 : :
4928 [ # # ]: 0 : if (da1->typ[idrv] & DERIV_RING)
4929 : : {
4930 : : /* find the first ord of this derivative; ord of ring derivatives are in pairs */
4931 : 0 : j = -1;
4932 [ # # # # ]: 0 : for (i = 0; i < DERIV_AT_LEN && da1->typ[i]; i++)
4933 : : {
4934 [ # # ]: 0 : if (da1->typ[i] & DERIV_RING)
4935 : : {
4936 [ # # # # ]: 0 : if (i == idrv || i + 1 == idrv)
4937 : : {
4938 : 0 : j = i;
4939 : 0 : break;
4940 : : }
4941 : 0 : i++; /* bypass the second bond to the same derivatization agent */
4942 : : }
4943 : : }
4944 : :
4945 : : /* delete if data are consistent */
4946 [ # # # # : 0 : if (j >= 0 && j + 1 < DERIV_AT_LEN && ( da1->typ[j] & DERIV_RING ) && ( da1->typ[j + 1] & DERIV_RING ))
# # # # ]
4947 : : {
4948 [ # # # # ]: 0 : for (; j < DERIV_AT_LEN - 2 && da1->typ[j + 2]; j++)
4949 : : {
4950 : 0 : da1->typ[j] = da1->typ[j + 2];
4951 : 0 : da1->num[j] = da1->num[j + 2];
4952 : 0 : da1->ord[j] = da1->ord[j + 2];
4953 : : }
4954 [ # # ]: 0 : for (; j < DERIV_AT_LEN; j++)
4955 : : {
4956 : 0 : da1->typ[j] = 0;
4957 : 0 : da1->num[j] = 0;
4958 : 0 : da1->ord[j] = 0;
4959 : : }
4960 : 0 : ret = 0;
4961 : : }
4962 : : }
4963 : : else
4964 : : {
4965 : 0 : j = idrv;
4966 [ # # # # ]: 0 : for (; j < DERIV_AT_LEN - 1 && da1->typ[j + 1]; j++)
4967 : : {
4968 : 0 : da1->typ[j] = da1->typ[j + 1];
4969 : 0 : da1->num[j] = da1->num[j + 1];
4970 : 0 : da1->ord[j] = da1->ord[j + 1];
4971 : : }
4972 [ # # ]: 0 : for (; j < DERIV_AT_LEN; j++)
4973 : : {
4974 : 0 : da1->typ[j] = 0;
4975 : 0 : da1->num[j] = 0;
4976 : 0 : da1->ord[j] = 0;
4977 : : }
4978 : 0 : ret = 0;
4979 : : }
4980 : :
4981 : 0 : return ret;
4982 : : }
4983 : :
4984 : :
4985 : : /****************************************************************************/
4986 : 0 : int remove_deriv_mark( DERIV_AT *da1, int idrv )
4987 : : {
4988 : 0 : int i, j, ret = -1;
4989 [ # # ]: 0 : if (da1->typ[idrv] & DERIV_RING)
4990 : : {
4991 : : /* find the first ord of this derivative; ord of ring derivatives are in pairs */
4992 : 0 : j = -1;
4993 [ # # # # ]: 0 : for (i = 0; i < DERIV_AT_LEN && da1->typ[i]; i++)
4994 : : {
4995 [ # # ]: 0 : if (da1->typ[i] & DERIV_RING)
4996 : : {
4997 [ # # # # ]: 0 : if (i == idrv || i + 1 == idrv)
4998 : : {
4999 : 0 : j = i;
5000 : 0 : break;
5001 : : }
5002 : 0 : i++; /* bypass the second bond to the same derivatization agent */
5003 : : }
5004 : : }
5005 : : /* delete if data are consistent */
5006 [ # # # # : 0 : if (j >= 0 && j + 1 < DERIV_AT_LEN && ( da1->typ[j] & DERIV_RING ) && ( da1->typ[j + 1] & DERIV_RING ))
# # # # ]
5007 : : {
5008 : 0 : da1->typ[j] |= DERIV_DUPLIC;
5009 : 0 : da1->typ[j + 1] |= DERIV_DUPLIC;
5010 : 0 : ret = 0;
5011 : : }
5012 : : }
5013 : : else
5014 : : {
5015 : 0 : j = idrv;
5016 : 0 : da1->typ[j] |= DERIV_DUPLIC;
5017 : 0 : ret = 0;
5018 : : }
5019 : :
5020 : 0 : return ret;
5021 : : }
5022 : :
5023 : :
5024 : : /****************************************************************************/
5025 : 0 : void underiv_buf_clear( char *szUnderiv )
5026 : : {
5027 [ # # ]: 0 : if (NULL != szUnderiv)
5028 : : {
5029 : 0 : szUnderiv[0] = '\0';
5030 : : }
5031 : 0 : }
5032 : :
5033 : : /****************************************************************************/
5034 : 0 : int underiv_list_add( char *szUnderivList, int lenUnderivList, const char *szUnderiv, char cDelimiter )
5035 : : {
5036 [ # # # # : 0 : if (NULL != szUnderivList && lenUnderivList > 0 && NULL != szUnderiv && *szUnderiv)
# # # # ]
5037 : : {
5038 : 0 : int lenList = strlen( szUnderivList );
5039 : 0 : int lenAdd = strlen( szUnderiv );
5040 : 0 : int bDelimiter = cDelimiter ? 1 : 0;
5041 [ # # ]: 0 : if (lenList + lenAdd + bDelimiter < lenUnderivList)
5042 : : {
5043 [ # # # # ]: 0 : if (lenList && bDelimiter)
5044 : : {
5045 : 0 : szUnderivList[lenList++] = cDelimiter;
5046 : : }
5047 : 0 : memcpy(szUnderivList + lenList, szUnderiv, (long long)lenAdd + 1); /* +1 adds zero termination */ /* djb-rwth: cast operator added */
5048 : 0 : return lenList + lenAdd;
5049 : : }
5050 : : }
5051 : :
5052 : 0 : return 0;
5053 : : }
5054 : :
5055 : :
5056 : : /****************************************************************************/
5057 : 0 : const char* underiv_list_get_last( const char *szUnderivList,
5058 : : char cDelimiter )
5059 : : {
5060 [ # # # # ]: 0 : if (szUnderivList && cDelimiter)
5061 : : {
5062 : 0 : const char *p = strrchr( szUnderivList, cDelimiter );
5063 [ # # ]: 0 : if (NULL == p)
5064 : : {
5065 : 0 : p = szUnderivList;
5066 : : }
5067 : 0 : return p;
5068 : : }
5069 : :
5070 : 0 : return NULL;
5071 : : }
5072 : :
5073 : :
5074 : : /****************************************************************************/
5075 : 0 : int underiv_compare( const void *p1, const void *p2 )
5076 : : {
5077 : 0 : return strcmp( *(const char **) p1, *(const char **) p2 );
5078 : : }
5079 : :
5080 : :
5081 : : /****************************************************************************/
5082 : 0 : int underiv_list_add_two_cuts( char *szUnderivList,
5083 : : int lenUnderivList,
5084 : : char *szUnderiv,
5085 : : const char cDelim )
5086 : : {
5087 : : /* may happen only in RN- case, DERIV_AMINE_tN, but not always */
5088 : 0 : const char szDelim[] = { cDelim, 0 };
5089 : 0 : char *p1 = strtok( szUnderiv, szDelim );
5090 [ # # ]: 0 : char *p2 = p1 ? strtok( NULL, szDelim ) : NULL;
5091 [ # # ]: 0 : char *p1m = p1 ? strchr( p1, '-' ) : NULL;
5092 [ # # ]: 0 : char *p2m = p2 ? strchr( p2, '-' ) : NULL;
5093 : : char *pm;
5094 : :
5095 [ # # # # ]: 0 : if (p1m && p2m)
5096 : : {
5097 [ # # # # ]: 0 : if (p1m - p1 == p2m - p2 && !memcmp( p1, p2, p1m - p1 ))
5098 : 0 : {
5099 : : /* found common prefix */
5100 : : int diff;
5101 : 0 : *p1m++ = '\0';
5102 : 0 : *p2m++ = '\0';
5103 : : /* output
5104 : : [common prefix]-(suffix1)+(suffix2): (suffix1)<(suffix2) or
5105 : : [common prefix]-2(suffix1): (suffix1)==(suffix2)
5106 : : */
5107 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p1, cDelim ); /* [common prefix] */
5108 : 0 : underiv_list_add( szUnderivList, lenUnderivList, "-", 0 ); /* - */
5109 : 0 : diff = strcmp( p1m, p2m );
5110 [ # # ]: 0 : if (diff > 0)
5111 : : {
5112 : 0 : pm = p1m;
5113 : 0 : p1m = p2m; /* (suffix1) - smaller */
5114 : 0 : p2m = pm; /* (suffix2) - greater */
5115 : : }
5116 [ # # ]: 0 : if (diff)
5117 : : {
5118 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p1m, 0 ); /* (suffix1) */
5119 : 0 : underiv_list_add( szUnderivList, lenUnderivList, "+", 0 ); /* - */
5120 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p2m, 0 ); /* (suffix2) */
5121 : : }
5122 : : else
5123 : : {
5124 : 0 : underiv_list_add( szUnderivList, lenUnderivList, "2", 0 ); /* 2 */
5125 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p1m, 0 ); /* (suffix1) */
5126 : : }
5127 : : }
5128 : : else
5129 : : {
5130 : : /* should not happen */
5131 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p1, cDelim );
5132 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p2, cDelim );
5133 : : }
5134 : : }
5135 : : else
5136 : : {
5137 [ # # # # ]: 0 : if (p1 && p2)
5138 : : {
5139 : : /* should not happen */
5140 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p1, cDelim );
5141 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p2, cDelim );
5142 : : }
5143 : : else
5144 : : {
5145 [ # # ]: 0 : if (p1)
5146 : : {
5147 : : /* happens in case only one num[] is not zero, namely, DERIV_RING2_OUTSIDE_PRECUR */
5148 : 0 : underiv_list_add( szUnderivList, lenUnderivList, p1, cDelim );
5149 : : }
5150 : : }
5151 : : }
5152 : :
5153 : 0 : return 0;
5154 : : }
5155 : :
5156 : :
5157 : : /****************************************************************************/
5158 : : #if( UNDERIVATIZE_REPORT == 1 )
5159 : 0 : int sort_merge_underiv( char *pSdfValue,
5160 : : int bOutputSdf,
5161 : : char *szUnderivList,
5162 : : char cDerivSeparator,
5163 : : const char *pszUnderivPrefix,
5164 : : const char *pszUnderivPostfix )
5165 : : {
5166 : : #define UNDERIV_MAX_NUM 512 /*max. number of records in szUnderivList */
5167 : 0 : int num, numUnderiv = 0, i, j, k, m, n;
5168 : : char *q;
5169 : : char coeff[16];
5170 : : char *pszUnderiv[UNDERIV_MAX_NUM];
5171 : :
5172 : 0 : num = strlen( pSdfValue );
5173 : 0 : n = num + strlen( pszUnderivPrefix ) + 1;
5174 : :
5175 [ # # ]: 0 : if (n + strlen( pszUnderivPostfix ) + 1 + strlen( szUnderivList ) < MAX_SDF_VALUE)
5176 : : {
5177 [ # # # # ]: 0 : for (numUnderiv = 0, q = strtok( szUnderivList, " " ); numUnderiv < UNDERIV_MAX_NUM && q; q = strtok( NULL, " " ), numUnderiv++)
5178 : : {
5179 : 0 : pszUnderiv[numUnderiv] = q;
5180 : : }
5181 : : /*if ( !bOutputSdf || num ) {*/
5182 : 0 : n = underiv_list_add( pSdfValue, MAX_SDF_VALUE, pszUnderivPrefix, 0 );
5183 : : /*}*/
5184 [ # # ]: 0 : if (numUnderiv > 1)
5185 : : {
5186 : 0 : qsort( pszUnderiv, numUnderiv, sizeof( pszUnderiv[0] ), underiv_compare );
5187 : : }
5188 [ # # ]: 0 : for (i = 0; i < numUnderiv; i = j)
5189 : : {
5190 [ # # # # ]: 0 : for (j = i + 1; j < numUnderiv && !underiv_compare( pszUnderiv + i, pszUnderiv + j ); j++)
5191 : : {
5192 : : ; /* find identical derivatives */
5193 : : }
5194 : 0 : k = strlen( pszUnderiv[i] );
5195 [ # # ]: 0 : if (1 < ( num = j - i ))
5196 : : {
5197 : 0 : k = sprintf(coeff, "%d", num);
5198 : : }
5199 [ # # ]: 0 : if ((long long)n + (long long)k + sizeof( pszUnderivPostfix ) < MAX_SDF_VALUE) /* djb-rwth: cast operators added */
5200 : : {
5201 [ # # ]: 0 : m = i ? cDerivSeparator : 0;
5202 [ # # ]: 0 : if (num > 1)
5203 : : {
5204 : 0 : underiv_list_add( pSdfValue, MAX_SDF_VALUE, coeff, m );
5205 : 0 : m = 0;
5206 : : }
5207 : 0 : n = underiv_list_add( pSdfValue, MAX_SDF_VALUE, pszUnderiv[i], m );
5208 : : }
5209 : : else
5210 : : {
5211 : 0 : underiv_list_add( pSdfValue, MAX_SDF_VALUE, "!", 0 ); /* overflow indicator */
5212 : 0 : numUnderiv = -( 1 + numUnderiv );
5213 : 0 : break;
5214 : : }
5215 : : }
5216 [ # # # # ]: 0 : if (!bOutputSdf || num)
5217 : : {
5218 : 0 : underiv_list_add( pSdfValue, MAX_SDF_VALUE, pszUnderivPostfix, 0 );
5219 : : }
5220 : : }
5221 : :
5222 : 0 : return numUnderiv;
5223 : : #undef UNDERIV_MAX_NUM
5224 : : }
5225 : : #endif /* UNDERIVATIZE_REPORT == 1 */
5226 : :
5227 : :
5228 : : /****************************************************************************/
5229 : 0 : int eliminate_deriv_not_in_list( inp_ATOM *at,
5230 : : DERIV_AT *da,
5231 : : int num_atoms,
5232 : : char *szUnderivList,
5233 : : int lenUnderivList,
5234 : : char *szUnderivList2,
5235 : : int lenUnderivList2,
5236 : : BIT_UNDERIV *bitUnderivList )
5237 : : {
5238 : 0 : int i, j, num_da, num_cuts = 0, num_cuts_this_atom, ret = 0;
5239 : : #if( UNDERIVATIZE_REPORT == 1 )
5240 : : #define UNDERIV_LEN 128
5241 : : #define UNDERIV_LEN2 128
5242 : : char szUnderiv[UNDERIV_LEN];
5243 : : char szUnderiv2[UNDERIV_LEN2];
5244 : : BIT_UNDERIV bitUnderiv;
5245 : : #else
5246 : : #define UNDERIV_LEN 0
5247 : : #define UNDERIV_LEN2 0
5248 : : char *szUnderiv = NULL;
5249 : : char *szUnderiv2 = NULL;
5250 : : BIT_UNDERIV bitUnderiv;
5251 : : #endif
5252 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
5253 : : {
5254 [ # # ]: 0 : if (!da[i].typ[0])
5255 : : {
5256 : 0 : continue;
5257 : : }
5258 : : /* count deriative attachments */
5259 [ # # # # ]: 0 : for (num_da = 0; num_da < DERIV_AT_LEN && da[i].typ[num_da]; num_da++)
5260 : : {
5261 : : ;
5262 : : }
5263 [ # # ]: 0 : if (num_da > 2)
5264 : : {
5265 : 0 : return -1; /* should not happen */
5266 : : }
5267 [ # # # # ]: 0 : if (num_da == 2 && da[i].typ[0] != da[i].typ[1])
5268 : : {
5269 : 0 : da[i].typ[0] = da[i].typ[1] = 0; /* do not allow */
5270 : 0 : continue;
5271 : : }
5272 : :
5273 : 0 : underiv_buf_clear( szUnderiv );
5274 : 0 : underiv_buf_clear( szUnderiv2 );
5275 : 0 : bitUnderiv = 0;
5276 : :
5277 : 0 : num_cuts_this_atom = 0;
5278 [ # # ]: 0 : if (da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR)
5279 : : {
5280 : 0 : ret = 0;
5281 : : #ifndef UNDERIV_SYLYL_ONLY
5282 [ # # # # : 0 : if (num_da == 2 && 1 + da[i].num[0] + da[i].num[1] <= MAX_AT_DERIV &&
# # ]
5283 : 0 : 0 < ( ret = is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR( at, i, num_atoms, da + i, 0, szUnderiv, UNDERIV_LEN, szUnderiv2, UNDERIV_LEN2, &bitUnderiv ) ))
5284 : : {
5285 : 0 : num_cuts += 2;
5286 : 0 : underiv_list_add( szUnderivList, lenUnderivList, szUnderiv, ' ' );
5287 : 0 : underiv_list_add( szUnderivList2, lenUnderivList2, szUnderiv2, ' ' );
5288 : 0 : *bitUnderivList |= bitUnderiv;
5289 : : }
5290 : : else
5291 : : #endif
5292 : : {
5293 [ # # ]: 0 : if (ret < 0)
5294 : : {
5295 : 0 : return ret;
5296 : : }
5297 : : else
5298 : : {
5299 : 0 : da[i].typ[0] = da[i].typ[1] = 0; /* not a derivative */
5300 : : }
5301 : : }
5302 : : }
5303 : : else
5304 : : {
5305 : 0 : ret = 0;
5306 : : /*if ( da[i].num[0] <= MAX_AT_DERIV && 0 < (ret = is_deriv_chain( at, i, num_atoms, da+i, 0 )) )*/
5307 [ # # # # : 0 : if (IS_DA_NUM_LE( da + i, 0, MAX_AT_DERIV ) && 0 < ( ret = is_deriv_chain( at, i, num_atoms, da + i, 0, szUnderiv, UNDERIV_LEN, szUnderiv2, UNDERIV_LEN2, &bitUnderiv ) ))
# # # # ]
5308 : : {
5309 : 0 : num_cuts++;
5310 : 0 : num_cuts_this_atom++;
5311 : 0 : j = 1;
5312 : : /*underiv_list_add( szUnderivList, lenUnderivList, szUnderiv, ' ' );*/
5313 : : }
5314 : : else
5315 : : {
5316 [ # # ]: 0 : if (ret < 0)
5317 : : {
5318 : 0 : return ret;
5319 : : }
5320 : : else
5321 : : {
5322 : 0 : da[i].ord[0] = da[i].ord[1];
5323 : 0 : da[i].num[0] = da[i].num[1];
5324 : 0 : da[i].typ[0] = da[i].typ[1];
5325 : 0 : da[i].typ[1] = 0;
5326 : 0 : j = 0;
5327 : : }
5328 : : }
5329 : : /*underiv_buf_clear( szUnderiv );*/
5330 : : /*if ( da[i].typ[j] && da[i].num[j] <= MAX_AT_DERIV &&*/
5331 [ # # # # : 0 : if (IS_DA_NUM_LE( da + i, j, MAX_AT_DERIV ) &&
# # # # ]
5332 : 0 : 0 < ( ret = is_deriv_chain( at, i, num_atoms, da + i, j, szUnderiv, UNDERIV_LEN, szUnderiv2, UNDERIV_LEN2, &bitUnderiv ) ))
5333 : : {
5334 : 0 : num_cuts++;
5335 : 0 : num_cuts_this_atom++;
5336 : : /*underiv_list_add( szUnderivList, lenUnderivList, szUnderiv, ' ' );*/
5337 : : }
5338 : : else
5339 : : {
5340 [ # # ]: 0 : if (ret < 0)
5341 : : {
5342 : 0 : return ret;
5343 : : }
5344 : : else
5345 : : {
5346 : 0 : da[i].typ[j] = 0;
5347 : : }
5348 : : }
5349 [ # # ]: 0 : if (num_cuts_this_atom == 2)
5350 : : {
5351 : : /* may happen only in RN- case, DERIV_AMINE_tN, but not always */
5352 : 0 : underiv_list_add_two_cuts( szUnderivList, lenUnderivList, szUnderiv, ' ' );
5353 : 0 : underiv_list_add( szUnderivList2, lenUnderivList2, szUnderiv2, ' ' );
5354 : 0 : *bitUnderivList |= bitUnderiv;
5355 : : }
5356 : : else
5357 : : {
5358 [ # # ]: 0 : if (num_cuts_this_atom == 1)
5359 : : {
5360 : 0 : underiv_list_add( szUnderivList, lenUnderivList, szUnderiv, ' ' );
5361 : 0 : underiv_list_add( szUnderivList2, lenUnderivList2, szUnderiv2, ' ' );
5362 : 0 : *bitUnderivList |= bitUnderiv;
5363 : : }
5364 : : }
5365 : : }
5366 : : }
5367 : :
5368 : 0 : return num_cuts;
5369 : : }
5370 : :
5371 : :
5372 : : /****************************************************************************/
5373 : 0 : int make_single_cut( inp_ATOM *at, DERIV_AT *da, int iat, int icut )
5374 : : {
5375 : 0 : int ret = -1; /* error flag */
5376 : 0 : int iord = (int) da[iat].ord[icut]; /* ord of the bond in iat */
5377 : :
5378 [ # # ]: 0 : if (da[iat].typ[icut] & DERIV_DUPLIC)
5379 : : {
5380 : 0 : return 0;
5381 : : }
5382 : :
5383 [ # # ]: 0 : if (iord < 0)
5384 : : {
5385 : 0 : return -1; /* program error */
5386 : : }
5387 : :
5388 : : else
5389 : : {
5390 : : /* find other da[] that affect at[iat] */
5391 : :
5392 : 0 : int jat = at[iat].neighbor[iord]; /* opposite atom */
5393 : 0 : AT_NUMB *p = is_in_the_list( at[jat].neighbor, (AT_NUMB) iat, at[jat].valence );
5394 [ # # ]: 0 : int jord = p ? ( p - at[jat].neighbor ) : -1;
5395 : : int i;
5396 : 0 : const int iT = 2;
5397 : : #ifdef UNDERIV_ADD_D_TO_PRECURSOR
5398 : : const int iD = 1;
5399 : : #endif
5400 : :
5401 [ # # ]: 0 : if (jord < 0)
5402 : : {
5403 : 0 : return -1; /* program error */
5404 : : }
5405 : :
5406 : 0 : ret = DisconnectInpAtBond( at, NULL, iat, iord );
5407 : :
5408 [ # # ]: 0 : if (ret == 1)
5409 : : {
5410 [ # # ]: 0 : if (da[iat].typ[icut] & DERIV_RING_OUTSIDE_PRECURSOR)
5411 : : {
5412 : : /* at[jat] belongs to the main structure */
5413 : 0 : at[jat].num_H++;
5414 : : #ifdef UNDERIV_ADD_D_TO_PRECURSOR
5415 : : at[jat].num_iso_H[iD] ++; /* add D to the main structure */
5416 : : #endif
5417 : 0 : at[iat].num_H++; /* add T to the derivatizing fragment */
5418 : 0 : at[iat].num_iso_H[iT] ++;
5419 : : }
5420 : : else
5421 : : {
5422 [ # # # # ]: 0 : if (da[iat].typ[icut] && ( da[iat].typ[icut] & DERIV_REPL_N_WITH_O ) == da[iat].typ[icut])
5423 : : {
5424 : 0 : at[jat].num_H++;
5425 : 0 : at[jat].num_iso_H[iT] ++; /* add T to the derivatizing fragment ??? */
5426 : : /* replace R=N-DerivAgent with R=O H-DerivAgent */
5427 : 0 : at[iat].elname[0] = 'O';
5428 : 0 : at[iat].el_number = EL_NUMBER_O; /* since N replaced with O, do not add H */
5429 : : }
5430 : : else
5431 : : {
5432 [ # # # # : 0 : if (!icut && da[iat].typ[icut] && ( da[iat].typ[icut] & DERIV_REPL_N_WITH_OH ) == da[iat].typ[icut])
# # ]
5433 : : {
5434 : : /* cut #0 is the second; in case of DERIV_RING2_OUTSIDE_PRECUR on the 1st cut H has already been added */
5435 : 0 : at[jat].num_H++;
5436 : 0 : at[jat].num_iso_H[iT] ++; /* add T to the derivatizing fragment ??? */
5437 : : /* replace R=N-DerivAgent with R=O H-DerivAgent */
5438 : 0 : at[iat].elname[0] = 'O';
5439 : 0 : at[iat].el_number = EL_NUMBER_O; /* since N replaced with O, do not add H */
5440 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
5441 [ # # ]: 0 : if (!( da[iat].typ[icut] & DERIV_RING2_OUTSIDE_PRECUR ))
5442 : : {
5443 : 0 : at[iat].num_H++;
5444 : : }
5445 : : #endif
5446 : : }
5447 : : else
5448 : : {
5449 : 0 : at[iat].num_H++;
5450 : : #ifdef UNDERIV_ADD_D_TO_PRECURSOR
5451 : : at[iat].num_iso_H[iD] ++; /* add D to the main structure */
5452 : : #endif
5453 : 0 : at[jat].num_H++; /* add T to the derivatizing fragment */
5454 : 0 : at[jat].num_iso_H[iT] ++;
5455 : : }
5456 : : }
5457 : : }
5458 : :
5459 : : /* adjust ord for other bonds */
5460 [ # # # # ]: 0 : for (i = 0; i < DERIV_AT_LEN && da[iat].typ[i]; i++)
5461 : : {
5462 [ # # ]: 0 : if (da[iat].ord[i] == iord)
5463 : : {
5464 : 0 : da[iat].ord[i] = -( 1 + da[iat].ord[i] ); /* mark the bond being disconnected */
5465 : : }
5466 [ # # ]: 0 : else if (da[iat].ord[i] > iord)
5467 : : {
5468 : 0 : da[iat].ord[i] --;
5469 : : }
5470 : : }
5471 [ # # # # ]: 0 : for (i = 0; i < DERIV_AT_LEN && da[jat].typ[i]; i++)
5472 : : {
5473 [ # # ]: 0 : if (da[jat].ord[i] == jord)
5474 : : {
5475 : : /* opposite atom needs the same bond to be disconnected */
5476 : : #ifdef NEVER /* not needed */
5477 : : if (da[iat].num[icut] == da[jat].num[i])
5478 : : {
5479 : : iD = 2; /* mark both as fragments */
5480 : : }
5481 : : else
5482 : : if (da[iat].num[icut] > da[jat].num[i])
5483 : : {
5484 : : iD = 2; /* greater as a main structure */
5485 : : iT = 1; /* mark smaller as a derivatizing fragment */
5486 : : }
5487 : : #endif
5488 : 0 : da[jat].ord[i] = -( 1 + da[jat].ord[i] );
5489 : 0 : da[jat].typ[i] |= DERIV_DUPLIC; /* do not cut again */
5490 : : }
5491 [ # # ]: 0 : else if (da[jat].ord[i] > jord)
5492 : : {
5493 : 0 : da[jat].ord[i] --;
5494 : : }
5495 : :
5496 : : }
5497 : : }
5498 : : }
5499 : :
5500 : :
5501 : 0 : return ret;
5502 : : }
5503 : :
5504 : :
5505 : : /****************************************************************************/
5506 : 0 : int fill_out_bond_cuts( inp_ATOM *at,
5507 : : DERIV_AT *da,
5508 : : int num_atoms,
5509 : : R2C_ATPAIR *ap,
5510 : : int num_cuts_to_check )
5511 : : {
5512 : : int i, j, k, n;
5513 : : AT_NUMB at1, at2;
5514 : 0 : int ret = 0;
5515 : : /* fill out the array of bonds to be cut */
5516 [ # # ]: 0 : for (i = j = 0; i < num_atoms; i++)
5517 : : {
5518 [ # # # # ]: 0 : if (( da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR ) && ( da[i].typ[1] & DERIV_RING_OUTSIDE_PRECURSOR ) &&
5519 [ # # # # ]: 0 : da[i].num[0] <= MAX_AT_DERIV && da[i].num[1] <= MAX_AT_DERIV)
5520 : : {
5521 [ # # ]: 0 : if (j + 1 >= num_cuts_to_check)
5522 : : {
5523 : 0 : ret = -2;
5524 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
5525 : : }
5526 [ # # ]: 0 : for (k = 0; k < 2; k++)
5527 : : {
5528 : 0 : at1 = i;
5529 : 0 : at2 = at[at1].neighbor[(int) da[at1].ord[k]];
5530 : 0 : n = ( at1 > at2 );
5531 : 0 : ap[j].at[n] = at1;
5532 : 0 : ap[j].at[1 - n] = at2; /* ap[j].at[0] < ap[j].at[1] */
5533 : 0 : ap[j].atno = i;
5534 : 0 : j++;
5535 : : }
5536 [ # # ]: 0 : if (0 < cmp_r2c_atpair( ap + j - 2, ap + j - 1 ))
5537 : : {
5538 : 0 : R2C_ATPAIR ap1 = ap[j - 2];
5539 : 0 : ap[j - 2] = ap[j - 1];
5540 : 0 : ap[j - 1] = ap1; /* sort each pair */
5541 : : }
5542 : : }
5543 : : else
5544 : : {
5545 : : /* 2013-12-04 DT */
5546 [ # # ]: 0 : if (da[i].typ[0] & DERIV_RING_DMOX_DEOX)
5547 : : {
5548 : 0 : int other_atom = (int) da[i].other_atom - 1;
5549 [ # # # # : 0 : if (da[i].typ[1] || other_atom < 0 || i == other_atom || da[other_atom].other_atom != i + 1 ||
# # # # ]
5550 [ # # # # ]: 0 : !( da[other_atom].typ[0] & DERIV_RING_DMOX_DEOX ) || da[other_atom].typ[1])
5551 : : {
5552 : 0 : ret = -3;
5553 : 0 : goto exit_r2c_num;
5554 : : /* no other cut may be at the atom in addition to DERIV_RING_DMOX_DEOX
5555 : : or no other_atom or other_atom has wrong deriv. type */
5556 : : }
5557 : : /* make sure the ap[] for the two cuts in the same ring are adjacent */
5558 [ # # ]: 0 : if (other_atom > i)
5559 : : {
5560 [ # # ]: 0 : if (j + 1 >= num_cuts_to_check)
5561 : : {
5562 : 0 : ret = -2;
5563 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
5564 : : }
5565 : : /* cut #1 */
5566 : 0 : at1 = i;
5567 : 0 : at2 = at[at1].neighbor[(int) da[at1].ord[0]];
5568 : 0 : n = ( at1 > at2 );
5569 : 0 : ap[j].at[n] = at1;
5570 : 0 : ap[j].at[1 - n] = at2; /* ap[j].at[0] < ap[j].at[1] */
5571 : 0 : ap[j].atno = i;
5572 : 0 : j++;
5573 : : /* cut #2 */
5574 : 0 : at1 = other_atom;
5575 : 0 : at2 = at[at1].neighbor[(int) da[at1].ord[0]];
5576 : 0 : n = ( at1 > at2 );
5577 : 0 : ap[j].at[n] = at1;
5578 : 0 : ap[j].at[1 - n] = at2; /* ap[j].at[0] < ap[j].at[1] */
5579 : 0 : ap[j].atno = i;
5580 : 0 : j++;
5581 : : }
5582 : : else
5583 : : {
5584 : : /* add each pair of cuts only once */
5585 : 0 : continue;
5586 : : }
5587 : : }
5588 : : #if ( COUNT_ALL_NOT_DERIV == 1 )
5589 : : else
5590 : : {
5591 [ # # # # ]: 0 : for (k = 0; k < DERIV_AT_LEN && da[i].typ[k]; k++)
5592 : : {
5593 [ # # # # ]: 0 : if (j >= num_cuts_to_check || ( da[i].typ[k] & DERIV_RING_OUTSIDE_PRECURSOR ))
5594 : : {
5595 : 0 : ret = -2;
5596 : 0 : goto exit_r2c_num; /* wrong number of cuts = num or wrong type */
5597 : : }
5598 : 0 : at1 = i;
5599 : 0 : at2 = at[i].neighbor[(int) da[i].ord[k]];
5600 : 0 : n = ( at1 > at2 );
5601 : : /* pair of atoms possibly to be disconnected */
5602 : 0 : ap[j].at[n] = at1;
5603 : 0 : ap[j].at[1 - n] = at2; /* ap[j].at[0] < ap[j].at[1] */
5604 : : /* precursor's atom */
5605 : 0 : ap[j].atno = i;
5606 : 0 : j++;
5607 : : }
5608 : : }
5609 : : #endif
5610 : : }
5611 : : }
5612 : 0 : return j;
5613 : :
5614 : 0 : exit_r2c_num:
5615 : :
5616 : 0 : return ret;
5617 : : }
5618 : :
5619 : :
5620 : : /****************************************************************************/
5621 : 0 : int mark_deriv_agents( inp_ATOM *at,
5622 : : DERIV_AT *da,
5623 : : int num_atoms,
5624 : : R2C_ATPAIR *ap,
5625 : : int num_cuts_to_check,
5626 : : AT_NUMB *pnum_comp,
5627 : : int *pcur_num_at )
5628 : : {
5629 : : /* mark components to be disconnected */
5630 : 0 : int comp_num = 0; /* number of components */
5631 : 0 : int cur_num_at = 0; /* number of atoms left after disconnecting the derivatizing agent */
5632 : 0 : int ret = 0;
5633 : 0 : int i, j, k = -1, n;
5634 : 0 : *pnum_comp = 0;
5635 : 0 : *pcur_num_at = 0;
5636 : 0 : UnMarkOtherIndicators( at, num_atoms );
5637 [ # # ]: 0 : for (i = 0; i < num_cuts_to_check; i++)
5638 : : {
5639 : 0 : n = 0;
5640 [ # # ]: 0 : for (j = 0; j < 2; j++)
5641 : : {
5642 [ # # ]: 0 : if (da[(int) ap[i].at[j]].typ[0])
5643 : : {
5644 : 0 : k = j;
5645 : 0 : n++;
5646 : : }
5647 : : }
5648 [ # # ]: 0 : if (n != 1)
5649 : : {
5650 : 0 : ret = -3;
5651 : 0 : goto exit_r2c_num; /* wrong atom pair */
5652 : : }
5653 : 0 : n = ap[i].at[k]; /* marked atom */
5654 [ # # ]: 0 : if (( da[n].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR ))
5655 : : {
5656 : 0 : n = ap[i].at[1 - k];
5657 : : }
5658 : : /* at[n] belongs to the precursor */
5659 [ # # ]: 0 : if (!at[n].at_type)
5660 : : {
5661 : 0 : comp_num++;
5662 : 0 : cur_num_at = mark_atoms_ap( at, n, ap, num_cuts_to_check, cur_num_at, comp_num );
5663 : : }
5664 : : }
5665 : :
5666 : 0 : *pnum_comp = comp_num;
5667 : 0 : *pcur_num_at = cur_num_at;
5668 : :
5669 : 0 : exit_r2c_num:
5670 : :
5671 : 0 : return ret;
5672 : : }
5673 : :
5674 : :
5675 : : #ifdef UNDERIV_ADD_EXPLICIT_H
5676 : :
5677 : :
5678 : : /*****************************************************************************/
5679 : 0 : int add_explicit_H( INP_ATOM_DATA *inp_cur_data )
5680 : : {
5681 : : /* do not care about stereo parities for now */
5682 : 0 : int curRemovedH, num_added_explicit_H, iat, num_removed_H, m, num_H, num_atoms = inp_cur_data->num_at;
5683 [ # # ]: 0 : if (( num_removed_H = inp_cur_data->num_removed_H ) > 0)
5684 : : {
5685 : 0 : inp_ATOM *at_H = (inp_ATOM *) inchi_calloc( num_removed_H, sizeof( inp_ATOM ) );
5686 : 0 : inp_ATOM *at = inp_cur_data->at;
5687 [ # # ]: 0 : for (curRemovedH = num_atoms, num_added_explicit_H = 0; curRemovedH < num_atoms + num_removed_H; curRemovedH++)
5688 : : {
5689 [ # # ]: 0 : if (at[curRemovedH].el_number == EL_NUMBER_H &&
5690 [ # # ]: 0 : 1 == at[curRemovedH].valence &&
5691 [ # # ]: 0 : ( iat = (int) at[curRemovedH].neighbor[0] ) < num_atoms &&
5692 [ # # # # ]: 0 : 0 <= ( m = at[curRemovedH].iso_atw_diff ) &&
5693 : : m <= NUM_H_ISOTOPES)
5694 : : {
5695 : : /* num_H is the total number of all implicit H including isotopic H */
5696 [ # # # # : 0 : if (at_H && 0 < at[iat].num_H && 0 <= ( num_H = at[iat].num_H - NUM_ISO_H( at, iat ) ) && ( (!m && num_H) || (m && at[iat].num_iso_H[m - 1]) )) /* djb-rwth: addressing LLVM warning; fixing a NULL pointer dereference */
# # # # #
# # # #
# ]
5697 : : { /* number of implicit H > 0 */
5698 : 0 : int val = at[iat].valence;
5699 : : /* set hydrogen atom */
5700 : 0 : at_H[num_added_explicit_H] = at[curRemovedH];
5701 : 0 : at_H[num_added_explicit_H].neighbor[0] = iat;
5702 : 0 : at_H[num_added_explicit_H].valence = 1;
5703 : 0 : at_H[num_added_explicit_H].chem_bonds_valence = at_H[num_added_explicit_H].bond_type[0];
5704 : : /* set heavy atom */
5705 : 0 : at[iat].neighbor[val] = num_atoms + num_added_explicit_H;
5706 : 0 : at[iat].bond_type[val] = at_H[num_added_explicit_H].bond_type[0];
5707 : 0 : at[iat].bond_stereo[val] = -at_H[num_added_explicit_H].bond_stereo[0];
5708 : 0 : at[iat].valence++;
5709 [ # # # # ]: 0 : if (BOND_SINGLE <= at[iat].bond_type[val] && at[iat].bond_type[val] <= BOND_TRIPLE)
5710 : : {
5711 : 0 : at[iat].chem_bonds_valence += at[iat].bond_type[val];
5712 : : }
5713 : : else
5714 : : {
5715 : : /* should not happen */
5716 : 0 : at_H[num_added_explicit_H].bond_type[0] = at[iat].bond_type[val] = BOND_SINGLE;
5717 : 0 : at[iat].chem_bonds_valence += BOND_SINGLE;
5718 : 0 : at_H[num_added_explicit_H].chem_bonds_valence = BOND_SINGLE;
5719 : : }
5720 : 0 : at[iat].num_H--;
5721 [ # # ]: 0 : if (m)
5722 : : {
5723 : 0 : at[iat].num_iso_H[m - 1] --;
5724 : : }
5725 : 0 : num_added_explicit_H++;
5726 : : }
5727 : : }
5728 : : }
5729 [ # # # # ]: 0 : if (0 < num_added_explicit_H && num_added_explicit_H <= num_removed_H)
5730 : : {
5731 : 0 : memcpy(at + num_atoms, at_H, num_added_explicit_H * sizeof(at));
5732 : 0 : inp_cur_data->num_removed_H = 0;
5733 : 0 : inp_cur_data->num_at = ( num_atoms += num_added_explicit_H );
5734 : : }
5735 [ # # ]: 0 : inchi_free( at_H );
5736 : : }
5737 : 0 : return num_atoms;
5738 : : }
5739 : : #endif /* UNDERIV_ADD_EXPLICIT_H */
5740 : :
5741 : :
5742 : : /****************************************************************************
5743 : : Main underivatization procedure
5744 : : ****************************************************************************/
5745 : 0 : int OAD_Edit_Underivatize( struct tagINCHI_CLOCK *ic,
5746 : : struct tagCANON_GLOBALS *pCG,
5747 : : ORIG_ATOM_DATA *orig_inp_data,
5748 : : int bOutputSdf,
5749 : : int bOutputReport,
5750 : : char *pSdfValue )
5751 : : {
5752 : :
5753 : : #define ALLOC_AP \
5754 : : if ( 0 < num_cuts_to_check && (lenAllocated_ap < num_cuts_to_check || !ap) ) {\
5755 : : if ( ap )\
5756 : : inchi_free( ap );\
5757 : : ap = (R2C_ATPAIR *) inchi_malloc( num_cuts_to_check * sizeof(ap[0]) );\
5758 : : if ( !ap ) {\
5759 : : ret = -1;\
5760 : : goto exit_function; /* malloc failure */\
5761 : : }\
5762 : : lenAllocated_ap = num_cuts_to_check;\
5763 : : }
5764 : :
5765 : 0 : int ret = 0, i, j, k, m, n, num_atoms, num_components, i_component, nFound, num, cur_num_at = 0, len, ind1, ind2, ind3; /* djb-rwth: adding variables for char -> int conversion of subscripts; initialisation added */
5766 : : int num_cuts, num_ring_cuts, num_cut_pieces, num_cuts_to_check;
5767 : 0 : inp_ATOM *at = orig_inp_data->at; /* djb-rwth: ignoring LLVM warning: value used */
5768 : 0 : INP_ATOM_DATA *inp_cur_data = NULL;
5769 : 0 : DERIV_AT *da = NULL;
5770 : 0 : R2C_ATPAIR *ap = NULL;
5771 : 0 : int lenAllocated_ap = 0;
5772 : 0 : int nTotNumCuts = 0;
5773 : 0 : int num_removed_H = 0; /* djb-rwth: ignoring LLVM warning: variable used */
5774 : : #ifdef FIX_UNDERIV_TO_SDF
5775 : 0 : inp_ATOM *at2 = NULL;
5776 : : #endif
5777 : : #if ( UNDERIVATIZE_REPORT == 1 )
5778 : : #define UNDERIV_LIST_LEN 2048
5779 : : #define UNDERIV_LIST_LEN2 2048
5780 : 0 : char szUnderivList[UNDERIV_LIST_LEN] = "";
5781 : 0 : char szUnderivList2[UNDERIV_LIST_LEN2] = "";
5782 : 0 : char underivPrefix[] = "\tDeriv=";
5783 : 0 : char underivPostfix[] = "";
5784 : 0 : char underivPrefix2[] = "\tDeriv2=";
5785 : 0 : char underivPostfix2[] = "";
5786 : 0 : char underivPrefix3[] = "\tDerivBits=";
5787 : 0 : char underivPostfix3[] = "";
5788 : 0 : char cDerivSeparator = ',';
5789 : 0 : int numUnderiv = 0, numUnderiv2 = 0, numUnderiv3 = 0; /* djb-rwth: ignoring LLVM warning: variables used to store function return value */
5790 : 0 : BIT_UNDERIV bitUnderivList = 0;
5791 : : char szbitUnderivList[16]; /* int32 has at most 32/4=8 hexadecimal digits + 0x prefix + zero termination = 8+2+1=11 */
5792 : : #else
5793 : : #define UNDERIV_LIST_LEN 0
5794 : : #define UNDERIV_LIST_LEN2 0
5795 : : #define UNDERIV_MAX_NUM 0 /*max. number of records in szUnderivList */
5796 : : char *szUnderivList = NULL;
5797 : : char *szUnderivList2 = NULL;
5798 : : char **pszUnderiv = NULL;
5799 : : BIT_UNDERIV bitUnderivList = 0;
5800 : : #endif
5801 : :
5802 : :
5803 : : /* Prepare */
5804 : :
5805 : : /*set_R2C_el_numbers( );*/
5806 : :
5807 : : #ifndef UNDERIV_ADD_EXPLICIT_H
5808 : : num_atoms = remove_terminal_HDT( orig_inp_data->num_inp_atoms, at, 1, NULL );
5809 : : /*^^^^^ always accomodate accomodate FIX_TERM_H_CHRG_BUG - IPl, July 2008*/
5810 : : num_removed_H = orig_inp_data->num_inp_atoms - num_atoms;
5811 : : orig_inp_data->num_inp_atoms = num_atoms;
5812 : : #endif
5813 : :
5814 : : /* Initialize */
5815 : 0 : UnMarkDisconnectedComponents( orig_inp_data );
5816 : : /* djb-rwth: removing redundant code */
5817 : :
5818 : : /* Mark */
5819 : 0 : num_components = MarkDisconnectedComponents( orig_inp_data, 0 );
5820 : 0 : inp_cur_data = (INP_ATOM_DATA *) inchi_calloc( num_components, sizeof( inp_cur_data[0] ) );
5821 : :
5822 [ # # ]: 0 : for (i_component = 0; i_component < num_components; i_component++)
5823 : : {
5824 : 0 : CreateInpAtomData(inp_cur_data + i_component, orig_inp_data->nCurAtLen[i_component], 0);
5825 : :
5826 : 0 : inp_cur_data[i_component].num_at = ExtractConnectedComponent(orig_inp_data->at, orig_inp_data->num_inp_atoms, i_component + 1, inp_cur_data[i_component].at);
5827 : :
5828 : : /* error processing */
5829 [ # # # # ]: 0 : if (inp_cur_data[i_component].num_at <= 0 || orig_inp_data->nCurAtLen[i_component] != inp_cur_data[i_component].num_at)
5830 : : {
5831 : 0 : ret = -(i_component + 1); /* severe error */
5832 : 0 : goto exit_function;
5833 : : }
5834 : :
5835 : : #ifdef UNDERIV_ADD_EXPLICIT_H
5836 : 0 : num_atoms = remove_terminal_HDT(inp_cur_data[i_component].num_at, inp_cur_data[i_component].at, 1, NULL);
5837 : 0 : inp_cur_data[i_component].num_removed_H = inp_cur_data[i_component].num_at - num_atoms;
5838 : 0 : inp_cur_data[i_component].num_at = num_atoms;
5839 : : #endif
5840 : :
5841 : : /* Initialize */
5842 : 0 : num_atoms = inp_cur_data[i_component].num_at;
5843 : 0 : at = inp_cur_data[i_component].at;
5844 : 0 : add_DT_to_num_H(num_atoms, at);
5845 : :
5846 : 0 : UnMarkRingSystemsInp(at, num_atoms);
5847 : 0 : UnMarkOtherIndicators(at, num_atoms);
5848 : 0 : UnMarkOneComponent(at, num_atoms);
5849 : 0 : MarkRingSystemsInp(at, num_atoms, 0);
5850 : : #ifdef FIX_UNDERIV_TO_SDF
5851 [ # # ]: 0 : if (bOutputSdf)
5852 : : {
5853 : : /* save orig. bond types to restore them after replacing them with aromatic */
5854 [ # # ]: 0 : if (at2)
5855 : : {
5856 [ # # ]: 0 : inchi_free(at2);
5857 : : }
5858 [ # # ]: 0 : if ((at2 = (inp_ATOM*)inchi_malloc(num_atoms * sizeof(inp_ATOM)))) /* djb-rwth: addressing LLVM warning */
5859 : : {
5860 : 0 : memcpy(at2, at, num_atoms * sizeof(inp_ATOM));
5861 : : }
5862 : : }
5863 : : #endif
5864 : :
5865 : : /* Mark aromatic bonds */
5866 : 0 : ret = mark_arom_bonds(ic, pCG, at, num_atoms);
5867 [ # # ]: 0 : if (ret < 0)
5868 : : {
5869 : 0 : goto exit_function;
5870 : : }
5871 : 0 : ret = 0;
5872 : :
5873 [ # # ]: 0 : if (da)
5874 : : {
5875 [ # # ]: 0 : inchi_free(da);
5876 : : }
5877 : 0 : da = (DERIV_AT*)inchi_calloc(num_atoms, sizeof(da[0]));
5878 : :
5879 : : /* Detect derivatives */
5880 : 0 : nFound = 0;
5881 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
5882 : : {
5883 [ # # # # ]: 0 : if (at[i].bCutVertex && !da[i].typ[inchi_min(at[i].valence, DERIV_AT_LEN) - 1])
5884 : : {
5885 [ # # ]: 0 : for (k = 0; k < at[i].valence; k++)
5886 : : {
5887 : 0 : num = count_one_bond_atoms(at, da, i, k, CFLAG_MARK_BRANCH, &nFound);
5888 : 0 : UnMarkOtherIndicators(at, num_atoms);
5889 [ # # ]: 0 : if (num < 0)
5890 : : {
5891 : 0 : ret = num; /* severe error */
5892 : 0 : goto exit_function;
5893 : : }
5894 : : }
5895 : : }
5896 : : }
5897 : :
5898 : : /* Prepare cuts: remove cuts that are not to be done */
5899 : : /* in addition, count ring cuts DERIV_RING_OUTSIDE_PRECURSOR */
5900 : 0 : num_ring_cuts = 0;
5901 : 0 : num_cuts = 0;
5902 : 0 : num_cut_pieces = 0;
5903 [ # # ]: 0 : if (da) /* djb-rwth: fixing a NULL pointer dereference */
5904 : : {
5905 [ # # ]: 0 : for (i = num = 0; i < num_atoms; i++) /* djb-rwth: ignoring LLVM warning: variable used */
5906 : : {
5907 : : /*for ( len = 0; len < MAX_AT_DERIV && da[i].typ[len]; len ++ ) -- bug fixed 2013-11-07 DCh */
5908 [ # # # # ]: 0 : for (len = 0; len < DERIV_AT_LEN && da[i].typ[len]; len++)
5909 : : {
5910 : : ;
5911 : : }
5912 [ # # # # : 0 : switch (len)
# # ]
5913 : : {
5914 : :
5915 : 0 : case 0:
5916 : 0 : continue;
5917 : :
5918 : 0 : case 1:
5919 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
5920 [ # # ]: 0 : if (da[i].typ[0] & DERIV_RING_DMOX_DEOX)
5921 : : {
5922 [ # # # # ]: 0 : if (!da[i].other_atom || (j = da[i].other_atom - 1) >= num_atoms ||
5923 [ # # ]: 0 : (da[j].typ[0] ^ DERIV_RING_DMOX_DEOX) != da[i].typ[0] ||
5924 [ # # ]: 0 : da[j].other_atom - 1 != i)
5925 : : {
5926 : : /* program error */
5927 : 0 : da[i].num[0] = NOT_AT_DERIV;
5928 : : }
5929 : : else
5930 : : {
5931 : : /* one of 2 ring cuts */
5932 : 0 : num_cuts += 1;
5933 : 0 : num_ring_cuts += 1;
5934 : 0 : num_cut_pieces += (i > j); /* count pieces only once */
5935 : : }
5936 : : }
5937 : : else
5938 : : #endif
5939 : : {
5940 : : /* single cut: unconditional */
5941 : 0 : num_cuts += 1;
5942 : 0 : num_cut_pieces += 1;
5943 : : }
5944 : 0 : continue;
5945 : :
5946 : 0 : case 2:
5947 [ # # # # ]: 0 : if ((da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR) && (da[i].typ[1] & DERIV_RING_OUTSIDE_PRECURSOR))
5948 : : {
5949 : : /* double cut, unconditional */
5950 : 0 : num_ring_cuts += 2;
5951 : 0 : num_cuts += 2;
5952 : 0 : num_cut_pieces += 1;
5953 : 0 : continue;
5954 : : }
5955 : : else
5956 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
5957 [ # # # # : 0 : if (da[i].typ[0] && (da[i].typ[0] & DERIV_RING2_OUTSIDE_PRECUR) == da[i].typ[0] && da[i].typ[1] == da[i].typ[0])
# # ]
5958 : : {
5959 : : /* double cut, unconditional */
5960 : 0 : num_ring_cuts += 2;
5961 : 0 : num_cuts += 2;
5962 : 0 : num_cut_pieces += 1;
5963 : 0 : continue;
5964 : : }
5965 : : else
5966 : : #endif
5967 [ # # # # ]: 0 : if (da[i].typ[0] == DERIV_AMINE_tN && da[i].typ[1] == DERIV_AMINE_tN)
5968 : : {
5969 : : /* double cut, unconditional */
5970 : 0 : num_cuts += 2;
5971 : 0 : num_cut_pieces += 2;
5972 : 0 : continue;
5973 : : }
5974 : : else
5975 : : #ifdef DERIV_RO_COX
5976 [ # # # # ]: 0 : if (da[i].typ[0] == DERIV_RO_COX && da[i].typ[1] == DERIV_RO_COX)
5977 : : {
5978 [ # # ]: 0 : if (da[i].num[0] == da[i].num[1])
5979 : : {
5980 : 0 : memset(da + i, 0, sizeof(da[0])); /* don't remove if the two agents are identical */ /* djb-rwth: memset_s C11/Annex K variant? */
5981 : 0 : continue;
5982 : : }
5983 : : else
5984 : : {
5985 [ # # # # ]: 0 : if (da[i].num[0] && da[i].num[1])
5986 : 0 : {
5987 : : static char pref_RO_COX[] = {/*likely deriv.agent*/12, 9, 6, 13, 3, 8/*likely precursor*/, 0 };
5988 : 0 : char* p0 = strchr(pref_RO_COX, da[i].num[0]);
5989 : 0 : char* p1 = strchr(pref_RO_COX, da[i].num[1]);
5990 [ # # # # ]: 0 : if (p0 && p1)
5991 : : {
5992 : 0 : j = p1 < p0; /* j=1 => deriv. agent num[1] has higher priority */
5993 : : }
5994 : : else
5995 : : {
5996 [ # # # # ]: 0 : j = p0 ? 0 : p1 ? 1 : -1; /* we are here if there is a program error */
5997 : : }
5998 : : }
5999 : : else
6000 : : {
6001 [ # # # # ]: 0 : j = da[i].num[0] ? 0 : da[i].num[1] ? 1 : -1; /* we are here if there is a program error */
6002 : : }
6003 : : }
6004 : :
6005 [ # # # # ]: 0 : switch (j)
6006 : : {
6007 : 0 : case 1:
6008 : 0 : da[i].num[0] = da[i].num[1];
6009 : 0 : da[i].ord[0] = da[i].ord[1];
6010 : : /* fall through */
6011 : 0 : case 0:
6012 : 0 : da[i].typ[1] = 0;
6013 : 0 : da[i].num[1] = 0;
6014 : 0 : da[i].ord[1] = 0;
6015 : 0 : num_cuts += 1;
6016 : 0 : num_cut_pieces += 1;
6017 : 0 : continue;
6018 : 0 : case -1:
6019 : 0 : memset(da + i, 0, sizeof(da[0])); /* djb-rwth: memset_s C11/Annex K variant? */
6020 : 0 : break; /* will produce error */
6021 : : }
6022 : : }
6023 : : #endif /* DERIV_RO_COX */
6024 : : else
6025 [ # # ]: 0 : if (da[i].typ[0] == da[i].typ[1])
6026 : 0 : {
6027 : 0 : int sy0 = 0, sy1 = 0;
6028 : : /* DERIV_BRIDGE_O or DERIV_BRIDGE_NH ; cut off the smallest */
6029 [ # # ]: 0 : if (0 == is_deriv_chain(at, i, num_atoms, da + i, 0, NULL, 0, NULL, 0, NULL))
6030 : : {
6031 : 0 : da[i].num[0] = NOT_AT_DERIV;
6032 : : }
6033 : : else
6034 : : {
6035 : 0 : ind1 = da[i].ord[0] - '0'; /* djb-rwth: converting char to int for subscript use */
6036 : 0 : sy0 = is_silyl2(at, at[i].neighbor[ind1], i);
6037 : : }
6038 [ # # ]: 0 : if (0 == is_deriv_chain(at, i, num_atoms, da + i, 1, NULL, 0, NULL, 0, NULL))
6039 : : {
6040 : 0 : da[i].num[1] = NOT_AT_DERIV;
6041 : : }
6042 : : else
6043 : : {
6044 : 0 : ind2 = da[i].ord[1] - '0'; /* djb-rwth: converting char to int for subscript use */
6045 : 0 : sy1 = is_silyl2(at, at[i].neighbor[ind2], i);
6046 : : }
6047 [ # # # # : 0 : if ((sy1 && (!sy0 || sy1 < sy0)) || (!(sy0 || sy1) && da[i].num[0] > da[i].num[1])) /* djb-rwth: addressing LLVM warnings */
# # # # #
# # # ]
6048 : : {
6049 : 0 : da[i].num[0] = da[i].num[1];
6050 : 0 : da[i].ord[0] = da[i].ord[1];
6051 : 0 : da[i].typ[0] = da[i].typ[1];
6052 : 0 : da[i].typ[1] = 0;
6053 : 0 : num_cuts += 1;
6054 : 0 : num_cut_pieces += 1;
6055 : : }
6056 : : else
6057 : : {
6058 [ # # # # : 0 : if ((sy0 && (!sy1 || sy0 < sy1)) || (!(sy0 || sy1) && da[i].num[0] < da[i].num[1])) /* djb-rwth: addressing LLVM warning */
# # # # #
# # # ]
6059 : : {
6060 : 0 : da[i].typ[1] = 0;
6061 : 0 : num_cuts += 1;
6062 : 0 : num_cut_pieces += 1;
6063 : : }
6064 : : else
6065 : : {
6066 : : /* attachments have same size: ignore both */
6067 : : /* ??? check for standard derivatizations ??? */
6068 : 0 : da[i].typ[0] = 0;
6069 : 0 : da[i].typ[1] = 0;
6070 : : }
6071 : : }
6072 : 0 : continue;
6073 : : }
6074 : : #ifdef DERIV_RO_COX
6075 : : else
6076 [ # # # # ]: 0 : if ((da[i].typ[0] & (DERIV_RO_COX | DERIV_BRIDGE_O)) && (da[i].typ[1] & (DERIV_RO_COX | DERIV_BRIDGE_O)))
6077 : : {
6078 : : /*static char pref_RO_COX2[] = {13, 3, 8*/
6079 : : /*likely precursor*/
6080 : : /*, 0};*/
6081 : 0 : j = (da[i].typ[0] == DERIV_BRIDGE_O); /* da[i].typ[j] == DERIV_RO_COX */
6082 : : /*------------------------------------------------------------------------*
6083 : : * discard DERIV_RO_COX only in case [CH3-C(=O)]-O-[CH3] *
6084 : : * precursor DERIV_BRIDGE_O DERIV_RO_COX precursor *
6085 : : * has already been done in finding DERIV_RO_COX *
6086 : : *------------------------------------------------------------------------*/
6087 : : #ifdef NEVER
6088 : : /* methyl/ethyl alcoholes have already been excluded in get_traversed_deriv_type(...)
6089 : : for etyl/methyl acetate/benzoate. Only acetate/benzoic acids may their precursors */
6090 : : if (da[i].num[j] == 3 && /* -O-[C(=O)-CH3] : DERIV_RO_COX*/
6091 : : da[i].num[1 - j] == 1)
6092 : : { /* [CH3]-O-C(=O)-R : DERIV_BRIDGE_O; derivatizin agent in [] */
6093 : : j = 1 - j; /* remove da[i].xxx[j] */
6094 : : }
6095 : : #endif
6096 : : /*
6097 : : O
6098 : : ||
6099 : : R----O----C---X
6100 : :
6101 : : R----O---OC---X
6102 : : DERIV_BRIDGE_O \___/\____precursor__/
6103 : :
6104 : : R----O----COX
6105 : : \___precursor__/ \___/ DERIV_RO_COX
6106 : :
6107 : : rule: If R is >Si< then select DERIV_BRIDGE_O
6108 : :
6109 : : */
6110 : :
6111 [ # # ]: 0 : if (j /* choose DERIV_RO_COX */)
6112 : : {
6113 : : /* da[i].typ[1]=DERIV_RO_COX is not likely a precursor */
6114 : 0 : da[i].typ[0] = da[i].typ[1];
6115 : 0 : da[i].num[0] = da[i].num[1];
6116 : 0 : da[i].ord[0] = da[i].ord[1];
6117 : : }
6118 : 0 : da[i].typ[1] = 0;
6119 : 0 : da[i].num[1] = 0;
6120 : 0 : da[i].ord[1] = 0;
6121 : :
6122 : 0 : num_cuts += 1;
6123 : 0 : num_cut_pieces += 1;
6124 : 0 : continue;
6125 : : }
6126 : : #endif
6127 : 0 : ret = -88;
6128 : 0 : goto exit_function; /* unexpected */
6129 : :
6130 : 0 : case 3:
6131 [ # # ]: 0 : if (da[i].typ[0] == da[i].typ[1] &&
6132 [ # # ]: 0 : da[i].typ[0] == da[i].typ[2] &&
6133 [ # # ]: 0 : da[i].typ[0] == DERIV_AMINE_tN)
6134 : 0 : {
6135 : : int x, y, z;
6136 : 0 : int sy[3] = { 0, 0, 0 }; /* silyl */
6137 : :
6138 [ # # ]: 0 : if (0 == is_deriv_chain(at, i, num_atoms, da + i, 0, NULL, 0, NULL, 0, NULL))
6139 : : {
6140 : 0 : da[i].num[0] = NOT_AT_DERIV;
6141 : : }
6142 : : else
6143 : : {
6144 : 0 : ind1 = da[i].ord[0] - '0'; /* djb-rwth: converting char to int for subscript use */
6145 : 0 : sy[0] = is_silyl2(at, at[i].neighbor[ind1], i);
6146 : : }
6147 : :
6148 [ # # ]: 0 : if (0 == is_deriv_chain(at, i, num_atoms, da + i, 1, NULL, 0, NULL, 0, NULL))
6149 : : {
6150 : 0 : da[i].num[1] = NOT_AT_DERIV;
6151 : : }
6152 : : else
6153 : : {
6154 : 0 : ind2 = da[i].ord[1] - '0'; /* djb-rwth: converting char to int for subscript use */
6155 : 0 : sy[1] = is_silyl2(at, at[i].neighbor[ind2], i);
6156 : : }
6157 : :
6158 [ # # ]: 0 : if (0 == is_deriv_chain(at, i, num_atoms, da + i, 2, NULL, 0, NULL, 0, NULL))
6159 : : {
6160 : 0 : da[i].num[2] = NOT_AT_DERIV;
6161 : : }
6162 : : else
6163 : : {
6164 : 0 : ind3 = da[i].ord[2] - '0'; /* djb-rwth: converting char to int for subscript use */
6165 : 0 : sy[2] = is_silyl2(at, at[i].neighbor[ind3], i);
6166 : : }
6167 : :
6168 : : /* djb-rwth: removing redundant code */
6169 : :
6170 [ # # # # : 0 : x = ((sy[0] && (!sy[1] || sy[0] < sy[1])) || (!(sy[0] || sy[1]) && da[i].num[0] < da[i].num[1])) ? 0 : 1; /* djb-rwth: addressing LLVM warning */
# # # # #
# # # ]
6171 : 0 : z = !x;
6172 [ # # # # : 0 : x = ((sy[x] && (!sy[2] || sy[x] < sy[2])) || (!(sy[x] || sy[2]) && da[i].num[x] < da[i].num[2])) ? x : 2; /* min */ /* djb-rwth: addressing LLVM warning */
# # # # #
# # # ]
6173 : : /*z = (da[i].num[0] < da[i].num[1])? 1 : 0;*/
6174 : : /*z = (da[i].num[x] < da[i].num[2])? 2 : z;*/ /* max */
6175 [ # # # # : 0 : z = ((sy[x] && (!sy[2] || sy[x] < sy[2])) || (!(sy[x] || sy[2]) && da[i].num[x] < da[i].num[2])) ? 2 : z; /* max */ /* djb-rwth: addressing LLVM warning */
# # # # #
# # # ]
6176 : 0 : y = ((x + 1) ^ (z + 1)) - 1; /* median */
6177 : :
6178 [ # # # # ]: 0 : if (da[i].num[x] == da[i].num[z] && sy[x] == sy[z])
6179 : : {
6180 : : /* no cuts */
6181 : 0 : da[i].typ[0] = 0;
6182 : 0 : da[i].typ[1] = 0;
6183 : 0 : da[i].typ[2] = 0;
6184 : 0 : continue; /* all deriv. agents have same size, ignore */
6185 : : /* ??? check for standard derivatizations ??? */
6186 : : }
6187 : : else
6188 : : {
6189 [ # # # # : 0 : if ((da[i].num[x] == da[i].num[y] && sy[x] == sy[y]) || (sy[x] && sy[y] && !sy[z])) /* djb-rwth: addressing LLVM warning */
# # # # #
# ]
6190 : : {
6191 : : /* two smallest */
6192 [ # # # # ]: 0 : switch (z)
6193 : : {
6194 : 0 : case 0:
6195 : 0 : da[i].num[0] = da[i].num[1];
6196 : 0 : da[i].ord[0] = da[i].ord[1];
6197 : 0 : da[i].typ[0] = da[i].typ[1];
6198 : :
6199 : 0 : da[i].num[1] = da[i].num[2];
6200 : 0 : da[i].ord[1] = da[i].ord[2];
6201 : 0 : da[i].typ[1] = da[i].typ[2];
6202 : 0 : break;
6203 : 0 : case 1:
6204 : 0 : da[i].num[1] = da[i].num[2];
6205 : 0 : da[i].ord[1] = da[i].ord[2];
6206 : 0 : da[i].typ[1] = da[i].typ[2];
6207 : 0 : break;
6208 : 0 : case 2:
6209 : 0 : break;
6210 : : }
6211 : 0 : da[i].typ[2] = 0;
6212 : 0 : num_cuts += 2;
6213 : 0 : num_cut_pieces += 2;
6214 : : }
6215 : : else
6216 : : {
6217 : : /* one smallest */
6218 [ # # ]: 0 : if (x)
6219 : : {
6220 : 0 : da[i].num[0] = da[i].num[x];
6221 : 0 : da[i].ord[0] = da[i].ord[x];
6222 : 0 : da[i].typ[0] = da[i].typ[x];
6223 : : }
6224 : 0 : da[i].typ[1] = 0;
6225 : 0 : da[i].typ[2] = 0;
6226 : 0 : num_cuts += 1;
6227 : 0 : num_cut_pieces += 1;
6228 : : }
6229 : : }
6230 : 0 : continue;
6231 : : }
6232 : 0 : ret = -88;
6233 : 0 : goto exit_function; /* unexpected */
6234 : :
6235 : 0 : case 4:
6236 [ # # # # ]: 0 : if ((da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR) && (da[i].typ[1] & DERIV_RING_OUTSIDE_PRECURSOR) &&
6237 [ # # # # ]: 0 : (da[i].typ[2] & DERIV_RING_OUTSIDE_PRECURSOR) && (da[i].typ[3] & DERIV_RING_OUTSIDE_PRECURSOR))
6238 : 0 : {
6239 : 0 : int n01 = inchi_max(da[i].num[0], da[i].num[1]);
6240 : 0 : int n23 = inchi_max(da[i].num[2], da[i].num[3]);
6241 [ # # # # ]: 0 : if (n01 < n23 && 0 < is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR(at, i, num_atoms, da + i, 0, NULL, 0, NULL, 0, NULL))
6242 : : {
6243 : 0 : da[i].typ[2] = 0;
6244 : 0 : da[i].typ[3] = 0;
6245 : 0 : num_cuts += 2;
6246 : 0 : num_ring_cuts += 2;
6247 : 0 : num_cut_pieces += 1;
6248 : : }
6249 : : else
6250 : : {
6251 [ # # # # ]: 0 : if (n01 > n23 && 0 < is_DERIV_RING_O_or_NH_OUTSIDE_PRECURSOR(at, i, num_atoms, da + i, 2, NULL, 0, NULL, 0, NULL))
6252 : : {
6253 : 0 : da[i].num[0] = da[i].num[2];
6254 : 0 : da[i].ord[0] = da[i].ord[2];
6255 : 0 : da[i].typ[0] = da[i].typ[2];
6256 : :
6257 : 0 : da[i].num[1] = da[i].num[3];
6258 : 0 : da[i].ord[1] = da[i].ord[3];
6259 : 0 : da[i].typ[1] = da[i].typ[3];
6260 : :
6261 : 0 : da[i].typ[2] = 0;
6262 : 0 : da[i].typ[3] = 0;
6263 : 0 : num_cuts += 2;
6264 : 0 : num_ring_cuts += 2;
6265 : 0 : num_cut_pieces += 1;
6266 : : }
6267 : : else
6268 : : {
6269 : 0 : da[i].typ[0] = 0;
6270 : 0 : da[i].typ[1] = 0;
6271 : 0 : da[i].typ[2] = 0;
6272 : 0 : da[i].typ[3] = 0;
6273 : : }
6274 : : }
6275 : 0 : continue;
6276 : : }
6277 : 0 : ret = -88;
6278 : 0 : goto exit_function; /* unexpected */
6279 : : }
6280 : : }
6281 : :
6282 : : /*
6283 : : Eliminate cases when
6284 : : da[i1].typ[j1] && da[i2].typ[j2] &&
6285 : : at[i1].neighbor[da[i1].ord[j1]] == i2 && at[i2].neighbor[da[i2].ord[j2]] == i1
6286 : : that is, same bond is in the da[] elements of the adjacent atoms
6287 : : */
6288 : :
6289 : 0 : nFound = 0; /* number of cuts to remove */
6290 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
6291 : : {
6292 : : /*for ( j = 0; j < MAX_AT_DERIV && da[i].typ[j]; j ++ ) -- bug fixed 2013-11-07 DCh */
6293 [ # # # # ]: 0 : for (j = 0; j < DERIV_AT_LEN && da[i].typ[j]; j++)
6294 : : {
6295 [ # # ]: 0 : if (da[i].typ[j] & DERIV_DUPLIC)
6296 : : {
6297 : 0 : continue;
6298 : : }
6299 : 0 : n = at[i].neighbor[(int)da[i].ord[j]];
6300 [ # # ]: 0 : if (n < i)
6301 : : {
6302 : 0 : continue;
6303 : : }
6304 : : /*for ( k = 0; k < MAX_AT_DERIV && da[n].typ[k]; k ++ ) -- bug fixed 2013-11-07 DCh */
6305 [ # # # # : 0 : for (k = 0; k < DERIV_AT_LEN && n< num_atoms && da[n].typ[k]; k++)
# # ]
6306 : : {
6307 [ # # ]: 0 : if (da[n].typ[k] & DERIV_DUPLIC)
6308 : : {
6309 : 0 : continue;
6310 : : }
6311 : 0 : m = at[n].neighbor[(int)da[n].ord[k]];
6312 [ # # ]: 0 : if (m == i)
6313 : : {
6314 : : /* same bond in da[i].typ[j] and da[n].typ[k] */
6315 : : /* check whether both derivatives are acceptable */
6316 : 0 : int k1 = k, j1 = j;
6317 : 0 : int ret_i = is_deriv_chain_or_ring(at, i, num_atoms, da + i, &j1);
6318 : 0 : int ret_n = is_deriv_chain_or_ring(at, n, num_atoms, da + n, &k1);
6319 [ # # ]: 0 : if (ret_i < 0)
6320 : : {
6321 : 0 : ret = ret_i;
6322 : 0 : goto exit_function;
6323 : : }
6324 [ # # ]: 0 : if (ret_n < 0)
6325 : : {
6326 : 0 : ret = ret_n;
6327 : 0 : goto exit_function;
6328 : : }
6329 [ # # # # : 0 : if (!ret_i || (ret_i && ret_n)) /* djb-rwth: addressing LLVM warning */
# # ]
6330 : : {
6331 [ # # ]: 0 : if (da[i].typ[j1] & DERIV_RING_OUTSIDE_PRECURSOR)
6332 : : {
6333 : 0 : num_cuts -= 2;
6334 : 0 : num_ring_cuts -= 2;
6335 : : }
6336 : : else
6337 : : {
6338 : 0 : num_cuts -= 1;
6339 : : }
6340 : 0 : num_cut_pieces -= 1;
6341 [ # # ]: 0 : if ((ret = remove_deriv_mark(da + i, j1))) /* djb-rwth: addressing LLVM warning */
6342 : : {
6343 : 0 : goto exit_function;
6344 : : }
6345 : 0 : nFound++;
6346 : : }
6347 [ # # # # : 0 : if (!ret_n || (ret_i && ret_n)) /* djb-rwth: addressing LLVM warning */
# # ]
6348 : : {
6349 [ # # ]: 0 : if (da[n].typ[k1] & DERIV_RING_OUTSIDE_PRECURSOR)
6350 : : {
6351 : 0 : num_cuts -= 2;
6352 : 0 : num_ring_cuts -= 2;
6353 : : }
6354 : : else
6355 : : {
6356 : 0 : num_cuts -= 1;
6357 : : }
6358 : 0 : num_cut_pieces -= 1;
6359 [ # # ]: 0 : if ((ret = remove_deriv_mark(da + n, k1))) /* djb-rwth: addressing LLVM warning */
6360 : : {
6361 : 0 : goto exit_function;
6362 : : }
6363 : 0 : nFound++;
6364 : : }
6365 : : }
6366 : : }
6367 : : }
6368 : : }
6369 : :
6370 [ # # ]: 0 : if (nFound)
6371 : : {
6372 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
6373 : : {
6374 : : /*for ( j = 0; j < MAX_AT_DERIV && da[i].typ[j]; j ++ ) -- bug fixed 2013-11-07 DCh */
6375 [ # # # # ]: 0 : for (j = 0; j < DERIV_AT_LEN && da[i].typ[j]; j++)
6376 : : {
6377 : : /* attn: j is changed inside the cycle body */
6378 [ # # ]: 0 : if (da[i].typ[j] & DERIV_DUPLIC)
6379 : : {
6380 [ # # ]: 0 : if ((ret = remove_deriv(da + i, j))) /* djb-rwth: addressing LLVM warning */
6381 : : {
6382 : 0 : goto exit_function;
6383 : : }
6384 : 0 : j--;
6385 : : }
6386 : : }
6387 : : }
6388 : : }
6389 : : }
6390 : :
6391 : : /* make sure DERIV_RING_OUTSIDE_PRECURSOR type disconnections increase */
6392 : : /* number of components by the number of disconnected derivateves */
6393 : : /* Avoid cases like these:
6394 : :
6395 : : O--R--O DO--R--OD
6396 : : / \
6397 : : R--X Y--R => R--XT2 T2Y--R
6398 : : \ /
6399 : : O--R--O DO--R--OD
6400 : :
6401 : :
6402 : :
6403 : : O--O DO--OD
6404 : : / \
6405 : : R--X--O---Y--R => R--X OD2 Y--R
6406 : : T2 T2
6407 : :
6408 : : */
6409 : : /* count DERIV_RING_OUTSIDE_PRECURSOR-type attachments */
6410 : :
6411 : : #if ( COUNT_ALL_NOT_DERIV == 1 )
6412 : 0 : num_cuts_to_check = num_cuts; /* STOP HERE */
6413 : : #else
6414 : : num_cuts_to_check = num_ring_cuts;
6415 : : #endif
6416 [ # # # # : 0 : ALLOC_AP
# # # # #
# # # ]
6417 : :
6418 [ # # ]: 0 : if (num_cuts_to_check >= 2)
6419 : : {
6420 : : /* check */
6421 : : AT_NUMB comp_num;
6422 : : int /*n,*/ m_at, m_ord;
6423 : : /*AT_NUMB at1, at2;*/
6424 : :
6425 : 0 : repeat_without_deriv_ring:
6426 : :
6427 [ # # # # : 0 : ALLOC_AP
# # # # #
# # # ]
6428 : :
6429 : 0 : comp_num = 0;
6430 : : /* fill out the array of bonds to be cut */
6431 : 0 : j = fill_out_bond_cuts( at, da, num_atoms, ap, num_cuts_to_check );
6432 [ # # ]: 0 : if (j < 0)
6433 : : {
6434 : 0 : ret = j;
6435 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
6436 : : }
6437 [ # # ]: 0 : if (j != num_cuts_to_check)
6438 : : {
6439 : 0 : ret = -3;
6440 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
6441 : : }
6442 : : /* can't sort the bonds for subsequent searching by bisections in
6443 : : mark_atoms_ap() -> has_atom_pair() 2013-08-48 DCh */
6444 : : /* !!!!!!!! check that there are no derivatives inside a derivative */
6445 : 0 : comp_num = 0; /* here it is the number of removed cuts */
6446 [ # # ]: 0 : for (i = 0; i < num_cuts_to_check; i += j)
6447 : : {
6448 [ # # ]: 0 : for (j = n = 0; j < 2; j++)
6449 : : {
6450 : 0 : int atj = (int) ap[i].at[j];
6451 [ # # # # ]: 0 : if (da[atj].typ[0] && at[atj].neighbor[(int) da[atj].ord[0]] == ap[i].at[1 - j])
6452 : : {
6453 : 0 : k = j; /* ap[i].at[k] is precursor atom */
6454 : 0 : n++;
6455 : 0 : m_at = atj; /* precursor atom at[m_at], da[m_at] */
6456 : 0 : m_ord = 0; /* da[m_at].typ[m_ord] - type of the deriv.bond to break */
6457 : : }
6458 : : else
6459 : : {
6460 [ # # # # ]: 0 : if (da[atj].typ[1] && at[atj].neighbor[(int) da[atj].ord[1]] == ap[i].at[1 - j])
6461 : : {
6462 : 0 : k = j;
6463 : 0 : n++;
6464 : 0 : m_at = atj;
6465 : 0 : m_ord = 1;
6466 : : }
6467 : : }
6468 : : }
6469 : :
6470 [ # # ]: 0 : if (n != 1)
6471 : : {
6472 : 0 : ret = -3;
6473 : 0 : goto exit_r2c_num; /* wrong atom pair */
6474 : : }
6475 : :
6476 [ # # ]: 0 : if (( da[m_at].typ[m_ord] & DERIV_RING_OUTSIDE_PRECURSOR ))
6477 : : {
6478 : 0 : n = (int) ap[i].at[k]; /* atom inside the derivation attachment */
6479 : 0 : j = 2; /* number of bonds to cut */
6480 [ # # # # : 0 : if (i + j > num_cuts_to_check || ((int) ap[i + 1].at[0] != n && (int) ap[i + 1].at[1] != n)) /* djb-rwth: addressing LLVM warning */
# # ]
6481 : : {
6482 : 0 : ret = -3;
6483 : 0 : goto exit_r2c_num; /* wrong atom pair */
6484 : : }
6485 : : }
6486 : : else
6487 : : {
6488 : 0 : n = ap[i].at[1 - k]; /* atom inside the tentative derivation attachment */
6489 : 0 : j = 1; /* number of bonds to cut */
6490 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
6491 : : /*j += (0 != (da[m_at].typ[m_ord] & DERIV_RING_DMOX_DEOX)); */
6492 : : /* these 2 cuts are always adjacent */
6493 [ # # # # ]: 0 : j += ( da[m_at].typ[m_ord] && da[m_at].typ[m_ord] == ( da[m_at].typ[m_ord] & DERIV_RING_DMOX_DEOX ) ); /* these 2 cuts are always adjacent */
6494 : : #endif
6495 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
6496 [ # # # # ]: 0 : j += ( da[m_at].typ[m_ord] && da[m_at].typ[m_ord] == ( da[m_at].typ[m_ord] & DERIV_RING2_OUTSIDE_PRECUR ) ); /* these 2 cuts are always adjacent */
6497 : : #endif
6498 : : }
6499 : :
6500 : : /* at[n] belongs to the derivation agent */
6501 : 0 : cur_num_at = mark_atoms_ap( at, n, ap + i, j, 0, 1 );
6502 [ # # ]: 0 : for (k = 0; k < num_cuts_to_check; k++)
6503 : : {
6504 [ # # # # ]: 0 : if (k == i || k == i + j - 1) /* not more than 2 cuts per derivatization agent */
6505 : : {
6506 : 0 : continue; /* skip current 1 or 2 cuts */
6507 : : }
6508 [ # # # # ]: 0 : if (at[(int) ap[k].at[0]].at_type || at[(int) ap[k].at[1]].at_type)
6509 : : {
6510 : : /*#ifdef DERIV_X_OXIME*/
6511 [ # # ]: 0 : if (( da[m_at].typ[m_ord] & DERIV_UNEXPADABLE ) == da[m_at].typ[m_ord])
6512 : : {
6513 : : /* this derivatization agent cannot be inside another, larger deriv. agent */
6514 : : /* disable cuts of the larger derivatization agent */
6515 [ # # ]: 0 : if (ap[k].atno != m_at)
6516 : : {
6517 [ # # # # ]: 0 : for (j = 0; j < 2 && da[ap[k].atno].typ[j]; j++)
6518 : : {
6519 : 0 : da[ap[k].atno].typ[j] |= DERIV_UNMARK;
6520 : : }
6521 : 0 : num_cuts -= 1;
6522 : 0 : num_cut_pieces -= 1;
6523 [ # # ]: 0 : if (j == 2)
6524 : : {
6525 : 0 : num_cuts -= 1;
6526 : 0 : num_ring_cuts -= 2;
6527 : : }
6528 : 0 : comp_num++;
6529 : : }
6530 : : /* djb-rwth: removing redundant code */
6531 : : }
6532 : : else
6533 : : /* #endif */
6534 : : /* unmark the cut: found a cut inside the derivatizing agent */
6535 : : {
6536 : 0 : da[m_at].typ[m_ord] |= DERIV_UNMARK;
6537 : 0 : num_cuts -= 1;
6538 : 0 : num_cut_pieces -= 1;
6539 [ # # ]: 0 : if (j == 2)
6540 : : {
6541 : 0 : da[m_at].typ[1 - m_ord] |= DERIV_UNMARK;
6542 : 0 : num_cuts -= 1;
6543 : 0 : num_ring_cuts -= 2;
6544 : : }
6545 : 0 : comp_num++;
6546 : : }
6547 : 0 : break;
6548 : : }
6549 : : }
6550 : 0 : UnMarkOtherIndicators( at, num_atoms );
6551 : : }
6552 : :
6553 [ # # ]: 0 : if (comp_num)
6554 : : {
6555 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
6556 : : {
6557 [ # # ]: 0 : if (da[i].typ[0] & DERIV_UNMARK)
6558 : : {
6559 : 0 : da[i].num[0] = da[i].num[1];
6560 : 0 : da[i].ord[0] = da[i].ord[1];
6561 : 0 : da[i].typ[0] = da[i].typ[1];
6562 : 0 : da[i].typ[1] = 0;
6563 : 0 : j = 0;
6564 : : }
6565 : : else
6566 : : {
6567 : 0 : j = 1;
6568 : : }
6569 [ # # ]: 0 : if (da[i].typ[j] & DERIV_UNMARK)
6570 : : {
6571 : 0 : da[i].typ[j] = 0;
6572 : : }
6573 : : }
6574 : :
6575 : : #if ( COUNT_ALL_NOT_DERIV == 1 )
6576 : 0 : num_cuts_to_check = num_cuts;
6577 : : #else
6578 : : num_cuts_to_check = num_ring_cuts;
6579 : : #endif
6580 [ # # # # : 0 : if (num_cuts < 0 || num_ring_cuts < 0 || num_cut_pieces < 0)
# # ]
6581 : : {
6582 : 0 : ret = -3;
6583 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
6584 : : }
6585 : : #if( defined(DERIV_X_OXIME) || defined(DERIV_RO_COX) )
6586 [ # # ]: 0 : if (num_cuts_to_check > 0)
6587 : : #endif
6588 : : {
6589 : 0 : goto repeat_without_deriv_ring;
6590 : : }
6591 : : }
6592 : :
6593 : : /* Sort the bonds for subsequent searching by bisections
6594 : : -- disabled because DERIV_RING_DMOX_DEOX have to be adjacent in ap
6595 : : if ( num_cuts_to_check > 1 ) {
6596 : : qsort( ap, num_cuts_to_check, sizeof(ap[0]), cmp_r2c_atpair);
6597 : : }
6598 : : */
6599 [ # # ]: 0 : if ((ret = mark_deriv_agents( at, da, num_atoms, ap, num_cuts_to_check, &comp_num, &cur_num_at ))) /* djb-rwth: addressing LLVM warning */
6600 : : {
6601 : 0 : goto exit_r2c_num; /* wrong atom pair */
6602 : : }
6603 [ # # ]: 0 : if (comp_num > 1)
6604 : : {
6605 : : /* eliminate offending DERIV_RING_OUTSIDE_PRECURSOR type derivatives */
6606 [ # # ]: 0 : if (num_ring_cuts <= 2)
6607 : : {
6608 : 0 : ret = -99;
6609 : 0 : goto exit_r2c_num;
6610 : : }
6611 : 0 : n = 0;
6612 [ # # ]: 0 : for (i = j = 0; i < num_atoms; i++) /* djb-rwth: ignoring LLVM warning: variable used */
6613 : : {
6614 [ # # # # ]: 0 : if (( da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR ) && ( da[i].typ[1] & DERIV_RING_OUTSIDE_PRECURSOR ))
6615 : : {
6616 : 0 : int at1a = at[i].neighbor[(int) da[i].ord[0]];
6617 : 0 : int at2a = at[i].neighbor[(int) da[i].ord[1]];
6618 [ # # ]: 0 : if (at[at1a].at_type != at[at2a].at_type)
6619 : : {
6620 : 0 : da[i].typ[0] = 0; /* eliminate this cut */
6621 : 0 : da[i].typ[1] = 0;
6622 : 0 : n++;
6623 : 0 : num_cuts_to_check -= 2;
6624 : 0 : num_cuts -= 2;
6625 : 0 : num_ring_cuts -= 2;
6626 : 0 : num_cut_pieces -= 1;
6627 : : }
6628 : : }
6629 : : }
6630 [ # # # # ]: 0 : if (n > 0 && num_cuts_to_check > 2)
6631 : : {
6632 : 0 : UnMarkOtherIndicators( at, num_atoms );
6633 : 0 : goto repeat_without_deriv_ring;
6634 : : }
6635 : : }
6636 : 0 : ret = 0;
6637 : :
6638 : 0 : exit_r2c_num:
6639 : : /*inchi_free( ap );*/
6640 : 0 : UnMarkOtherIndicators( at, num_atoms );
6641 : : /*if ( ret < 0 || num_cuts_to_check >= 2 && cur_num_at < MIN_AT_LEFT_DERIV ) */
6642 : : /* -- bug: cur_num_at may include later rejected deriv. agents 2013-11-08 DCh */
6643 [ # # ]: 0 : if (ret < 0)
6644 : : {
6645 : 0 : goto exit_function; /* unexpected error or nothing left */
6646 : : }
6647 : : }
6648 : :
6649 [ # # ]: 0 : if (!num_cuts)
6650 : : {
6651 : 0 : continue; /*goto exit_function;*/
6652 : : }
6653 : :
6654 : : /* Eliminate derivatives that are not in the list */
6655 : 0 : num_cuts = eliminate_deriv_not_in_list( at, da, num_atoms, szUnderivList, UNDERIV_LIST_LEN, szUnderivList2, UNDERIV_LIST_LEN2, &bitUnderivList );
6656 [ # # ]: 0 : if (num_cuts < 0)
6657 : : {
6658 : 0 : ret = num_cuts;
6659 : 0 : goto exit_function;
6660 : : }
6661 : :
6662 : : /* Check how many atoms was left in the precursor - begin - 2013-11-12 DT */
6663 [ # # ]: 0 : if (( num_cuts_to_check = num_cuts ) >= 1)
6664 : : {
6665 : 0 : AT_NUMB comp_num = 0; /* here it is the number of removed cuts */
6666 : : int /*n,*/ m_at, m_ord;
6667 : :
6668 [ # # # # : 0 : ALLOC_AP
# # # # #
# # # ]
6669 : :
6670 : : /* Fill out the array of bonds to be cut */
6671 : 0 : j = fill_out_bond_cuts( at, da, num_atoms, ap, num_cuts_to_check );
6672 [ # # ]: 0 : if (j < 0)
6673 : : {
6674 : 0 : ret = j;
6675 : 0 : goto exit_r2c_num2; /* wrong number of cuts = num */
6676 : : }
6677 [ # # ]: 0 : if (j != num_cuts_to_check)
6678 : : {
6679 : 0 : ret = -3;
6680 : 0 : goto exit_r2c_num2; /* wrong number of cuts = num */
6681 : : }
6682 : :
6683 : : /* The following code was copied from above to mark removed */
6684 [ # # ]: 0 : for (i = 0; i < num_cuts_to_check; i += j)
6685 : : {
6686 [ # # ]: 0 : for (j = n = 0; j < 2; j++)
6687 : : {
6688 : 0 : int atj = (int) ap[i].at[j];
6689 [ # # # # : 0 : if (atj < num_atoms && da[atj].typ[0] && at[atj].neighbor[(int) da[atj].ord[0]] == ap[i].at[1 - j])
# # ]
6690 : : {
6691 : 0 : k = j; /* ap[i].at[k] is precursor atom */
6692 : 0 : n++;
6693 : 0 : m_at = atj; /* precursor atom at[m_at], da[m_at] */
6694 : 0 : m_ord = 0; /* da[m_at].typ[m_ord] - type of the deriv.bond to break */
6695 : : }
6696 : : else
6697 : : {
6698 [ # # # # : 0 : if (atj < num_atoms && da[atj].typ[1] && at[atj].neighbor[(int) da[atj].ord[1]] == ap[i].at[1 - j])
# # ]
6699 : : {
6700 : 0 : k = j;
6701 : 0 : n++;
6702 : 0 : m_at = atj;
6703 : 0 : m_ord = 1;
6704 : : }
6705 : : }
6706 : : }
6707 [ # # ]: 0 : if (n != 1)
6708 : : {
6709 : 0 : ret = -3;
6710 : 0 : goto exit_r2c_num2; /* wrong atom pair */
6711 : : }
6712 [ # # ]: 0 : if (( da[m_at].typ[m_ord] & DERIV_RING_OUTSIDE_PRECURSOR ))
6713 : : {
6714 : 0 : n = (int) ap[i].at[k]; /* atom inside the derivation attachment */
6715 : 0 : j = 2; /* number of bonds to cut */
6716 [ # # # # : 0 : if (i + j > num_cuts_to_check || ((int) ap[i + 1].at[0] != n && (int) ap[i + 1].at[1] != n)) /* djb-rwth: addressing LLVM warning */
# # ]
6717 : : {
6718 : 0 : ret = -3;
6719 : 0 : goto exit_r2c_num2; /* wrong atom pair */
6720 : : }
6721 : : }
6722 : : else
6723 : : {
6724 : 0 : n = ap[i].at[1 - k]; /* atom inside the tentative derivation attachment */
6725 : 0 : j = 1; /* number of bonds to cut */
6726 : : #if( defined(DERIV_RING_DMOX_DEOX_N) && defined(DERIV_RING_DMOX_DEOX_O) )
6727 : : /*j += (0 != (da[m_at].typ[m_ord] & DERIV_RING_DMOX_DEOX));*/
6728 : : /* these 2 cuts are always adjacent */
6729 [ # # # # ]: 0 : j += ( da[m_at].typ[m_ord] && da[m_at].typ[m_ord] == ( da[m_at].typ[m_ord] & DERIV_RING_DMOX_DEOX ) ); /* these 2 cuts are always adjacent */
6730 : : #endif
6731 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
6732 [ # # # # ]: 0 : j += ( da[m_at].typ[m_ord] && da[m_at].typ[m_ord] == ( da[m_at].typ[m_ord] & DERIV_RING2_OUTSIDE_PRECUR ) ); /* these 2 cuts are always adjacent */
6733 : : #endif
6734 : : }
6735 : :
6736 : : /* at[n] belongs to the derivation agent */
6737 : 0 : cur_num_at = mark_atoms_ap( at, n, ap + i, j, 0, 1 );
6738 : 0 : UnMarkOtherIndicators( at, num_atoms );
6739 : : }
6740 : 0 : ret = mark_deriv_agents( at, da, num_atoms, ap, num_cuts_to_check, &comp_num, &cur_num_at );
6741 : 0 : UnMarkOtherIndicators( at, num_atoms );
6742 [ # # ]: 0 : if (ap)
6743 : : {
6744 [ # # ]: 0 : inchi_free( ap );
6745 : 0 : ap = NULL;
6746 : : }
6747 [ # # ]: 0 : if (ret)
6748 : : {
6749 : 0 : goto exit_r2c_num2; /* wrong atom pair */
6750 : : }
6751 : : }
6752 : :
6753 : 0 : exit_r2c_num2:
6754 : :
6755 [ # # ]: 0 : if (ap)
6756 : : {
6757 [ # # ]: 0 : inchi_free( ap );
6758 : 0 : ap = NULL;
6759 : : }
6760 [ # # # # : 0 : if (ret < 0 || (num_cuts_to_check >= 2 && cur_num_at < MIN_AT_LEFT_DERIV)) /* -- bug: cur_num_at may include later rejected deriv. agents 2013-11-08 DCh */ /* djb-rwth: addressing LLVM warning */
# # ]
6761 : : {
6762 : 0 : goto exit_function; /* unexpected error or nothing left */
6763 : : }
6764 : :
6765 : : /* Check how many atoms was left in the precursor - end - 2013-11-12 DT */
6766 : :
6767 : : /* make cuts */
6768 : 0 : num_cuts = 0;
6769 [ # # ]: 0 : for (i = num = 0; i < num_atoms; i++) /* djb-rwth: ignoring LLVM warning: variable used */
6770 : : {
6771 : : /*for ( len = 0; len < MAX_AT_DERIV && da[i].typ[len]; len ++ ) -- bug fixed 2013-11-07 DCh */
6772 [ # # # # ]: 0 : for (len = 0; len < DERIV_AT_LEN && da[i].typ[len]; len++)
6773 : : {
6774 : : ;
6775 : : }
6776 [ # # # # : 0 : switch (len)
# # ]
6777 : : {
6778 : 0 : case 0:
6779 : 0 : continue;
6780 : 0 : case 1:
6781 : : /* single cut: unconditional */
6782 : 0 : make_single_cut( at, da, i, 0 );
6783 : 0 : num_cuts += 1;
6784 : 0 : continue;
6785 : 0 : case 2:
6786 [ # # # # ]: 0 : if (( (da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR ) && ( da[i].typ[1] & DERIV_RING_OUTSIDE_PRECURSOR )) ||
6787 [ # # # # ]: 0 : (da[i].typ[0] == DERIV_AMINE_tN && da[i].typ[1] == DERIV_AMINE_tN)
6788 : : #ifdef DERIV_RING2_OUTSIDE_PRECUR
6789 [ # # # # ]: 0 : || (da[i].typ[0] && da[i].typ[0] == ( da[i].typ[0] & DERIV_RING2_OUTSIDE_PRECUR ) &&
6790 [ # # ]: 0 : da[i].typ[1] == da[i].typ[0])
6791 : : #endif
6792 : : ) /* djb-rwth: addressing LLVM warning */
6793 : : {
6794 : : /* double cut, unconditional */
6795 : 0 : make_single_cut( at, da, i, 1 );
6796 : 0 : make_single_cut( at, da, i, 0 );
6797 : 0 : num_cuts += 1;
6798 : 0 : continue;
6799 : : }
6800 [ # # ]: 0 : if (da[i].typ[0] == da[i].typ[1])
6801 : : {
6802 : : /* DERIV_BRIDGE_O or DERIV_BRIDGE_NH; cut off the smallest */
6803 [ # # ]: 0 : if (da[i].num[0] > da[i].num[1])
6804 : : {
6805 : 0 : make_single_cut( at, da, i, 1 );
6806 : 0 : num_cuts += 1;
6807 : : }
6808 : : else
6809 : : {
6810 [ # # ]: 0 : if (da[i].num[0] < da[i].num[1])
6811 : : {
6812 : 0 : make_single_cut( at, da, i, 0 );
6813 : 0 : num_cuts += 1;
6814 : : }
6815 : : }
6816 : 0 : continue;
6817 : : }
6818 : 0 : ret = -88;
6819 : 0 : goto exit_function; /* unexpected */
6820 : 0 : case 3:
6821 [ # # ]: 0 : if (da[i].typ[0] == da[i].typ[1] &&
6822 [ # # ]: 0 : da[i].typ[0] == da[i].typ[2] &&
6823 [ # # ]: 0 : da[i].typ[0] == DERIV_AMINE_tN)
6824 : 0 : {
6825 : : int x, y, z;
6826 : 0 : x = ( da[i].num[0] < da[i].num[1] ) ? 0 : 1;
6827 [ # # ]: 0 : x = ( da[i].num[x] < da[i].num[2] ) ? x : 2; /* min */
6828 : 0 : z = ( da[i].num[0] < da[i].num[1] ) ? 1 : 0;
6829 [ # # ]: 0 : z = ( da[i].num[x] < da[i].num[2] ) ? 2 : z; /* max */
6830 : 0 : y = ( ( x + 1 ) ^ ( z + 1 ) ) - 1; /* median */
6831 [ # # ]: 0 : if (da[i].num[x] == da[i].num[z])
6832 : 0 : continue; /* all deriv. agents have same size */
6833 : : /* two smallest */
6834 [ # # # # ]: 0 : if (da[i].num[x] == da[i].num[y] && x < y)
6835 : : {
6836 : 0 : int t = x; /* first cut x > y */
6837 : 0 : x = y;
6838 : 0 : y = t;
6839 : : }
6840 : 0 : make_single_cut( at, da, i, x );
6841 : 0 : num_cuts += 1;
6842 [ # # ]: 0 : if (da[i].num[x] == da[i].num[y])
6843 : : {
6844 : : /* equally small */
6845 : 0 : make_single_cut( at, da, i, y );
6846 : 0 : num_cuts += 1;
6847 : : }
6848 : 0 : continue;
6849 : : }
6850 : 0 : ret = -88;
6851 : 0 : goto exit_function; /* unexpected */
6852 : 0 : case 4:
6853 [ # # # # ]: 0 : if (( da[i].typ[0] & DERIV_RING_OUTSIDE_PRECURSOR ) && ( da[i].typ[1] & DERIV_RING_OUTSIDE_PRECURSOR ) &&
6854 [ # # # # ]: 0 : ( da[i].typ[2] & DERIV_RING_OUTSIDE_PRECURSOR ) && ( da[i].typ[3] & DERIV_RING_OUTSIDE_PRECURSOR ))
6855 : 0 : {
6856 : 0 : int n01 = inchi_max( da[i].num[0], da[i].num[1] );
6857 : 0 : int n23 = inchi_max( da[i].num[2], da[i].num[3] );
6858 [ # # ]: 0 : if (n01 < n23)
6859 : : {
6860 : 0 : make_single_cut( at, da, i, 1 );
6861 : 0 : make_single_cut( at, da, i, 0 );
6862 : 0 : num_cuts += 1;
6863 : : }
6864 : : else
6865 : : {
6866 [ # # ]: 0 : if (n01 > n23)
6867 : : {
6868 : 0 : make_single_cut( at, da, i, 3 );
6869 : 0 : make_single_cut( at, da, i, 2 );
6870 : 0 : num_cuts += 1;
6871 : : }
6872 : : }
6873 : 0 : continue;
6874 : : }
6875 : : }
6876 : : }
6877 : :
6878 : 0 : nTotNumCuts += num_cuts;
6879 : :
6880 : : #ifdef FIX_UNDERIV_TO_SDF
6881 [ # # # # ]: 0 : if (bOutputSdf && at2)
6882 : : {
6883 : : /* replace arom bonds with original */
6884 : 0 : replace_arom_bonds( at, num_atoms, at2, num_atoms );
6885 [ # # ]: 0 : if (at2)
6886 : : {
6887 [ # # ]: 0 : inchi_free( at2 );
6888 : 0 : at2 = NULL;
6889 : : }
6890 : : }
6891 : : #endif
6892 : :
6893 : : #ifdef UNDERIV_ADD_EXPLICIT_H
6894 : : /********** Add explicit hydrogens ************************/
6895 : 0 : num_atoms = add_explicit_H( inp_cur_data + i_component );
6896 : : #endif
6897 : :
6898 [ # # ]: 0 : if (num_cuts)
6899 : : {
6900 : 0 : remove_cut_derivs( num_atoms, at, inp_cur_data, i_component, &ret );
6901 : : }
6902 : :
6903 : :
6904 : : } /* for (i_component = 0; i_component < num_components; i_component++) */
6905 : :
6906 : :
6907 [ # # ]: 0 : if (nTotNumCuts)
6908 : : {
6909 : 0 : OAD_Edit_MergeComponentsAndRecreateOAD( orig_inp_data, inp_cur_data, num_components, &ret );
6910 : : }
6911 : :
6912 : 0 : exit_function:
6913 : :
6914 : 0 : free_underiv_temp_data( ap, da, at2, inp_cur_data, num_components );
6915 : :
6916 : : #if( UNDERIVATIZE_REPORT == 1 )
6917 [ # # # # : 0 : if (!ret && nTotNumCuts && pSdfValue && bOutputReport)
# # # # ]
6918 : : {
6919 : 0 : numUnderiv = sort_merge_underiv( pSdfValue, bOutputSdf, szUnderivList, cDerivSeparator, underivPrefix, underivPostfix ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
6920 : 0 : numUnderiv2 = sort_merge_underiv( pSdfValue, bOutputSdf, szUnderivList2, cDerivSeparator, underivPrefix2, underivPostfix2 ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
6921 : 0 : sprintf(szbitUnderivList, "0x%.8X", bitUnderivList); /* djb-rwth: addressing GCC warning about 0 flag being ignored */
6922 : 0 : numUnderiv3 = sort_merge_underiv( pSdfValue, bOutputSdf, szbitUnderivList, cDerivSeparator, underivPrefix3, underivPostfix3 ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
6923 : : }
6924 : : #endif
6925 : :
6926 [ # # ]: 0 : return ret ? ret : nTotNumCuts;
6927 : : }
6928 : :
6929 : :
6930 : : #endif /* UNDERIVATIZE */
6931 : :
6932 : :
6933 : : /****************************************************************************/
6934 : : #if ( RING2CHAIN == 1 )
6935 : : /*
6936 : : type=1 (incl sugars: W=O, A=C(sat), Z=C(sat), Y=O, B=C(sat)-OH
6937 : :
6938 : : A---W A---WH
6939 : : / | /
6940 : : | | ---> |
6941 : : \ | \
6942 : : B---Z---YH B---Z===Y
6943 : : | |
6944 : : | |
6945 : : C(opt) C(opt)
6946 : :
6947 : : type=2 [not implemented]
6948 : :
6949 : : R---W R---WH
6950 : : / \ /
6951 : : | Z ---> | Z
6952 : : \ / \ //
6953 : : R---YH R---Y
6954 : :
6955 : : */
6956 : : #define R2C_EMPTY 127
6957 : : typedef struct tagRing2Chain { /* atom Z */
6958 : : char type; /* 1 => sugar-like */
6959 : : char ordW; /* ordering number of W-neighbor; bond to break; H to add */
6960 : : char ordY; /* ordering number of YH-neighbor; bond to increment; H to remove */
6961 : : char ordC; /* atom B = C(sat) */
6962 : : char ordCopt; /* if exists, saturated C connected by a chain-bond to Z */
6963 : : } R2C_AT;
6964 : :
6965 : : int detect_r2c_Zatom( inp_ATOM *at, R2C_AT *da, int iZ );
6966 : : int cut_ring_to_chain( inp_ATOM *at, R2C_AT *da, int iZ );
6967 : :
6968 : :
6969 : : /****************************************************************************/
6970 : 0 : int detect_r2c_Zatom( inp_ATOM *at, R2C_AT *da, int iZ )
6971 : : {
6972 : : int i, j, neigh, neighneigh, nRingSystem, num_found;
6973 : : R2C_AT da1;
6974 : :
6975 [ # # ]: 0 : if (at[iZ].valence > 4)
6976 : : {
6977 : 0 : return 0;
6978 : : }
6979 [ # # ]: 0 : if (at[iZ].valence != at[iZ].chem_bonds_valence)
6980 : : {
6981 : 0 : return 0; /* approach limitation: no double bonds */
6982 : : }
6983 [ # # ]: 0 : if (at[iZ].el_number != EL_NUMBER_C)
6984 : : {
6985 : 0 : return 0; /* sugar-specific */
6986 : : }
6987 [ # # ]: 0 : if (at[iZ].nNumAtInRingSystem < 5)
6988 : : {
6989 : 0 : return 0; /* not in a suitable ring */
6990 : : }
6991 [ # # ]: 0 : if (!at[iZ].bCutVertex)
6992 : : {
6993 : 0 : return 0; /* recognize only type 1 for now */
6994 : : }
6995 : :
6996 : 0 : nRingSystem = at[iZ].nRingSystem;
6997 : 0 : memset( &da1, R2C_EMPTY, sizeof( da1 ) ); /* djb-rwth: memset_s C11/Annex K variant? */
6998 : :
6999 [ # # ]: 0 : for (i = 0, num_found = 0; i < at[iZ].valence; i++)
7000 : : {
7001 : 0 : neigh = at[iZ].neighbor[i];
7002 [ # # # # ]: 0 : if (at[neigh].charge || at[neigh].radical)
7003 : : {
7004 : 0 : return 0;
7005 : : }
7006 [ # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_O &&
7007 [ # # ]: 0 : at[neigh].valence == 1 &&
7008 [ # # ]: 0 : at[neigh].chem_bonds_valence == 1 &&
7009 [ # # ]: 0 : at[neigh].num_H == 1)
7010 : : {
7011 : : /* found Z-OH, i.e. Z-YH */
7012 [ # # ]: 0 : if (da1.ordY == R2C_EMPTY)
7013 : : {
7014 : 0 : da1.ordY = i;
7015 : 0 : num_found++;
7016 : 0 : continue;
7017 : : }
7018 : : else
7019 : : {
7020 : 0 : return 0;
7021 : : }
7022 : : }
7023 [ # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_O &&
7024 [ # # ]: 0 : at[neigh].valence == 2 &&
7025 [ # # ]: 0 : at[neigh].chem_bonds_valence == 2 &&
7026 [ # # ]: 0 : at[neigh].num_H == 0 &&
7027 [ # # ]: 0 : at[neigh].nRingSystem == nRingSystem)
7028 : : {
7029 : : /* found Z-O-, i.e. Z-W- */
7030 [ # # ]: 0 : if (da1.ordW == R2C_EMPTY)
7031 : : {
7032 : : /* j = index of the oppozite to at[iZ] neighbor of at[neigh] */
7033 : 0 : j = ( at[neigh].neighbor[0] == iZ );
7034 : 0 : neighneigh = at[neigh].neighbor[j];
7035 [ # # ]: 0 : if (at[neighneigh].valence != at[neighneigh].chem_bonds_valence ||
7036 [ # # ]: 0 : at[neighneigh].el_number != EL_NUMBER_C)
7037 : 0 : return 0; /* sugar-specific */
7038 : 0 : da1.ordW = i;
7039 : 0 : num_found++;
7040 : 0 : continue;
7041 : : }
7042 : : else
7043 : : {
7044 : 0 : return 0;
7045 : : }
7046 : : }
7047 [ # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_C &&
7048 [ # # ]: 0 : at[neigh].valence > 2 &&
7049 [ # # ]: 0 : at[neigh].chem_bonds_valence == at[neigh].valence &&
7050 [ # # ]: 0 : at[neigh].num_H <= 1 &&
7051 [ # # ]: 0 : at[neigh].nRingSystem == nRingSystem)
7052 : : {
7053 : : /* sugar-specfic: carbon in the ring should have -OH neighbor */
7054 : : int iOH;
7055 [ # # ]: 0 : for (j = 0; j < at[neigh].valence; j++)
7056 : : {
7057 : 0 : iOH = at[neigh].neighbor[j];
7058 [ # # ]: 0 : if (at[iOH].el_number == EL_NUMBER_O &&
7059 [ # # ]: 0 : at[iOH].valence == 1 &&
7060 [ # # ]: 0 : at[iOH].chem_bonds_valence == 1 &&
7061 [ # # ]: 0 : at[iOH].num_H == 1 &&
7062 [ # # # # ]: 0 : !at[iOH].charge && !at[iOH].radical)
7063 : : {
7064 [ # # ]: 0 : if (da1.ordC == R2C_EMPTY)
7065 : : {
7066 : 0 : da1.ordC = i;
7067 : 0 : num_found++;
7068 : 0 : break;
7069 : : }
7070 : : else
7071 : : {
7072 : 0 : return 0;
7073 : : }
7074 : : }
7075 : : }
7076 [ # # ]: 0 : if (j < at[neigh].valence)
7077 : : {
7078 : 0 : continue;
7079 : : }
7080 : : }
7081 [ # # ]: 0 : if (at[neigh].el_number == EL_NUMBER_C &&
7082 [ # # ]: 0 : at[neigh].chem_bonds_valence == at[neigh].valence &&
7083 [ # # ]: 0 : at[neigh].nRingSystem != nRingSystem)
7084 : : {
7085 : : /* extra carbon neighbor of Z */
7086 [ # # ]: 0 : if (da1.ordCopt == R2C_EMPTY)
7087 : : {
7088 : 0 : da1.ordCopt = i;
7089 : 0 : continue;
7090 : : }
7091 : : }
7092 : 0 : return 0; /* unexpectd neighbor */
7093 : : }
7094 : :
7095 [ # # ]: 0 : if (num_found == 3)
7096 : : {
7097 : 0 : da1.type = 1;
7098 : 0 : da[iZ] = da1;
7099 : 0 : return 1; /* disconnection found */
7100 : : }
7101 : :
7102 : 0 : return 0;
7103 : : }
7104 : :
7105 : :
7106 : : /****************************************************************************/
7107 : 0 : int cut_ring_to_chain( inp_ATOM *at, R2C_AT *da, int iZ )
7108 : : {
7109 : 0 : int ret = -1; /* error flag */
7110 : 0 : int iordW = (int) da[iZ].ordW; /* ord of the bond in iZ */
7111 : 0 : int iordY = (int) da[iZ].ordY; /* ord of the bond in iZ */
7112 : 0 : int iordC = (int) da[iZ].ordC;
7113 : : int iW, iY, num_iso_H, i, jordZ;
7114 : : AT_NUMB *p;
7115 : :
7116 [ # # ]: 0 : if (da[iZ].type != 1)
7117 : : {
7118 : 0 : return 0;
7119 : : }
7120 [ # # # # : 0 : if (0 > iordW || iordW >= at[iZ].valence ||
# # ]
7121 [ # # # # ]: 0 : 0 > iordY || iordY >= at[iZ].valence ||
7122 [ # # ]: 0 : 0 > iordC || iordC >= at[iZ].valence /* suger-specific*/)
7123 : : {
7124 : 0 : return -1; /* program error */
7125 : : }
7126 : : /* find other da[] that affect at[iZ] */
7127 : 0 : iW = at[iZ].neighbor[iordW]; /* opposite atom to disconnect and add H */
7128 : 0 : iY = at[iZ].neighbor[iordY]; /* opposite atom to increment the bond and remove H*/
7129 [ # # # # ]: 0 : if (!at[iY].num_H || at[iZ].bond_type[iordY] != BOND_TYPE_SINGLE)
7130 : : {
7131 : 0 : return -2; /* program error */
7132 : : }
7133 : : /* increment at[iZ]--at[iY] bond */
7134 : 0 : p = is_in_the_list( at[iY].neighbor, (AT_NUMB) iZ, at[iY].valence );
7135 [ # # ]: 0 : if (!p)
7136 : : {
7137 : 0 : return -3; /* program error */
7138 : : }
7139 : 0 : jordZ = p - at[iY].neighbor;
7140 : 0 : at[iZ].bond_type[iordY] ++;
7141 : 0 : at[iZ].chem_bonds_valence++;
7142 : 0 : at[iY].bond_type[jordZ] ++;
7143 : 0 : at[iY].chem_bonds_valence++;
7144 : :
7145 : : /* disconnect at[iZ]--at[iW] bond */
7146 : 0 : ret = DisconnectInpAtBond( at, NULL, iZ, iordW );
7147 [ # # ]: 0 : if (ret != 1)
7148 : : {
7149 : 0 : return -4; /* program error */
7150 : : }
7151 : : /* disconnection succeeded */
7152 : : /* transfer H from at[iY] to at[iW] */
7153 : 0 : num_iso_H = NUM_ISO_H( at, iY );
7154 [ # # ]: 0 : if (at[iY].num_H == num_iso_H)
7155 : : {
7156 [ # # ]: 0 : for (i = 0; i < NUM_H_ISOTOPES; i++)
7157 : : {
7158 [ # # ]: 0 : if (at[iY].num_iso_H[i])
7159 : : {
7160 : 0 : at[iY].num_iso_H[i] --;
7161 : 0 : at[iW].num_iso_H[i] ++;
7162 : : }
7163 : : }
7164 : : }
7165 : 0 : at[iY].num_H--;
7166 : 0 : at[iW].num_H++;
7167 : :
7168 : 0 : return 1;
7169 : : }
7170 : :
7171 : :
7172 : : /****************************************************************************/
7173 : 0 : int Ring2Chain( struct tagINCHI_CLOCK *ic,
7174 : : struct tagCANON_GLOBALS *pCG,
7175 : : ORIG_ATOM_DATA *orig_inp_data )
7176 : : {
7177 : 0 : int ret = 0, i, j, n, num_atoms, num_components, num, num_cuts, iZ; /* djb-rwth: removing redundant variables */
7178 : 0 : inp_ATOM *at = orig_inp_data->at;
7179 : 0 : INP_ATOM_DATA *inp_cur_data = NULL;
7180 : 0 : R2C_AT *da = NULL;
7181 : :
7182 : :
7183 : : /* prepare */
7184 : :
7185 : : /*set_R2C_el_numbers( );*/
7186 : :
7187 : 0 : num_atoms = remove_terminal_HDT( orig_inp_data->num_inp_atoms, at, 1, NULL );
7188 : : /*^^^^^ always accomodate accomodate FIX_TERM_H_CHRG_BUG - IPl, July 2008*/
7189 : 0 : orig_inp_data->num_inp_atoms = num_atoms;
7190 : :
7191 : : /* initialize */
7192 : 0 : UnMarkDisconnectedComponents( orig_inp_data );
7193 : 0 : num_cuts = 0;
7194 : : /* mark */
7195 : 0 : num_components = MarkDisconnectedComponents( orig_inp_data, 0 );
7196 : 0 : inp_cur_data = (INP_ATOM_DATA *) inchi_calloc( num_components, sizeof( inp_cur_data[0] ) );
7197 : 0 : iZ = -1;
7198 [ # # ]: 0 : for (j = 0; j < num_components; j++)
7199 : : {
7200 : 0 : CreateInpAtomData( inp_cur_data + j, orig_inp_data->nCurAtLen[j], 0 );
7201 : 0 : inp_cur_data[j].num_at = ExtractConnectedComponent( orig_inp_data->at, orig_inp_data->num_inp_atoms, j + 1, inp_cur_data[j].at );
7202 : : /* error processing */
7203 [ # # # # ]: 0 : if (inp_cur_data[j].num_at <= 0 || orig_inp_data->nCurAtLen[j] != inp_cur_data[j].num_at)
7204 : : {
7205 : 0 : ret = -( j + 1 ); /* severe error */
7206 : 0 : goto exit_function;
7207 : : }
7208 : : /* initialize */
7209 : 0 : num_atoms = inp_cur_data[j].num_at;
7210 : 0 : at = inp_cur_data[j].at;
7211 : 0 : add_DT_to_num_H( num_atoms, at );
7212 : :
7213 : 0 : UnMarkRingSystemsInp( at, num_atoms );
7214 : 0 : UnMarkOtherIndicators( at, num_atoms );
7215 : 0 : UnMarkOneComponent( at, num_atoms );
7216 : 0 : MarkRingSystemsInp( at, num_atoms, 0 );
7217 : 0 : ret = mark_arom_bonds( ic, pCG, at, num_atoms );
7218 [ # # ]: 0 : if (ret < 0)
7219 : : {
7220 : 0 : goto exit_function;
7221 : : }
7222 : 0 : ret = 0;
7223 [ # # ]: 0 : if (da)
7224 : : {
7225 [ # # ]: 0 : inchi_free( da );
7226 : : }
7227 : 0 : da = (R2C_AT *) inchi_calloc( num_atoms, sizeof( da[0] ) );
7228 : :
7229 : : /* detect ring-to-chain possibilities */
7230 : : /* djb-rwth: removing redundant code */
7231 [ # # ]: 0 : for (i = 0, num = 0; i < num_atoms; i++)
7232 : : {
7233 [ # # # # ]: 0 : if (at[i].bCutVertex /* type 1 specific*/ && !da[i].type)
7234 : : {
7235 : 0 : num += ( n = detect_r2c_Zatom( at, da, i ) );
7236 [ # # ]: 0 : if (n == 1)
7237 : : {
7238 : 0 : iZ = i;
7239 : : }
7240 : 0 : UnMarkOtherIndicators( at, num_atoms );
7241 : : }
7242 : : }
7243 : :
7244 [ # # ]: 0 : if (num == 1)
7245 : : {
7246 : : /* convert ring to chain: make single cut */
7247 : 0 : ret = cut_ring_to_chain( at, da, iZ );
7248 [ # # ]: 0 : if (ret < 0)
7249 : : {
7250 : 0 : goto exit_function;
7251 : : }
7252 : 0 : num_cuts += ( ret == 1 );
7253 : : }
7254 : : else
7255 : : {
7256 [ # # ]: 0 : if (num)
7257 : : {
7258 : : /* allocate an array of bonds to be cut */
7259 : 0 : R2C_ATPAIR *ap = (R2C_ATPAIR *) inchi_malloc( sizeof( ap[0] ) * num );
7260 : 0 : AT_NUMB comp_num = 0;
7261 [ # # ]: 0 : if (!ap)
7262 : : {
7263 : 0 : ret = -1; /* malloc failure */
7264 : 0 : goto exit_function;
7265 : : }
7266 : : /* fill out the array of bonds to be cut */
7267 [ # # ]: 0 : for (i = j = 0; i < num_atoms; i++)
7268 : : {
7269 [ # # ]: 0 : if (da[i].type == 1)
7270 : : {
7271 : 0 : AT_NUMB at1 = i;
7272 : 0 : AT_NUMB at2 = at[i].neighbor[(int) da[i].ordW];
7273 [ # # ]: 0 : if (j >= num)
7274 : : {
7275 : 0 : ret = -2;
7276 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
7277 : : }
7278 : 0 : n = ( at1 > at2 );
7279 : 0 : ap[j].at[n] = at1;
7280 : 0 : ap[j].at[1 - n] = at2; /* ap[j].at[0] < ap[j].at[1] */
7281 : 0 : j++;
7282 : : }
7283 : : }
7284 [ # # ]: 0 : if (j != num)
7285 : : {
7286 : 0 : ret = -3;
7287 : 0 : goto exit_r2c_num; /* wrong number of cuts = num */
7288 : : }
7289 : : /* sort the bonds for subsequent searching by bisections */
7290 : 0 : qsort( ap, num, sizeof( ap[0] ), cmp_r2c_atpair );
7291 : : /* mark components to be disconnected */
7292 [ # # ]: 0 : for (i = 0; i < num; i++)
7293 : : {
7294 [ # # ]: 0 : for (j = 0; j < 2; j++)
7295 : : {
7296 [ # # ]: 0 : if (!at[ap[i].at[j]].at_type)
7297 : : {
7298 : 0 : comp_num++;
7299 : 0 : mark_atoms_ap( at, (int) ap[i].at[j], ap, num, 0, comp_num );
7300 : : }
7301 : : }
7302 : : }
7303 : : /* convert ring to chain */
7304 [ # # ]: 0 : for (i = 0; i < num; i++)
7305 : : {
7306 : 0 : int i1 = ap[i].at[0];
7307 : 0 : int i2 = ap[i].at[1];
7308 : 0 : iZ = -1;
7309 [ # # ]: 0 : if (at[i1].at_type == at[i2].at_type)
7310 : : {
7311 : : /* by definition, there are no adjacent iZ atoms; one iZ atom per bond */
7312 [ # # # # ]: 0 : if (da[i1].type == 1 && at[i1].neighbor[(int) da[i1].ordW] == i2)
7313 : : {
7314 : 0 : iZ = i1;
7315 : : }
7316 : : else
7317 [ # # # # ]: 0 : if (da[i2].type == 1 && at[i2].neighbor[(int) da[i2].ordW] == i1)
7318 : : {
7319 : 0 : iZ = i2;
7320 : : }
7321 : : else
7322 : : {
7323 : 0 : ret = -3;
7324 : 0 : goto exit_r2c_num;
7325 : : }
7326 : 0 : ret = cut_ring_to_chain( at, da, iZ );
7327 [ # # ]: 0 : if (ret < 0)
7328 : : {
7329 : 0 : goto exit_r2c_num;
7330 : : }
7331 : 0 : num_cuts += ( ret == 1 );
7332 : : }
7333 : : }
7334 : 0 : ret = 0;
7335 : 0 : exit_r2c_num:
7336 [ # # ]: 0 : inchi_free( ap );
7337 : 0 : UnMarkOtherIndicators( at, num_atoms );
7338 [ # # ]: 0 : if (ret < 0)
7339 : : {
7340 : 0 : goto exit_function;
7341 : : }
7342 : : }
7343 : : }
7344 : : }
7345 : :
7346 [ # # ]: 0 : if (num_cuts)
7347 : : {
7348 : 0 : OAD_Edit_MergeComponentsAndRecreateOAD( orig_inp_data, inp_cur_data, num_components, &ret );
7349 : : }
7350 : :
7351 : 0 : exit_function:
7352 : :
7353 [ # # ]: 0 : if (da)
7354 : : {
7355 [ # # ]: 0 : inchi_free( da );
7356 : 0 : da = NULL;
7357 : : }
7358 [ # # ]: 0 : for (j = 0; j < num_components; j++)
7359 : : {
7360 : 0 : FreeInpAtomData( inp_cur_data + j );
7361 : : }
7362 [ # # ]: 0 : inchi_free( inp_cur_data );
7363 : 0 : inp_cur_data = NULL;
7364 : :
7365 [ # # ]: 0 : return ret ? ret : num_cuts;
7366 : : }
7367 : :
7368 : :
7369 : : #endif /* RING2CHAIN */
7370 : :
7371 : :
7372 : : #if ( RING2CHAIN == 1 || UNDERIVATIZE == 1 )
7373 : : /****************************************************************************/
7374 : 0 : void OAD_Edit_MergeComponentsAndRecreateOAD( ORIG_ATOM_DATA *orig_OrigAtomData,
7375 : : INP_ATOM_DATA *curr_InpAtomData,
7376 : : int num_components,
7377 : : int *errcode )
7378 : : {
7379 : 0 : int i, num_atoms = 0, cur_num_at = 0;
7380 : : inp_ATOM *at;
7381 : :
7382 [ # # ]: 0 : if (num_components <= 0)
7383 : : {
7384 : 0 : *errcode = -999; /* num atoms mismatch */
7385 : 0 : return;
7386 : : }
7387 : :
7388 : : /* Merge kept components into 'at' */
7389 [ # # ]: 0 : for (i = 0; i < num_components; i++)
7390 : : {
7391 : 0 : num_atoms += curr_InpAtomData[i].num_at;
7392 : : }
7393 : :
7394 : 0 : at = (inp_ATOM *) inchi_calloc( num_atoms, sizeof( at[0] ) );
7395 : 0 : cur_num_at = 0;
7396 : :
7397 [ # # ]: 0 : for (i = 0; i < num_components; i++)
7398 : : {
7399 : : /* Clean and prepare */
7400 : 0 : UnMarkRingSystemsInp( curr_InpAtomData[i].at, curr_InpAtomData[i].num_at );
7401 : 0 : UnMarkOtherIndicators( curr_InpAtomData[i].at, curr_InpAtomData[i].num_at );
7402 : 0 : UnMarkOneComponent( curr_InpAtomData[i].at, curr_InpAtomData[i].num_at );
7403 : :
7404 : 0 : subtract_DT_from_num_H( curr_InpAtomData[i].num_at, curr_InpAtomData[i].at );
7405 : :
7406 : : /* Merge one by one */
7407 : 0 : cur_num_at = add_inp_ATOM( at, num_atoms, cur_num_at, curr_InpAtomData[i].at, curr_InpAtomData[i].num_at );
7408 : : }
7409 : :
7410 : : /* Replace original OrigAtomData structure */
7411 [ # # ]: 0 : if (cur_num_at == num_atoms)
7412 : : {
7413 [ # # ]: 0 : inchi_free( orig_OrigAtomData->at );
7414 : 0 : orig_OrigAtomData->at = at;
7415 : :
7416 : 0 : orig_OrigAtomData->num_inp_atoms = cur_num_at;
7417 : :
7418 : : /* Destroy original coordinates as we destroyed a part of original input structure */
7419 [ # # ]: 0 : if (orig_OrigAtomData->szCoord)
7420 : : {
7421 [ # # ]: 0 : inchi_free( orig_OrigAtomData->szCoord );
7422 : 0 : orig_OrigAtomData->szCoord = NULL;
7423 : : }
7424 : :
7425 : 0 : UnMarkDisconnectedComponents( orig_OrigAtomData );
7426 : : }
7427 : : else
7428 : : {
7429 : : /* Create copy error! */
7430 [ # # ]: 0 : if (at)
7431 : : {
7432 [ # # ]: 0 : inchi_free( at );
7433 : 0 : at = NULL;
7434 : : }
7435 : 0 : *errcode = -999; /* num atoms mismatch */
7436 : : }
7437 : :
7438 : 0 : return;
7439 : : }
7440 : :
7441 : :
7442 : : /****************************************************************************/
7443 : 0 : void free_underiv_temp_data( R2C_ATPAIR *ap,
7444 : : DERIV_AT *da,
7445 : : inp_ATOM *at2,
7446 : : INP_ATOM_DATA *inp_cur_data,
7447 : : int num_components )
7448 : : {
7449 : : int i_component;
7450 [ # # ]: 0 : if (ap)
7451 : : {
7452 [ # # ]: 0 : inchi_free( ap );
7453 : 0 : ap = NULL;
7454 : : }
7455 [ # # ]: 0 : if (da)
7456 : : {
7457 [ # # ]: 0 : inchi_free( da );
7458 : 0 : da = NULL;
7459 : : }
7460 : : #ifdef FIX_UNDERIV_TO_SDF
7461 [ # # ]: 0 : if (at2)
7462 : : {
7463 [ # # ]: 0 : inchi_free( at2 );
7464 : 0 : at2 = NULL;
7465 : : }
7466 : : #endif
7467 [ # # ]: 0 : for (i_component = 0; i_component < num_components; i_component++)
7468 : : {
7469 : 0 : FreeInpAtomData( inp_cur_data + i_component );
7470 : : }
7471 [ # # ]: 0 : inchi_free( inp_cur_data );
7472 : 0 : inp_cur_data = NULL;
7473 : 0 : }
7474 : :
7475 : :
7476 : : /****************************************************************************/
7477 : 0 : void remove_cut_derivs( int num_atoms,
7478 : : inp_ATOM *at,
7479 : : INP_ATOM_DATA *inp_cur_data,
7480 : : int i_component,
7481 : : int *errcode )
7482 : : {
7483 : : /* Remove marked with Tritium disconnected derivative attachments */
7484 : : ORIG_ATOM_DATA Orig_inp_data1, *orig_inp_data1;
7485 : 0 : INP_ATOM_DATA *inp_cur_data1 = NULL;
7486 : 0 : int i, num_components1, i_component1, cur_num_at = 0; /* djb-rwth: removing redundant variables */
7487 : :
7488 : 0 : orig_inp_data1 = &Orig_inp_data1;
7489 : 0 : memset( orig_inp_data1, 0, sizeof( orig_inp_data1[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */
7490 : :
7491 : 0 : UnMarkRingSystemsInp( at, num_atoms );
7492 : 0 : UnMarkOtherIndicators( at, num_atoms );
7493 : 0 : UnMarkOneComponent( at, num_atoms );
7494 : :
7495 [ # # ]: 0 : for (i = 0; i < num_atoms; i++)
7496 : : {
7497 : 0 : orig_inp_data1->num_inp_bonds += at[i].valence;
7498 : : }
7499 : 0 : orig_inp_data1->num_inp_bonds /= 2;
7500 : 0 : orig_inp_data1->num_inp_atoms = num_atoms;
7501 : :
7502 : 0 : orig_inp_data1->at = at; /* = from inp_cur_data[i_component].at */
7503 : :
7504 : 0 : num_components1 = MarkDisconnectedComponents( orig_inp_data1, 0 );
7505 : :
7506 : 0 : inp_cur_data1 = (INP_ATOM_DATA *) inchi_calloc( num_components1, sizeof( inp_cur_data1[0] ) );
7507 : :
7508 [ # # # # ]: 0 : if (inp_cur_data1 && (num_components1 > 0)) /* djb-rwth: fixing a NULL pointer dereference */
7509 : : {
7510 : : /* Extract components and discard disconnected derivatizing agents */
7511 [ # # ]: 0 : for (i_component1 = 0; i_component1 < num_components1; i_component1++)
7512 : : {
7513 : 0 : CreateInpAtomData( inp_cur_data1 + i_component1, orig_inp_data1->nCurAtLen[i_component1], 0 );
7514 : 0 : inp_cur_data1[i_component1].num_at = ExtractConnectedComponent( orig_inp_data1->at, orig_inp_data1->num_inp_atoms,
7515 : 0 : i_component1 + 1, inp_cur_data1[i_component1].at );
7516 : : /* error processing */
7517 [ # # # # ]: 0 : if (inp_cur_data1[i_component1].num_at <= 0 || orig_inp_data1->nCurAtLen[i_component1] != inp_cur_data1[i_component1].num_at)
7518 : : {
7519 : 0 : *errcode = -( i_component1 + 1 ); /* severe error */
7520 : 0 : break;
7521 : : }
7522 : : /* if the component has tritium then discard: it is a derivatizing agent */
7523 [ # # ]: 0 : for (i = 0; i < inp_cur_data1[i_component1].num_at; i++)
7524 : : {
7525 : : #ifdef UNDERIV_ADD_D_TO_PRECURSOR
7526 : : if (inp_cur_data1[i_component1].at[i].num_iso_H[1])
7527 : : {
7528 : : inp_cur_data1[i_component1].at[i].num_iso_H[1] = 0; /* remove deuterium */
7529 : : }
7530 : : #endif
7531 [ # # ]: 0 : if (inp_cur_data1[i_component1].at[i].num_iso_H[2])
7532 : : {
7533 : 0 : FreeInpAtomData( inp_cur_data1 + i_component1 );
7534 : 0 : break;
7535 : : }
7536 : : }
7537 : : }
7538 : : /* Merge components into one -- must be only one */
7539 [ # # ]: 0 : for (i_component1 = 0, num_atoms = 0; i_component1 < num_components1; i_component1++)
7540 : : {
7541 : 0 : num_atoms += inp_cur_data1[i_component1].num_at;
7542 : : }
7543 : 0 : at = (inp_ATOM *) inchi_calloc( num_atoms, sizeof( at[0] ) );
7544 : 0 : cur_num_at = 0;
7545 [ # # ]: 0 : for (i_component1 = 0; i_component1 < num_components1; i_component1++)
7546 : : {
7547 : : /* clean and prepare */
7548 [ # # ]: 0 : if (!inp_cur_data1[i_component1].num_at)
7549 : : {
7550 : 0 : continue; /* removed derivatizing object */
7551 : : /*UnMarkOneComponent( inp_cur_data1[i_component1].at, inp_cur_data1[i_component1].num_at );*/
7552 : : /* merge one by one */
7553 : : }
7554 : 0 : cur_num_at = add_inp_ATOM( at, num_atoms, cur_num_at, inp_cur_data1[i_component1].at, inp_cur_data1[i_component1].num_at );
7555 : 0 : FreeInpAtomData( inp_cur_data1 + i_component1 ); /* cleanup */
7556 : : /* djb-rwth: removing redundant code */
7557 : : }
7558 : : }
7559 : :
7560 : : /* Replace the component */
7561 : : /* Order of the following two statements is critically important */
7562 : :
7563 : 0 : UnMarkDisconnectedComponents( orig_inp_data1 ); /* orig_inp_data1->at is same as inp_cur_data[i_component].at */
7564 : 0 : FreeInpAtomData( inp_cur_data + i_component ); /* cleanup the original component */
7565 : :
7566 : 0 : inp_cur_data[i_component].at = at;
7567 : 0 : inp_cur_data[i_component].num_at = cur_num_at;
7568 [ # # ]: 0 : inchi_free( inp_cur_data1 );
7569 : 0 : }
7570 : : #endif /* #if ( RING2CHAIN == 1 || UNDERIVATIZE == 1 ) */
7571 : :
|