third_party/inchi/INCHI_BASE/src/runichi3.c
int  OAD_PolymerUnit_OrderBondAtomsAndBondsThemselves( OAD_PolymerUnit  *u,
                                                       int n_star_atoms,
                                                       int *star_atoms )
{
    int k;

    /* Sort bond atoms */
    for (k = 0; k < u->nb; k++)
    {
        /* Place not-in-unit bond end to first place */
        int a1 = u->blist[2 * k];
        int a2 = u->blist[2 * k + 1];
        int a1_is_not_in_alist = 0;
        int a1_is_star_atom = 0;
        int a2_is_not_in_alist = 0;
        int a2_is_star_atom = 0;

        if (!is_in_the_ilist( u->alist, a1, u->na ))
        {
            a1_is_not_in_alist = 1;
        }
        if (is_in_the_ilist( star_atoms, a1, n_star_atoms ))
        {
            a1_is_star_atom = 1;
        }

        if (!is_in_the_ilist( u->alist, a2, u->na ))
        {
            a2_is_not_in_alist = 1;
        }
        if (is_in_the_ilist( star_atoms, a2, n_star_atoms ))
        {
            a2_is_star_atom = 1;
        }

        if (( a1_is_not_in_alist || a1_is_star_atom ) &&
            ( a2_is_not_in_alist || a2_is_star_atom ))
        {
            /* Both the ends are out of unit: the crossing bond is invalid */
            return 1;
        }
        /* If a2 is star atom or non-star external to the current unit, swap(a2,a1) */
        if (a2_is_star_atom || a2_is_not_in_alist)
        {
            u->blist[2 * k] = a2;
            u->blist[2 * k + 1] = a1;
        }
    }

    /* Sort bond themselves
        for now, consider only the simplest cases of 2 bonds
    */
    if (u->nb == 2)            /* two bonds in SBL */
    {
        int b1a1 = u->blist[0];
        int b1a2 = u->blist[1];
        int b2a1 = u->blist[2];
        int b2a2 = u->blist[3];
        if (b1a1 > b2a1)
        {
            /* swap */
            u->blist[0] = b2a1; u->blist[1] = b2a2;
            u->blist[2] = b1a1; u->blist[3] = b1a2;
        }
    }

    /* for single or no bonds, do nothing
    else
        ;
    */

    return 0;
}
/****************************************************************************
 Sort SRU bond lists atoms and bonds themselves
****************************************************************************/
Sort SRU bond lists atoms and bonds themselves
Sort SRU bond lists atoms and bonds themselves
int  OAD_PolymerUnit_OrderBondAtomsAndBondsThemselves( OAD_PolymerUnit  *u,
                                                       int n_star_atoms,
                                                       int *star_atoms )
{
    int k;
    for (k = 0; k < u->nb; k++)
    {
        int a1 = u->blist[2 * k];
        int a2 = u->blist[2 * k + 1];
        int a1_is_not_in_alist = 0;
        int a1_is_star_atom = 0;
        int a2_is_not_in_alist = 0;
        int a2_is_star_atom = 0;
        if (!is_in_the_ilist( u->alist, a1, u->na ))
        {
            a1_is_not_in_alist = 1;
        }
        if (is_in_the_ilist( star_atoms, a1, n_star_atoms ))
        {
            a1_is_star_atom = 1;
        }
        if (!is_in_the_ilist( u->alist, a2, u->na ))
        {
            a2_is_not_in_alist = 1;
        }
        if (is_in_the_ilist( star_atoms, a2, n_star_atoms ))
        {
            a2_is_star_atom = 1;
        }
        if (( a1_is_not_in_alist || a1_is_star_atom ) &&
            ( a2_is_not_in_alist || a2_is_star_atom ))
        {
            return 1;
        }
        if (a2_is_star_atom || a2_is_not_in_alist)
        {
            u->blist[2 * k] = a2;
            u->blist[2 * k + 1] = a1;
        }
    }
    if (u->nb == 2)            
    {
        int b1a1 = u->blist[0];
        int b1a2 = u->blist[1];
        int b2a1 = u->blist[2];
        int b2a2 = u->blist[3];
        if (b1a1 > b2a1)
        {
            u->blist[0] = b2a1; u->blist[1] = b2a2;
            u->blist[2] = b1a1; u->blist[3] = b1a2;
        }
    }
    return 0;
}
int OAD_PolymerUnit_OrderBondAtomsAndBondsThemselves ( OAD_PolymerUnit * u , int n_star_atoms , int * star_atoms ) { int k ; for ( k = 0 ; k < u -> nb ; k ++ ) { int a1 = u -> blist [ 2 * k ] ; int a2 = u -> blist [ 2 * k + 1 ] ; int a1_is_not_in_alist = 0 ; int a1_is_star_atom = 0 ; int a2_is_not_in_alist = 0 ; int a2_is_star_atom = 0 ; if ( ! is_in_the_ilist ( u -> alist , a1 , u -> na ) ) { a1_is_not_in_alist = 1 ; } if ( is_in_the_ilist ( star_atoms , a1 , n_star_atoms ) ) { a1_is_star_atom = 1 ; } if ( ! is_in_the_ilist ( u -> alist , a2 , u -> na ) ) { a2_is_not_in_alist = 1 ; } if ( is_in_the_ilist ( star_atoms , a2 , n_star_atoms ) ) { a2_is_star_atom = 1 ; } if ( ( a1_is_not_in_alist || a1_is_star_atom ) && ( a2_is_not_in_alist || a2_is_star_atom ) ) { return 1 ; } if ( a2_is_star_atom || a2_is_not_in_alist ) { u -> blist [ 2 * k ] = a2 ; u -> blist [ 2 * k + 1 ] = a1 ; } } if ( u -> nb == 2 ) { int b1a1 = u -> blist [ 0 ] ; int b1a2 = u -> blist [ 1 ] ; int b2a1 = u -> blist [ 2 ] ; int b2a2 = u -> blist [ 3 ] ; if ( b1a1 > b2a1 ) { u -> blist [ 0 ] = b2a1 ; u -> blist [ 1 ] = b2a2 ; u -> blist [ 2 ] = b1a1 ; u -> blist [ 3 ] = b1a2 ; } } return 0 ; }
Sort SRU bond lists atoms and bonds themselves
Sort SRU bond lists atoms and bonds themselves
/* Sort bond atoms */ /* Place not-in-unit bond end to first place */ /* Both the ends are out of unit: the crossing bond is invalid */ /* If a2 is star atom or non-star external to the current unit, swap(a2,a1) */ /* Sort bond themselves
        for now, consider only the simplest cases of 2 bonds
    */ /* two bonds in SBL */ /* swap */ /* for single or no bonds, do nothing
    else
        ;
    */