# include "util.h" # include "pdb.h" # include "fit.h" #define SHORT_STRING_09 "%4.4s%c%3.3s %c%4d%c " #define SHORT_STRING_10 " %3.3s%c%3.3s %c%4d%c" /* ==================== */ int sprintfAtomShortForm (char * buf,atom_record * atom) /* ==================== */ { char ch = (atom->chain == ' ' ? '_' : atom->chain); return sprintf(buf ,atom->name[3] == '\0' ? SHORT_STRING_09 : SHORT_STRING_10 , atom->name, atom->extraflag, atom->resname, atom->chain, atom->resnum, atom->x_char) ; } double nrDistance3D(double * a, double *b) { double v[4]; v[1] = a[1] - b[1]; v[2] = a[2] - b[2]; v[3] = a[3] - b[3]; return sqrt(v[1]*v[1] + v[2]*v[2] + v[3]*v[3]); } atom_record * GetNextSelectedAtom(file_records * f, int flag, atom_record * a) { if (a == NULL) { atom_record * b = f->atoms[0] ; if (!(b->flags & flag)) return b; else GetNextSelectedAtom(f,flag,b); } else { int ii; for (ii = a->Index+1 ; ii < f->atomnum ; ii++) { atom_record * b = f->atoms[ii]; if (!(b->flags & flag)) { return b ; } } return NULL ; } } double EquivSecondToFirst (file_records * First, file_records * Second, int flag) { atom_record * a1 = GetNextSelectedAtom(First,flag,NULL) ; atom_record * a2 = GetNextSelectedAtom(Second,flag,NULL) ; while (a1 != NULL && a2 != NULL) { a2->chaining = a1 ; a2->surface = nrDistance3D(a1->v,a2->v); a1 = GetNextSelectedAtom(First,flag,a1) ; a2 = GetNextSelectedAtom(Second,flag,a2) ; } } /* ============ */ double AtomDistance(atom_record * a1, atom_record * a2) /* ============ */ { double dx = a1->x - a2->x ; double dy = a1->y - a2->y ; double dz = a1->z - a2->z ; assert(dx*dx + dy*dy + dz*dz > 0); return sqrt(dx*dx + dy*dy + dz*dz); } /* =============================== */ double CompareCoordinatesSecondToFirst /* =============================== */ (file_records * First, file_records * Second, int flag) { int ii, i1=0, i0=0; Statistic s = {0} , *S = &s ; char buf1 [BUFSIZ], buf2 [BUFSIZ]; EquivSecondToFirst(First,Second,flag); InitStats(S); S->name = "Distance" ; printf("CompareCoordinatesSecondToFirst:\n"); printf("%-17s|%-12s|%-17s\n","First"," Distance"," Second"); printf(" %-15s|%-12s| %-15s\n",First->name," ",Second->name); for (ii = 0;iiatomnum; ii++) { atom_record * a2 = Second->atoms[ii]; if (!(a2->flags & FLAG_2_DESELECT)) { atom_record * a1 = a2->chaining ; double d = AtomDistance(a1,a2); if (d != a2->surface) STDERR("(d != a2->surface)"); IncrementStats(S,a2->surface); sprintfAtomShortForm(buf2,a2); sprintfAtomShortForm(buf1,a1); printf("%s | %8.4lf | %s\n",buf1,d,buf2); } } # ifdef OFF NDumpStats(S,stdout); # endif printf("Number-of-Atoms: %9.0f RMS: %9.4f\n",S->num,S->rms); printf("Max-Deviation: %9.4f Min-Deviation: %9.4f\n",S->max,S->min); printf("Avg-Deviation: %9.4f Num*RMS: %9.4f\n",S->mean,S->num*S->rms); return S->rms; } /* ================ */ void FlagOnEverywhere(file_records * f, int flag) /* ================ */ { int ii; residue_record * r ; for (r = f->FirstResidue ; r != NULL ; r = r->next) { SWITCH_ON(r,flag); } for (ii=0; iiatomnum; ii++) { atom_record * ap = f->atoms[ii]; SWITCH_ON(ap,flag); } } /* ================= */ void FlagOffEverywhere(file_records * f, int flag) /* ================= */ { int ii; residue_record * r ; for (r = f->FirstResidue ; r != NULL ; r = r->next) { SWITCH_OFF(r,flag); } for (ii=0; iiatomnum; ii++) { atom_record * ap = f->atoms[ii]; SWITCH_OFF(ap,flag); } } void FlagOffForCAInChain (file_records * f, char ch, int flag) { residue_record * r; for (r = f->FirstResidue ; r != NULL ; r = r->next) { if (r->ca != NULL && r->chain == ch) { SWITCH_OFF(r->ca,flag); SWITCH_OFF(r,flag); } } }