bool ReadFeat(istream &ifs,OBMol &mol, const char *title) { char buffer[BUFF_SIZE]; int i,natoms; ifs.getline(buffer,BUFF_SIZE); sscanf(buffer,"%d",&natoms); mol.ReserveAtoms(natoms); mol.BeginModify(); if (!ifs.getline(buffer,BUFF_SIZE)) return(false); mol.SetTitle(buffer); double x,y,z; char type[20]; OBAtom *atom; for (i = 0; i < natoms;i++) { if (!ifs.getline(buffer,BUFF_SIZE)) return(false); sscanf(buffer,"%s %lf %lf %lf", type, &x, &y, &z); CleanAtomType(type); atom = mol.NewAtom(); atom->SetVector(x,y,z); atom->SetAtomicNum(etab.GetAtomicNum(type)); } mol.EndModify(); return(true); }
bool BGFFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv) { OBMol* pmol = pOb->CastAndClear<OBMol>(); if(pmol==NULL) return false; //Define some references so we can use the old parameter names istream &ifs = *pConv->GetInStream(); OBMol &mol = *pmol; mol.SetTitle( pConv->GetTitle()); //default title is the filename mol.BeginModify(); char buffer[BUFF_SIZE]; char tmp[16],tmptyp[16]; vector<string> vs; while (ifs.getline(buffer,BUFF_SIZE)) { if (EQn(buffer,"CRYSTX",6)) { // Parse unit cell tokenize(vs,buffer," \n\t,"); if (vs.size() != 7) continue; // something strange double A, B, C, Alpha, Beta, Gamma; A = atof(vs[1].c_str()); B = atof(vs[2].c_str()); C = atof(vs[3].c_str()); Alpha = atof(vs[4].c_str()); Beta = atof(vs[5].c_str()); Gamma = atof(vs[6].c_str()); OBUnitCell *uc = new OBUnitCell; uc->SetOrigin(fileformatInput); uc->SetData(A, B, C, Alpha, Beta, Gamma); mol.SetData(uc); } else if (EQn(buffer,"FORMAT",6)) break; } ttab.SetFromType("DRE"); ttab.SetToType("INT"); OBAtom *atom; double x,y,z,chrg; for (;;) { if (!ifs.getline(buffer,BUFF_SIZE)) break; if (EQn(buffer,"FORMAT",6)) break; sscanf(buffer,"%*s %*s %*s %*s %*s %*s %lf %lf %lf %15s %*s %*s %lf", &x,&y,&z, tmptyp, &chrg); atom = mol.NewAtom(); ttab.Translate(tmp,tmptyp); atom->SetType(tmp); CleanAtomType(tmptyp); atom->SetAtomicNum(etab.GetAtomicNum(tmptyp)); atom->SetVector(x,y,z); } unsigned int i; vector<int> vtmp; vector<vector<int> > vcon; vector<vector<int> > vord; for (i = 0; i < mol.NumAtoms();i++) { vcon.push_back(vtmp); vord.push_back(vtmp); } unsigned int bgn; for (;;) { if (!ifs.getline(buffer,BUFF_SIZE) || EQn(buffer,"END",3)) break; tokenize(vs,buffer); if (vs.empty() || vs.size() < 3 || vs.size() > 10) continue; if (EQn(buffer,"CONECT",6)) { bgn = atoi((char*)vs[1].c_str()) - 1; if (bgn < 1 || bgn > mol.NumAtoms()) continue; for (i = 2;i < vs.size();i++) { vcon[bgn].push_back(atoi((char*)vs[i].c_str())); vord[bgn].push_back(1); } } else if (EQn(buffer,"ORDER",5)) { bgn = atoi((char*)vs[1].c_str()) - 1; if (bgn < 1 || bgn > mol.NumAtoms()) continue; if (vs.size() > vord[bgn].size()+2) continue; for (i = 2;i < vs.size();i++) vord[bgn][i-2] = atoi((char*)vs[i].c_str()); } } unsigned int j; for (i = 1;i <= mol.NumAtoms();i++) if (!vcon[i - 1].empty()) for (j = 0;j < vcon[i - 1].size();j++) { mol.AddBond(i,vcon[i - 1][j],vord[i - 1][j]); } //load up the next line after the END marker ifs.getline(buffer,BUFF_SIZE); mol.EndModify(); return(true); }