Skip to content

Commit

Permalink
reconstruction fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Feb 27, 2024
1 parent be738e7 commit 510ce62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
49 changes: 21 additions & 28 deletions src/datablock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ void datablock::write(std::ostream &os) const
cat_order_t cat_order;

for (auto &cat : *this)
{
if (cat.name() == "entry" or cat.name() == "audit_conform")
continue;
cat_order.emplace_back(cat.name(), -1, false);
}

for (auto i = cat_order.begin(); i != cat_order.end(); ++i)
calculate_cat_order(cat_order, i, *m_validator);
Expand All @@ -292,25 +296,18 @@ void datablock::write(std::ostream &os) const
const auto &[cat_a, count_a, on_stack_a] = a;
const auto &[cat_b, count_b, on_stack_b] = b;

int d = 0;

if (cat_a == "audit_conform")
d = -1;
else if (cat_b == "audit_conform")
d = 1;
else if (cat_a == "entry")
d = -1;
else if (cat_b == "entry")
d = 1;
else
{
d = std::get<1>(a) - std::get<1>(b);
if (d == 0)
d = cat_b.compare(cat_a);
}
int d = std::get<1>(a) - std::get<1>(b);
if (d == 0)
d = cat_b.compare(cat_a);

return d < 0; });

if (auto entry = get("entry"); entry != nullptr)
entry->write(os);

if (auto audit_conform = get("audit_conform"); audit_conform != nullptr)
audit_conform->write(os);

for (auto &&[cat, count, on_stack] : cat_order)
get(cat)->write(os);
}
Expand All @@ -320,20 +317,13 @@ void datablock::write(std::ostream &os) const
// and if it exists, _AND_ we have a Validator, write out the
// audit_conform record.

for (auto &cat : *this)
{
if (cat.name() != "entry")
continue;

cat.write(os);

break;
}
if (auto entry = get("entry"); entry != nullptr)
entry->write(os);

// If the dictionary declares an audit_conform category, put it in,
// but only if it does not exist already!
if (get("audit_conform"))
get("audit_conform")->write(os);
if (auto audit_conform = get("audit_conform"); audit_conform != nullptr)
audit_conform->write(os);

for (auto &cat : *this)
{
Expand All @@ -348,7 +338,7 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &item_nam
os << "data_" << m_name << '\n'
<< "# \n";

std::vector<std::string> cat_order;
std::vector<std::string> cat_order{ "entry", "audit_conform" };
for (auto &o : item_name_order)
{
std::string cat_name, item_name;
Expand All @@ -360,6 +350,9 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &item_nam

for (auto &c : cat_order)
{
if (c == "entry" or c == "audit_conform")
continue;

auto cat = get(c);
if (cat == nullptr)
continue;
Expand Down
10 changes: 7 additions & 3 deletions src/pdb/reconstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,16 @@ void checkAtomRecords(datablock &db)

auto chem_comp_entry = chem_comp.find_first("id"_key == comp_id);

std::optional<bool> non_std;
if (cf.is_monomer(comp_id))
non_std = cf.is_std_monomer(comp_id);

if (not chem_comp_entry)
{
chem_comp.emplace({ //
{ "id", comp_id },
{ "type", compound->type() },
{ "mon_nstd_flag", cf.is_std_monomer(comp_id) ? "y" : "n" },
{ "mon_nstd_flag", non_std },
{ "name", compound->name() },
{ "formula", compound->formula() },
{ "formula_weight", compound->formula_weight() } });
Expand All @@ -402,8 +406,8 @@ void checkAtomRecords(datablock &db)

if (not chem_comp_entry["type"])
items.emplace_back(item{ "type", compound->type() });
if (not chem_comp_entry["mon_nstd_flag"])
items.emplace_back(item{ "mon_nstd_flag", cf.is_std_monomer(comp_id) ? "y" : "n" });
if (not chem_comp_entry["mon_nstd_flag"] and non_std.has_value())
items.emplace_back(item{ "mon_nstd_flag", non_std });
if (not chem_comp_entry["name"])
items.emplace_back(item{ "name", compound->name() });
if (not chem_comp_entry["formula"])
Expand Down

0 comments on commit 510ce62

Please sign in to comment.