Commit 6dd9522b by Maarten L. Hekkelman

optimized mmcif::Atom

parent 5e352cb8
...@@ -134,8 +134,6 @@ if(MSVC) ...@@ -134,8 +134,6 @@ if(MSVC)
message(FATAL_ERROR "Unsupported or unknown processor type ${CMAKE_SYSTEM_PROCESSOR}") message(FATAL_ERROR "Unsupported or unknown processor type ${CMAKE_SYSTEM_PROCESSOR}")
endif() endif()
set(COFF_SPEC "--coff=${COFF_TYPE}")
# for mrc, just in case # for mrc, just in case
list(APPEND CMAKE_PREFIX_PATH "$ENV{LOCALAPPDATA}/mrc") list(APPEND CMAKE_PREFIX_PATH "$ENV{LOCALAPPDATA}/mrc")
endif() endif()
...@@ -151,12 +149,12 @@ endif() ...@@ -151,12 +149,12 @@ endif()
if(WIN32 AND BUILD_SHARED_LIBS) if(WIN32 AND BUILD_SHARED_LIBS)
message("Not using resources when building shared libraries for Windows") message("Not using resources when building shared libraries for Windows")
else() else()
find_program(MRC mrc) find_package(Mrc)
if(MRC) if(MRC_FOUND)
option(CIFPP_USE_RSRC "Use mrc to create resources" ON) option(USE_RSRC "Use mrc to create resources" ON)
else() else()
message("Using resources not possible since mrc was not found") message(WARNING "Not using resources since mrc was not found")
endif() endif()
if(CIFPP_USE_RSRC STREQUAL "ON") if(CIFPP_USE_RSRC STREQUAL "ON")
...@@ -334,6 +332,13 @@ install(TARGETS cifpp ...@@ -334,6 +332,13 @@ install(TARGETS cifpp
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(MSVC)
install(
FILES $<TARGET_PDB_FILE:${PROJECT_NAME}>
DESTINATION ${CMAKE_INSTALL_LIBDIR}
OPTIONAL)
endif()
install(EXPORT cifppTargets install(EXPORT cifppTargets
FILE "cifppTargets.cmake" FILE "cifppTargets.cmake"
NAMESPACE cifpp:: NAMESPACE cifpp::
...@@ -407,13 +412,6 @@ option(CIFPP_BUILD_TESTS "Build test exectuables" OFF) ...@@ -407,13 +412,6 @@ option(CIFPP_BUILD_TESTS "Build test exectuables" OFF)
if(CIFPP_BUILD_TESTS) if(CIFPP_BUILD_TESTS)
if(CIFPP_USE_RSRC)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cifpp_test_rsrc.obj
COMMAND ${MRC} -o ${CMAKE_CURRENT_BINARY_DIR}/cifpp_test_rsrc.obj ${CMAKE_SOURCE_DIR}/rsrc/mmcif_pdbx_v50.dic ${COFF_SPEC}
)
set(CIFPP_TEST_RESOURCE ${CMAKE_CURRENT_BINARY_DIR}/cifpp_test_rsrc.obj)
endif()
list(APPEND CIFPP_tests list(APPEND CIFPP_tests
# pdb2cif # pdb2cif
rename-compound rename-compound
...@@ -424,7 +422,7 @@ if(CIFPP_BUILD_TESTS) ...@@ -424,7 +422,7 @@ if(CIFPP_BUILD_TESTS)
set(CIFPP_TEST "${CIFPP_TEST}-test") set(CIFPP_TEST "${CIFPP_TEST}-test")
set(CIFPP_TEST_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/test/${CIFPP_TEST}.cpp") set(CIFPP_TEST_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/test/${CIFPP_TEST}.cpp")
add_executable(${CIFPP_TEST} ${CIFPP_TEST_SOURCE} ${CIFPP_TEST_RESOURCE}) add_executable(${CIFPP_TEST} ${CIFPP_TEST_SOURCE})
target_include_directories(${CIFPP_TEST} PRIVATE target_include_directories(${CIFPP_TEST} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
...@@ -433,6 +431,10 @@ if(CIFPP_BUILD_TESTS) ...@@ -433,6 +431,10 @@ if(CIFPP_BUILD_TESTS)
target_link_libraries(${CIFPP_TEST} PRIVATE Threads::Threads cifpp ${Boost_LIBRARIES} std::filesystem ${ZLIB_LIBRARIES} ${BZip2_LIBRARIES}) target_link_libraries(${CIFPP_TEST} PRIVATE Threads::Threads cifpp ${Boost_LIBRARIES} std::filesystem ${ZLIB_LIBRARIES} ${BZip2_LIBRARIES})
if(CIFPP_USE_RSRC)
mrc_target_resources(${CIFPP_TEST} ${CMAKE_SOURCE_DIR}/rsrc/mmcif_pdbx_v50.dic)
endif()
if(MSVC) if(MSVC)
# Specify unwind semantics so that MSVC knowns how to handle exceptions # Specify unwind semantics so that MSVC knowns how to handle exceptions
target_compile_options(${CIFPP_TEST} PRIVATE /EHsc) target_compile_options(${CIFPP_TEST} PRIVATE /EHsc)
......
...@@ -120,13 +120,13 @@ class Atom ...@@ -120,13 +120,13 @@ class Atom
} }
// specifications // specifications
std::string labelAtomID() const; const std::string& labelAtomID() const { return mAtomID; }
std::string labelCompID() const; const std::string& labelCompID() const { return mCompID; }
std::string labelAsymID() const; const std::string& labelAsymID() const { return mAsymID; }
std::string labelEntityID() const; std::string labelEntityID() const;
int labelSeqID() const; int labelSeqID() const { return mSeqID; }
std::string labelAltID() const; const std::string& labelAltID() const { return mAltID; }
bool isAlternate() const; bool isAlternate() const { return not mAltID.empty(); }
std::string authAtomID() const; std::string authAtomID() const;
std::string authCompID() const; std::string authCompID() const;
...@@ -159,6 +159,11 @@ class Atom ...@@ -159,6 +159,11 @@ class Atom
void swap(Atom &b) void swap(Atom &b)
{ {
std::swap(mImpl_, b.mImpl_); std::swap(mImpl_, b.mImpl_);
std::swap(mAtomID, b.mAtomID);
std::swap(mCompID, b.mCompID);
std::swap(mAsymID, b.mAsymID);
std::swap(mSeqID, b.mSeqID);
std::swap(mAltID, b.mAltID);
} }
int compare(const Atom &b) const; int compare(const Atom &b) const;
...@@ -178,6 +183,13 @@ class Atom ...@@ -178,6 +183,13 @@ class Atom
const AtomImpl *impl() const; const AtomImpl *impl() const;
struct AtomImpl *mImpl_; struct AtomImpl *mImpl_;
// cached values
std::string mAtomID;
std::string mCompID;
std::string mAsymID;
int mSeqID;
std::string mAltID;
}; };
inline void swap(mmcif::Atom &a, mmcif::Atom &b) inline void swap(mmcif::Atom &a, mmcif::Atom &b)
......
...@@ -208,11 +208,11 @@ struct AtomImpl ...@@ -208,11 +208,11 @@ struct AtomImpl
: mDb(i.mDb) : mDb(i.mDb)
, mID(i.mID) , mID(i.mID)
, mType(i.mType) , mType(i.mType)
, mAtomID(i.mAtomID) // , mAtomID(i.mAtomID)
, mCompID(i.mCompID) // , mCompID(i.mCompID)
, mAsymID(i.mAsymID) // , mAsymID(i.mAsymID)
, mSeqID(i.mSeqID) // , mSeqID(i.mSeqID)
, mAltID(i.mAltID) // , mAltID(i.mAltID)
, mLocation(i.mLocation) , mLocation(i.mLocation)
, mRefcount(1) , mRefcount(1)
, mRow(i.mRow) , mRow(i.mRow)
...@@ -235,7 +235,7 @@ struct AtomImpl ...@@ -235,7 +235,7 @@ struct AtomImpl
mRow = cat[cif::Key("id") == mID]; mRow = cat[cif::Key("id") == mID];
prefetch(); // prefetch();
} }
AtomImpl(cif::Datablock &db, cif::Row &row) AtomImpl(cif::Datablock &db, cif::Row &row)
...@@ -245,7 +245,7 @@ struct AtomImpl ...@@ -245,7 +245,7 @@ struct AtomImpl
, mRow(row) , mRow(row)
, mCompound(nullptr) , mCompound(nullptr)
{ {
prefetch(); // prefetch();
} }
AtomImpl(cif::Datablock &db, const std::string &id, cif::Row row) AtomImpl(cif::Datablock &db, const std::string &id, cif::Row row)
...@@ -255,18 +255,18 @@ struct AtomImpl ...@@ -255,18 +255,18 @@ struct AtomImpl
, mRow(row) , mRow(row)
, mCompound(nullptr) , mCompound(nullptr)
{ {
prefetch(); // prefetch();
} }
AtomImpl(const AtomImpl &impl, const Point &loc, const std::string &sym_op) AtomImpl(const AtomImpl &impl, const Point &loc, const std::string &sym_op)
: mDb(impl.mDb) : mDb(impl.mDb)
, mID(impl.mID) , mID(impl.mID)
, mType(impl.mType) , mType(impl.mType)
, mAtomID(impl.mAtomID) // , mAtomID(impl.mAtomID)
, mCompID(impl.mCompID) // , mCompID(impl.mCompID)
, mAsymID(impl.mAsymID) // , mAsymID(impl.mAsymID)
, mSeqID(impl.mSeqID) // , mSeqID(impl.mSeqID)
, mAltID(impl.mAltID) // , mAltID(impl.mAltID)
, mLocation(loc) , mLocation(loc)
, mRefcount(1) , mRefcount(1)
, mRow(impl.mRow) , mRow(impl.mRow)
...@@ -278,11 +278,11 @@ struct AtomImpl ...@@ -278,11 +278,11 @@ struct AtomImpl
{ {
} }
void prefetch() void prefetch(std::string &atomID, std::string &compID, std::string &asymID, int &seqID, std::string &altID)
{ {
// Prefetch some data // Prefetch some data
std::string symbol; std::string symbol;
cif::tie(symbol, mAtomID, mCompID, mAsymID, mSeqID, mAltID) = cif::tie(symbol, atomID, compID, asymID, seqID, altID) =
mRow.get("type_symbol", "label_atom_id", "label_comp_id", "label_asym_id", "label_seq_id", "label_alt_id"); mRow.get("type_symbol", "label_atom_id", "label_comp_id", "label_asym_id", "label_seq_id", "label_alt_id");
if (symbol != "X") if (symbol != "X")
...@@ -292,11 +292,6 @@ struct AtomImpl ...@@ -292,11 +292,6 @@ struct AtomImpl
cif::tie(x, y, z) = mRow.get("Cartn_x", "Cartn_y", "Cartn_z"); cif::tie(x, y, z) = mRow.get("Cartn_x", "Cartn_y", "Cartn_z");
mLocation = Point(x, y, z); mLocation = Point(x, y, z);
std::string compID;
cif::tie(compID) = mRow.get("label_comp_id");
// mCompound = CompoundFactory::instance().create(compID);
} }
void reference() void reference()
...@@ -373,12 +368,6 @@ struct AtomImpl ...@@ -373,12 +368,6 @@ struct AtomImpl
return *mCompound; return *mCompound;
} }
bool isWater() const
{
// mCompound may still be null here, and besides, this check is not that exciting anyway
return mCompID == "HOH" or mCompID == "H2O" or mCompID == "WAT";
}
float radius() const float radius() const
{ {
return mRadius; return mRadius;
...@@ -411,30 +400,15 @@ struct AtomImpl ...@@ -411,30 +400,15 @@ struct AtomImpl
std::get<1>(mCachedRefs.back()) = value; std::get<1>(mCachedRefs.back()) = value;
} }
int compare(const AtomImpl &b) const
{
int d = mAsymID.compare(b.mAsymID);
if (d == 0)
d = mSeqID - b.mSeqID;
if (d == 0)
d = mAtomID.compare(b.mAtomID);
return d;
}
void swapAtomLabels(AtomImpl &b)
{
std::swap(mAtomID, b.mAtomID);
}
const cif::Datablock &mDb; const cif::Datablock &mDb;
std::string mID; std::string mID;
AtomType mType; AtomType mType;
std::string mAtomID; // std::string mAtomID;
std::string mCompID; // std::string mCompID;
std::string mAsymID; // std::string mAsymID;
int mSeqID; // int mSeqID;
std::string mAltID; // std::string mAltID;
Point mLocation; Point mLocation;
int mRefcount; int mRefcount;
...@@ -461,18 +435,43 @@ struct AtomImpl ...@@ -461,18 +435,43 @@ struct AtomImpl
// //
Atom::Atom() Atom::Atom()
: mImpl_(nullptr) : Atom(nullptr)
{ {
} }
Atom::Atom(AtomImpl *impl) Atom::Atom(AtomImpl *impl)
: mImpl_(impl) : mImpl_(impl)
{ {
if (mImpl_)
mImpl_->prefetch(mAtomID, mCompID, mAsymID, mSeqID, mAltID);
} }
Atom::Atom(cif::Datablock &db, cif::Row &row) Atom::Atom(cif::Datablock &db, cif::Row &row)
: mImpl_(new AtomImpl(db, row)) : Atom(new AtomImpl(db, row))
{
}
Atom::Atom(const Atom &rhs, const Point &loc, const std::string &sym_op)
: Atom(new AtomImpl(*rhs.mImpl_, loc, sym_op))
{
}
Atom::Atom(const Atom &rhs)
: mImpl_(rhs.mImpl_)
, mAtomID(rhs.mAtomID)
, mCompID(rhs.mCompID)
, mAsymID(rhs.mAsymID)
, mSeqID(rhs.mSeqID)
, mAltID(rhs.mAltID)
{ {
if (mImpl_)
mImpl_->reference();
}
Atom::~Atom()
{
if (mImpl_)
mImpl_->release();
} }
AtomImpl *Atom::impl() AtomImpl *Atom::impl()
...@@ -494,31 +493,20 @@ Atom Atom::clone() const ...@@ -494,31 +493,20 @@ Atom Atom::clone() const
return Atom(mImpl_ ? new AtomImpl(*mImpl_) : nullptr); return Atom(mImpl_ ? new AtomImpl(*mImpl_) : nullptr);
} }
Atom::Atom(const Atom &rhs, const Point &loc, const std::string &sym_op)
: mImpl_(new AtomImpl(*rhs.mImpl_, loc, sym_op))
{
}
Atom::Atom(const Atom &rhs)
: mImpl_(rhs.mImpl_)
{
if (mImpl_)
mImpl_->reference();
}
Atom::~Atom()
{
if (mImpl_)
mImpl_->release();
}
Atom &Atom::operator=(const Atom &rhs) Atom &Atom::operator=(const Atom &rhs)
{ {
if (this != &rhs) if (this != &rhs)
{ {
if (mImpl_) if (mImpl_)
mImpl_->release(); mImpl_->release();
mImpl_ = rhs.mImpl_; mImpl_ = rhs.mImpl_;
mAtomID = rhs.mAtomID;
mCompID = rhs.mCompID;
mAsymID = rhs.mAsymID;
mSeqID = rhs.mSeqID;
mAltID = rhs.mAltID;
if (mImpl_) if (mImpl_)
mImpl_->reference(); mImpl_->reference();
} }
...@@ -604,40 +592,40 @@ float Atom::occupancy() const ...@@ -604,40 +592,40 @@ float Atom::occupancy() const
return property<float>("occupancy"); return property<float>("occupancy");
} }
std::string Atom::labelAtomID() const // const std::string& Atom::labelAtomID() const
{ // {
return impl()->mAtomID; // return impl()->mAtomID;
} // }
std::string Atom::labelCompID() const // const std::string& Atom::labelCompID() const
{ // {
return impl()->mCompID; // return impl()->mCompID;
} // }
std::string Atom::labelAsymID() const // const std::string& Atom::labelAsymID() const
{ // {
return impl()->mAsymID; // return impl()->mAsymID;
} // }
std::string Atom::labelEntityID() const std::string Atom::labelEntityID() const
{ {
return property<std::string>("label_entity_id"); return property<std::string>("label_entity_id");
} }
std::string Atom::labelAltID() const // const std::string& Atom::labelAltID() const
{ // {
return impl()->mAltID; // return impl()->mAltID;
} // }
bool Atom::isAlternate() const // bool Atom::isAlternate() const
{ // {
return not impl()->mAltID.empty(); // return not impl()->mAltID.empty();
} // }
int Atom::labelSeqID() const // int Atom::labelSeqID() const
{ // {
return impl()->mSeqID; // return impl()->mSeqID;
} // }
std::string Atom::authAsymID() const std::string Atom::authAsymID() const
{ {
...@@ -671,7 +659,7 @@ std::string Atom::authSeqID() const ...@@ -671,7 +659,7 @@ std::string Atom::authSeqID() const
std::string Atom::labelID() const std::string Atom::labelID() const
{ {
return property<std::string>("label_comp_id") + '_' + impl()->mAsymID + '_' + std::to_string(impl()->mSeqID) + ':' + impl()->mAtomID; return mCompID + '_' + mAsymID + '_' + std::to_string(mSeqID) + ':' + mAtomID;
} }
std::string Atom::pdbID() const std::string Atom::pdbID() const
...@@ -743,7 +731,8 @@ const Compound &Atom::comp() const ...@@ -743,7 +731,8 @@ const Compound &Atom::comp() const
bool Atom::isWater() const bool Atom::isWater() const
{ {
return impl()->isWater(); (void)impl();
return mCompID == "HOH" or mCompID == "H2O" or mCompID == "WAT";
} }
bool Atom::operator==(const Atom &rhs) const bool Atom::operator==(const Atom &rhs) const
...@@ -774,7 +763,13 @@ float Atom::radius() const ...@@ -774,7 +763,13 @@ float Atom::radius() const
int Atom::compare(const Atom &b) const int Atom::compare(const Atom &b) const
{ {
return impl() == b.impl() ? 0 : impl()->compare(*b.impl()); int d = mAsymID.compare(b.mAsymID);
if (d == 0)
d = mSeqID - b.mSeqID;
if (d == 0)
d = mAtomID.compare(b.mAtomID);
return d;
} }
void Atom::setID(int id) void Atom::setID(int id)
...@@ -1843,7 +1838,6 @@ void Structure::loadAtomsForModel(StructureOpenOptions options) ...@@ -1843,7 +1838,6 @@ void Structure::loadAtomsForModel(StructureOpenOptions options)
} }
} }
Structure::Structure(const Structure &s) Structure::Structure(const Structure &s)
: mFile(s.mFile) : mFile(s.mFile)
, mModelNr(s.mModelNr) , mModelNr(s.mModelNr)
...@@ -2424,7 +2418,7 @@ void Structure::swapAtoms(Atom &a1, Atom &a2) ...@@ -2424,7 +2418,7 @@ void Structure::swapAtoms(Atom &a1, Atom &a2)
auto l2 = r2["label_atom_id"]; auto l2 = r2["label_atom_id"];
l1.swap(l2); l1.swap(l2);
a1.impl()->swapAtomLabels(*a2.impl()); std::swap(a1.mAtomID, a2.mAtomID);
auto l3 = r1["auth_atom_id"]; auto l3 = r1["auth_atom_id"];
auto l4 = r2["auth_atom_id"]; auto l4 = r2["auth_atom_id"];
......
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