Commit 700575ad by Maarten L. Hekkelman

Merged

parent 9fe6e5df
...@@ -215,8 +215,8 @@ set(project_sources ...@@ -215,8 +215,8 @@ set(project_sources
# ${PROJECT_SOURCE_DIR}/src/pdb/PDB2Cif.cpp # ${PROJECT_SOURCE_DIR}/src/pdb/PDB2Cif.cpp
# ${PROJECT_SOURCE_DIR}/src/pdb/PDB2CifRemark3.cpp # ${PROJECT_SOURCE_DIR}/src/pdb/PDB2CifRemark3.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/AtomType.cpp ${PROJECT_SOURCE_DIR}/src/structure/AtomType.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/BondMap.cpp ${PROJECT_SOURCE_DIR}/src/structure/BondMap.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/Compound.cpp # ${PROJECT_SOURCE_DIR}/src/structure/Compound.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/Secondary.cpp # ${PROJECT_SOURCE_DIR}/src/structure/Secondary.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/Structure.cpp # ${PROJECT_SOURCE_DIR}/src/structure/Structure.cpp
...@@ -261,14 +261,13 @@ add_library(cifpp ${project_sources} ${project_headers} ${CMAKE_SOURCE_DIR}/src/ ...@@ -261,14 +261,13 @@ add_library(cifpp ${project_sources} ${project_headers} ${CMAKE_SOURCE_DIR}/src/
set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(NEED_BOOST_REGEX) if(NEED_BOOST_REGEX)
target_compile_definitions(cifpp PUBLIC USE_BOOST_REGEX=1) target_compile_definitions(cifpp PUBLIC USE_BOOST_REGEX=1 BOOST_REGEX_STANDALONE=1)
endif() endif()
target_include_directories(cifpp target_include_directories(cifpp
PUBLIC PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
${Boost_INCLUDE_DIR}
) )
target_include_directories(cifpp target_include_directories(cifpp
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <filesystem> #include <filesystem>
#include <list> #include <list>
#include <mutex> #include <mutex>
#include <utility>
#include <cif++/utilities.hpp> #include <cif++/utilities.hpp>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <stdexcept> #include <stdexcept>
#include <unordered_map> #include <unordered_map>
#include <cif++/Structure.hpp> #include <cif++/structure/Structure.hpp>
namespace mmcif namespace mmcif
{ {
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <filesystem> #include <filesystem>
#include <gzstream/gzstream.hpp> #include <zstream/zstream.hpp>
#include <boost/logic/tribool.hpp> #include <boost/logic/tribool.hpp>
...@@ -3448,9 +3448,7 @@ void File::load(const std::filesystem::path &p) ...@@ -3448,9 +3448,7 @@ void File::load(const std::filesystem::path &p)
{ {
fs::path path(p); fs::path path(p);
if (path.extension() == ".gz") zstream::ifstream in(p);
{
gzstream::ifstream in(p);
try try
{ {
...@@ -3462,36 +3460,12 @@ void File::load(const std::filesystem::path &p) ...@@ -3462,36 +3460,12 @@ void File::load(const std::filesystem::path &p)
std::cerr << "Error loading file " << path << std::endl; std::cerr << "Error loading file " << path << std::endl;
throw; throw;
} }
}
else
{
std::ifstream inFile(p, std::ios_base::in | std::ios_base::binary);
try
{
load(inFile);
}
catch (const std::exception &ex)
{
if (cif::VERBOSE >= 0)
std::cerr << "Error loading file " << path << std::endl;
throw;
}
}
} }
void File::save(const std::filesystem::path &p) void File::save(const std::filesystem::path &p)
{ {
if (p.extension() == ".gz") zstream::ofstream outFile(p);
{
gzstream::ofstream outFile(p);
save(outFile); save(outFile);
}
else
{
std::ofstream outFile(p, std::ios_base::out | std::ios_base::binary);
save(outFile);
}
} }
void File::load(std::istream &is) void File::load(std::istream &is)
...@@ -3526,23 +3500,13 @@ void File::load(std::istream &is, const std::string &datablock) ...@@ -3526,23 +3500,13 @@ void File::load(std::istream &is, const std::string &datablock)
void File::load(const char *data, std::size_t length) void File::load(const char *data, std::size_t length)
{ {
bool gzipped = length > 2 and data[0] == static_cast<char>(0x1f) and data[1] == static_cast<char>(0x8b);
struct membuf : public std::streambuf struct membuf : public std::streambuf
{ {
membuf(char *data, size_t length) { this->setg(data, data, data + length); } membuf(char *data, size_t length) { this->setg(data, data, data + length); }
} buffer(const_cast<char *>(data), length); } buffer(const_cast<char *>(data), length);
if (gzipped) zstream::istream is(&buffer);
{
gzstream::istream is(&buffer);
load(is); load(is);
}
else
{
std::istream is(&buffer);
load(is);
}
} }
void File::save(std::ostream &os) void File::save(std::ostream &os)
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <gzstream/gzstream.hpp> #include <zstream/zstream.hpp>
#include <cif++/cif/file.hpp> #include <cif++/cif/file.hpp>
...@@ -161,16 +161,8 @@ void file::load(std::istream &is) ...@@ -161,16 +161,8 @@ void file::load(std::istream &is)
void file::save(const std::filesystem::path &p) const void file::save(const std::filesystem::path &p) const
{ {
if (p.extension() == ".gz") zstream::ofstream outFile(p);
{
gzstream::ofstream outFile(p);
save(outFile); save(outFile);
}
else
{
std::ofstream outFile(p, std::ios_base::binary);
save(outFile);
}
} }
void file::save(std::ostream &os) const void file::save(std::ostream &os) const
......
...@@ -435,7 +435,7 @@ const validator &validator_factory::operator[](std::string_view dictionary_name) ...@@ -435,7 +435,7 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
if (std::filesystem::exists(p, ec) and not ec) if (std::filesystem::exists(p, ec) and not ec)
{ {
gxrio::ifstream in(p); gzstream::ifstream in(p);
if (not in.is_open()) if (not in.is_open())
throw std::runtime_error("Could not open dictionary (" + p.string() + ")"); throw std::runtime_error("Could not open dictionary (" + p.string() + ")");
......
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
#include <fstream> #include <fstream>
#include <mutex> #include <mutex>
#include <cif++/BondMap.hpp> #include <cif++/cif.hpp>
#include <cif++/Cif++.hpp> #include <cif++/structure/BondMap.hpp>
#include <cif++/structure/Compound.hpp>
#include <cif++/utilities.hpp> #include <cif++/utilities.hpp>
#include <cif++/Compound.hpp>
namespace mmcif namespace mmcif
{ {
...@@ -233,7 +233,7 @@ BondMap::BondMap(const Structure &p) ...@@ -233,7 +233,7 @@ BondMap::BondMap(const Structure &p)
link[b].insert(a); link[b].insert(a);
}; };
cif::Datablock &db = p.datablock(); cif::v2::datablock &db = p.datablock();
// collect all compounds first // collect all compounds first
std::set<std::string> compounds; std::set<std::string> compounds;
...@@ -266,7 +266,7 @@ BondMap::BondMap(const Structure &p) ...@@ -266,7 +266,7 @@ BondMap::BondMap(const Structure &p)
std::string lastAsymID, lastAuthSeqID; std::string lastAsymID, lastAuthSeqID;
int lastSeqID = 0; int lastSeqID = 0;
for (const auto &[asymID, seqID, authSeqID] : db["pdbx_poly_seq_scheme"].rows<std::string,int,std::string>("asym_id", "seq_id", "pdb_seq_num")) for (const auto &[asymID, seqID, authSeqID] : db["pdbx_poly_seq_scheme"].rows<std::string, int, std::string>("asym_id", "seq_id", "pdb_seq_num"))
{ {
if (asymID != lastAsymID) // first in a new sequece if (asymID != lastAsymID) // first in a new sequece
{ {
...@@ -298,7 +298,7 @@ BondMap::BondMap(const Structure &p) ...@@ -298,7 +298,7 @@ BondMap::BondMap(const Structure &p)
int seqId1 = 0, seqId2 = 0; int seqId1 = 0, seqId2 = 0;
std::string authSeqId1, authSeqId2; std::string authSeqId1, authSeqId2;
cif::tie(asym1, asym2, atomId1, atomId2, seqId1, seqId2, authSeqId1, authSeqId2) = cif::v2::tie(asym1, asym2, atomId1, atomId2, seqId1, seqId2, authSeqId1, authSeqId2) =
l.get("ptnr1_label_asym_id", "ptnr2_label_asym_id", l.get("ptnr1_label_asym_id", "ptnr2_label_asym_id",
"ptnr1_label_atom_id", "ptnr2_label_atom_id", "ptnr1_label_atom_id", "ptnr2_label_atom_id",
"ptnr1_label_seq_id", "ptnr2_label_seq_id", "ptnr1_label_seq_id", "ptnr2_label_seq_id",
...@@ -341,11 +341,11 @@ BondMap::BondMap(const Structure &p) ...@@ -341,11 +341,11 @@ BondMap::BondMap(const Structure &p)
}; };
// loop over poly_seq_scheme // loop over poly_seq_scheme
for (auto r : db["pdbx_poly_seq_scheme"].find(cif::Key("mon_id") == c)) for (auto r : db["pdbx_poly_seq_scheme"].find(cif::v2::key("mon_id") == c))
{ {
std::string asymID; std::string asymID;
int seqID; int seqID;
cif::tie(asymID, seqID) = r.get("asym_id", "seq_id"); cif::v2::tie(asymID, seqID) = r.get("asym_id", "seq_id");
std::vector<Atom> rAtoms; std::vector<Atom> rAtoms;
copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms), copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms),
...@@ -363,10 +363,10 @@ BondMap::BondMap(const Structure &p) ...@@ -363,10 +363,10 @@ BondMap::BondMap(const Structure &p)
} }
// loop over pdbx_nonpoly_scheme // loop over pdbx_nonpoly_scheme
for (auto r : db["pdbx_nonpoly_scheme"].find(cif::Key("mon_id") == c)) for (auto r : db["pdbx_nonpoly_scheme"].find(cif::v2::key("mon_id") == c))
{ {
std::string asymID; std::string asymID;
cif::tie(asymID) = r.get("asym_id"); cif::v2::tie(asymID) = r.get("asym_id");
std::vector<Atom> rAtoms; std::vector<Atom> rAtoms;
copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms), copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms),
...@@ -389,7 +389,7 @@ BondMap::BondMap(const Structure &p) ...@@ -389,7 +389,7 @@ BondMap::BondMap(const Structure &p)
} }
// loop over pdbx_branch_scheme // loop over pdbx_branch_scheme
for (const auto &[asym_id, pdb_seq_num] : db["pdbx_branch_scheme"].find<std::string,std::string>(cif::Key("mon_id") == c, "asym_id", "pdb_seq_num")) for (const auto &[asym_id, pdb_seq_num] : db["pdbx_branch_scheme"].find<std::string, std::string>(cif::v2::key("mon_id") == c, "asym_id", "pdb_seq_num"))
{ {
std::vector<Atom> rAtoms; std::vector<Atom> rAtoms;
copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms), copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms),
......
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <cif++/Cif++.hpp> #include <cif++/cif.hpp>
#include <cif++/CifParser.hpp> // #include <cif++/CifParser.hpp>
#include <cif++/utilities.hpp> #include <cif++/utilities.hpp>
#include <cif++/Compound.hpp> #include <cif++/structure/Compound.hpp>
#include <cif++/Point.hpp> #include <cif++/point.hpp>
namespace fs = std::filesystem; namespace fs = std::filesystem;
...@@ -112,14 +112,14 @@ struct CompoundBondLess ...@@ -112,14 +112,14 @@ struct CompoundBondLess
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Compound // Compound
Compound::Compound(cif::Datablock &db) Compound::Compound(cif::v2::datablock &db)
{ {
auto &chemComp = db["chem_comp"]; auto &chemComp = db["chem_comp"];
if (chemComp.size() != 1) if (chemComp.size() != 1)
throw std::runtime_error("Invalid compound file, chem_comp should contain a single row"); throw std::runtime_error("Invalid compound file, chem_comp should contain a single row");
cif::tie(mID, mName, mType, mFormula, mFormulaWeight, mFormalCharge) = cif::v2::tie(mID, mName, mType, mFormula, mFormulaWeight, mFormalCharge) =
chemComp.front().get("id", "name", "type", "formula", "formula_weight", "pdbx_formal_charge"); chemComp.front().get("id", "name", "type", "formula", "formula_weight", "pdbx_formal_charge");
// The name should not contain newline characters since that triggers validation errors later on // The name should not contain newline characters since that triggers validation errors later on
...@@ -132,7 +132,7 @@ Compound::Compound(cif::Datablock &db) ...@@ -132,7 +132,7 @@ Compound::Compound(cif::Datablock &db)
{ {
CompoundAtom atom; CompoundAtom atom;
std::string typeSymbol; std::string typeSymbol;
cif::tie(atom.id, typeSymbol, atom.charge, atom.aromatic, atom.leavingAtom, atom.stereoConfig, atom.x, atom.y, atom.z) = cif::v2::tie(atom.id, typeSymbol, atom.charge, atom.aromatic, atom.leavingAtom, atom.stereoConfig, atom.x, atom.y, atom.z) =
row.get("atom_id", "type_symbol", "charge", "pdbx_aromatic_flag", "pdbx_leaving_atom_flag", "pdbx_stereo_config", row.get("atom_id", "type_symbol", "charge", "pdbx_aromatic_flag", "pdbx_leaving_atom_flag", "pdbx_stereo_config",
"model_Cartn_x", "model_Cartn_y", "model_Cartn_z"); "model_Cartn_x", "model_Cartn_y", "model_Cartn_z");
atom.typeSymbol = AtomTypeTraits(typeSymbol).type(); atom.typeSymbol = AtomTypeTraits(typeSymbol).type();
...@@ -144,13 +144,13 @@ Compound::Compound(cif::Datablock &db) ...@@ -144,13 +144,13 @@ Compound::Compound(cif::Datablock &db)
{ {
CompoundBond bond; CompoundBond bond;
std::string valueOrder; std::string valueOrder;
cif::tie(bond.atomID[0], bond.atomID[1], valueOrder, bond.aromatic, bond.stereoConfig) = row.get("atom_id_1", "atom_id_2", "value_order", "pdbx_aromatic_flag", "pdbx_stereo_config"); cif::v2::tie(bond.atomID[0], bond.atomID[1], valueOrder, bond.aromatic, bond.stereoConfig) = row.get("atom_id_1", "atom_id_2", "value_order", "pdbx_aromatic_flag", "pdbx_stereo_config");
bond.type = from_string(valueOrder); bond.type = from_string(valueOrder);
mBonds.push_back(std::move(bond)); mBonds.push_back(std::move(bond));
} }
} }
Compound::Compound(cif::Datablock &db, const std::string &id, const std::string &name, const std::string &type, const std::string &group) Compound::Compound(cif::v2::datablock &db, const std::string &id, const std::string &name, const std::string &type, const std::string &group)
: mID(id) : mID(id)
, mName(name) , mName(name)
, mType(type) , mType(type)
...@@ -161,7 +161,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string ...@@ -161,7 +161,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string
{ {
CompoundAtom atom; CompoundAtom atom;
std::string typeSymbol; std::string typeSymbol;
cif::tie(atom.id, typeSymbol, atom.charge, atom.x, atom.y, atom.z) = cif::v2::tie(atom.id, typeSymbol, atom.charge, atom.x, atom.y, atom.z) =
row.get("atom_id", "type_symbol", "charge", "x", "y", "z"); row.get("atom_id", "type_symbol", "charge", "x", "y", "z");
atom.typeSymbol = AtomTypeTraits(typeSymbol).type(); atom.typeSymbol = AtomTypeTraits(typeSymbol).type();
...@@ -176,7 +176,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string ...@@ -176,7 +176,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string
{ {
CompoundBond bond; CompoundBond bond;
std::string btype; std::string btype;
cif::tie(bond.atomID[0], bond.atomID[1], btype, bond.aromatic) = row.get("atom_id_1", "atom_id_2", "type", "aromatic"); cif::v2::tie(bond.atomID[0], bond.atomID[1], btype, bond.aromatic) = row.get("atom_id_1", "atom_id_2", "type", "aromatic");
using cif::iequals; using cif::iequals;
...@@ -446,7 +446,7 @@ class CCDCompoundFactoryImpl : public CompoundFactoryImpl ...@@ -446,7 +446,7 @@ class CCDCompoundFactoryImpl : public CompoundFactoryImpl
Compound *create(const std::string &id) override; Compound *create(const std::string &id) override;
cif::DatablockIndex mIndex; cif::v2::datablockIndex mIndex;
fs::path mCompoundsFile; fs::path mCompoundsFile;
}; };
...@@ -562,7 +562,7 @@ Compound *CCP4CompoundFactoryImpl::create(const std::string &id) ...@@ -562,7 +562,7 @@ Compound *CCP4CompoundFactoryImpl::create(const std::string &id)
auto &cat = mFile["comp_list"]["chem_comp"]; auto &cat = mFile["comp_list"]["chem_comp"];
auto rs = cat.find(cif::Key("three_letter_code") == id); auto rs = cat.find(cif::v2::key("three_letter_code") == id);
if (rs.size() == 1) if (rs.size() == 1)
{ {
...@@ -570,7 +570,7 @@ Compound *CCP4CompoundFactoryImpl::create(const std::string &id) ...@@ -570,7 +570,7 @@ Compound *CCP4CompoundFactoryImpl::create(const std::string &id)
std::string name, group; std::string name, group;
uint32_t numberAtomsAll, numberAtomsNh; uint32_t numberAtomsAll, numberAtomsNh;
cif::tie(name, group, numberAtomsAll, numberAtomsNh) = cif::v2::tie(name, group, numberAtomsAll, numberAtomsNh) =
row.get("name", "group", "number_atoms_all", "number_atoms_nh"); row.get("name", "group", "number_atoms_all", "number_atoms_nh");
fs::path resFile = mCLIBD_MON / cif::toLowerCopy(id.substr(0, 1)) / (id + ".cif"); fs::path resFile = mCLIBD_MON / cif::toLowerCopy(id.substr(0, 1)) / (id + ".cif");
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <iomanip> #include <iomanip>
#include <numeric> #include <numeric>
#include <gzstream/gzstream.hpp> #include <zstream/zstream.hpp>
#if __cpp_lib_format #if __cpp_lib_format
#include <format> #include <format>
...@@ -1285,28 +1285,16 @@ float Branch::weight() const ...@@ -1285,28 +1285,16 @@ float Branch::weight() const
void File::load(const std::filesystem::path &path) void File::load(const std::filesystem::path &path)
{ {
std::string ext = path.extension().string(); zstream::ifstream in(path);
if (ext == ".gz")
{
gzstream::ifstream in(path);
auto ext = path.extension().string();
if (ext == ".gz" or ext = ".xz")
ext = path.stem().extension().string(); ext = path.stem().extension().string();
if (ext == ".pdb" or ext == ".ent") if (ext == ".pdb" or ext == ".ent")
ReadPDBFile(in, *this); ReadPDBFile(in, *this);
else else
cif::File::load(in); cif::File::load(in);
}
else
{
std::ifstream in(path, std::ios_base::binary);
if (ext == ".pdb" or ext == ".ent")
ReadPDBFile(in, *this);
else
cif::File::load(in);
}
// validate, otherwise lots of functionality won't work // validate, otherwise lots of functionality won't work
loadDictionary("mmcif_pdbx_v50"); loadDictionary("mmcif_pdbx_v50");
...@@ -1316,22 +1304,16 @@ void File::load(const std::filesystem::path &path) ...@@ -1316,22 +1304,16 @@ void File::load(const std::filesystem::path &path)
void File::save(const std::filesystem::path &path) void File::save(const std::filesystem::path &path)
{ {
fs::path file = path.filename(); zstream::ostream outFile(path);
std::unique_ptr<std::ostream> outFile; auto ext = path.extension().string();
if (ext == ".gz" or ext = ".xz")
if (file.extension() == ".gz") ext = path.stem().extension().string();
{
outFile.reset(new gzstream::ofstream(path));
file.replace_extension("");
}
else
outFile.reset(new std::ofstream(path, std::ios_base::out | std::ios_base::binary));
if (file.extension() == ".pdb") if (ext == ".pdb" or ext == ".ent")
WritePDBFile(*outFile, data()); WritePDBFile(outFile, data());
else else
cif::File::save(*outFile); cif::File::save(outFile);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
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