/* Program LGSCORE written by Scott M. Le Grand Even more modified and completely changed in 1999 by Arne Elofsson Modified by Arne Elofsson in 1994 Copyright 1992, Scott M. Le Grand and Arne Elofsson (1999) The program is available under the Gnu public license (see www.fsf.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. With the exception that if you use this program in any scientific work you have to explicitly state that you have used LGSCORE and cite the relevant publication (dependent on what you have used LGSCORE for). My publicationlist can be found at http://www.sbc.su.se/~arne/papers/. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (in the file gpl.txt); if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-13 */ #include #include #include #include //#include "/afs/pdc.kth.se/home/b/bjornw/bjorn/source/c/pdb/molecule.h" //#include "/afs/pdc.kth.se/home/b/bjornw/bjorn/source/c/pdb/quality_measure/lgscore.h" #include "molecule.h" #include "lgscore.h" double LGscore(char *file1,char *file2,double minsim,int L, double factor) { molecule m[2]; /* Molecules to be compared */ int out_flag; int b_flag; int align_flag; int select1_flag; int select2_flag; int verbose_flag; /* Verbose output flag */ int fraction_flag; /* Output flag */ int short_flag; int arglist; char outfile[800]; /* Output name */ double rms; /* final RMS error */ int ma[2]; /*int temp;*/ //molecule m0,m1; int files=0; /* Number of files parsed */ int i,j,k,a,b; /* Counter variable */ // int L=4; // Minimum length of fragment for FindMaxSub matching int minatoms=19; /* Variable for min no of atoms for P-value*/ double s[3][3]; /* Final transformation matrix */ double maxrmsd,minrmsd; double fraction=1; double numfrac=0; double maxpvalue=1,maxpvalue1=1.; double score,maxrms,maxrms1,maxscore,maxscore1; double pvalue; double logLGscore=0; int maxatoms,maxpos,minpos,atoms; int length=0; int maxsub_15=0; int maxsub_20=0; int maxsub_25=0; int maxsub_30=0; int maxsub_35=0; int maxselect1_0[MAXATMS],maxselect1_1[MAXATMS]; int maxselect2_0[MAXATMS],maxselect2_1[MAXATMS]; double bestsizescore[MAXATMS]; int maxatoms1; int all_read=1; double cutoffrmsd=0.; // double cutoffrms=3.; // double minsim=25.0; double cutoff; double ss;//Added by Fang int count; int maxcount=10; char filename[400][800]; char target[400][10]; char template[400][10]; char method[400][20]; int rank[400]; char filelist[800]; char bb[3]; int len_filelist; int dotcount=0; int lastchar=' '; double x,y,z; FILE *fp; /* Initialize */ files=2; verbose_flag=FALSE; out_flag=FALSE; select2_flag=FALSE; select1_flag=FALSE; short_flag=FALSE; arglist=FALSE; fraction_flag=FALSE; align_flag=TRUE; /* Parse command line for PDB files and options */ i=1; // for(a=0;a bestsizescore[j]){bestsizescore[j]=score;} } if (fraction_flag) { if ((double)j/atoms <= fraction ) { printf("FRAC1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); fraction-=numfrac; //printf("TEST %f %f\n",fraction,numfrac); } } if ((pvalue <= maxpvalue) && (j>minatoms)) { if (fraction_flag) { printf("GOOD1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); } //printf ("TEST:\t%d\t%f\t%f\t%f\n",m[0].atoms,pvalue,rms,score); maxpvalue=pvalue; maxatoms=j; maxrms=rms; maxscore=score; for (k=0;katm[i].x*m2->atm[i].x+m2->atm[i].y*m2->atm[i].y+m2->atm[i].z*m2->atm[i].z; //rintf(stderr,"TEST1-m2\t %d\t%6.3f*%6.3f %6.3f*%6.3f %6.3f*%6.3f\n",i,s[0][0],m[1].atm[i].x,s[0][1],m[1].atm[i].y,s[0][2],m[1].atm[i].z); //printf(stderr,"TEST2-m2\t %d\t%6.3f*%6.3f %6.3f*%6.3f %6.3f*%6.3f\n",i,s[1][0],m[1].atm[i].x,s[1][1],m[1].atm[i].y,s[1][2],m[1].atm[i].z); //fprintf(stderr,"TEST3-m2\t %d\t%6.3f*%6.3f %6.3f*%6.3f %6.3f*%6.3f\n",i,s[2][0],m[1].atm[i].x,s[2][1],m[1].atm[i].y,s[2][2],m[1].atm[i].z); // fprintf(stderr,"TEST1-m2\t %d\t%6.3f %6.3f %6.3f\n",i,m[1].atm[i].x,m[1].atm[i].y,m[1].atm[i].z); x=s[0][0]*m[1].atm[i].x+s[0][1]*m[1].atm[i].y+s[0][2]*m[1].atm[i].z; y=s[1][0]*m[1].atm[i].x+s[1][1]*m[1].atm[i].y+s[1][2]*m[1].atm[i].z; z=s[2][0]*m[1].atm[i].x+s[2][1]*m[1].atm[i].y+s[2][2]*m[1].atm[i].z; m[1].atm[i].x=x; m[1].atm[i].y=y; m[1].atm[i].z=z; // fprintf(stderr,"TEST2-m2\t %d\t%6.3f %6.3f %6.3f\n",i,m[1].atm[i].x,m[1].atm[i].y,m[1].atm[i].z); } //fp=fopen("foo10.pdb","w"); //if (fp!=NULL) // { // for (i=0;i bestsizescore[j]){bestsizescore[j]=score;} } if (fraction_flag) { if ((double)j/atoms <= fraction ) { printf("FRAC1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); fraction-=numfrac; //printf("TEST %f %f\n",fraction,numfrac); } } if ((pvalue <= maxpvalue) && (j>minatoms)) { if (fraction_flag) { printf("GOOD1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); } //printf ("TEST:\t%d\t%f\t%f\t%f\n",m[0].atoms,pvalue,rms,score); maxpvalue=pvalue; maxatoms=j; maxrms=rms; maxscore=score; for (k=0;katm[i].x*m2->atm[i].x+m2->atm[i].y*m2->atm[i].y+m2->atm[i].z*m2->atm[i].z; //rintf(stderr,"TEST1-m2\t %d\t%6.3f*%6.3f %6.3f*%6.3f %6.3f*%6.3f\n",i,s[0][0],m[1].atm[i].x,s[0][1],m[1].atm[i].y,s[0][2],m[1].atm[i].z); //printf(stderr,"TEST2-m2\t %d\t%6.3f*%6.3f %6.3f*%6.3f %6.3f*%6.3f\n",i,s[1][0],m[1].atm[i].x,s[1][1],m[1].atm[i].y,s[1][2],m[1].atm[i].z); //fprintf(stderr,"TEST3-m2\t %d\t%6.3f*%6.3f %6.3f*%6.3f %6.3f*%6.3f\n",i,s[2][0],m[1].atm[i].x,s[2][1],m[1].atm[i].y,s[2][2],m[1].atm[i].z); // fprintf(stderr,"TEST1-m2\t %d\t%6.3f %6.3f %6.3f\n",i,m[1].atm[i].x,m[1].atm[i].y,m[1].atm[i].z); x=best_rotation_matrix[0][0]*all_atom[1].atm[i].x+best_rotation_matrix[0][1]*all_atom[1].atm[i].y+best_rotation_matrix[0][2]*all_atom[1].atm[i].z; y=best_rotation_matrix[1][0]*all_atom[1].atm[i].x+best_rotation_matrix[1][1]*all_atom[1].atm[i].y+best_rotation_matrix[1][2]*all_atom[1].atm[i].z; z=best_rotation_matrix[2][0]*all_atom[1].atm[i].x+best_rotation_matrix[2][1]*all_atom[1].atm[i].y+best_rotation_matrix[2][2]*all_atom[1].atm[i].z; x+=best_center.x; y+=best_center.y; z+=best_center.z; all_atom[1].atm[i].x=x; all_atom[1].atm[i].y=y; all_atom[1].atm[i].z=z; // fprintf(stderr,"TEST2-m2\t %d\t%6.3f %6.3f %6.3f\n",i,m[1].atm[i].x,m[1].atm[i].y,m[1].atm[i].z); } fp=fopen(file3,"w"); if (fp!=NULL) { for (i=0;i{field}[$i],$self->{atomno}[$i],$self->{atomtype}[$i],$self->{atom_alt_loc}[$i],$self->{res}[$i],$chain,$lookup_hash{$self->{resno}[$i].$self->{insertion_code}[$i]},$self->{x}[$i],$self->{y}[$i],$self->{z}[$i],1,$self->{bfactor}[$i]); //printf("%d %s\n",i,m[1].atm[i].chain); fprintf(fp,"%-6s%5d %4s%1s%3s %1s%4d %8.3f%8.3f%8.3f%6.2f%6.2f\n","ATOM",all_atom[1].atm[i].number,all_atom[1].atm[i].name," ",all_atom[1].atm[i].residue,all_atom[1].atm[i].chain,all_atom[1].atm[i].resnum,all_atom[1].atm[i].x,all_atom[1].atm[i].y,all_atom[1].atm[i].z,1.00,all_atom[1].atm[i].bfactor); //fprintf(fp,"%-6s%5d %-4s%1s%3s %1s%5s %8.3f%8.3f%8.3f%6.2f%6.2f\n","ATOM", // m[1].atm[i].number,m[1].atm[i].name,"", // m[1].atm[i].residue,m[1].atm[i].chain,m[1].atm[i].resnum, // m[1].atm[i].x,m[1].atm[i].y,m[1].atm[i].z,1,m[1].atm[i].bfactor); //m[0].atm[i].selected); } fprintf(fp,"TER\nEND\n"); ///* printf("test %d %d \n",m[1].atoms,m[0].atoms);*/ //for (i=0;i bestsizescore[j]){ bestsizescore[j]=score; } } if (fraction_flag) { if ((double)j/atoms <= fraction ) { printf("FRAC1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); fraction-=numfrac; //printf("TEST %f %f\n",fraction,numfrac); } } // if ((score >= maxscore) && (j>minatoms)){ //LGscore // if ((pvalue <= maxpvalue) && (j>minatoms)) #ifdef Sscore if ((score >= maxscore) && (j>minatoms)) { //printf("Sscore rule!\n"); // if ((pvalue <= maxpvalue) && (j>minatoms)) { #else if ((pvalue <= maxpvalue) && (j>minatoms)) { #endif // { if (fraction_flag) { printf("GOOD1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); } //printf ("TEST:\t%d\t%f\t%f\t%f\n",m[0].atoms,pvalue,rms,score); maxpvalue=pvalue; maxatoms=j; maxrms=rms; maxscore=score; for (k=0;k bestsizescore[j]){bestsizescore[j]=score;} } if (fraction_flag) { if ((double)j/atoms <= fraction ) { printf("FRAC1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); fraction-=numfrac; //printf("TEST %f %f\n",fraction,numfrac); } } if ((pvalue <= maxpvalue) && (j>minatoms)) { if (fraction_flag) { printf("GOOD1:\t%.2f\t%d\t%.1f\t%.1f\t%e\n", (double)j/atoms,j,rms,score, pvalue); } //printf ("TEST:\t%d\t%f\t%f\t%f\n",m[0].atoms,pvalue,rms,score); maxpvalue=pvalue; maxatoms=j; maxrms=rms; maxscore=score; for (k=0;katoms;i++){ if (m->atm[i].selected){ xcen+=m->atm[i].x; ycen+=m->atm[i].y; zcen+=m->atm[i].z; natoms++; } } /* Now center molecule */ xcen/=(double)natoms; ycen/=(double)natoms; zcen/=(double)natoms; vec.x=xcen; vec.y=ycen; vec.z=zcen; // printf("TEST CEN natoms: %d %f %f %f \n",natoms,xcen,ycen,zcen); for (i=0;iatoms;i++) { m->atm[i].x-=xcen; m->atm[i].y-=ycen; m->atm[i].z-=zcen; // printf("TEST natoms: %d %f %f %f \n",i,m->atm[i].x,m->atm[i].y,m->atm[i].z); } //i--; //printf("TEST natoms: %d %f %f %f \n",i,m->atm[i].x,m->atm[i].y,m->atm[i].z); return vec; } int multiply_matrix(a,b,c) /* computes C=AB */ double a[3][3],b[3][3],c[3][3]; { int i,j,k; for (i=0;i<3;i++) for (j=0;j<3;j++) { c[i][j]=0.0; for (k=0;k<3;k++) c[i][j]+=a[i][k]*b[k][j]; } } int copy_matrix(f,t) /* copy matrix f into matrix t */ double f[3][3],t[3][3]; { int i,j; for (i=0;i<3;i++) for (j=0;j<3;j++) t[i][j]=f[i][j]; } int transpose_matrix(m) /* Transpose a 3x3 matrix */ double m[3][3]; { double dummy; dummy=m[0][1]; m[0][1]=m[1][0]; m[1][0]=dummy; dummy=m[0][2]; m[0][2]=m[2][0]; m[2][0]=dummy; dummy=m[1][2]; m[1][2]=m[2][1]; m[2][1]=dummy; } int delete_atom(molecule *m1,int num) { int i,j,k; for (i=num;iatoms;i++) { j=i+1; strcpy(m1->atm[i].name,m1->atm[j].name); strcpy(m1->atm[i].residue,m1->atm[j].residue); strcpy(m1->atm[i].resname,m1->atm[j].resname); m1->atm[i].x=m1->atm[j].x; m1->atm[i].y=m1->atm[j].y; m1->atm[i].z=m1->atm[j].z; /* m1->atm[i].rms=m1->atm[j].rms; */ m1->atm[i].number=m1->atm[j].number; m1->atm[i].resnum=m1->atm[j].resnum; } m1->atoms--; } int check_molecules2(molecule *m1,molecule *m2) { /* this will delete all atoms that are not in both molecules */ /* Now we should extract the part of the molecules that exists in both */ int i,j,minlength; int found; minlength=m1->atoms; if (minlength>m1->atoms) minlength=m2->atoms; i=0; for(i=0;iatoms;i++) { for(j=0;jatoms;j++) { } } while (i<=m1->atoms && i<=m2->atoms ){ while ( m1->atm[i].resnum < m2->atm[i].resnum && i< m1->atoms ){ // printf("Deleting m1: %d %d %d\n",i,m1->atm[i].resnum,m2->atm[i].resnum); delete_atom(m1,i); } while (m1->atm[i].resnum > m2->atm[i].resnum && i< m2->atoms ){ //printf("Deleting m2: %d %d %d\n",i,m1->atm[i].resnum,m2->atm[i].resnum); delete_atom(m2,i); } i++; } while (m1->atoms < m2->atoms){ delete_atom(m2,m2->atoms) ;} while (m1->atoms > m2->atoms){ delete_atom(m1,m1->atoms) ;} } int check_molecules(m1,m2) molecule *m1,*m2; { /* this will delete all atoms that are not in both molecules */ /* Now we should extract the part of the molecules that exists in both */ int i,j,minlength; int found; int current_resnum; char current_atom[4]; minlength=m1->atoms; if (minlength>m2->atoms) minlength=m2->atoms; i=0; while(iatoms) { if(!atom_exist(m1->atm[i].name,m1->atm[i].resname,m2)) { //delete_atom(m1,i); //printf("NO m1: %d %s %s %d \"%s\"\n", // i, // m1->atm[i].name, // m1->atm[i].residue, // m1->atm[i].resnum, // m1->atm[i].resname); delete_atom(m1,i); } else { i++; //printf("NO\n"); //delete_atom(m1,i); } } //exit(1); i=0; while(iatoms) { if(!atom_exist(m2->atm[i].name,m2->atm[i].resname,m1)) { // printf("NO m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m2->atm[i].resnum,m1->atm[i].resnum); delete_atom(m2,i); //printf("NO m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m2->atm[i].resnum,m1->atm[i].resnum); //printf("YES m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m2->atm[i].resnum,m1->atm[i].resnum); } else { i++; } } // for(i=0;iatoms;i++) // { // printf("1: %d %d %s %s %d %lf %lf %lf --- ",i,m1->atm[i].number,m1->atm[i].name,m1->atm[i].residue,m1->atm[i].resnum,m1->atm[i].x,m1->atm[i].y,m1->atm[i].z); // printf("2: %d %d %s %s %d %lf %lf %lf\n",i,m2->atm[i].number,m2->atm[i].name,m2->atm[i].residue,m2->atm[i].resnum,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); // } // while (i<=m1->atoms && i<=m2->atoms ){ // //printf("%d %d %d\n",i,m1->atm[i].resnum,m2->atm[i].resnum); // printf("%d %d < %d\n",i,m1->atm[i].resnum,m2->atm[i].resnum); // while ( m1->atm[i].resnum < m2->atm[i].resnum && i< m1->atoms ) // { // printf("Deleting m1: %s %s %d %d %d\n",m1->atm[i].name,m1->atm[i].residue,i,m1->atm[i].resnum,m2->atm[i].resnum); // delete_atom(m1,i); // } // // while (m1->atm[i].resnum > m2->atm[i].resnum && i< m2->atoms ) // { // printf("Deleting m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m1->atm[i].resnum,m2->atm[i].resnum); // delete_atom(m2,i); // } // i++; // } // while (m1->atoms < m2->atoms){ delete_atom(m2,m2->atoms) ;} // while (m1->atoms > m2->atoms){ delete_atom(m1,m1->atoms) ;} // printf("sizes: %d %d\n",m1->atoms,m2->atoms); // for(i=0;iatoms;i++) // { // printf("1: %d %d %s %s %d %lf %lf %lf --- ",i,m1->atm[i].number,m1->atm[i].name,m1->atm[i].residue,m1->atm[i].resnum,m1->atm[i].x,m1->atm[i].y,m1->atm[i].z); // printf("2: %d %d %s %s %d %lf %lf %lf\n",i,m2->atm[i].number,m2->atm[i].name,m2->atm[i].residue,m2->atm[i].resnum,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); // } //for(i=0;iatoms;i++) // { //printf("2: %d %d %s %s %d %lf %lf %lf\n",i,m2->atm[i].number,m2->atm[i].name,m2->atm[i].residue,m2->atm[i].resnum,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); // } if (m1->atoms > 0){return(0);} else{ //fprintf(stderr,"no identical atoms in files %s %s \n",m1->filename,m2->filename); return(1); } } int check_molecules_mark_deleted(m1,m2) molecule *m1,*m2; { /* this will mark atoms that are are not in both molecules as deleted*/ /* Now we should extract the part of the molecules that exists in both */ int i,j,minlength; int found; int current_resnum; char current_atom[4]; minlength=m1->atoms; if (minlength>m2->atoms) minlength=m2->atoms; i=0; while(iatoms) { if(!atom_exist(m1->atm[i].name,m1->atm[i].resname,m2) || strcmp(m1->atm[i].name,"CA ")!=0) { //delete_atom(m1,i); //printf("NO m1: %d %s %s %d \"%s\" %d\n", // i, // m1->atm[i].name, // m1->atm[i].residue, // m1->atm[i].resnum, // m1->atm[i].name,strcmp(m1->atm[i].name,"CA ")); m1->atm[i].deleted=TRUE; //delete_atom(m1,i); } i++; // else //{ // i++; //printf("NO\n"); //delete_atom(m1,i); //} } //exit(1); i=0; while(iatoms) { if(!atom_exist(m2->atm[i].name,m2->atm[i].resname,m1) || strcmp(m2->atm[i].name,"CA ")!=0) { // printf("NO m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m2->atm[i].resnum,m1->atm[i].resnum); //delete_atom(m2,i); m2->atm[i].deleted=TRUE; //printf("NO m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m2->atm[i].resnum,m1->atm[i].resnum); //printf("YES m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m2->atm[i].resnum,m1->atm[i].resnum); } // else // { i++; // } } // for(i=0;iatoms;i++) // { // printf("1: %d %d %s %s %d %lf %lf %lf --- ",i,m1->atm[i].number,m1->atm[i].name,m1->atm[i].residue,m1->atm[i].resnum,m1->atm[i].x,m1->atm[i].y,m1->atm[i].z); // printf("2: %d %d %s %s %d %lf %lf %lf\n",i,m2->atm[i].number,m2->atm[i].name,m2->atm[i].residue,m2->atm[i].resnum,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); // } // while (i<=m1->atoms && i<=m2->atoms ){ // //printf("%d %d %d\n",i,m1->atm[i].resnum,m2->atm[i].resnum); // printf("%d %d < %d\n",i,m1->atm[i].resnum,m2->atm[i].resnum); // while ( m1->atm[i].resnum < m2->atm[i].resnum && i< m1->atoms ) // { // printf("Deleting m1: %s %s %d %d %d\n",m1->atm[i].name,m1->atm[i].residue,i,m1->atm[i].resnum,m2->atm[i].resnum); // delete_atom(m1,i); // } // // while (m1->atm[i].resnum > m2->atm[i].resnum && i< m2->atoms ) // { // printf("Deleting m2: %s %s %d %d %d\n",m2->atm[i].name,m2->atm[i].residue,i,m1->atm[i].resnum,m2->atm[i].resnum); // delete_atom(m2,i); // } // i++; // } // while (m1->atoms < m2->atoms){ delete_atom(m2,m2->atoms) ;} // while (m1->atoms > m2->atoms){ delete_atom(m1,m1->atoms) ;} // printf("sizes: %d %d\n",m1->atoms,m2->atoms); // for(i=0;iatoms;i++) // { // printf("1: %d %d %s %s %d %lf %lf %lf --- ",i,m1->atm[i].number,m1->atm[i].name,m1->atm[i].residue,m1->atm[i].resnum,m1->atm[i].x,m1->atm[i].y,m1->atm[i].z); // printf("2: %d %d %s %s %d %lf %lf %lf\n",i,m2->atm[i].number,m2->atm[i].name,m2->atm[i].residue,m2->atm[i].resnum,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); // } //for(i=0;iatoms;i++) // { //printf("2: %d %d %s %s %d %lf %lf %lf\n",i,m2->atm[i].number,m2->atm[i].name,m2->atm[i].residue,m2->atm[i].resnum,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); // } if (m1->atoms > 0){return(0);} else{ //fprintf(stderr,"no identical atoms in files %s %s \n",m1->filename,m2->filename); return(1); } } int atom_selected(char* name,char* resname,molecule* m) { int i; for(i=0;iatoms;i++) { if(strcmp(name,m->atm[i].name)==0 && strcmp(m->atm[i].resname,resname)==0) return m->atm[i].selected; } return FALSE; } int atom_exist(char* name,char* resname,molecule* m) { int i; for(i=0;iatoms;i++) { if(strcmp(name,m->atm[i].name)==0 && strcmp(m->atm[i].resname,resname)==0) return TRUE; } return FALSE; } double Levitt_Gerstein(molecule *m1,molecule *m2) { int i,j,last1,last2; int numgap=0; double sum=0.; //double d0=25.; // 5**2 double d0=5.; // 2.24**2 double M=20.; last1=m1->atm[0].resnum-1; last2=m2->atm[0].resnum-1; j=0; for (i=0;iatoms;i++) { if (m1->atm[i].selected){ //printf("%d\n",m1->atm[i].resnum); last1++; last2++; if (m1->atm[i].resnum > last1 || m2->atm[i].resnum > last2 ) { numgap++; } sum+=1/(1+m1->atm[i].rms/d0); // printf("Test>\t%d\t%f\t%f\n",numgap,sum,m1->atm[i].rms); last1=m1->atm[i].resnum; last2=m2->atm[i].resnum; j++; // printf("Test> %d \t%d\t%d\t%f\n",i,m1->atm[i].selected,sum); } //else // { // m1->atm[i].Sstr=0; // } } //printf("TEST-LG>\t%d\t%d\t%f\t%f\n",j,numgap,sum,M*(sum-numgap/2)); //numgap=0; return(M*(sum-numgap/2)); } double LG_pvalue(int N,double MS) { double min_SD=1.e-20; double ln,Mean_MS,SD_MS,Z,expZ; double ln60=log(120.); double b=2.0*ln60*18.411424-4.501719; double a=(ln60*ln60)*18.411424+ln60*(-4.501719)+2.637163-b*ln60; if (N<6) { expZ=1.; return(expZ); } ln=log((double)N); if (N<120){ Mean_MS=ln*ln*18.411424+ln*(-4.501719)+ 2.637163; SD_MS=ln*21.351857 -37.521269; }else{ Mean_MS=ln*b+a; SD_MS=ln60*21.351857 -37.521269; } // if (SD_MS %d\t%f\t%f\t%e\t%e\t%e\t%e\n",N,MS,Mean_MS,SD_MS,Z,expZ,1-exp(-1*expZ)); if (Z>20){ return(expZ); // }else if (Z<-100){ //expZ=1.; //return(expZ); }else{ return(1-exp(-expZ)); } } double superimpose_molecules(m1,m2,s,error_cut) /* Find RMS superimposition of m1 on m2 */ molecule *m1,*m2; /* Molecules to be superimposed */ double s[3][3]; /* Final transformation matrix */ double error_cut; { int i,j,k; /* Counter variables */ int natoms=0; double u[3][3]; /* direct product matrix */ double t[3][3]; /* Temporary storage matrix */ double ma[3][3]; /* x axis rotation matrix */ double mb[3][3]; /* y axis rotation matrix */ double mg[3][3]; /* z axis rotation matrix */ double *d1,*d2; /* usefule pointers */ double error; /* Final superimposition error */ double error2; /* Final superimposition error */ double alpha=0.0; /* Angle of rotation around x axis */ double beta=0.0; /* Angle of rotation around y axis */ double gamma=0.0; /* Angle of rotation around z axis */ double dist,dist2,x,y,z; /* Temporary coordinate variables */ for (i=0;i<3;i++) /* Initialize matrices */ for (j=0;j<3;j++) s[i][j]=u[i][j]=0.0; s[0][0]=s[1][1]=s[2][2]=1.0; /* Initialize S matrix to I */ for (i=0;i<3;i++) /* Initialize rotation matrices to I */ for (j=0;j<3;j++) ma[i][j]=mb[i][j]=mg[i][j]=s[i][j]; for (i=0;iatoms;i++) /* Construct U matrix */ { if (m1->atm[i].selected){ d1= &(m1->atm[i].x); for (j=0;j<3;j++) { d2= &(m2->atm[i].x); for (k=0;k<3;k++) { u[j][k]+=(*d1)*(*d2); d2++; } d1++; } } } do { error=0.0; /* Calculate x axis rotation */ alpha=atan((u[2][1]-u[1][2])/(u[1][1]+u[2][2])); /* Insure we are heading for a minimum, not a maximum */ if (cos(alpha)*(u[1][1]+u[2][2])+sin(alpha)*(u[2][1]-u[1][2])<0.0) alpha+=PI; ma[1][1]=ma[2][2]=cos(alpha); ma[2][1]=sin(alpha); ma[1][2]= -ma[2][1]; transpose_matrix(ma); multiply_matrix(u,ma,t); transpose_matrix(ma); copy_matrix(t,u); multiply_matrix(ma,s,t); copy_matrix(t,s); /* Calculate y axis rotation */ beta=atan((u[0][2]-u[2][0])/(u[0][0]+u[2][2])); /* Insure we are heading for a minimum, not a maximum */ if (cos(beta)*(u[0][0]+u[2][2])+sin(beta)*(u[0][2]-u[2][0])<0.0) beta+=PI; mb[0][0]=mb[2][2]=cos(beta); mb[0][2]=sin(beta); mb[2][0]= -mb[0][2]; transpose_matrix(mb); multiply_matrix(u,mb,t); transpose_matrix(mb); copy_matrix(t,u); multiply_matrix(mb,s,t); copy_matrix(t,s); /* Calculate z axis rotation */ gamma=atan((u[1][0]-u[0][1])/(u[0][0]+u[1][1])); /* Insure we are heading for a minimum, not a maximum */ if (cos(gamma)*(u[0][0]+u[1][1])+sin(gamma)*(u[1][0]-u[0][1])<0.0) gamma+=PI; mg[0][0]=mg[1][1]=cos(gamma); mg[1][0]=sin(gamma); mg[0][1]= -mg[1][0]; transpose_matrix(mg); multiply_matrix(u,mg,t); transpose_matrix(mg); copy_matrix(t,u); multiply_matrix(mg,s,t); copy_matrix(t,s); error=fabs(alpha)+fabs(beta)+fabs(gamma); } while (error>error_cut); /* was 0.0001 before optimization Is error low enough to stop? */ /* Now calculate final RMS superimposition */ error=0.0; error2=0.0; natoms=0; //printf("testing7b %f %f\n",m2->atm[1].x,error); //printf ("s1:\t%f\t%f\t%f\n",s[0][0],s[0][1],s[0][2]); //printf ("s2:\t%f\t%f\t%f\n",s[1][0],s[1][1],s[1][2]); //printf ("s3:\t%f\t%f\t%f\n",s[2][0],s[2][1],s[2][2]); if (! (s[0][0]>0 || s[0][0]<0)) { // printf ("bar\n"); for (i=0;i<3;i++) /* Initialize matrices */ for (j=0;j<3;j++) s[i][j]=u[i][j]=0.0; s[0][0]=s[1][1]=s[2][2]=1.0; /* Initialize S matrix to I */ } for (i=0;iatoms;i++) { //dist=m2->atm[i].x*m2->atm[i].x+m2->atm[i].y*m2->atm[i].y+m2->atm[i].z*m2->atm[i].z; //printf("TEST1-m2\t %d\t%6.3f %6.3f %6.3f\t%e\n",i,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z,dist); x=s[0][0]*m2->atm[i].x+s[0][1]*m2->atm[i].y+s[0][2]*m2->atm[i].z; y=s[1][0]*m2->atm[i].x+s[1][1]*m2->atm[i].y+s[1][2]*m2->atm[i].z; z=s[2][0]*m2->atm[i].x+s[2][1]*m2->atm[i].y+s[2][2]*m2->atm[i].z; m2->atm[i].x=x; m2->atm[i].y=y; m2->atm[i].z=z; //dist2=m2->atm[i].x*m2->atm[i].x+m2->atm[i].y*m2->atm[i].y+m2->atm[i].z*m2->atm[i].z; //printf("TEST2-m2\t %d\t%6.3f %6.3f %6.3f\t%e\t%e\n",i,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z,dist2,dist2-dist); x=m1->atm[i].x-x; y=m1->atm[i].y-y; z=m1->atm[i].z-z; m2->atm[i].rms=m1->atm[i].rms=x*x+y*y+z*z; error+=m1->atm[i].rms; //printf("TEST:\t %d\t%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f \n",i,m1->atm[i].x,m2->atm[i].x,m1->atm[i].y,m2->atm[i].y,m1->atm[i].z,m2->atm[i].z); //printf("TEST1:\t %d\t%f %f %f\n",i,x*x,y*y,z*z); //printf("TEST2:\t %d %d\t%f\n",i,m1->atm[i].selected,m1->atm[i].rms); if (m1->atm[i].selected){ error2+=m1->atm[i].rms; natoms++; } /*printf ("TEST1: %f %f %f\n",m1->atm[i].x,m1->atm[i].y,m1->atm[i].z); printf ("TEST2: %f %f %f\n",m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); printf ("TEST3: %d %f %f\n",i,error,m1->atm[i].rms); */ } // printf("testing8 %f\n",m2->atm[1].x); error/=(double)(m1->atoms); error2/=(double)(natoms); if(natoms==0) error2=99999999; //printf("ERROR: %lf %lf %d\n",error2,sqrt(error2),natoms); return(sqrt(error2)); } //////////////////////// //The following is added by Fang double LG_pvalueF(N,score) int N; double score; { double Z,s1,mean,SD,sc,expZ; s1=(double)N; mean=pow(s1,0.3264)/(0.0437*pow(s1,0.0003)+0.0790); SD=s1/(0.0417*s1+3.3700); Z=(score/10-mean)/SD; expZ=exp((double)-1.*Z); if (Z>20)s1=expZ; else s1=1-exp(-expZ); return s1; } void copy_coord(m1,m2) molecule *m1,*m2; { int i; for (i=0;iatoms;i++){ m2->atm[i].x=m1->atm[i].x; m2->atm[i].y=m1->atm[i].y; m2->atm[i].z=m1->atm[i].z; } } void copy_molecule(m1,m2) molecule *m1,*m2; { int i; m2->atoms=m1->atoms; m2->xcen=m1->xcen; m2->ycen=m1->ycen; m2->zcen=m1->zcen; strcpy(m2->filename,m1->filename); for (i=0;iatoms;i++){ copy_res(m1,m2,i,i); } } void copy_res(m1,m2,i,j) molecule *m1,*m2; int i,j; { m2->atm[j].x=m1->atm[i].x; m2->atm[j].y=m1->atm[i].y; m2->atm[j].z=m1->atm[i].z; m2->atm[j].rms=m1->atm[i].rms; //strcpy(m1->atm[i].name,m2->atm[j].name); //strcpy(m1->atm[i].residue,m2->atm[j].residue); m2->atm[j].number=m1->atm[i].number; m2->atm[j].resnum=m1->atm[i].resnum; m2->atm[j].selected=m1->atm[i].selected; m2->atm[j].bfactor=m1->atm[i].bfactor; } void copymolecule(molecule *m1,dyn_molecule *m2) { /* Copy m2 to m1 */ int i; for(i=0;iatoms;i++) { m1->atm[i].x=m2->atm[i].x; m1->atm[i].y=m2->atm[i].y; m1->atm[i].z=m2->atm[i].z; //m1->atm[i].rms=0; //m2->atm[i].rms; m1->atm[i].resnum=m2->atm[i].resnum; m1->atm[i].number=m2->atm[i].number; m1->atm[i].rescount=m2->atm[i].rescount; m1->atm[i].selected=TRUE; strcpy(m1->atm[i].name,m2->atm[i].name); strcpy(m1->atm[i].residue,m2->atm[i].residue); strcpy(m1->atm[i].resname,m2->atm[i].resname); m1->atm[i].selected=TRUE; if(strcmp("CA ",m2->atm[i].name) == 0) { //printf("%s %s %s %s %d\n",m[0].filename,resname,residue,alt_loc,residues); m1->CA_ref[m2->atm[i].rescount-1]=i; } //printf("%-30s %lf %lf %lf == %lf %lf %lf\n",m2->filename,m1->atm[i].x,m1->atm[i].y,m1->atm[i].z,m2->atm[i].x,m2->atm[i].y,m2->atm[i].z); } m1->xcen=m2->xcen; m1->ycen=m2->ycen; m1->zcen=m2->zcen; m1->atoms=m2->atoms; m1->residues=m2->residues; strcpy(m1->sequence,m2->sequence); //printf("%d %d",m1->atoms,m2->atoms); strcpy(m1->filename,m2->filename); } void reset_rms(molecule *m1) { int i; for(i=0;iatoms;i++) { m1->atm[i].rms=0; } } //End ///////////////////////////