Created
March 13, 2012 06:44
-
-
Save jmbr/2027296 to your computer and use it in GitHub Desktop.
PDB to XYZ translator using ESBTL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <vector> | |
#include <iostream> | |
#include <ESBTL/default.h> | |
#include <ESBTL/selected_atom_iterator.h> | |
#include <ESBTL/atom_selectors.h> | |
int main(int argc, char *argv[]) { | |
if (argc < 3) { | |
std::cerr << "Usage: pdb2xyz INPUT OUTPUT\n"; | |
return EXIT_FAILURE; | |
} | |
std::string input_file(argv[1]); | |
std::string output_file(argv[2]); | |
typedef ESBTL::Accept_none_occupancy_policy<ESBTL::PDB::Line_format<> > | |
Accept_none_occupancy_policy; | |
std::vector<ESBTL::Default_system> systems; | |
ESBTL::Select_by_atmname selector("CA"); | |
ESBTL::Generic_line_selector<ESBTL::Select_by_atmname> sel(selector); | |
ESBTL::All_atom_system_builder<ESBTL::Default_system> | |
builder(systems, sel.max_nb_systems()); | |
if (ESBTL::read_a_pdb_file(input_file, sel, | |
builder, Accept_none_occupancy_policy()) == false) | |
{ | |
std::cerr << "Something went wrong.\n"; | |
return EXIT_FAILURE; | |
} | |
if (systems.empty() || systems[0].has_no_model()) { | |
std::cerr << "No valid atoms found.\n"; | |
return EXIT_FAILURE; | |
} | |
const auto model = *systems[0].models_begin(); | |
std::ofstream out(output_file); | |
out << model.number_of_atoms() << "\n" | |
<< "# " << input_file << "\n"; | |
for (auto i = model.atoms_begin(); i != model.atoms_end(); ++i) { | |
out << "CA " << i->x() << " " << i->y() << " " << i->z() << "\n"; | |
} | |
std::cout << c; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment