third_party/inchi/INCHI_BASE/src/strutil.c
int fix_non_uniform_drawn_amidiniums( int num_atoms,
                                      inp_ATOM *at,
                                      int *num_changes )

{
    /* Amidines include carboxamidines RC(=NR)NR2,
    sulfinamidines RS(=NR)NR2 and phosphinamidines, R2P(=NR)NR2.


    NR                              NR
    |                               |
    R"-Y-NHR'         ===>          R"-Y=N(+)HR'
    (+)


    Y = C, S, P


    Fix:
    move positive charge to nitrogen and change single bond to a double one.


    Comment:
    Fix is applied only if at least one of R's at N is hydrogen
    (otherwise we have just a '+' delocalization which is already recognized).


    */

    /* constants for element numbers */
    enum elems
    {
        dNone, dCl = 17, dBr = 35, dI = 53, dAt = 85, dO = 8,
        dS = 16, dSe = 34, dTe = 52, dP = 15, dC = 6, dN = 7
    };

    static U_CHAR  allowed_elnums_center[] = { dC, dS, dP };
    int en_center;
    int i, j, k, jj, kk, k1;
    int mismatch = 0, nuH = 0, nuN = 0, nitrogens[MAXVAL];

    for (i = 0; i < num_atoms; i++)
    {
        /* Find appropriate central atom. This center should be: ...*/

        /* charged exactly (+1) ... */
        if (at[i].charge != 1)
        {
            continue;
        }
        en_center = at[i].el_number;
        /*  from eligible element list ... */
        if (!memchr( allowed_elnums_center, en_center, sizeof( allowed_elnums_center ) ))
        {
            continue;
        }
        /* has exactly 3 neighbours connected by single bonds*/
        if (at[i].valence != 3)
        {
            continue;
        }
        if (at[i].chem_bonds_valence != 3)
        {
            continue;
        }

        /* non-radical. */
        if (at[i].radical && ( at[i].radical != RADICAL_SINGLET ))
        {
            continue;
        }

        /* NB: center must have neutral neighbours, two of them are aliphatic N's of which at least one bears H. */
        mismatch = nuH = nuN = jj = kk = 0;
        memset( nitrogens, 0, sizeof( nitrogens ) );
        jj = -1;
        for (k = 0; k < at[i].valence; k++)
        {
            j = at[i].neighbor[k];

            if (at[j].charge != 0)
            {
                mismatch = 1;
                break;
            }
            if (at[j].el_number == dN)
            {
                if (( at[j].valence > 3 ) || ( at[j].chem_bonds_valence > 3 ))
                {
                    mismatch = 1;
                    break;
                }
                nuH += NUMH( at, j );
                nuN++;
                if (jj < 0)
                {
                    jj = j;
                    kk = k;
                }
            }
        }

        /* If OK, apply changes. */
        if (mismatch)
        {
            continue;
        }
        if (nuN != 2)
        {
            continue;
        }
        if (nuH < 1)
        {
            continue;
        }
        if (jj >= 0)
        {
            at[i].charge = 0;
            at[jj].charge = 1;
            at[i].bond_type[kk] = BOND_TYPE_DOUBLE;
            for (k1 = 0; k1 < at[jj].valence && i != at[jj].neighbor[k1]; k1++)
                ;
            at[jj].bond_type[k1] = BOND_TYPE_DOUBLE;
            at[i].chem_bonds_valence++;
            at[jj].chem_bonds_valence++;
            /* NB: do nothing with wedge stereo bonds (retain wedge) */

            ( *num_changes )++;
        }
    }  /* end of search for candidate centers. */

    return 0;
}
/****************************************************************************
Correct non-uniformly drawn amidinium cations.
****************************************************************************/
Correct non-uniformly drawn amidinium cations.
Correct non - uniformly drawn amidinium cations .
int fix_non_uniform_drawn_amidiniums( int num_atoms,
                                      inp_ATOM *at,
                                      int *num_changes )
{
    enum elems
    {
        dNone, dCl = 17, dBr = 35, dI = 53, dAt = 85, dO = 8,
        dS = 16, dSe = 34, dTe = 52, dP = 15, dC = 6, dN = 7
    };
    static U_CHAR  allowed_elnums_center[] = { dC, dS, dP };
    int en_center;
    int i, j, k, jj, kk, k1;
    int mismatch = 0, nuH = 0, nuN = 0, nitrogens[MAXVAL];
    for (i = 0; i < num_atoms; i++)
    {
        if (at[i].charge != 1)
        {
            continue;
        }
        en_center = at[i].el_number;
        if (!memchr( allowed_elnums_center, en_center, sizeof( allowed_elnums_center ) ))
        {
            continue;
        }
        if (at[i].valence != 3)
        {
            continue;
        }
        if (at[i].chem_bonds_valence != 3)
        {
            continue;
        }
        if (at[i].radical && ( at[i].radical != RADICAL_SINGLET ))
        {
            continue;
        }
        mismatch = nuH = nuN = jj = kk = 0;
        memset( nitrogens, 0, sizeof( nitrogens ) );
        jj = -1;
        for (k = 0; k < at[i].valence; k++)
        {
            j = at[i].neighbor[k];
            if (at[j].charge != 0)
            {
                mismatch = 1;
                break;
            }
            if (at[j].el_number == dN)
            {
                if (( at[j].valence > 3 ) || ( at[j].chem_bonds_valence > 3 ))
                {
                    mismatch = 1;
                    break;
                }
                nuH += NUMH( at, j );
                nuN++;
                if (jj < 0)
                {
                    jj = j;
                    kk = k;
                }
            }
        }
        if (mismatch)
        {
            continue;
        }
        if (nuN != 2)
        {
            continue;
        }
        if (nuH < 1)
        {
            continue;
        }
        if (jj >= 0)
        {
            at[i].charge = 0;
            at[jj].charge = 1;
            at[i].bond_type[kk] = BOND_TYPE_DOUBLE;
            for (k1 = 0; k1 < at[jj].valence && i != at[jj].neighbor[k1]; k1++)
                ;
            at[jj].bond_type[k1] = BOND_TYPE_DOUBLE;
            at[i].chem_bonds_valence++;
            at[jj].chem_bonds_valence++;
            ( *num_changes )++;
        }
    }  
    return 0;
}
int fix_non_uniform_drawn_amidiniums ( int num_atoms , inp_ATOM * at , int * num_changes ) { enum elems { dNone , dCl = 17 , dBr = 35 , dI = 53 , dAt = 85 , dO = 8 , dS = 16 , dSe = 34 , dTe = 52 , dP = 15 , dC = 6 , dN = 7 } ; static U_CHAR allowed_elnums_center [ ] = { dC , dS , dP } ; int en_center ; int i , j , k , jj , kk , k1 ; int mismatch = 0 , nuH = 0 , nuN = 0 , nitrogens [ MAXVAL ] ; for ( i = 0 ; i < num_atoms ; i ++ ) { if ( at [ i ] . charge != 1 ) { continue ; } en_center = at [ i ] . el_number ; if ( ! memchr ( allowed_elnums_center , en_center , sizeof ( allowed_elnums_center ) ) ) { continue ; } if ( at [ i ] . valence != 3 ) { continue ; } if ( at [ i ] . chem_bonds_valence != 3 ) { continue ; } if ( at [ i ] . radical && ( at [ i ] . radical != RADICAL_SINGLET ) ) { continue ; } mismatch = nuH = nuN = jj = kk = 0 ; memset ( nitrogens , 0 , sizeof ( nitrogens ) ) ; jj = -1 ; for ( k = 0 ; k < at [ i ] . valence ; k ++ ) { j = at [ i ] . neighbor [ k ] ; if ( at [ j ] . charge != 0 ) { mismatch = 1 ; break ; } if ( at [ j ] . el_number == dN ) { if ( ( at [ j ] . valence > 3 ) || ( at [ j ] . chem_bonds_valence > 3 ) ) { mismatch = 1 ; break ; } nuH += NUMH ( at , j ) ; nuN ++ ; if ( jj < 0 ) { jj = j ; kk = k ; } } } if ( mismatch ) { continue ; } if ( nuN != 2 ) { continue ; } if ( nuH < 1 ) { continue ; } if ( jj >= 0 ) { at [ i ] . charge = 0 ; at [ jj ] . charge = 1 ; at [ i ] . bond_type [ kk ] = BOND_TYPE_DOUBLE ; for ( k1 = 0 ; k1 < at [ jj ] . valence && i != at [ jj ] . neighbor [ k1 ] ; k1 ++ ) ; at [ jj ] . bond_type [ k1 ] = BOND_TYPE_DOUBLE ; at [ i ] . chem_bonds_valence ++ ; at [ jj ] . chem_bonds_valence ++ ; ( * num_changes ) ++ ; } } return 0 ; }
Correct non-uniformly drawn amidinium cations.
Correct non - uniformly drawn amidinium cations .
/* Amidines include carboxamidines RC(=NR)NR2,
    sulfinamidines RS(=NR)NR2 and phosphinamidines, R2P(=NR)NR2.


    NR                              NR
    |                               |
    R"-Y-NHR'         ===>          R"-Y=N(+)HR'
    (+)


    Y = C, S, P


    Fix:
    move positive charge to nitrogen and change single bond to a double one.


    Comment:
    Fix is applied only if at least one of R's at N is hydrogen
    (otherwise we have just a '+' delocalization which is already recognized).


    */ /* constants for element numbers */ /* Find appropriate central atom. This center should be: ...*/ /* charged exactly (+1) ... */ /*  from eligible element list ... */ /* has exactly 3 neighbours connected by single bonds*/ /* non-radical. */ /* NB: center must have neutral neighbours, two of them are aliphatic N's of which at least one bears H. */ /* If OK, apply changes. */ /* NB: do nothing with wedge stereo bonds (retain wedge) */ /* end of search for candidate centers. */