Skip to content

Commit

Permalink
Fixes for dictionary loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Jan 28, 2025
1 parent 21e224b commit 05865c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Version 7.0.9
- Using cif::file::load_dictionary it is now possible to
load a dictionary along with its extensions in one go.
E.g. file.load_dictionary("mmcif_pdbx;dssp-extension")
- Fix in compound factory to avoid errors with lower case
compound id's
- Fix sac_parser's index to be case insensitive

Version 7.0.8
- Fix PDB Remark 3 parser
Expand Down
12 changes: 11 additions & 1 deletion include/cif++/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,17 @@ class sac_parser
{
public:
/** @cond */
using datablock_index = std::map<std::string, std::size_t>;
struct iless_op
{
bool operator()(std::string a, std::string b) const
{
to_upper(a);
to_upper(b);
return a < b;
}
};

using datablock_index = std::map<std::string, std::size_t, iless_op>;

virtual ~sac_parser() = default;
/** @endcond */
Expand Down
9 changes: 4 additions & 5 deletions src/compound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto

compound *get(std::string id)
{
cif::to_upper(id);

std::shared_lock lock(mMutex);

compound *result = nullptr;
Expand All @@ -318,7 +316,8 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto
break;
}

if (result == nullptr and m_missing.count(id) == 0)
if (result == nullptr and
find_if(m_missing.begin(), m_missing.end(), [&id](const std::string &m_id) { return cif::iequals(id, m_id); }) == m_missing.end())
{
for (auto impl = shared_from_this(); impl; impl = impl->m_next)
{
Expand All @@ -328,7 +327,7 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto
}

if (result == nullptr)
m_missing.insert(id);
m_missing.emplace_back(id);
}

return result;
Expand Down Expand Up @@ -361,7 +360,7 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto
cif::parser::datablock_index m_index;

std::vector<compound *> m_compounds;
std::set<std::string> m_missing;
std::vector<std::string> m_missing;
std::shared_ptr<compound_factory_impl> m_next;
};

Expand Down
2 changes: 1 addition & 1 deletion test/unit-v2-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3482,7 +3482,7 @@ TEST_CASE("compound_test_1")
cif::compound_factory::instance().push_dictionary(gTestDir / "REA_v2.cif");
auto compound = cif::compound_factory::instance().create("REA_v2");
REQUIRE(compound != nullptr);
REQUIRE(compound->id() == "REA_v2");
REQUIRE(cif::iequals(compound->id(), "REA_v2"));
}

// --------------------------------------------------------------------
Expand Down

0 comments on commit 05865c3

Please sign in to comment.