Commit 2e8a5294 by Maarten L. Hekkelman

Update example and README

parent 441e1427
...@@ -3,6 +3,53 @@ libcifpp ...@@ -3,6 +3,53 @@ libcifpp
This library contains code to work with mmCIF and PDB files. This library contains code to work with mmCIF and PDB files.
Synopsis
--------
```c++
// A simple program counting residues with an OXT atom
#include <filesystem>
#include <iostream>
#include <cif++.hpp>
namespace fs = std::filesystem;
int main(int argc, char *argv[])
{
if (argc != 2)
exit(1);
cif::file file = cif::pdb::read(argv[1]);
if (file.empty())
{
std::cerr << "Empty file" << std::endl;
exit(1);
}
auto &db = file.front();
auto &atom_site = db["atom_site"];
auto n = atom_site.find(cif::key("label_atom_id") == "OXT").size();
std::cout << "File contains " << atom_site.size() << " atoms of which "
<< n << (n == 1 ? " is" : " are") << " OXT" << std::endl
<< "residues with an OXT are:" << std::endl;
for (const auto &[asym, comp, seqnr] :
atom_site.find<std::string, std::string, int>(
cif::key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id",
"label_seq_id"))
{
std::cout << asym << ' ' << comp << ' ' << seqnr << std::endl;
}
return 0;
}
```
Requirements Requirements
------------ ------------
......
#include <iostream>
#include <filesystem> #include <filesystem>
#include <iostream>
#include <cif++.hpp> #include <cif++.hpp>
namespace fs = std::filesystem; namespace fs = std::filesystem;
int main() int main(int argc, char *argv[])
{ {
cif::file file; if (argc != 2)
file.load("1cbs.cif.gz"); exit(1);
cif::file file = cif::pdb::read(argv[1]);
if (file.empty())
{
std::cerr << "Empty file" << std::endl;
exit(1);
}
auto& db = file.front(); auto &db = file.front();
auto &atom_site = db["atom_site"]; auto &atom_site = db["atom_site"];
auto n = atom_site.find(cif::key("label_atom_id") == "OXT").size(); auto n = atom_site.find(cif::key("label_atom_id") == "OXT").size();
std::cout << "File contains " << atom_site.size() << " atoms of which " << n << (n == 1 ? " is" : " are") << " OXT" << std::endl std::cout << "File contains " << atom_site.size() << " atoms of which " << n << (n == 1 ? " is" : " are") << " OXT" << std::endl
<< "residues with an OXT are:" << std::endl; << "residues with an OXT are:" << std::endl;
for (const auto& [asym, comp, seqnr]: atom_site.find<std::string,std::string,int>( for (const auto &[asym, comp, seqnr] : atom_site.find<std::string, std::string, int>(
cif::key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id", "label_seq_id")) cif::key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id", "label_seq_id"))
{ {
std::cout << asym << ' ' << comp << ' ' << seqnr << std::endl; std::cout << asym << ' ' << comp << ' ' << seqnr << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment