int main(int argc, char** argv) { try { RMF_ADD_INPUT_FILE("rmf"); RMF_ADD_OUTPUT_FILE("pdb"); RMF_ADD_FRAMES; process_options(argc, argv); RMF::FileConstHandle rh = RMF::open_rmf_file_read_only(input); std::ostream* out; std::ofstream fout; if (!output.empty()) { fout.open(output.c_str()); if (!fout) { std::cerr << "Error opening file " << output << std::endl; return 1; } out = &fout; } else { out = &std::cout; } RMF::decorator::IntermediateParticleFactory ipf(rh); RMF::decorator::AtomFactory af(rh); RMF::decorator::ChainFactory cf(rh); RMF::decorator::ResidueFactory rf(rh); RMF::NodeConstHandle rn = rh.get_root_node(); for (unsigned int input_frame = start_frame, output_frame = 0; input_frame < rh.get_number_of_frames(); input_frame += step_frame, ++output_frame) { rh.set_current_frame(RMF::FrameID(input_frame)); *out << (boost::format("MODEL%1$9d") % (output_frame + 1)) << std::endl; write_atoms(*out, 0, rn, ipf, af, cf, rf); *out << "ENDMDL" << output_frame + 1 << std::endl; } return 0; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } }
int main() { char coordinate_input[BUFSIZ]; char ammp_output[BUFSIZ]; char dictionary[BUFSIZ]; char work[1000],keep[1000]; char atype[20],aname[20]; char *fgets(); float sigma,emin; int ifile,i,imreading,ii,myres; FILE *in1,*dict,*output,*fopen(); printf(" atom definition file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; dictionary[ifile -i ] = work[ifile]; dictionary[ifile -i +1 ] = '\0'; } /* now read in the atoms */ dict = fopen( dictionary, "r"); if( dict == NULL) { fprintf(stderr," sorry i can't open %s\n",dictionary); exit(0);} inkinds = 0; while ( fgets( work,256, dict) != NULL) { sscanf( work,"%s %f %f %f %f %f %f %f %f %f %f %f %f %f \n", &kinds[inkinds].type[0], &kinds[inkinds].r , &kinds[inkinds].theta , &sigma , &emin , &kinds[inkinds].Z , &kinds[inkinds].angle_inc, &kinds[inkinds].X , &kinds[inkinds].jaa , &kinds[inkinds].mass , &kinds[inkinds].charge , &kinds[inkinds].V, &kinds[inkinds].U , &kinds[inkinds].hybrid ); /* kinds[inkinds].theta *= 3.14159265/180.; */ sigma = sigma*sigma; sigma = sigma*sigma*sigma; /* kinds[inkinds].b = sqrt( 4.*emin*sigma*sigma); kinds[inkinds].a = sqrt( 4.*emin*sigma); */ kinds[inkinds].b = sqrt( emin*sigma*sigma); kinds[inkinds].a = sqrt( 2*emin*sigma); inkinds ++; if( inkinds > MAX_ATOM) { fprintf( stderr," too many kinds of atoms in dictionary\n"); exit(0); } } fclose( dict); printf(" Residue dictionary directory:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; dictionary[ifile -i ] = work[ifile]; dictionary[ifile -i +1 ] = '\0'; } ifile = ifile -i ; if( ifile == 0 ){ dictionary[ifile++] = '.'; dictionary[ifile] = '\0'; } if( dictionary[ifile-1] != '/') { ifile++; dictionary[ifile-1] = '/'; dictionary[ifile] = '\0';} printf(" atom input coordinate file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; coordinate_input[ifile -i ] = work[ifile]; coordinate_input[ifile -i +1 ] = '\0'; } printf(" AMMP file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; ammp_output[ifile -i ] = work[ifile]; ammp_output[ifile -i +1 ] = '\0'; } in1 = fopen( coordinate_input, "r"); output = fopen( ammp_output, "w"); if (in1 == NULL) goto NO_IN1_FILE; /* read in the first residue * stuff is read into work when the residue number changes then * work is copied into keep, so the first atom of any residue is * going to be in the keep buffer. to initialize we read the * first atom into keep */ keep[0] = '\0'; while( !(keep[0] == 'A' && keep[1] == 'T' && keep[2] == 'O' && keep[3] == 'M') && !(keep[0] == 'H'&& keep[1] == 'E' && keep[1] == 'T'&& keep[1] == 'A'&& keep[1] == 'T' ) ) { if( fgets(keep,90,in1) == NULL) { fprintf(stderr," no atoms in input file ? \n") ; NO_IN1_FILE: printf(" enter the dictionary name >\n"); fgets( keep, 90, stdin); i=0; while( (keep[i] == ' ' || keep[i] == '\t') && keep[i] != '\0') i++; for( imreading = 0; imreading < 3; imreading++) { aname[imreading] = toupper( keep[i + imreading] ); } aname[3] = '\0'; goto NO_ATOMS; } } imreading = 0; while( imreading == 0) {/* begining of imreading loop */ inres = 0; for(i=0; i< MAX_RES; i++) { mykind[i] = -1; defined[i] = -1; name[i][0] = '\0'; x[i] = 0.; y[i] = 0.; z[i] = 0.; } sscanf( &keep[22],"%d",&myres); sscanf(&keep[29],"%f %f %f",&x[inres],&y[inres],&z[inres]); sscanf(&keep[11],"%s",&atype[0]); sscanf(&keep[17],"%s",&aname[0]); serial[inres] = 100*myres + inres; ii = 0; for( i=0; i< 3; i++ ) { if( aname[i] == '\0') break; name[inres][ii++] = (char)tolower(aname[i]); } name[inres][ii++] = '.'; for(i=0; i< 4; i++) { if( atype[i] == '\0' ) break; name[inres][ii++] = (char)tolower(atype[i]); } name[inres][ii] = '\0'; a[inres] = 0.; b[inres] = 0.; q[inres] = 0.; mass[inres] = 1.; defined[inres] = 0; for( inres = 1; inres < MAX_RES; inres ++) { /* start of reading an atom loop */ if( fgets( work,90,in1) == NULL) { imreading = 1; break; } if( work[0] != 'A' && work[0] != 'H') { imreading = 1; break; } /* printf("%s\n",work); printf("%d\n",inres); */ sscanf( &work[22],"%d",&ii); if( ii != myres ) {ii = 0; while( work[ii] != '\0'){ keep[ii] = work[ii] ; ii++;} /* inres += 1; */ break; } sscanf(&work[29],"%f %f %f",&x[inres],&y[inres],&z[inres]); sscanf(&work[11],"%s",&atype[0]); sscanf(&work[17],"%s",&aname[0]); serial[inres] = 100*myres + inres; ii = 0; for( i=0; i< 3; i++ ) { if( aname[i] == '\0') break; name[inres][ii++] = (char)tolower(aname[i]); } name[inres][ii++] = '.'; for(i=0; i< 4; i++) { if( atype[i] == '\0' ) break; name[inres][ii++] = (char)tolower(atype[i]); } name[inres][ii] = '\0'; a[inres] = 0.; b[inres] = 0.; q[inres] = 0.; mass[inres] = 1.; defined[inres] = 0; }/* end of reading an atom loop */ /* for( i=0; i< inres; i++) printf(">%s<\n",&name[i][0]); */ /* if here then all of the atoms in the residue are read in */ /* now we have to open and read the dictionary file * there could be atoms in either the residue or dictionary which * are not there i.e. oxt for a residue or a missing H */ /* prepare the filename */ NO_ATOMS: i = 0; while(dictionary[i] != '\0') { work[i] = dictionary[i]; i++;} ii = 0; while(aname[ii] != '\0') {work[i] = aname[ii]; i++; ii++;} work[i++] = '\0'; dict = fopen(work,"r"); if( dict == NULL ){ fprintf(stderr," dictionary %s not found \n", work); write_atoms(output); goto DONE; } /* read the number of atoms */ if(fgets( work,80,dict)==NULL) { fprintf(stderr,"BAD DICTIONARY %s\n",aname); exit(0);} sscanf(work,"%d",&natoms); read_atoms( dict,natoms ); write_atoms(output); if(fgets( work,80,dict)==NULL) { fprintf(stderr,"BAD DICTIONARY %s\n",aname); exit(0);} sscanf(work,"%d",&nbond); do_bonds( dict,nbond,output); inbondlist = nbond; nangle = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&nangle); do_angle(dict,nangle,output); nhybrid = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&nhybrid); do_hybrid(dict,nhybrid,output); ntorsion = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&ntorsion); do_torsion(dict,ntorsion,output); DONE: fclose( dict ); }/* end of imreading loop */ }/* end of module main */