使用开源(经BSD许可)的chemkit库,可以在C ++中轻松读取和处理PDB文件。
作为示例,以下代码将读取PDB文件中的血红蛋白(PDB ID:2DHB),并打印出原子总数,链数和溶剂可及表面积:
#include <iostream>
#include <chemkit/polymer.h>
#include <chemkit/polymerfile.h>
#include <chemkit/molecularsurface.h>
using namespace chemkit;
int main()
{
PolymerFile file("2DHB.pdb");
bool ok = file.read();
if(!ok){
std::cerr << "Failed to read file: " << file.errorString() << std::endl;
return -1;
}
Polymer *protein = file.polymer();
if(!protein){
std::cerr << "File is empty." << std::endl;
return -1;
}
std::cout << "Number of Atoms: " << protein->atomCount() << std::endl;
std::cout << "Number of Chains: " << protein->chainCount() << std::endl;
MolecularSurface surface(protein);
surface.setSurfaceType(MolecularSurface::SolventAccessible);
std::cout << "Surface Area: " << surface.surfaceArea() << " A^2" << std::endl;
return 0;
}
输出:
Number of Atoms: 2201
Number of Chains: 2
Surface Area: 14791 A^2
有关更多信息,请参见上述类的文档: