~ubuntu-branches/ubuntu/feisty/openbabel/feisty

« back to all changes in this revision

Viewing changes to src/formats/inchi/ichiisot.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-05-14 19:46:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060514194601-h3j1wovvc42cigxl
Tags: 2.0.1-1
* New upstream release. (Closes: #341628)
* debian/patches/04_zipstream_fix.diff: Removed, applied upstream.
* debian/rules (DEB_MAKE_CHECK_TARGET): Readded.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * International Union of Pure and Applied Chemistry (IUPAC)
 
3
 * International Chemical Identifier (InChI)
 
4
 * Version 1
 
5
 * Software version 1.00
 
6
 * April 13, 2005
 
7
 * Developed at NIST
 
8
 */
 
9
 
 
10
#include <stdio.h>
 
11
#include <stdlib.h>
 
12
#include <string.h>
 
13
 
 
14
#include "mode.h"
 
15
 
 
16
#include "comdef.h"
 
17
#include "extr_ct.h"
 
18
#include "ichitaut.h"
 
19
#include "ichicant.h"
 
20
#include "ichicomn.h"
 
21
 
 
22
#ifdef NEVER
 
23
/**********************************************************************************/
 
24
int unpack_iso_sort_key( AT_ISO_SORT_KEY iso_sort_key, S_CHAR *num_1H, S_CHAR *num_2H, S_CHAR *num_3H, S_CHAR *iso_atw_diff )
 
25
{
 
26
    int is_negative;
 
27
    AT_ISO_SORT_KEY HOnlyAtwPart;
 
28
    static const AT_ISO_SORT_KEY MultAtwDiff = AT_ISO_SORT_KEY_MULT*AT_ISO_SORT_KEY_MULT*AT_ISO_SORT_KEY_MULT;
 
29
    if ( !iso_sort_key ) {
 
30
        *num_1H = *num_2H = *num_3H = *iso_atw_diff = 0;
 
31
        return 0;
 
32
    } else
 
33
    if ( iso_sort_key < 0 ) {
 
34
        is_negative = 1;
 
35
        iso_sort_key = -iso_sort_key;
 
36
        HOnlyAtwPart = MultAtwDiff - iso_sort_key % MultAtwDiff;
 
37
        iso_sort_key += HOnlyAtwPart;
 
38
    } else {
 
39
        is_negative = 0;
 
40
        HOnlyAtwPart  = iso_sort_key % MultAtwDiff;
 
41
        iso_sort_key -= HOnlyAtwPart;
 
42
    }
 
43
    
 
44
    iso_sort_key /= MultAtwDiff;
 
45
    
 
46
    *num_1H = (S_CHAR)(HOnlyAtwPart % AT_ISO_SORT_KEY_MULT);
 
47
    HOnlyAtwPart /= AT_ISO_SORT_KEY_MULT;
 
48
    *num_2H = (S_CHAR)(HOnlyAtwPart % AT_ISO_SORT_KEY_MULT);
 
49
    HOnlyAtwPart /= AT_ISO_SORT_KEY_MULT;
 
50
    *num_3H = (S_CHAR)(HOnlyAtwPart % AT_ISO_SORT_KEY_MULT);
 
51
    
 
52
    *iso_atw_diff = (S_CHAR)(is_negative? -iso_sort_key : iso_sort_key);
 
53
    
 
54
    return 1;
 
55
}
 
56
#endif
 
57
 
 
58
/**********************************************************************************/
 
59
AT_ISO_SORT_KEY make_iso_sort_key( int iso_atw_diff, int num_1H, int num_2H, int num_3H)
 
60
{
 
61
    AT_ISO_SORT_KEY iso_sort_key = 0, mult=1;
 
62
    
 
63
    iso_sort_key += mult * num_1H;
 
64
    mult *= AT_ISO_SORT_KEY_MULT;
 
65
    iso_sort_key += mult * num_2H;
 
66
    mult *= AT_ISO_SORT_KEY_MULT;
 
67
    iso_sort_key += mult * num_3H;
 
68
    mult *= AT_ISO_SORT_KEY_MULT;
 
69
    iso_sort_key += mult * iso_atw_diff;
 
70
    return iso_sort_key;
 
71
}
 
72
/**********************************************************************************/
 
73
/*  set sp_ATOM isotopic sort keys */
 
74
int set_atom_iso_sort_keys(  int num_at, sp_ATOM *at, T_GROUP_INFO* t_group_info, int *bHasIsotopicInTautomerGroups )
 
75
{
 
76
    int             i, num_isotopic = 0, bMergedTgroup;
 
77
    AT_ISO_SORT_KEY iso_sort_key;
 
78
    T_GROUP        *t_group =
 
79
                       (t_group_info &&
 
80
                        t_group_info->t_group &&
 
81
                        t_group_info->num_t_groups > 0)? t_group_info->t_group : NULL;
 
82
 
 
83
    if ( bHasIsotopicInTautomerGroups )
 
84
        *bHasIsotopicInTautomerGroups = 0;
 
85
    for ( i = 0; i < num_at; i ++ ) {
 
86
        bMergedTgroup = (t_group_info && t_group_info->nIsotopicEndpointAtomNumber && (at[i].cFlags & AT_FLAG_ISO_H_POINT));
 
87
        if ( (!at[i].endpoint || !t_group) && !bMergedTgroup ) {
 
88
            iso_sort_key = make_iso_sort_key(at[i].iso_atw_diff, at[i].num_iso_H[0], at[i].num_iso_H[1], at[i].num_iso_H[2]);
 
89
        } else {
 
90
            /*  H isotopes go to the tautomer part of the CT (name) */
 
91
            /*  if (at[i].endpoint && t_group) ... */
 
92
            iso_sort_key = make_iso_sort_key(at[i].iso_atw_diff, 0, 0, 0);
 
93
            if ( bHasIsotopicInTautomerGroups )
 
94
                *bHasIsotopicInTautomerGroups += (at[i].num_iso_H[0] || at[i].num_iso_H[1] || at[i].num_iso_H[2] || bMergedTgroup);
 
95
        }
 
96
        at[i].iso_sort_key = iso_sort_key;
 
97
        num_isotopic += (iso_sort_key != 0);
 
98
    }
 
99
    return num_isotopic;
 
100
}
 
101