From 2e8a52949e3d2ca31142451c73d151a57a67d222 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Wed, 31 May 2023 15:54:53 +0200 Subject: [PATCH] Update example and README --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++ examples/example.cpp | 26 +++++++++++++++--------- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1e95ae2..e1711e7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,53 @@ libcifpp This library contains code to work with mmCIF and PDB files. +Synopsis +-------- + +```c++ +// A simple program counting residues with an OXT atom + +#include +#include + +#include + +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( + 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 ------------ diff --git a/examples/example.cpp b/examples/example.cpp index c20bc10..f08f18c 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -1,24 +1,32 @@ -#include #include +#include #include namespace fs = std::filesystem; -int main() +int main(int argc, char *argv[]) { - cif::file file; - file.load("1cbs.cif.gz"); + if (argc != 2) + exit(1); - auto& db = file.front(); + 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( - cif::key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id", "label_seq_id")) + << "residues with an OXT are:" << std::endl; + + for (const auto &[asym, comp, seqnr] : atom_site.find( + cif::key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id", "label_seq_id")) { std::cout << asym << ' ' << comp << ' ' << seqnr << std::endl; }