#include "MakeNewAtom.h" atom_record * RadFileStringToNewAtom(char * string) { if (string == NULL) return NULL ; else { int ii ; int type = RECORD_ATOM ; char t12 = string[12] ; atom_record * newrec = (atom_record *) malloc(sizeof(atom_record)); char *name = newrec->name ; int flags = 0 ; newrec->atomtype = type ; strncpy(newrec->ident,"ATOM ", 6) ; newrec->ident[6] = 0 ; { /* From */ /* ====================== */ /* int rd_richards_RAD_volume */ /* ====================== */ int ncalc,i,numchn,numfil; char atm[10], res3[10]; int seqnum; double x, y, z, rvdw, rcov, volume; int ns ; char *buf1 = string + 1; sscanf(buf1,"%5d%5d%3d%3d%6c%6c%5d%8lf%8lf%8lf%5lf%5lf%8lf%5d", &ncalc,&i,&numchn,&numfil,atm,res3,&seqnum, &x,&y,&z,&rvdw,&rcov,&volume,&ns); /* fix for volumes of 1000 */ sscanf(buf1 + 67,"%8lf",&volume); newrec->number = i ; strcpy(newrec->resname,res3); strcpy(newrec->name,atm); if (type == RECORD_ATOM && ((name[0] == 'C' && name[1] == ' ') || (name[0] == 'C' && name[1] == 'A' && name[2] == ' ')|| (name[0] == 'O' && name[1] == ' ') || (name[0] == 'N' && name[1] == ' ') )) flags |= MAIN_CHAIN_ATOM ; newrec->extraflag = ' ' ; newrec->chain = ' ' ; newrec->x_char = ' '; newrec->resnum = seqnum ; newrec->x = x ; newrec->y = y ; newrec->z = z ; newrec->occ = rvdw ; newrec->b = rcov ; newrec->restype = find_residue_type(newrec->resname) ; newrec->definition = find_atom_definition(newrec->restype,newrec->name) ; newrec->volume = volume ; newrec->dumm_solvents = ns ; newrec->flags = flags ; } return newrec; } } file_records *ReadRadFile(FILE * ff, int format) { file_records * f = (file_records *) calloc(1,sizeof(file_records)) ; int ii; int n = 0; bool start = false ; int tmp_n = 10000 ; atom_record ** tmp_atoms =(atom_record **) calloc (tmp_n,sizeof(atom_record *)) ; char string[BUFSIZ]; do { char *sa = fgets (string, 200, ff) ; if (sa == NULL && feof(ff) != 0) { STDERR("barf! Bad RAD file format. Couldn't get started."); return NULL ; } else if (StreqWithSpaces(sa,"BEGIN")) { start = true ; } } while (!start) ; while (start) { char *sa = fgets (string, 200, ff) ; if (sa == NULL) { start = false ; } else if (StreqWithSpaces(sa,"TOTAL")) { start = false ; } else { tmp_atoms[n] = RadFileStringToNewAtom(sa); if (tmp_atoms[n] == NULL) start = false ; else n++; } } f->atomnum = n; f->atoms =(atom_record **) calloc (n,sizeof(atom_record *)) ; for (ii=0; iiatoms[ii] = tmp_atoms[ii]; } free(tmp_atoms); make_residues(f) ; f->name = NULL ; LinkUp_Residues_Atoms(f); return f ; } file_records *OpenReadRadFile(char * name,int format) { if (dumm_residue == NULL) serious_error(1, "do_initialization was not called before reading a file","") ; fprintf(stderr,"OpenReadRadFile(): Trying to read %s\n", name) ; { FILE * ff= fopen(name,"r") ; if (ff == NULL) { fprintf(stderr,"OpenReadRadFile(): Unable to open file, returning NULL.\n"); return(NULL) ; } else { file_records *new = ReadRadFile ( ff, format) ; fclose(ff) ; if (new != NULL) { new->name = new_string(name); new->header = NULL ; } return new ; } } }