Skip to content

Commit

Permalink
Deal with missing entity.type
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Jan 29, 2025
1 parent dcd812a commit d84a9fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cmake_minimum_required(VERSION 3.23)
# set the project name
project(
libcifpp
VERSION 7.0.9
VERSION 7.0.10
LANGUAGES CXX)

list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 7.0.10
- Deal with missing _entity.type in reconstructing mmCIF files

Version 7.0.9
- Using cif::file::load_dictionary it is now possible to
load a dictionary along with its extensions in one go.
Expand Down
27 changes: 26 additions & 1 deletion src/pdb/reconstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,35 @@ void checkEntities(datablock &db)

for (auto entity : db["entity"].find("formula_weight"_key == null or "formula_weight"_key == 0))
{
const auto &[entity_id, type] = entity.get<std::string, std::string>("id", "type");
auto &&[entity_id, type] = entity.get<std::string, std::string>("id", "type");

float formula_weight = 0;

if (type.empty()) // yes, that happens
{
const auto comp_id = db["atom_site"].find_first<std::string>("label_entity_id"_key == entity_id, "label_comp_id");
auto compound = cf.create(comp_id);
if (compound != nullptr)
{
if (compound->is_base() or compound->is_peptide())
type = "polymer";
else if (compound->is_water())
type = "water";
else
{
if (db["pdbx_entity_branch_link"].exists("entity_id"_key == entity_id))
type = "branched";
else
type = "non-polymer";
}
}

if (type.empty())
throw std::runtime_error("Entity without type and cannot determine what it should be");

entity["type"] = type;
}

if (type == "polymer")
{
int n = 0;
Expand Down

0 comments on commit d84a9fe

Please sign in to comment.