#include "pdb.h" /* This needs to be updated to reflect the correct location of the symmetry library */ char *symm_filename = "./symop.lib"; char * find_symm_filename (void) { char * a = Expand1stEnvVar("$SYMMETRY_LIB"); /* if (a != NULL) { fprintf(stderr,"Trying symmetry library %s\n",a); return a; } else */ { fprintf(stderr,"Trying symmetry library %s\n",symm_filename); return symm_filename ; } } void free_space_group(space_group *sp) { if (sp != NULL) free(sp) ; } int read_coordinate_spec(char *string,int index, double *x,double *y, double *z, double *add) { int plus = 1 ; while(1) { int cc= string[index] ; if (debugging & DEBUG_SYMMETRY) printf("index %d char [%c]\n", index,cc) ; switch(cc) { case '\n':case '\0' : return 0 ; case ' ' :goto again; case '-' : plus = 0 ;goto again; case '+' : plus = 1 ;goto again; case ',' : return index +1 ; case '*' : return index +1 ; } if (plus < 0) serious_error(ARG_TYPE_STRING,"something wrong in symmetry", string) ; switch(cc) { case 'X': case 'x': *x = plus ? 1.0 : -1.0 ; plus = -1 ; goto again ; case 'Y': case 'y': *y = plus ? 1.0 : -1.0 ; plus = -1; goto again ; case 'Z': case 'z': *z = plus ? 1.0 : -1.0 ; plus = -1; goto again ; case '1': case '2':case '3':case '4':case '5':case '6': case '7':case '8':case '9': { int a = atoi(string +index); double val ; if (debugging & DEBUG_SYMMETRY) printf("a = %d, string [%s]\n", a , string+index) ; while (isdigit(string[index])) index ++; while (isspace(string[index])) index ++; if (string[index] == '/') { index++ ; while (isspace(string[index])) index ++; { int b = 0 ; b = atoi(string+index) ; if (b == 0) serious_error(ARG_TYPE_STRING,"something wrong in symmetry", string) ; val = (double)a ; val = val /(double ) b ; if (debugging & DEBUG_SYMMETRY) printf ("a = %d , b = %d, val %Lf\n", a,b,val); while (isdigit(string[index])) index ++; *add = plus ? val : 0 - val ; } } else *add = (double) ( plus ? a : 0.0 - a) ; } if (debugging & DEBUG_SYMMETRY) printf("%Lf\n", *add) ; continue ; } serious_error(ARG_TYPE_STRING,"something wrong in symmetry", string) ; again: index++ ; } } int read_operator(symmetry_operation *op, char *string,int index) { if(index = read_coordinate_spec(string,index, &op->xx,&op->yx,&op->zx,&op->addx)) if(index = read_coordinate_spec(string,index, &op->xy,&op->yy,&op->zy,&op->addy)) return read_coordinate_spec(string,index, &op->xz,&op->yz,&op->zz,&op->addz); return -1; } void read_symmetry_operations (space_group *sp, FILE *ff, int lines_number) { char string[200] ; int ii ; int read_index = 0 ; sp->ops_number = 0 ; fgets(string,200,ff) ; for(ii = 0 ; ii< lines_number ; ii++) { fgets(string,200,ff) ; while ((read_index = read_operator(&sp->ops[sp->ops_number],string,read_index)) > 0) sp->ops_number++ ; if(!read_index) sp->ops_number++; } } space_group * find_space_group (int number,char * name) { space_group * sp = (space_group *) malloc(sizeof(space_group)) ; sp->number = number ; if (fill_space_group(sp,name)) return sp ; else { free(sp) ; return NULL; } } int fill_space_group (space_group *sp,char *name) { FILE *ff = fopen(find_symm_filename(), "r") ; char string[300] ; int lines_number; int number = sp->number ; char *read_into = name == sp->s_name ? string : sp->s_name ; if (ff == NULL) serious_error (ARG_TYPE_STRING,"Failed to open symmetry file", find_symm_filename) ; while(1) { int ii ; fscanf(ff,"%d %d %d %s %s", &sp->number, &lines_number, &sp->primitives, read_into , sp->name) ; if (name == NULL ? number == sp->number : (!strcmp (name, read_into) || ! strcmp(sp->name,read_into))) { read_symmetry_operations(sp,ff,lines_number) ; return 1; } for (ii = 0 ; ii<= lines_number ; ii++) if (fgets(string,300, ff) == NULL) { sp->number = number ; return 0; } } } void fractionalize_atom(atom_record *atom, file_records *file, int index) { double tx,ty,tz; symmetry_operation *so = &file->scale ; OPERATION_TRANSFORM(so,tx,ty,tx,atom->x,atom->y,atom->z) ; atom->x = tx + so->addx; atom->y = ty + so->addy; atom->z = tz + so->addz; } void un_fractionalize_atom(atom_record *atom, file_records *file, int index) { double tx,ty,tz; symmetry_operation *so = &file->scale ; a_matrix *ma = &file->inverse_scale ; tx = atom->x - so->addx; ty = atom->y - so->addy; tz = atom->z - so->addz; MATRIX_TRANSFORM(ma,atom->x,atom->y,atom->z,tx,ty,tz) ; } void fractionalize(file_records *file) { traverse_file_atom_records(file, fractionalize_atom,file) ; } void un_fractionalize(file_records *file) { traverse_file_atom_records(file, un_fractionalize_atom,file) ; } /* } void transform(space_group *sp, int opnum,double *x, double *y, double*z) { space_operator * so = double xx = *x; double xx = *x; double xx = *x; */