-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistinguish_competitive_atoms.c
421 lines (320 loc) · 11.2 KB
/
distinguish_competitive_atoms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// distinguish_competitive_atoms.c
/*******************************************************
基準となる原子を利用して, その他の順位の付いていない
原子(2,3個)の順位を決める関数
********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main_canost.h"
// #define TEST_DIST_COMP_ONE 1
extern int iatm;
extern struct atom *a1st;
extern int new_atm;
extern int start;
extern struct level root;
extern struct level *top;
extern struct level *reef;
extern int *cast_codes;
extern int *direct_parent;
extern int *relative_parent;
extern int *relation;
extern int *confined_bond;
int distinguish_competitive_atoms( int pivot, int *competitor, int compeNum ){
int i,j;
struct bond *bp;
int *caddy; // 同順位の原子集合が入る配列
int scale; // 同順位の原子集合が入る配列の大きさ
int higher; // 作為的に順位を高くする原子の番号
int *class; //順位を記憶しておくための配列
int scanned;
int iso_type;
int standard;
int new_scanned;
int new_standard;
int compe_type;
int axis_type;
int iso_type_compe;
int standard_compe;
int *comrade;
int comNum;
int *twins;
#ifdef TEST_DIST_COMP_ONE
printf(" distinguish_competitive_atoms \n");
#endif
// TIE_*** の判定
if( compeNum == 2 ){
compe_type = TIE_TWO;
}else if( compeNum == 3 ){
compe_type = TIE_THREE;
}else{
printf(" error : Error ocuured in distinguish_competitive_atoms \n");
exit( EXIT_FAILURE );
}
// 同順位の子が入る配列を用意
if( (comrade=(int *)malloc(TUPLE_SIZE*sizeof(int))) == NULL ){
printf(" error : Cannot allocate memory in distinguish_competitive_atoms \n");
exit( EXIT_FAILURE );
}
comNum = 0;
/*** 初期化 ***/
scanned = MINUS;
iso_type = MINUS;
axis_type = NOAXIS_TYPE_ONE;
standard = pivot;
new_standard = MINUS;
cast_codes[ standard ] = UK;
while( confined_bond[ standard ] >= 2 ){
scanned = standard;
iso_type = scan_children( scanned, &standard, comrade, &comNum );
#ifdef TEST_DIST_COMP_ONE
printf("scanned %d standard %d iso_type %d \n",scanned,standard,iso_type);
#endif
if( iso_type == FIRST_ONE ){
// start -- scanned -- standard の成す角度
relative_parent[ scanned ] = start;
if( linearity( start, scanned , standard ) == FALSE ){ // 一直線でない場合
// 軸が決定
axis_type = AXIS_TYPE_ONE;
#ifdef TEST_DIST_COMP_ONE
printf("AXIS_TYPE_ONE \n");
#endif
break;
}else{
cast_codes[ standard ] = UK;
}
}else{
if( iso_type == FIRST_TWO || iso_type == INDIVID_CHILDREN ||
iso_type == FIRST_THREE || iso_type == THIRD_THREE ){
// 軸が決定
axis_type = AXIS_TYPE_TWO;
#ifdef TEST_DIST_COMP_ONE
printf("AXIS_TYPE_TWO \n");
#endif
break;
}else if( iso_type == TIE_TWO || iso_type == TIE_THREE ){
// 軸が未決定
axis_type = NOAXIS_TYPE_TWO;
#ifdef TEST_DIST_COMP_ONE
printf("NOAXIS_TYPE_TWO \n");
#endif
break;
}else{
printf(" error : Error occured in distinguish_competitive_atoms \n");
exit( EXIT_FAILURE );
}
}
} // end of while
if( axis_type == AXIS_TYPE_ONE || axis_type == AXIS_TYPE_TWO ){ // 軸がある
// pivot の direct_parent を一時的に MINUS に設定
direct_parent[ pivot ] = MINUS;
// competitor のCASTコードをふる
for( i=0; i < compeNum ; i++ ){
cast_codes[ competitor[i] ] = get_dihedral_angle( standard, scanned, start, competitor[i] );
}
// pivot -- start の結合関係は start -- pivot
relation[ start ] = relation[ pivot ];
// competitor の順位付け
if( set_children( competitor, compeNum, &standard_compe, compe_type ) != EXIT_SUCCESS ){
printf(" error : Cannot execute set_children \n");
exit( EXIT_FAILURE );
}
// pivot の direct_parent を start に戻す
direct_parent[ pivot ] = start;
// 元に戻す
relation[ start ] = MINUS;
if( axis_type == AXIS_TYPE_TWO ){
if( iso_type == FIRST_THREE || iso_type == THIRD_THREE ){
// standard_compe -- start -- scanned -- bp->alias で bp->alias にCASTコードをふる
for( bp=a1st[ scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ scanned ].layer+1 ){
cast_codes[ bp->alias ] = get_dihedral_angle( standard_compe, start, scanned, bp->alias );
}
}
// 順位を付ける
if( set_children( comrade, comNum, NULL, iso_type ) != EXIT_SUCCESS ){
printf(" error : Cannot execute set_children \n");
exit( EXIT_FAILURE );
}
}else{
for( bp=a1st[ scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ scanned ].layer+1 ){
cast_codes[ bp->alias ] = UK;
}
}
}
}
for( i=0; i < compeNum ;i++ ){
new_scanned = MINUS;
new_standard = competitor[i];
cast_codes[ new_standard ] = UK;
while( confined_bond[ new_standard ] >= 2 ){
new_scanned = new_standard;
iso_type_compe = scan_children( new_scanned, &new_standard, comrade, &comNum );
if( iso_type_compe == FIRST_ONE ){
// start -- new_scanned -- new_standard の成す角度
relative_parent[ new_scanned ] = start;
if( linearity( start, new_scanned, new_standard ) == FALSE ){ // 一直線ではない
cast_codes[ new_standard ] = get_dihedral_angle( pivot, start, new_scanned, new_standard );
break;
}else{
cast_codes[ new_standard ] = UK;
}
}else{
if( iso_type_compe == FIRST_THREE || iso_type_compe == THIRD_THREE ||
iso_type_compe == TIE_TWO || iso_type_compe == TIE_THREE ){
// pivot -- start -- new_scanned -- bp->alias で bp->alias にCASTコードをふる
for( bp=a1st[ new_scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ new_scanned ].layer+1 ){
cast_codes[ bp->alias ] = get_dihedral_angle( pivot, start, new_scanned, bp->alias );
}
}
// 順位を付ける
if( set_children( comrade, comNum, NULL, iso_type_compe ) != EXIT_SUCCESS ){
printf(" error : Cannot execute set_children \n");
exit( EXIT_FAILURE );
}
}else{
for( bp=a1st[ new_scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ new_scanned ].layer+1 ){
cast_codes[ bp->alias ] = UK;
}
}
}
break;
}
} // end of while( confined_bond[ new_standard ] >= 2 )
}
// レベル 2 の層まで順位確定
if( apply_cast() != EXIT_SUCCESS ){
printf(" error : Cannot execute apply_cast \n");
exit( EXIT_FAILURE );
}
}else{ // axis_type == NOAXIS_TYPE_*** 軸がない
if( (class=(int *)malloc((iatm+new_atm)*sizeof(int)))==NULL){
printf(" error : Cannot allocate memory in distinguish_competitive_atoms \n");
exit( EXIT_FAILURE );
}
for(i=1;i<iatm+new_atm;i++){
class[i]=a1st[i].grade;
}
scale = compeNum;
if( (caddy=(int *)malloc(scale*sizeof(int)))==NULL){
printf(" error : Cannot allocate memory in distinguish_competitive_atoms \n");
exit( EXIT_FAILURE );
}
for(i=0; i < scale ;i++){
caddy[i] = competitor[i];
}
for(i=0;i<scale;i++){
for(j=0; j < scale ;j++){
// ZERO -- pivot -- start -- caddy[j] で caddy[j] にCASTコードをふる
cast_codes[ caddy[j] ] = get_dihedral_angle( ZERO, pivot, start, caddy[j] );
}
higher = caddy[i];
standard_compe = higher;
if( raise_and_order( higher, caddy, scale ) != EXIT_SUCCESS ){
printf(" error : Cannot execute raise_and_order \n");
exit( EXIT_FAILURE );
}
if( compe_type == TIE_THREE ){
// pivot の direct_parent を一時的に MINUS に設定
direct_parent[ pivot ] = MINUS;
if( (twins=(int *)malloc(2*sizeof(int)))==NULL){
printf(" error : Cannot allocate memory in distinguish_competitive_atoms \n");
exit( EXIT_FAILURE );
}
if( i == 0 ){
twins[0] = caddy[1];
twins[1] = caddy[2];
}else if( i == 1 ){
twins[0] = caddy[0];
twins[1] = caddy[2];
}else{
twins[0] = caddy[0];
twins[1] = caddy[1];
}
// 順位を付ける
if( set_children( twins, 2, NULL, FIRST_THREE ) != EXIT_SUCCESS ){
printf(" error : Cannot execute set_children \n");
exit( EXIT_FAILURE );
}
free(twins);
// pivot の direct_parent を start に戻す
direct_parent[ pivot ] = start;
}
if( ordering() != EXIT_SUCCESS ){
printf(" error : Cannot execute ordering \n");
exit( EXIT_FAILURE );
}
// pivot の先の原子に順位が付いていないので順位を付ける
if( axis_type == NOAXIS_TYPE_TWO ){
// standard_compe -- start -- scanned -- bp->alias で bp->alias にCASTコードをふる
for( bp=a1st[ scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ scanned ].layer+1 ){
cast_codes[ bp->alias ] = get_dihedral_angle( standard_compe, start, scanned, bp->alias );
}
}
// 順位を付ける
if( set_children( comrade, comNum, NULL, iso_type ) != EXIT_SUCCESS ){
printf(" error : Cannot execute set_children \n");
exit( EXIT_FAILURE );
}
}
// competitor の先の原子に順位を付ける
for( j=0; j < compeNum ;j++ ){
new_scanned = MINUS;
new_standard = competitor[j];
cast_codes[ new_standard ] = UK;
while( confined_bond[ new_standard ] >= 2 ){
new_scanned = new_standard;
iso_type_compe = scan_children( new_scanned, &new_standard, comrade, &comNum );
if( iso_type_compe == FIRST_ONE ){
// start -- new_scanned -- new_standard の成す角度
relative_parent[ new_scanned ] = start;
if( linearity( start, new_scanned, new_standard ) == FALSE ){ // 一直線ではない
cast_codes[ new_standard ] = get_dihedral_angle( pivot, start, new_scanned, new_standard );
break;
}else{
cast_codes[ new_standard ] = UK;
}
}else{
if( iso_type_compe == FIRST_THREE || iso_type_compe == THIRD_THREE ||
iso_type_compe == TIE_TWO || iso_type_compe == TIE_THREE ){
// pivot -- start -- new_scanned -- bp->alias で bp->alias にCASTコードをふる
for( bp=a1st[ new_scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ new_scanned ].layer+1 ){
cast_codes[ bp->alias ] = get_dihedral_angle( pivot, start, new_scanned, bp->alias );
}
}
// 順位を付ける
if( set_children( comrade, comNum, NULL, iso_type_compe ) != EXIT_SUCCESS ){
printf(" error : Cannot execute set_children \n");
exit( EXIT_FAILURE );
}
}else{
for( bp=a1st[ new_scanned ].adj_list ; bp != NULL ; bp=bp->next ){
if( a1st[ bp->alias ].layer == a1st[ new_scanned ].layer+1 ){
cast_codes[ bp->alias ] = UK;
}
}
}
break;
}
} // end of while( confined_bond[ new_standard ] >= 2 )
}
// レベル 2 の層まで順位確定
if( apply_cast() != EXIT_SUCCESS ){
printf(" error : Cannot execute apply_cast \n");
exit( EXIT_FAILURE );
}
for( j=1 ; j < iatm+new_atm ; j++){
a1st[j].grade = class[j];
cast_codes[j] = MINUS;
}
}
free(class);
free(caddy);
}
return EXIT_SUCCESS;
}