third_party/inchi/INCHI_BASE/src/runichi3.c
int OAD_CollectReachableAtoms( ORIG_ATOM_DATA  *orig_at_data,
                               int start_atom,
                               int nforbidden_bonds,
                               int *forbidden_bond_atoms,
                               int *n_reachable,
                               int *reachable,
                               int *err,
                               char *pStrErr)
{
    int iatom, natnums, max_atoms, j, ret = _IS_OKAY;
    int max_n_reachable = *n_reachable;
    int *atnums = NULL;
    subgraf *sg = NULL;
    subgraf_pathfinder *spf = NULL;

    natnums = 0;
    max_atoms = orig_at_data->num_inp_atoms;
    iatom = start_atom - 1;
    *n_reachable = 0;

    atnums = (int *)inchi_calloc(max_atoms, sizeof(int));
    if (!atnums)
    {
        ret = _IS_ERROR;
        goto exit_function;
    }
    for (j = 0; j < max_atoms; j++)
    {
        atnums[j] = orig_at_data->at[j].orig_at_number;
    }
    sg = subgraf_new(orig_at_data, max_atoms, atnums);
    if (!sg)
    {
        ret = _IS_ERROR;
        goto exit_function;
    }
    spf = subgraf_pathfinder_new(sg, orig_at_data, iatom, iatom);
    if (!spf)
    {
        ret = _IS_ERROR;
        goto exit_function;
    }

    /* move from orig# to node# */
    spf->start = iatom;
    for (j = 0; j < nforbidden_bonds; j++)
    {
        forbidden_bond_atoms[2 * j]      = sg->orig2node[forbidden_bond_atoms[2 * j] ];
        forbidden_bond_atoms[2 * j + 1]  = sg->orig2node[forbidden_bond_atoms[2 * j + 1] ];
    }

    /*memset(atnums, -1, max_atoms * sizeof(int));*/
    for (j = 0; j < max_atoms; j++)
    {
        atnums[j] = -1;
    }

    spf->nseen = 0;
    natnums = subgraf_pathfinder_collect_all(spf, nforbidden_bonds, forbidden_bond_atoms, atnums);

    if (natnums)
    {
        if (natnums > max_n_reachable)
        {
            ret = _IS_ERROR;
            goto exit_function;
        }

        for (j = 0; j < natnums; j++)
        {
            reachable[(*n_reachable)++ ] = atnums[j];
        }
    }

exit_function:
    subgraf_free(sg);
    subgraf_pathfinder_free(spf);
    if (atnums)
    {
        inchi_free(atnums);
    }
    
    return ret;
}
/****************************************************************************
Collect all atoms reachable from start_atom
****************************************************************************/
Collect all atoms reachable from start_atom
Collect all atoms reachable from start_atom
int OAD_CollectReachableAtoms( ORIG_ATOM_DATA  *orig_at_data,
                               int start_atom,
                               int nforbidden_bonds,
                               int *forbidden_bond_atoms,
                               int *n_reachable,
                               int *reachable,
                               int *err,
                               char *pStrErr)
{
    int iatom, natnums, max_atoms, j, ret = _IS_OKAY;
    int max_n_reachable = *n_reachable;
    int *atnums = NULL;
    subgraf *sg = NULL;
    subgraf_pathfinder *spf = NULL;
    natnums = 0;
    max_atoms = orig_at_data->num_inp_atoms;
    iatom = start_atom - 1;
    *n_reachable = 0;
    atnums = (int *)inchi_calloc(max_atoms, sizeof(int));
    if (!atnums)
    {
        ret = _IS_ERROR;
        goto exit_function;
    }
    for (j = 0; j < max_atoms; j++)
    {
        atnums[j] = orig_at_data->at[j].orig_at_number;
    }
    sg = subgraf_new(orig_at_data, max_atoms, atnums);
    if (!sg)
    {
        ret = _IS_ERROR;
        goto exit_function;
    }
    spf = subgraf_pathfinder_new(sg, orig_at_data, iatom, iatom);
    if (!spf)
    {
        ret = _IS_ERROR;
        goto exit_function;
    }
    spf->start = iatom;
    for (j = 0; j < nforbidden_bonds; j++)
    {
        forbidden_bond_atoms[2 * j]      = sg->orig2node[forbidden_bond_atoms[2 * j] ];
        forbidden_bond_atoms[2 * j + 1]  = sg->orig2node[forbidden_bond_atoms[2 * j + 1] ];
    }
    for (j = 0; j < max_atoms; j++)
    {
        atnums[j] = -1;
    }
    spf->nseen = 0;
    natnums = subgraf_pathfinder_collect_all(spf, nforbidden_bonds, forbidden_bond_atoms, atnums);
    if (natnums)
    {
        if (natnums > max_n_reachable)
        {
            ret = _IS_ERROR;
            goto exit_function;
        }
        for (j = 0; j < natnums; j++)
        {
            reachable[(*n_reachable)++ ] = atnums[j];
        }
    }
exit_function:
    subgraf_free(sg);
    subgraf_pathfinder_free(spf);
    if (atnums)
    {
        inchi_free(atnums);
    }
    return ret;
}
int OAD_CollectReachableAtoms ( ORIG_ATOM_DATA * orig_at_data , int start_atom , int nforbidden_bonds , int * forbidden_bond_atoms , int * n_reachable , int * reachable , int * err , char * pStrErr ) { int iatom , natnums , max_atoms , j , ret = _IS_OKAY ; int max_n_reachable = * n_reachable ; int * atnums = NULL ; subgraf * sg = NULL ; subgraf_pathfinder * spf = NULL ; natnums = 0 ; max_atoms = orig_at_data -> num_inp_atoms ; iatom = start_atom - 1 ; * n_reachable = 0 ; atnums = ( int * ) inchi_calloc ( max_atoms , sizeof ( int ) ) ; if ( ! atnums ) { ret = _IS_ERROR ; goto exit_function ; } for ( j = 0 ; j < max_atoms ; j ++ ) { atnums [ j ] = orig_at_data -> at [ j ] . orig_at_number ; } sg = subgraf_new ( orig_at_data , max_atoms , atnums ) ; if ( ! sg ) { ret = _IS_ERROR ; goto exit_function ; } spf = subgraf_pathfinder_new ( sg , orig_at_data , iatom , iatom ) ; if ( ! spf ) { ret = _IS_ERROR ; goto exit_function ; } spf -> start = iatom ; for ( j = 0 ; j < nforbidden_bonds ; j ++ ) { forbidden_bond_atoms [ 2 * j ] = sg -> orig2node [ forbidden_bond_atoms [ 2 * j ] ] ; forbidden_bond_atoms [ 2 * j + 1 ] = sg -> orig2node [ forbidden_bond_atoms [ 2 * j + 1 ] ] ; } for ( j = 0 ; j < max_atoms ; j ++ ) { atnums [ j ] = -1 ; } spf -> nseen = 0 ; natnums = subgraf_pathfinder_collect_all ( spf , nforbidden_bonds , forbidden_bond_atoms , atnums ) ; if ( natnums ) { if ( natnums > max_n_reachable ) { ret = _IS_ERROR ; goto exit_function ; } for ( j = 0 ; j < natnums ; j ++ ) { reachable [ ( * n_reachable ) ++ ] = atnums [ j ] ; } } exit_function : subgraf_free ( sg ) ; subgraf_pathfinder_free ( spf ) ; if ( atnums ) { inchi_free ( atnums ) ; } return ret ; }
Collect all atoms reachable from start_atom
Collect all atoms reachable from start_atom
/* move from orig# to node# */ /*memset(atnums, -1, max_atoms * sizeof(int));*/