label_flex.c
来自「最经典的分子对结软件」· C语言 代码 · 共 1,658 行 · 第 1/3 页
C
1,658 行
) if ((molecule->segment[i].heavy_total + molecule->segment[i].neighbor_total) >= label_flex->anchor_size) { molecule->transform.anchor_atom = molecule->segment[i].atom[0]; anchor_found = TRUE; } }/** Identify the largest segment (counting all heavy atoms and one atom* from each neighbor)* 1/97 te*/ if ( (anchor_found == FALSE) && (((label_flex->multiple_anchors == TRUE) && (anchor_count == 0)) || (label_flex->multiple_anchors == FALSE)) ) { for ( i = 0, size = INT_MIN; i < molecule->total.segments; i++ ) if ((molecule->segment[i].heavy_total + molecule->segment[i].neighbor_total) > size) { size = molecule->segment[i].heavy_total + molecule->segment[i].neighbor_total; molecule->transform.anchor_atom = molecule->segment[i].atom[0]; } anchor_found = TRUE; } if (anchor_found == TRUE) return TRUE; else return EOF;}/* /////////////////////////////////////////////////////////////////////Routine to initialize segments by1. updating atom segment ids2. assigning torsions to each segment and3. transfering bond target atoms from the target segment back to the origin segment (since they do not move during bond rotation).11/96 te///////////////////////////////////////////////////////////////////// */void initialize_segments( LABEL_FLEX *label_flex, MOLECULE *molecule){ int i, j, k; int atom_id; /* Atom id */ int origin; /* Origin atom id */ int target; /* Target atom id */ int segment; /* Current segment id */ int anchor_atom; /* Anchor atom of molecule */ static SEARCH search = {0}; static MOLECULE temporary = {0};/** Quit this routine if only one segment (no rotatable bonds* 3/98 te*/ if (molecule->total.segments == 1) return;/** Reset atom segment records and neighbor flags* 12/96 te*/ for (i = 0; i < molecule->total.segments; i++) for (j = 0; j < molecule->segment[i].atom_total; j++) { atom_id = molecule->segment[i].atom[j]; molecule->atom[atom_id].segment_id = i; }/** Allocate extra space in temporary structure and copy from molecule* 12/96 te*/ temporary.total.segments = molecule->total.segments; reallocate_segments (&temporary); for (i = 0; i < molecule->total.segments; i++) { temporary.segment[i].atom_total = molecule->total.atoms; reallocate_segment_atoms (&temporary.segment[i]); } copy_atoms (&temporary, molecule); copy_bonds (&temporary, molecule); copy_segments (&temporary, molecule);/** Sort atoms radially from anchor atom* 1/97 te*/ if (molecule->transform.anchor_atom != NEITHER) anchor_atom = molecule->transform.anchor_atom; else anchor_atom = 0; for ( i = 0; breadth_search ( &search, molecule->atom, molecule->total.atoms, get_atom_neighbor, flag_atom_neighbor, &anchor_atom, 1, NEITHER, i ) != EOF; i++ );/** Assign each flexible bond to segments and transfer target atom* over to origin segment, since it does not move upon bond rotation.* 11/96 te*/ for (i = 0; i < molecule->total.torsions; i++) { if (molecule->torsion[i].flex_id) {/* fprintf (global.outfile, "tors %d orig %s (%d) targ %s (%d)\n", i, molecule->atom[molecule->torsion[i].origin].name, molecule->atom[molecule->torsion[i].origin].segment_id, molecule->atom[molecule->torsion[i].target].name, molecule->atom[molecule->torsion[i].target].segment_id);*/ origin = molecule->torsion[i].origin; target = molecule->torsion[i].target; if (get_search_radius (&search, origin, NEITHER) > get_search_radius (&search, target, NEITHER)) reverse_torsion (&molecule->torsion[i]); origin = molecule->torsion[i].origin; target = molecule->torsion[i].target;/** Update segment torsion records* 3/97 te*/ segment = temporary.atom[target].segment_id; molecule->torsion[i].segment_id = segment; if (temporary.segment[segment].torsion_id == NEITHER) temporary.segment[segment].torsion_id = i; else exit (fprintf (global.outfile, "ERROR initialize_segments: torsion assigned twice to segment\n")); temporary.segment[segment].conform_total = label_flex->member[molecule->torsion[i].flex_id].torsion_total;/** Update segment atom records* 3/97 te*/ if (temporary.atom[origin].segment_id != temporary.atom[target].segment_id) {/** Delete target atom from target segment* 11/96 te*/ for (j = 0; j < temporary.segment[segment].atom_total; j++) if (temporary.segment[segment].atom[j] == target) { for (k = j + 1; k < temporary.segment[segment].atom_total; k++) temporary.segment[segment].atom[k - 1] = temporary.segment[segment].atom[k]; temporary.segment[segment].atom_total--; if (temporary.atom[target].heavy_flag) temporary.segment[segment].heavy_total--; break; }/** Add target atom to origin segment* 11/96 te*/ segment = temporary.atom[origin].segment_id; atom_id = temporary.segment[segment].atom_total++; temporary.segment[segment].atom[atom_id] = target; molecule->atom[target].segment_id = segment; if (temporary.atom[target].heavy_flag) temporary.segment[segment].heavy_total++; } else exit (fprintf (global.outfile, "ERROR initialize_segments: torsion atoms in same segment\n")); } } copy_segments (molecule, &temporary); if (label_flex->flag && (global.output_volume == 'v')) { fprintf (global.outfile, "\nFinal segments\n"); for (i = 0; i < molecule->total.segments; i++) { fprintf (global.outfile, " segment : %d\n", i + 1); fprintf (global.outfile, " conforms : %d\n", molecule->segment[i].conform_total); fprintf (global.outfile, " neighbors:"); for (j = 0; j < molecule->segment[i].neighbor_total; j++) fprintf (global.outfile, " %d", molecule->segment[i].neighbor[j].id + 1); fprintf (global.outfile, "\n atoms :"); for (j = 0; j < molecule->segment[i].atom_total; j++) fprintf (global.outfile, " %s", molecule->atom[molecule->segment[i].atom[j]].name); fprintf (global.outfile, "\n"); } }}/* /////////////////////////////////////////////////////////////////// */void initialize_anchor_layer( LABEL_FLEX *label_flex, MOLECULE *molecule){ int segment; int segment_id; int segment_anchor; int layer; static SEARCH search = {0}; SORT_INT *list = NULL;/** If no anchor search, initialize first layer to contain all segments* 3/97 te*/ if (label_flex->anchor_flag == FALSE) { molecule->total.layers = 1; reallocate_layers (molecule); molecule->layer[0].segment_total = molecule->total.segments; reallocate_layer_segments (&molecule->layer[0]); if (molecule->transform.anchor_atom != NEITHER) segment_anchor = molecule->atom[molecule->transform.anchor_atom].segment_id; else segment_anchor = 0; molecule->layer[0].segment[0] = segment_anchor; molecule->layer[0].conform_total = 1; for ( segment = 0, segment_id = 1; segment < molecule->total.segments; segment++ ) { if (segment != segment_anchor) molecule->layer[0].segment[segment_id++] = segment; if (label_flex->drive_flag == TRUE) { if ( molecule->layer[0].conform_total < INT_MAX / molecule->segment[segment].conform_total ) molecule->layer[0].conform_total *= molecule->segment[segment].conform_total; else molecule->layer[0].conform_total = INT_MAX; } molecule->segment[segment].layer_id = 0; molecule->segment[segment].active_flag = TRUE; molecule->segment[segment].min_flag = TRUE; } return; }/** Otherwise, allocate enough layers to hold one segment each AND* each of these layers to hold all segments (if necessary).* 3/97 te*/ molecule->total.layers = molecule->total.segments + 1; reallocate_layers (molecule); for (layer = 0; layer < molecule->total.layers; layer++) { molecule->layer[layer].segment_total = molecule->total.segments; reallocate_layer_segments (&molecule->layer[layer]); } molecule->total.layers = 1;/** Assign anchor segment to first layer and initialize layer_id of all segments* 3/97 te*/ segment_anchor = molecule->atom[molecule->transform.anchor_atom].segment_id; molecule->layer[0].segment_total = 1; molecule->layer[0].segment[0] = segment_anchor; molecule->layer[0].conform_total = 1; molecule->segment[segment_anchor].layer_id = 0; molecule->segment[segment_anchor].active_flag = TRUE; molecule->segment[segment_anchor].min_flag = TRUE; for (segment = 0; segment < molecule->total.segments; segment++) if (segment != segment_anchor) molecule->segment[segment].layer_id = NEITHER;/** Flag the segment neighbors radially from the anchor segment* 3/97 te NOTE: This section of the code has been disabled. It allows additional segments to be added to the anchor layer to satisfy the anchor_size parameter. Since this adds flexibility to the anchor, I have decided to temporarily disable it until it can be proven to be necessary. 3/97 te for ( segment = 0; breadth_search ( &search, molecule->segment, molecule->total.segments, get_segment_neighbor, flag_segment_neighbor, &segment_anchor, 1, NEITHER, segment ) != EOF; segment++ );* Build the anchor layer from anchor segment until it is sufficiently large.* Merge the largest adjacent segment at each iteration.* 3/97 te for ( anchor_size = molecule->segment[segment_anchor].heavy_total; anchor_size < label_flex->anchor_size; ) { for ( segment_id = 0, segment_anchor = NEITHER, heavy_max = INT_MIN; segment_id < molecule->layer[0].segment_total; segment_id++ ) { segment = molecule->layer[0].segment[segment_id]; for ( neighbor_id = 0; neighbor_id < molecule->segment[segment].neighbor_total; neighbor_id++ ) { if (molecule->segment[segment].neighbor[neighbor_id].out_flag == TRUE) { neighbor = molecule->segment[segment].neighbor[neighbor_id].id; if ( (molecule->segment[neighbor].layer_id == NEITHER) && (molecule->segment[neighbor].heavy_total > heavy_max) ) { heavy_max = molecule->segment[neighbor].heavy_total; segment_anchor = neighbor; } } } } if (segment_anchor != NEITHER) { molecule->layer[0].segment[molecule->layer[0].segment_total++] = segment_anchor; molecule->layer[0].conform_total *= molecule->segment[segment_anchor].conform_total; molecule->segment[segment_anchor].layer_id = 0; molecule->segment[segment_anchor].active_flag = TRUE; molecule->segment[segment_anchor].min_flag = TRUE; anchor_size += molecule->segment[segment_anchor].heavy_total; } else break; }*//** Regroup the segments radially from the anchor segment* 3/97 te*/ for ( segment = 0; breadth_search ( &search, molecule->segment, molecule->total.segments, get_segment_neighbor, flag_segment_neighbor, molecule->layer[0].segment, molecule->layer[0].segment_total, NEITHER, segment ) != EOF; segment++ );/** Assign segments to outer layers* 3/97 te*/ ecalloc ( (void **) &list, molecule->total.segments, sizeof (SORT_INT), "initial layer sort list", global.outfile ); molecule->total.layers = search.radius + 1; for ( layer = 1; layer <= search.radius; layer++ ) { molecule->layer[layer].segment_total = search.total[layer]; molecule->layer[layer].conform_total = 1; for ( segment_id = 0; segment_id < search.total[layer]; segment_id++ ) { segment = search.target[layer][segment_id]; list[segment_id].id = segment; list[segment_id].value = molecule->segment[segment].heavy_total; } qsort ( list, search.total[layer], sizeof (SORT_INT), (int (*)()) compare_int_descend ); for ( segment_id = 0; segment_id < search.total[layer]; segment_id++ ) { segment = list[segment_id].id; molecule->segment[segment].layer_id = layer; molecule->layer[layer].segment[segment_id] = segment; molecule->layer[layer].conform_total *= molecule->segment[segment].conform_total; } } efree ((void **) &list); if (global.output_volume == 'v') { fprintf (global.outfile, "Molecule Layers\n"); for (layer = 0; layer < molecule->total.layers; layer++) { fprintf (global.outfile, "layer %2d: conforms %4d, segments", layer + 1, molecule->layer[layer].conform_total); for ( segment = 0; segment < molecule->layer[layer].segment_total; segment++ ) fprintf (global.outfile, " %2d ", molecule->layer[layer].segment[segment] + 1); fprintf (global.outfile, "\n"); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?