📄 autosphere.c
字号:
else { temp = temp->next; } } } if (DB_RES) {printf(" returning %d spheres.\n", SphLen(spheres));} return (spheres);}/** mark SurfDistThin **//**************************************************************************** Author: Jim Arnold** Purpose: Removes spheres that are farther than max_surf_dist away** from any protein heavy atom.** Notes: Actually keeps spheres that are closer than max_surf_dist** away from a protein heavy atom, because that check can ** terminate early.**************************************************************************/SPHERE* SurfDistThin(TS_INFO *info, SPHERE *spheres, MOLECULE *mol) { int i, keep; float d; SPHERE *temp, *temp2; static SPHERE dsp; if (DB_TSP_SURF) {printf("**SurfDistThin, sph: %d, cut: %4.1f.\n",SphLen(spheres),info->surf_cut);} if (SphLen(spheres) <= 0) { if (DB_TSP_SURF) {printf(" GUARD: %d spheres passed to SurfDistThin.\n", SphLen(spheres));} } else { if (DB_TSP_SURF) {printf(" loop over spheres.\n");} temp = spheres; while (temp != NULL) { keep = false; for (i = 0; i < mol->total.atoms; i++) { if (IsHeavy(&(mol->atom[i]))) { dsp.x = mol->coord[i][0]; dsp.y = mol->coord[i][1]; dsp.z = mol->coord[i][2]; d = dist(temp, &dsp); if (DB_TSP_SURF_L) {printf(" dist is %4.1f.\n", d);} if (d < info->surf_cut) { if (DB_TSP_SURF_L) {printf(" dist < %4.1f, keep sph.\n", d);} keep = true; } } } if (keep equal false) { if (DB_TSP_SURF_L) {printf(" keep is false, remove sphere.\n");} temp2 = temp->next; /* temp get's freed if removed */ spheres = remove_sphere(temp, spheres); temp = temp2; } else { temp = temp->next; } } } if (DB_TSP_SURF) {printf(" returning %d spheres.\n", SphLen(spheres));} return (spheres);}/** mark IsHeavy **//**************************************************************************** Author: Jim Arnold** Purpose: Returns true if the passed atom is a heavy atom.** Notes: **************************************************************************/int IsHeavy(ATOM *at){ int retI = true; if (DB_IS_HEAVY) {printf("**IsHeavy, atom type: |%s|.\n", at->type);} if ((strstr(at->type, "H")) or (strstr(at->type, "Du"))) { retI = false; } if (DB_IS_HEAVY) {printf(" returning %d.\n", retI);} return (retI);}/** mark greedy_thin **//******************************************************************************* Author: Scott Pegg** Purpose: A function to thin remaining spheres using a greedy algorithm.** Notes: Greedy search (worst case is O(n^2)).*****************************************************************************/SPHERE* greedy_thin(TS_INFO *info, SPHERE *spheres) { int stop; float d = 0.0, best; SPHERE *temp, *temp2; SPHERE *start_sph; static SPHERE center; if (DB_GREEDY) {printf("**greedy_thin, sphere list len: %d.\n", SphLen(spheres));} if (SphLen(spheres) <= 0) { if (DB_TSP_SURF) {printf(" GUARD: %d spheres passed to greedy_thin.\n", SphLen(spheres));} } else { if (DB_GREEDY) {printf(" make a dummy sphere for the center of the enclosure.\n");} center.x = info->sph_x; center.y = info->sph_y; center.z = info->sph_z; if (DB_GREEDY) {printf(" Choose the sphere closest to the center of the enclosure.\n");} best = 10000.0; temp = spheres; while (temp != NULL) { d = dist(¢er, temp); if (DB_GREEDY) {printf(" dist is: %4.1f.\n", d);} if (d < best) { best = d; start_sph = temp; if (DB_GREEDY) {printf(" setting start_sph with distance: %4.1f.\n", best);} } temp = temp->next; } while (1) { if (DB_GREEDY) {printf(" mark starting sphere as visited - don't remove it.\n");} start_sph->visited = true; if (DB_GREEDY) {printf(" remove spheres within filt_cut of start.\n");} temp = spheres; while (temp != NULL) { temp2 = temp->next; /* temp get's freed if removed */ if (!temp->visited && dist(start_sph, temp) < info->filt_cut) { spheres = remove_sphere(temp, spheres); } temp = temp2; } if (DB_GREEDY) {printf(" choose the next sphere as the closest unvisited sphere.\n");} stop = 1; best = 10000; temp = spheres; while (temp != NULL) { if (!temp->visited) { stop = 0; d = dist(start_sph, temp); if (d < best) { best = d; temp2 = temp; } } temp = temp->next; } if (DB_GREEDY) {printf(" break out of the while(1) if all spheres visited.\n");} if (stop) break; start_sph = temp2; } } if (DB_GREEDY) {printf(" returning sph list %d long.\n", SphLen(spheres));} return (spheres);}/** mark write_spheres **//**************************************************************************** Author: Scott Pegg, Jim Arnold.** Purpose: A function to write spheres to a PDB file and a SPHGEN file.** Notes: **************************************************************************/void write_spheres(TS_INFO *info, SPHERE *spheres) { int count = 0; char sph_fileS[255], pdb_fileS[255]; FILE *file; SPHERE *temp; if (SphLen(spheres) <= 0) { printf(" No spheres being written. write_sphere passed %d spheres\n", SphLen(spheres)); } else { /********* PDB File of Spheres. ***********/ sprintf(pdb_fileS, "%s", info->sph_output); strcat(pdb_fileS, ".pdb"); file = fopen(pdb_fileS, "w"); if (file equal NULL) { printf("GUARD: unable to open file: |%s|.\n", pdb_fileS); } else { if (DB_WRITE) {printf(" Write a PDB format file to: |%s|.\n", pdb_fileS);} fprintf(file, "REMARK This file generated by \"TS\"\n"); temp = spheres; while (temp != NULL) { fprintf(file, "ATOM %4d C SPH %4d %8.3f%8.3f%8.3f\nTER\n", ++count, count, temp->x, temp->y, temp->z); temp = temp->next; } fclose(file); if (DB_WRITE) {printf(" wrote file: |%s|\n", pdb_fileS);} } /********* SPH File of Spheres. ***********/ sprintf(sph_fileS, "%s", info->sph_output); strcat(sph_fileS, ".sph"); file = fopen(sph_fileS, "w"); if (file equal NULL) { printf("GUARD: unable to open file: |%s|.\n", sph_fileS); } else { if (DB_WRITE) {printf(" Write a SPHGEN format file to: |%s|.\n", sph_fileS);} fprintf(file, "DOCK 3.5 receptor_spheres\n"); count = 0; temp = spheres; while (temp != NULL) { count++; temp = temp->next; } fprintf(file, "cluster 0 number of spheres in cluster %4d\n", count); if (DB_WRITE) {printf(" write the spheres.\n");} count = 0; temp = spheres; while (temp != NULL) { fprintf(file, "%5d %9.5f %9.5f %9.5f %7.3f %4d 0 0\n", ++count, temp->x, temp->y, temp->z, temp->radius, count); temp = temp->next; } fclose(file); if (DB_WRITE) {printf(" wrote file: |%s|\n", sph_fileS);} } } }/** mark add_sphere **//**************************************************************************** Author: Scott Pegg** Purpose: A function to add a sphere to the list** Notes: **************************************************************************/SPHERE *add_sphere(SPHERE *sphere, SPHERE *head){ SPHERE *temp; /* Note: I'm adding to the front of the list, not the end */ temp = head; head = sphere; sphere->next = temp; sphere->prev = NULL; if (temp != NULL) temp->prev = sphere; return head;}/** mark remove_sphere **//**************************************************************************** Author: Scott Pegg** Purpose: A function to remove a sphere from the list** Notes: **************************************************************************/SPHERE *remove_sphere(SPHERE *sphere, SPHERE *head) { if ( head == NULL || sphere == NULL) return head; if (head == sphere) head = sphere->next; else sphere->prev->next = sphere->next; if (sphere->next != NULL) sphere->next->prev = sphere->prev; free(sphere); return head;}/** mark dist **//**************************************************************************** Author: Scott Pegg** Purpose: Calculate the distance between two spheres ** Notes: **************************************************************************/float dist(SPHERE *a, SPHERE *b) { float t1, t2, t3, d; t1 = a->x - b->x; t2 = a->y - b->y; t3 = a->z - b->z; d = (float)sqrt((t1 * t1) + (t2 * t2) + (t3 * t3)); return (d);}/** mark SphLen **//**************************************************************************** Author: Jim Arnold** Purpose: Returns the length of the sphere list.** Notes: **************************************************************************/int SphLen(SPHERE *sph){ int lenI = 0; SPHERE *t; if (DB_LEN) {printf("**SphLen.\n");} t = sph; while (t != NULL) { lenI++; t = t->next; } if (DB_LEN) {printf(" returning length: %d.\n", lenI);} return (lenI);}/** mark ReadMol **//**************************************************************************** Author: Jim Arnold** Purpose: Reads molecule contained in the file given by the passed** string.** Notes: **************************************************************************/int ReadMol(FILE_NAME molS, MOLECULE *mol_ref, MOLECULE *mol_init){ int retI = true; LABEL label = {0}; FILE *file; if (DB_READ_MOL) {printf("**ReadMol from file: |%s|.\n", molS);} file = fopen(molS, "r"); if (file == NULL) { printf("Error: Could not open molecule file: %s\n", molS); retI = false; } else { if (DB_READ_MOL) {printf(" ref name: |%s|.\n", mol_ref->info.name);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -