#include #include #include #include #include #include using namespace std; using namespace OpenBabel; class MyMol : public OBMol { public: double MW; double logP; public: MyMol() : MW(0), logP(0) {} MyMol(const MyMol& Obj) : OBMol(Obj) { MW = Obj.MW; logP = Obj.logP; } MyMol& operator=(const MyMol& Obj) { if (this == &Obj) return *this; OBMol::operator=(Obj); MW = Obj.MW; logP = Obj.logP; return *this; } MyMol& operator+=(const MyMol& Obj) { OBMol::operator+=(Obj); return *this; } }; void printp(vector& lib) { cout << setw(10) << left << "id" << "\t" << "MW" << "\t" << "logP" << endl; for (auto ii = lib.begin(); ii != lib.end(); ii++) { cout << setw(10) << left << ii->GetTitle() << "\t" << fixed << setprecision(2) << ii->MW << "\t" << ii->logP << endl; } } int main(int argc, char* argv[]) { ifstream ifs("EGFR_lig.sdf"); OBConversion conv; conv.SetInFormat("SDF"); MyMol mol; vector lib; while (conv.Read(&mol, &ifs)) { string s_MW = mol.GetData("PUBCHEM_MOLECULAR_WEIGHT")->GetValue(); mol.MW = stof(s_MW); string s_logP = mol.GetData("PUBCHEM_XLOGP3_AA")->GetValue(); mol.logP = stof(s_logP); lib.push_back(mol); } ifs.close(); cout << "ソート前" << endl; printp(lib); sort(lib.begin(), lib.end(), [](const MyMol& A, const MyMol& B) { return A.MW < B.MW; }); cout << endl; cout << "ソート後" << endl; printp(lib); }