third_party/inchi/INCHI_BASE/src/runichi3.c
int OAD_Polymer_CompareRanksOfTwoAtoms( int atom1, int atom2, OAD_AtProps *aprops )
{
    const int HETEROCYC = 3, HETEROAT = 2, CARBOCYC = 1, CARBOAT = 0;
        /* NB: Carbon's rank is always 2, next to the lowest */

    int a1 = atom1 - 1;
    int a2 = atom2 - 1;
    int a1typ = CARBOAT;
    int a2typ = CARBOAT;

    if (aprops[a1].ring_size > 2)
    {
        if (aprops[a1].ring_erank <= 2)
        {
            a1typ = CARBOCYC;
        }
        else
        {
            a1typ = HETEROCYC;
        }
    }
    else
    {
        if (aprops[a1].erank == 2)
        {
            a1typ = CARBOAT;
        }
        else
        {
            a1typ = HETEROAT;
        }
    }

    if (aprops[a2].ring_size > 2)
    {
        if (aprops[a2].ring_erank <= 2)
        {
            a2typ = CARBOCYC;
        }
        else
        {
            a2typ = HETEROCYC;
        }
    }
    else
    {
        if (aprops[a2].erank == 2)
        {
            a2typ = CARBOAT;
        }
        else
        {
            a2typ = HETEROAT;
        }
    }

    /* Compare */

    /*
        Follow IUPAC Rule 1
            'The basic order of seniority of subunits is:
                heterocyclic rings and ring systems > heteroatom chains >
                    > carbocyclic rings and ring systems > acyclic carbon chains'
    */

    if (a1typ == HETEROCYC && a2typ == HETEROCYC)   /* a1 and a2 are HETEROCYC */
    {
        /* Try resolving by senior-heteroatom ring */
        if (aprops[a1].ring_erank < aprops[a2].ring_erank)
        {
            return  1;
        }
        if (aprops[a1].ring_erank > aprops[a2].ring_erank)
        {
            return -1;
        }
        /* Same senior-heteroatom rings, try resolving by total ring size */
        if (aprops[a1].ring_size < aprops[a2].ring_size)
        {
            return  1;
        }
        if (aprops[a1].ring_size > aprops[a2].ring_size)
        {
            return -1;
        }
        /* Could not resolve... */
        return 0;
    }
    else if (a1typ == HETEROCYC)
    {
        return -1;  /* a1 is HETEROCYC, a2 is any other (==junior) */
    }
    else if (a2typ == HETEROCYC)
    {
        return  1;  /* a2 is HETEROCYC, a1 is any other (==junior) */
    }

    /* HETEROCYC left out */

    if (a1typ == HETEROAT && a2typ == HETEROAT)  /* a1 and a2 are HETEROAT */
    {
        if (aprops[a1].erank < aprops[a2].erank)
        {
            return  1;
        }
        if (aprops[a1].erank > aprops[a2].erank)
        {
            return -1;
        }
        /* Could not resolve... */
        return 0;
    }
    else if (a1typ == HETEROAT)
    {
        return -1;  /* a1 is HETEROAT, a2 is any other (==junior) */
    }
    else if (a2typ == HETEROAT)
    {
        return  1;  /* a2 is HETEROAT, a1 is any other (==junior) */
    }

    /* HETEROAT left out */
    if (a1typ == CARBOCYC && a2typ == CARBOCYC) /* a1 and a2 are CARBOCYC */
    {
        /* Same senior-atom (C) ring, try resolving by total ring size */
        if (aprops[a1].ring_size < aprops[a2].ring_size)
        {
            return  1;
        }
        if (aprops[a1].ring_size > aprops[a2].ring_size)
        {
            return -1;
        }
        /* Could not resolve... */
        return 0;
    }
    else if (a1typ == CARBOCYC)
    {
        return -1;
    }
    else if (a2typ == CARBOCYC)
    {
        return  1;
    }

    return 0;        /* 0 means unresolved. It is legal here */
}
/****************************************************************************
 Compare seniority of two atoms in polymer SRU
 loosely following IUPAC guidelines.
 NB: no last resort check here, so 0 (=='same seniority') may be returned
****************************************************************************/
Compare seniority of two atoms in polymer SRU
loosely following IUPAC guidelines.
NB: no last resort check here, so 0 (=='same seniority') may be returned
Compare seniority of two atoms in polymer SRU loosely following IUPAC guidelines . NB : no last resort check here so 0 ( == ' same seniority ' ) may be returned
int OAD_Polymer_CompareRanksOfTwoAtoms( int atom1, int atom2, OAD_AtProps *aprops )
{
    const int HETEROCYC = 3, HETEROAT = 2, CARBOCYC = 1, CARBOAT = 0;
    int a1 = atom1 - 1;
    int a2 = atom2 - 1;
    int a1typ = CARBOAT;
    int a2typ = CARBOAT;
    if (aprops[a1].ring_size > 2)
    {
        if (aprops[a1].ring_erank <= 2)
        {
            a1typ = CARBOCYC;
        }
        else
        {
            a1typ = HETEROCYC;
        }
    }
    else
    {
        if (aprops[a1].erank == 2)
        {
            a1typ = CARBOAT;
        }
        else
        {
            a1typ = HETEROAT;
        }
    }
    if (aprops[a2].ring_size > 2)
    {
        if (aprops[a2].ring_erank <= 2)
        {
            a2typ = CARBOCYC;
        }
        else
        {
            a2typ = HETEROCYC;
        }
    }
    else
    {
        if (aprops[a2].erank == 2)
        {
            a2typ = CARBOAT;
        }
        else
        {
            a2typ = HETEROAT;
        }
    }
    if (a1typ == HETEROCYC && a2typ == HETEROCYC)   
    {
        if (aprops[a1].ring_erank < aprops[a2].ring_erank)
        {
            return  1;
        }
        if (aprops[a1].ring_erank > aprops[a2].ring_erank)
        {
            return -1;
        }
        if (aprops[a1].ring_size < aprops[a2].ring_size)
        {
            return  1;
        }
        if (aprops[a1].ring_size > aprops[a2].ring_size)
        {
            return -1;
        }
        return 0;
    }
    else if (a1typ == HETEROCYC)
    {
        return -1;  
    }
    else if (a2typ == HETEROCYC)
    {
        return  1;  
    }
    if (a1typ == HETEROAT && a2typ == HETEROAT)  
    {
        if (aprops[a1].erank < aprops[a2].erank)
        {
            return  1;
        }
        if (aprops[a1].erank > aprops[a2].erank)
        {
            return -1;
        }
        return 0;
    }
    else if (a1typ == HETEROAT)
    {
        return -1;  
    }
    else if (a2typ == HETEROAT)
    {
        return  1;  
    }
    if (a1typ == CARBOCYC && a2typ == CARBOCYC) 
    {
        if (aprops[a1].ring_size < aprops[a2].ring_size)
        {
            return  1;
        }
        if (aprops[a1].ring_size > aprops[a2].ring_size)
        {
            return -1;
        }
        return 0;
    }
    else if (a1typ == CARBOCYC)
    {
        return -1;
    }
    else if (a2typ == CARBOCYC)
    {
        return  1;
    }
    return 0;        
}
int OAD_Polymer_CompareRanksOfTwoAtoms ( int atom1 , int atom2 , OAD_AtProps * aprops ) { const int HETEROCYC = 3 , HETEROAT = 2 , CARBOCYC = 1 , CARBOAT = 0 ; int a1 = atom1 - 1 ; int a2 = atom2 - 1 ; int a1typ = CARBOAT ; int a2typ = CARBOAT ; if ( aprops [ a1 ] . ring_size > 2 ) { if ( aprops [ a1 ] . ring_erank <= 2 ) { a1typ = CARBOCYC ; } else { a1typ = HETEROCYC ; } } else { if ( aprops [ a1 ] . erank == 2 ) { a1typ = CARBOAT ; } else { a1typ = HETEROAT ; } } if ( aprops [ a2 ] . ring_size > 2 ) { if ( aprops [ a2 ] . ring_erank <= 2 ) { a2typ = CARBOCYC ; } else { a2typ = HETEROCYC ; } } else { if ( aprops [ a2 ] . erank == 2 ) { a2typ = CARBOAT ; } else { a2typ = HETEROAT ; } } if ( a1typ == HETEROCYC && a2typ == HETEROCYC ) { if ( aprops [ a1 ] . ring_erank < aprops [ a2 ] . ring_erank ) { return 1 ; } if ( aprops [ a1 ] . ring_erank > aprops [ a2 ] . ring_erank ) { return -1 ; } if ( aprops [ a1 ] . ring_size < aprops [ a2 ] . ring_size ) { return 1 ; } if ( aprops [ a1 ] . ring_size > aprops [ a2 ] . ring_size ) { return -1 ; } return 0 ; } else if ( a1typ == HETEROCYC ) { return -1 ; } else if ( a2typ == HETEROCYC ) { return 1 ; } if ( a1typ == HETEROAT && a2typ == HETEROAT ) { if ( aprops [ a1 ] . erank < aprops [ a2 ] . erank ) { return 1 ; } if ( aprops [ a1 ] . erank > aprops [ a2 ] . erank ) { return -1 ; } return 0 ; } else if ( a1typ == HETEROAT ) { return -1 ; } else if ( a2typ == HETEROAT ) { return 1 ; } if ( a1typ == CARBOCYC && a2typ == CARBOCYC ) { if ( aprops [ a1 ] . ring_size < aprops [ a2 ] . ring_size ) { return 1 ; } if ( aprops [ a1 ] . ring_size > aprops [ a2 ] . ring_size ) { return -1 ; } return 0 ; } else if ( a1typ == CARBOCYC ) { return -1 ; } else if ( a2typ == CARBOCYC ) { return 1 ; } return 0 ; }
Compare seniority of two atoms in polymer SRU
loosely following IUPAC guidelines.
Compare seniority of two atoms in polymer SRU loosely following IUPAC guidelines .
/* NB: Carbon's rank is always 2, next to the lowest */ /* Compare */ /*
        Follow IUPAC Rule 1
            'The basic order of seniority of subunits is:
                heterocyclic rings and ring systems > heteroatom chains >
                    > carbocyclic rings and ring systems > acyclic carbon chains'
    */ /* a1 and a2 are HETEROCYC */ /* Try resolving by senior-heteroatom ring */ /* Same senior-heteroatom rings, try resolving by total ring size */ /* Could not resolve... */ /* a1 is HETEROCYC, a2 is any other (==junior) */ /* a2 is HETEROCYC, a1 is any other (==junior) */ /* HETEROCYC left out */ /* a1 and a2 are HETEROAT */ /* Could not resolve... */ /* a1 is HETEROAT, a2 is any other (==junior) */ /* a2 is HETEROAT, a1 is any other (==junior) */ /* HETEROAT left out */ /* a1 and a2 are CARBOCYC */ /* Same senior-atom (C) ring, try resolving by total ring size */ /* Could not resolve... */ /* 0 means unresolved. It is legal here */