24 if ( argc < 3 || argc > 4 ) {
25 fprintf(stderr,
"Returns the maximum distance between two binary pdb files.\n");
26 fprintf(stderr,
"Optionally lists all differences greater than [tolerance].\n");
27 fprintf(stderr,
"Usage: %s <filename1> <filename2> [tolerance]\n",argv[0]);
31 if ( ( fd1 = open(argv[1], O_RDONLY) ) < 0 ) {
32 fprintf(stderr,
"Can't open %s for reading.\n",argv[1]);
36 if ( fstat(fd1,&statbuf) < 0 ) {
37 fprintf(stderr,
"Can't stat %s.\n",argv[1]);
43 if ( (s1 < 4) || ((s1-4) % 24) ) {
44 fprintf(stderr,
"Size %ld of %s is not 4 plus a multiple of 24.\n",s1,argv[1]);
50 if ( s1 != 4 + (off_t)n1 * 24 ) {
51 fprintf(stderr,
"Size %ld of %s is not 4 plus %d times 24.\n",s1,argv[1],n1);
55 if ( ( fd2 = open(argv[2], O_RDONLY) ) < 0 ) {
56 fprintf(stderr,
"Can't open %s for reading.\n",argv[2]);
60 if ( fstat(fd2,&statbuf) < 0 ) {
61 fprintf(stderr,
"Can't stat %s.\n",argv[2]);
67 if ( (s2 < 4) || ((s2-4) % 24) ) {
68 fprintf(stderr,
"Size %ld of %s is not 4 plus a multiple of 24.\n",s2,argv[2]);
74 if ( s2 != 4 + (off_t)n2 * 24 ) {
75 fprintf(stderr,
"Size %ld of %s is not 4 plus %d times 24.\n",s2,argv[2],n2);
80 fprintf(stderr,
"%s atomcount %d does not match %s atomcount %d..\n",
81 argv[1],n1,argv[2],n2);
89 if ( sscanf(argv[3],
"%lf",&dtol) != 1 ) {
90 fprintf(stderr,
"Unable to parse tolerance argument %s\n",argv[3]);
91 fprintf(stderr,
"Usage: %s <filename1> <filename2> [tolerance]\n",argv[0]);
95 if ( dtol > 0. ) dtol *= dtol;
101 int bufatoms = 1000000;
102 if ( bufatoms > n1 ) bufatoms = n1;
104 double *c1 = malloc(bufatoms*24);
105 double *c2 = malloc(bufatoms*24);
107 if ( ! c1 || ! c2 ) {
108 fprintf(stderr,
"Memory allocation failed.\n");
111 for ( i=0; i<n1; i+=bufatoms ) {
112 if ( i + bufatoms > n1 ) bufatoms = n1 - i;
113 if ( read(fd1,c1,bufatoms*24) != bufatoms*24 ) {
114 fprintf(stderr,
"Error reading %s.\n",argv[1]);
117 if ( read(fd2,c2,bufatoms*24) != bufatoms*24 ) {
118 fprintf(stderr,
"Error reading %s.\n",argv[2]);
122 for ( j=0; j<bufatoms; ++j ) {
123 double dx = c1[3*j+0] - c2[3*j+0];
124 double dy = c1[3*j+1] - c2[3*j+1];
125 double dz = c1[3*j+2] - c2[3*j+2];
126 double d = dx*dx + dy*dy + dz*dz;
127 if ( d > dmax ) { imax = i+j; dmax = d; }
128 if ( usetol && d > dtol ) {
129 printf(
"%lg at %d\n",sqrt(d),i+j);
136 if ( dtol ) printf(
"MAX: ");
137 printf(
"%lg at %d\n",dmax,imax);