Commit 510ce62d by Maarten L. Hekkelman

reconstruction fixes

parent be738e7f
...@@ -282,7 +282,11 @@ void datablock::write(std::ostream &os) const ...@@ -282,7 +282,11 @@ void datablock::write(std::ostream &os) const
cat_order_t cat_order; cat_order_t cat_order;
for (auto &cat : *this) for (auto &cat : *this)
{
if (cat.name() == "entry" or cat.name() == "audit_conform")
continue;
cat_order.emplace_back(cat.name(), -1, false); cat_order.emplace_back(cat.name(), -1, false);
}
for (auto i = cat_order.begin(); i != cat_order.end(); ++i) for (auto i = cat_order.begin(); i != cat_order.end(); ++i)
calculate_cat_order(cat_order, i, *m_validator); calculate_cat_order(cat_order, i, *m_validator);
...@@ -292,25 +296,18 @@ void datablock::write(std::ostream &os) const ...@@ -292,25 +296,18 @@ void datablock::write(std::ostream &os) const
const auto &[cat_a, count_a, on_stack_a] = a; const auto &[cat_a, count_a, on_stack_a] = a;
const auto &[cat_b, count_b, on_stack_b] = b; const auto &[cat_b, count_b, on_stack_b] = b;
int d = 0; int d = std::get<1>(a) - std::get<1>(b);
if (d == 0)
if (cat_a == "audit_conform") d = cat_b.compare(cat_a);
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);
}
return d < 0; }); 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) for (auto &&[cat, count, on_stack] : cat_order)
get(cat)->write(os); get(cat)->write(os);
} }
...@@ -320,20 +317,13 @@ void datablock::write(std::ostream &os) const ...@@ -320,20 +317,13 @@ void datablock::write(std::ostream &os) const
// and if it exists, _AND_ we have a Validator, write out the // and if it exists, _AND_ we have a Validator, write out the
// audit_conform record. // audit_conform record.
for (auto &cat : *this) if (auto entry = get("entry"); entry != nullptr)
{ entry->write(os);
if (cat.name() != "entry")
continue;
cat.write(os);
break;
}
// If the dictionary declares an audit_conform category, put it in, // If the dictionary declares an audit_conform category, put it in,
// but only if it does not exist already! // but only if it does not exist already!
if (get("audit_conform")) if (auto audit_conform = get("audit_conform"); audit_conform != nullptr)
get("audit_conform")->write(os); audit_conform->write(os);
for (auto &cat : *this) for (auto &cat : *this)
{ {
...@@ -348,7 +338,7 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &item_nam ...@@ -348,7 +338,7 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &item_nam
os << "data_" << m_name << '\n' os << "data_" << m_name << '\n'
<< "# \n"; << "# \n";
std::vector<std::string> cat_order; std::vector<std::string> cat_order{ "entry", "audit_conform" };
for (auto &o : item_name_order) for (auto &o : item_name_order)
{ {
std::string cat_name, item_name; std::string cat_name, item_name;
...@@ -360,6 +350,9 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &item_nam ...@@ -360,6 +350,9 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &item_nam
for (auto &c : cat_order) for (auto &c : cat_order)
{ {
if (c == "entry" or c == "audit_conform")
continue;
auto cat = get(c); auto cat = get(c);
if (cat == nullptr) if (cat == nullptr)
continue; continue;
......
...@@ -386,12 +386,16 @@ void checkAtomRecords(datablock &db) ...@@ -386,12 +386,16 @@ void checkAtomRecords(datablock &db)
auto chem_comp_entry = chem_comp.find_first("id"_key == comp_id); 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) if (not chem_comp_entry)
{ {
chem_comp.emplace({ // chem_comp.emplace({ //
{ "id", comp_id }, { "id", comp_id },
{ "type", compound->type() }, { "type", compound->type() },
{ "mon_nstd_flag", cf.is_std_monomer(comp_id) ? "y" : "n" }, { "mon_nstd_flag", non_std },
{ "name", compound->name() }, { "name", compound->name() },
{ "formula", compound->formula() }, { "formula", compound->formula() },
{ "formula_weight", compound->formula_weight() } }); { "formula_weight", compound->formula_weight() } });
...@@ -402,8 +406,8 @@ void checkAtomRecords(datablock &db) ...@@ -402,8 +406,8 @@ void checkAtomRecords(datablock &db)
if (not chem_comp_entry["type"]) if (not chem_comp_entry["type"])
items.emplace_back(item{ "type", compound->type() }); items.emplace_back(item{ "type", compound->type() });
if (not chem_comp_entry["mon_nstd_flag"]) if (not chem_comp_entry["mon_nstd_flag"] and non_std.has_value())
items.emplace_back(item{ "mon_nstd_flag", cf.is_std_monomer(comp_id) ? "y" : "n" }); items.emplace_back(item{ "mon_nstd_flag", non_std });
if (not chem_comp_entry["name"]) if (not chem_comp_entry["name"])
items.emplace_back(item{ "name", compound->name() }); items.emplace_back(item{ "name", compound->name() });
if (not chem_comp_entry["formula"]) if (not chem_comp_entry["formula"])
......
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