2
* International Union of Pure and Applied Chemistry (IUPAC)
3
* International Chemical Identifier (InChI)
5
* Software version 1.00
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 )
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;
33
if ( iso_sort_key < 0 ) {
35
iso_sort_key = -iso_sort_key;
36
HOnlyAtwPart = MultAtwDiff - iso_sort_key % MultAtwDiff;
37
iso_sort_key += HOnlyAtwPart;
40
HOnlyAtwPart = iso_sort_key % MultAtwDiff;
41
iso_sort_key -= HOnlyAtwPart;
44
iso_sort_key /= MultAtwDiff;
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);
52
*iso_atw_diff = (S_CHAR)(is_negative? -iso_sort_key : iso_sort_key);
58
/**********************************************************************************/
59
AT_ISO_SORT_KEY make_iso_sort_key( int iso_atw_diff, int num_1H, int num_2H, int num_3H)
61
AT_ISO_SORT_KEY iso_sort_key = 0, mult=1;
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;
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 )
76
int i, num_isotopic = 0, bMergedTgroup;
77
AT_ISO_SORT_KEY iso_sort_key;
80
t_group_info->t_group &&
81
t_group_info->num_t_groups > 0)? t_group_info->t_group : NULL;
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]);
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);
96
at[i].iso_sort_key = iso_sort_key;
97
num_isotopic += (iso_sort_key != 0);