mol.c
来自「最经典的分子对结软件」· C语言 代码 · 共 2,539 行 · 第 1/5 页
C
2,539 行
else length = 0; efwrite (&length, sizeof (int), 1, file); if (length > 0) efwrite (*string, sizeof (char), length, file);}/* //////////////////////////////////////////////////////////// *//*Routine to load the contents of a dynamically allocated characterstring.2/96 te*/void load_string (char **string, FILE *file){ int length; efread (&length, sizeof (int), 1, file); if (length > 0) { ecalloc ( (void **) string, length, sizeof (char), "molecule string", global.outfile ); efread (*string, sizeof (char), length, file); }}/* ///////////////////////////////////////////////////////////// */void atom_neighbors (MOLECULE *molecule){ int i; int origin; int target; int neighbor; for (i = 0; i < molecule->total.atoms; i++) { molecule->atom[i].neighbor_total = 0; molecule->atom[i].flag = TRUE; } if (molecule->total.bonds > 0) {/** Compute the total neighbors for each atom* 12/96 te*/ for (i = 0; i < molecule->total.bonds; i++) { molecule->atom[molecule->bond[i].origin].neighbor_total++; molecule->atom[molecule->bond[i].target].neighbor_total++; }/** Allocate space for atom neighbor lists and reset totals* 12/96 te*/ for (i = 0; i < molecule->total.atoms; i++) { reallocate_atom_neighbors (&molecule->atom[i]); molecule->atom[i].neighbor_total = 0; }/** Record bond information into atom neighbor lists* 12/96 te*/ for (i = 0; i < molecule->total.bonds; i++) { origin = molecule->bond[i].origin; target = molecule->bond[i].target; if ((origin < 0) || (origin >= molecule->total.atoms)) exit (fprintf (global.outfile, "ERROR atom_neighbors: origin atom incorrect for bond %d\n", i + 1)); if ((target < 0) || (target >= molecule->total.atoms)) exit (fprintf (global.outfile, "ERROR atom_neighbors: target atom incorrect for bond %d\n", i + 1)); neighbor = molecule->atom[origin].neighbor_total; molecule->atom[origin].neighbor[neighbor].id = target; molecule->atom[origin].neighbor[neighbor].bond_id = i; if (molecule->atom[target].flag == TRUE) molecule->atom[origin].neighbor[neighbor].out_flag = TRUE; molecule->atom[target].flag = FALSE; molecule->atom[origin].neighbor_total++; neighbor = molecule->atom[target].neighbor_total; molecule->atom[target].neighbor[neighbor].id = origin; molecule->atom[target].neighbor[neighbor].bond_id = i; molecule->atom[target].neighbor[neighbor].out_flag = FALSE; molecule->atom[target].neighbor_total++; } }}/* ///////////////////////////////////////////////////////////// */void flag_atom_neighbor( void *atom, int atom_id, int neighbor_id, int flag){ ((ATOM *) atom)[atom_id].neighbor[neighbor_id].out_flag = flag;}/* ///////////////////////////////////////////////////////////// */void flag_segment_neighbor( void *segment, int segment_id, int neighbor_id, int flag){ ((SEGMENT *) segment)[segment_id].neighbor[neighbor_id].out_flag = flag;}/* ///////////////////////////////////////////////////////////// */void revise_atom_neighbors (MOLECULE *molecule){ SEARCH search = {0}; int i, j; int bond;/** Perform breadth-first atom search, starting from anchor segment.* Also, flag atom neighbors during this search run.* 11/96 te*/ for ( i = 0; breadth_search ( &search, molecule->atom, molecule->total.atoms, get_atom_neighbor, flag_atom_neighbor, &molecule->transform.anchor_atom, 1, NEITHER, i ) != EOF; i++ );/** Update the origin and target entries in bond records* 1/97 te*/ for (i = 0; i < molecule->total.atoms; i++) for (j = 0; j < molecule->atom[i].neighbor_total; j++) if (molecule->atom[i].neighbor[j].out_flag == TRUE) { bond = molecule->atom[i].neighbor[j].bond_id; if (molecule->bond[bond].target == i) { molecule->bond[bond].origin = i; molecule->bond[bond].target = molecule->atom[i].neighbor[j].id; } } free_search (&search);}/* //////////////////////////////////////////////////////////////////////Subroutine to compute the centrality of an atom. This is done by performinga breadth-first search to identify the bond distance of the most distant atomfrom each atom.11/96 te////////////////////////////////////////////////////////////////////// */int get_atom_centrality (MOLECULE *molecule, int atom_id){ int i; static SEARCH search = {0}; if (molecule->atom[atom_id].centrality != NEITHER) return molecule->atom[atom_id].centrality; else { for ( i = molecule->atom[atom_id].centrality = 0; breadth_search ( &search, molecule->atom, molecule->total.atoms, get_atom_neighbor, NULL, &atom_id, 1, NEITHER, i ) != EOF; i++ ) molecule->atom[atom_id].centrality += search.radius; return molecule->atom[atom_id].centrality;/* return molecule->atom[atom_id].centrality = get_search_radius (&search, NEITHER, NEITHER);*/ }}/* //////////////////////////////////////////////////////////////////////Subroutine that determines the neighboring atoms to the origin and targetatoms for each torsion.11/96 te////////////////////////////////////////////////////////////////////// */void get_torsion_neighbors (MOLECULE *molecule){ int i, j, k; int bond_id; int origin; int target; int neighbor; int central_neighbor; int central; static SEARCH search = {0}; for (i = 0; i < molecule->total.torsions; i++) { bond_id = molecule->torsion[i].bond_id; origin = molecule->torsion[i].origin = molecule->bond[bond_id].origin; target = molecule->torsion[i].target = molecule->bond[bond_id].target;/** Determine which neighbor of the origin atom is most central* 11/96 te*/ if (molecule->atom[origin].neighbor_total > 1) { for ( j = central_neighbor = 0, central = INT_MIN; (neighbor = get_atom_neighbor (molecule->atom, origin, j)) != EOF; j++ ) { if (neighbor != target) { for ( k = 0; breadth_search ( &search, molecule->atom, molecule->total.atoms, get_atom_neighbor, NULL, &neighbor, 1, origin, k ) != EOF; k++ ); if (search.radius > central) { central = search.radius; central_neighbor = neighbor; } } } molecule->torsion[i].origin_neighbor = central_neighbor; } else molecule->torsion[i].origin_neighbor = NEITHER;/** Determine which neighbor of the target atom is most central* 11/96 te*/ if (molecule->atom[target].neighbor_total > 1) { for ( j = central_neighbor = 0, central = INT_MIN; (neighbor = get_atom_neighbor (molecule->atom, target, j)) != EOF; j++ ) { if (neighbor != origin) { for ( k = 0; breadth_search ( &search, molecule->atom, molecule->total.atoms, get_atom_neighbor, NULL, &neighbor, 1, target, k ) != EOF; k++ ); if (search.radius > central) { central = search.radius; central_neighbor = neighbor; } } } molecule->torsion[i].target_neighbor = central_neighbor; } else molecule->torsion[i].target_neighbor = NEITHER; }}/* //////////////////////////////////////////////////////////////////////Subroutine that switches the origin and target atoms in a torsion.11/96 te////////////////////////////////////////////////////////////////////// */void reverse_torsion (TORSION *torsion){ int atom; atom = torsion->origin; torsion->origin = torsion->target; torsion->target = atom; atom = torsion->origin_neighbor; torsion->origin_neighbor = torsion->target_neighbor; torsion->target_neighbor = atom;} /* //////////////////////////////////////////////////////////////////////Recursive subroutine that counts up the number of atoms directlyand indirectly bonded to a given atom.10/95 te////////////////////////////////////////////////////////////////////// */int bonded_atoms( MOLECULE *molecule, int current_atom){ int i; int total; /* Number of atoms seen on linkage path */ if (molecule->atom[current_atom].flag) return 0; else { molecule->atom[current_atom].flag = TRUE; total = 1; for (i = 0; i < molecule->atom[current_atom].neighbor_total; i++) total += bonded_atoms ( molecule, molecule->atom[current_atom].neighbor[i].id ); return total; }}/* //////////////////////////////////////////////////////////////Routine to construct a distance matrix.3/97 te////////////////////////////////////////////////////////////// */float calculate_distances (MOLECULE *molecule, float ***distances, int *size){ int i, j; float distance_max;/** Either allocate space for distance matrix, or reset previous space* 3/97 te*/ if (*size < molecule->total.atoms) { free_distances (distances, size); *size = molecule->total.atoms; ecalloc ( (void **) distances, *size, sizeof (float *), "distance matrix", global.outfile ); for (i = 0; i < *size; i++) ecalloc ( (void **) &(*distances)[i], *size, sizeof (float), "distance matrix", global.outfile ); } else { for (i = 0; i < *size; i++) memset ((*distances)[i], 0, *size * sizeof (float)); }/** Compute the distance between all pairs of atoms* 3/97 te*/ for (i = distance_max = 0; i < molecule->total.atoms; i++) { for (j = i + 1; j < molecule->total.atoms; j++) { (*distances)[i][j] = (*distances)[j][i] = dist3 (molecule->coord[i], molecule->coord[j]); if ((*distances)[i][j] > distance_max) distance_max = (*distances)[i][j]; } } return distance_max;}/* //////////////////////////////////////////////////////////////Routine to free distance matrix.5/97 te////////////////////////////////////////////////////////////// */void free_distances (float ***distances, int *size){ int i; for (i = 0; i < *size; i++) efree ((void **) &(*distances)[i]); efree ((void **) distances); *size = 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?