std::vector<PDBAtom> extractAtomsFromXYZ(std::string filename) { std::vector<PDBAtom> atoms; std::ifstream xyz_file(filename.c_str()); if (xyz_file.is_open() && xyz_file.good()) { // Read for 2 data lines. std::string comment_line; int number_of_atoms; xyz_file >> number_of_atoms; std::getline(xyz_file, comment_line); std::string atomic_symbol, x, y, z; for (int i = 0; i < number_of_atoms; ++i) { xyz_file >> atomic_symbol >> x >> y >> z; atoms.push_back(PDBAtom(atomic_symbol, atof(x.c_str()), atof(y.c_str()), atof(z.c_str()))); } }
void PDB::read(const char* filename){ printf("Reading %s.\n", filename); this->is_xyz = (!strcmp(filename + strlen(filename)-4, ".xyz")); if (this->is_xyz) { this->readXYZ(filename); return; } char buffer[BUF_SIZE]; FILE* file = safe_fopen(filename, "r"); while(fgets(buffer, BUF_SIZE, file) != NULL){ if(strncmp(buffer,"SSBOND",6) == 0){ this->ssbonds.push_back(PDBSSBond(buffer)); } if(strncmp(buffer, "ATOM", 4) == 0){ this->atoms.push_back(PDBAtom(buffer)); } } printf("Found %zu atoms and %zu SS-bonds.\n", this->atoms.size(), this->ssbonds.size()); printf("Done reading '%s'.\n", filename); fclose(file); }