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