#include "stdio.h" #include "stdlib.h" #include "math.h" #include "string.h" /* Convert sphere model from PyMol to WRL And create a geom as well. Not a general converter, highly specialised to this limited variety of PovRay file */ #define MIN(x,y) (x < y ? x : y) #define MAX(x,y) (x > y ? x : y) #define TRUE 1 #define FALSE 0 typedef struct { double x,y,z; } XYZ; typedef struct { double r,g,b; } COLOUR; typedef struct { XYZ p; double r; COLOUR c; } SPHERE; void WRLHeader(FILE *,char *,double); void WRLSphere(FILE *,XYZ,double,COLOUR); int ReadUntil(FILE *,int,char *); int main(int argc,char **argv) { int i; SPHERE *spheres = NULL; int nspheres = 0; double scale = 1; char fname[128]; char aline[1024],skip[256]; COLOUR c,red = {1,0,0}; XYZ p; double r; FILE *fptr; XYZ themin = {1e32,1e32,1e32}, themax = {-1e32,-1e32,-1e32},themid; double rmin = 1e32,rmax = -1e32; // Command line if (argc < 2) { fprintf(stderr,"Usage: %s [options] povfilename\n",argv[0]); fprintf(stderr,"Options:\n"); fprintf(stderr," -s n scale factor\n"); exit(-1); } for (i=1;i') aline[i] = ' '; } // Detect sphere lines if (strstr(aline,"sphere") != NULL) { if (sscanf(aline,"%s %lf %lf %lf %lf",skip,&p.x,&p.y,&p.z,&r) != 5) { fprintf(stderr,"Unexpected sphere line encountered\n"); exit(-1); } spheres = realloc(spheres,(nspheres+1)*sizeof(SPHERE)); spheres[nspheres].p = p; spheres[nspheres].r = r; spheres[nspheres].c = red; nspheres++; } // Detect pigment lines if (strstr(aline,"pigment") != NULL) { if (sscanf(aline,"%s %s %s %lf %lf %lf",skip,skip,skip,&c.r,&c.g,&c.b) != 6) { fprintf(stderr,"Unexpected pigment line encountered\n"); exit(-1); } if (nspheres > 0) spheres[nspheres-1].c = c; } } fclose(fptr); fprintf(stderr,"Found %d spheres\n",nspheres); for (i=0;i