Commit b4dfdb55 by Maarten L. Hekkelman

Revert "Work around dropped categories _pdbx_item_linked_group_list and _pdbx_item_linked_group"

This reverts commit 71a46cd1.
parent d2d322ba
...@@ -13,5 +13,3 @@ libcif++.la ...@@ -13,5 +13,3 @@ libcif++.la
config.status config.status
config.log config.log
libtool libtool
version-info*.txt
rsrc/lib-version.txt
...@@ -143,6 +143,7 @@ struct ValidateLink ...@@ -143,6 +143,7 @@ struct ValidateLink
std::vector<std::string> mParentKeys; std::vector<std::string> mParentKeys;
std::string mChildCategory; std::string mChildCategory;
std::vector<std::string> mChildKeys; std::vector<std::string> mChildKeys;
std::string mLinkGroupLabel;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -1676,8 +1676,6 @@ auto Category::erase(iterator pos) -> iterator ...@@ -1676,8 +1676,6 @@ auto Category::erase(iterator pos) -> iterator
// a std::set of keys from one category is mapped to another. // a std::set of keys from one category is mapped to another.
// If all values in a child are the same as the specified parent ones // If all values in a child are the same as the specified parent ones
// the child is removed as well, recursively of course. // the child is removed as well, recursively of course.
// --------------------------------------------------------------------
// update: the category is gone, so use the stored relations instead
if (mValidator != nullptr) if (mValidator != nullptr)
{ {
...@@ -1956,7 +1954,7 @@ void Category::validateLinks() const ...@@ -1956,7 +1954,7 @@ void Category::validateLinks() const
if (missing) if (missing)
{ {
std::cerr << "Links for " << linkValidator->mParentCategory << "->" << linkValidator->mChildCategory << " are incomplete" << std::endl std::cerr << "Links for " << linkValidator->mLinkGroupLabel << " are incomplete" << std::endl
<< " There are " << missing << " items in " << mName << " that don't have matching parent items in " << parent->mName << std::endl; << " There are " << missing << " items in " << mName << " that don't have matching parent items in " << parent->mName << std::endl;
} }
} }
......
...@@ -888,10 +888,43 @@ void DictParser::linkItems() ...@@ -888,10 +888,43 @@ void DictParser::linkItems()
{ {
if (not mDataBlock) if (not mDataBlock)
error("no datablock"); error("no datablock");
auto& dict = *mDataBlock;
std::map<std::tuple<std::string,std::string,int>,size_t> linkIndex; std::map<std::tuple<std::string,std::string>,size_t> linkIndex;
std::map<std::tuple<std::string,std::string>,int> linkGroupIds;
std::vector<std::tuple<std::vector<std::string>,std::vector<std::string>>> linkKeys; std::vector<std::tuple<std::vector<std::string>,std::vector<std::string>>> linkKeys;
for (auto gl: dict["pdbx_item_linked_group_list"])
{
std::string child, parent;
int link_group_id;
cif::tie(child, parent, link_group_id) = gl.get("child_name", "parent_name", "link_group_id");
auto civ = mValidator.getValidatorForItem(child);
if (civ == nullptr)
error("in pdbx_item_linked_group_list, item '" + child + "' is not specified");
auto piv = mValidator.getValidatorForItem(parent);
if (piv == nullptr)
error("in pdbx_item_linked_group_list, item '" + parent + "' is not specified");
auto key = std::make_tuple(piv->mCategory->mName, civ->mCategory->mName);
if (not linkIndex.count(key))
{
linkIndex[key] = linkKeys.size();
linkKeys.push_back({});
linkGroupIds[key] = link_group_id;
}
size_t ix = linkIndex.at(key);
std::get<0>(linkKeys.at(ix)).push_back(piv->mTag);
std::get<1>(linkKeys.at(ix)).push_back(civ->mTag);
}
// for links recorded in categories but not in pdbx_item_linked_group_list
for (auto li: mImpl->mLinkedItems) for (auto li: mImpl->mLinkedItems)
{ {
std::string child, parent; std::string child, parent;
...@@ -904,8 +937,8 @@ void DictParser::linkItems() ...@@ -904,8 +937,8 @@ void DictParser::linkItems()
auto piv = mValidator.getValidatorForItem(parent); auto piv = mValidator.getValidatorForItem(parent);
if (piv == nullptr) if (piv == nullptr)
error("in pdbx_item_linked_group_list, item '" + parent + "' is not specified"); error("in pdbx_item_linked_group_list, item '" + parent + "' is not specified");
auto key = std::make_tuple(piv->mCategory->mName, civ->mCategory->mName, 0); auto key = std::make_tuple(piv->mCategory->mName, civ->mCategory->mName);
if (not linkIndex.count(key)) if (not linkIndex.count(key))
{ {
linkIndex[key] = linkKeys.size(); linkIndex[key] = linkKeys.size();
...@@ -918,14 +951,26 @@ void DictParser::linkItems() ...@@ -918,14 +951,26 @@ void DictParser::linkItems()
std::get<1>(linkKeys.at(ix)).push_back(civ->mTag); std::get<1>(linkKeys.at(ix)).push_back(civ->mTag);
} }
auto& linkedGroup = dict["pdbx_item_linked_group"];
// now store the links in the validator // now store the links in the validator
for (auto& kv: linkIndex) for (auto& kv: linkIndex)
{ {
ValidateLink link; ValidateLink link = {};
std::tie(link.mParentCategory, link.mChildCategory, link.mLinkGroupID) = kv.first; std::tie(link.mParentCategory, link.mChildCategory) = kv.first;
if (linkGroupIds.count(kv.first))
link.mLinkGroupID = linkGroupIds[kv.first];
std::tie(link.mParentKeys, link.mChildKeys) = linkKeys[kv.second]; std::tie(link.mParentKeys, link.mChildKeys) = linkKeys[kv.second];
// look up the label
for (auto r: linkedGroup.find(cif::Key("category_id") == link.mChildCategory and cif::Key("link_group_id") == link.mLinkGroupID))
{
link.mLinkGroupLabel = r["label"].as<std::string>();
break;
}
mValidator.addLinkValidator(std::move(link)); mValidator.addLinkValidator(std::move(link));
} }
......
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