Commit 3c62a386 by Maarten L. Hekkelman

write out PDB files

parent 7ffda74e
...@@ -31,14 +31,30 @@ ...@@ -31,14 +31,30 @@
namespace cif::pdb namespace cif::pdb
{ {
file read(std::istream &is); /// \brief Read a file in either mmCIF or PDB format, compressed or not,
/// depending on the content.
file read(const std::filesystem::path &file); file read(const std::filesystem::path &file);
/// \brief Read a file in either mmCIF or PDB format, compressed or not,
/// depending on the content.
file read(std::istream &is);
/// \brief Write out a file in PDB format
void write(std::ostream &os, const datablock &db); void write(std::ostream &os, const datablock &db);
/// \brief Write out a file in PDB format
inline void write(std::ostream &os, const file &f) inline void write(std::ostream &os, const file &f)
{ {
write(os, f.front()); write(os, f.front());
} }
/// \brief Write out a file in PDB format or mmCIF format, depending on the filename extension
void write(const std::filesystem::path &file, const datablock &db);
/// \brief Write out a file in PDB format or mmCIF format, depending on the filename extension
inline void write(const std::filesystem::path &p, const file &f)
{
write(p, f.front());
}
} }
\ No newline at end of file
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <regex> #include <regex>
#include <set> #include <set>
#include <gxrio.hpp>
#include <cif++.hpp> #include <cif++.hpp>
#include <cif++/pdb/cif2pdb.hpp> #include <cif++/pdb/cif2pdb.hpp>
...@@ -3723,4 +3724,21 @@ void write(std::ostream &os, const datablock &db) ...@@ -3723,4 +3724,21 @@ void write(std::ostream &os, const datablock &db)
<< "END" << std::endl; << "END" << std::endl;
} }
void write(const std::filesystem::path &p, const datablock &db)
{
gxrio::ofstream out(p);
bool writePDB = false;
if (p.extension() == ".gz")
writePDB = iequals(p.stem().extension().string(), ".pdb");
else
writePDB = iequals(p.extension().string(), ".pdb");
if (writePDB)
write(out, db);
else
db.write(out);
}
} // namespace cif::pdb } // namespace cif::pdb
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