Commit 82e73a95 by Maarten L. Hekkelman

All tests pass

parent adc316d6
......@@ -12,4 +12,6 @@ CMakeSettings.json
msvc/
Testing/
rsrc/feature-request.txt
test/test-create_sugar_2.cif
test/test-create_sugar_?.cif
test/oprofile_data/abi
test/oprofile_data/samples/operf.log
......@@ -358,6 +358,9 @@ namespace detail
std::regex mRx;
};
// TODO: Optimize and_condition by having a list of sub items.
// That way you can also collapse multiple _is_ conditions in
// case they make up an indexed tuple.
struct and_condition_impl : public condition_impl
{
and_condition_impl(condition &&a, condition &&b)
......
......@@ -609,7 +609,10 @@ class sugar : public residue
size_t get_link_nr() const
{
return m_link ? std::stoi(m_link.get_auth_seq_id()) : 0;
size_t result = 0;
if (m_link)
result = m_link.get_property_int("auth_seq_id");
return result;
}
private:
......
......@@ -307,6 +307,11 @@ class row_initializer : public std::vector<item>
row_initializer(row_handle rh);
void set_value(std::string_view name, std::string_view value);
void set_value(item &&i)
{
set_value(i.name(), i.value());
}
void set_value_if_empty(std::string_view name, std::string_view value);
void set_value_if_empty(item &&i)
{
......
......@@ -986,6 +986,11 @@ condition category::get_children_condition(row_handle rh, const category &childC
condition result;
iset mandatoryChildFields;
auto childCatValidator = m_validator->get_validator_for_category(childCat.name());
if (childCatValidator != nullptr)
mandatoryChildFields = childCatValidator->m_mandatory_fields;
for (auto &link : m_validator->get_links_for_parent(m_name))
{
if (link->m_child_category != childCat.m_name)
......@@ -1002,14 +1007,13 @@ condition category::get_children_condition(row_handle rh, const category &childC
if (parentValue.empty())
cond = std::move(cond) and key(childKey) == null;
else if (link->m_parent_keys.size() > 1 and not mandatoryChildFields.contains(childKey))
cond = std::move(cond) and (key(childKey) == parentValue.text() or key(childKey) == null);
else
cond = std::move(cond) and key(childKey) == parentValue.text();
}
if (result)
result = std::move(result) or std::move(cond);
else
result = std::move(cond);
}
return result;
......
......@@ -48,6 +48,9 @@ bool file::is_valid() const
for (auto &d : *this)
result = d.is_valid() and result;
if (result)
result = validate_links();
return result;
}
......@@ -203,6 +206,9 @@ void file::save(const std::filesystem::path &p) const
void file::save(std::ostream &os) const
{
if (not is_valid())
std::cout << "File is not valid!" << std::endl;
for (auto &db : *this)
db.write(os);
}
......
......@@ -1859,11 +1859,9 @@ void structure::change_residue(residue &res, const std::string &newCompound,
// create a copy of the entity first
auto &entity = m_db["entity"];
try
{
entityID = entity.find1<std::string>("type"_key == "non-polymer" and "pdbx_description"_key == compound->name(), "id");
}
catch (const std::exception &ex)
if (entityID.empty())
{
entityID = entity.get_unique_id("");
entity.emplace({{"id", entityID},
......@@ -1881,6 +1879,7 @@ void structure::change_residue(residue &res, const std::string &newCompound,
for (auto nps : pdbxNonPolyScheme.find("asym_id"_key == asym_id))
{
nps.assign("mon_id", newCompound, true);
nps.assign("pdb_mon_id", newCompound, true);
nps.assign("auth_mon_id", newCompound, true);
nps.assign("entity_id", entityID, true);
}
......@@ -2192,13 +2191,13 @@ std::string structure::create_non_poly(const std::string &entity_id, std::vector
atom.set_value("name", atom_id);
atom.set_value("label_asym_id", asym_id);
atom.set_value("auth_asym_id", asym_id);
atom.set_value("label_entity_id", entity_id);
atom.set_value_if_empty({"group_PDB", "HETATM"});
atom.set_value_if_empty({"label_comp_id", comp_id});
atom.set_value_if_empty({"label_seq_id", ""});
atom.set_value_if_empty({"label_entity_id", entity_id});
atom.set_value_if_empty({"auth_comp_id", comp_id});
atom.set_value_if_empty({"auth_asym_id", asym_id});
atom.set_value_if_empty({"auth_seq_id", 1});
atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
atom.set_value_if_empty({"label_alt_id", ""});
......@@ -2256,14 +2255,14 @@ branch &structure::create_branch(std::vector<row_initializer> atoms)
atom.set_value("id", atom_id);
atom.set_value("label_asym_id", asym_id);
atom.set_value("auth_asym_id", asym_id);
atom.set_value("label_entity_id", tmp_entity_id);
atom.set_value({ "auth_seq_id", 1 });
atom.set_value_if_empty({"group_PDB", "HETATM"});
atom.set_value_if_empty({"label_comp_id", "NAG"});
atom.set_value_if_empty({"label_seq_id", "."});
atom.set_value_if_empty({"label_entity_id", tmp_entity_id});
atom.set_value_if_empty({"auth_comp_id", "NAG"});
atom.set_value_if_empty({"auth_asym_id", asym_id});
atom.set_value_if_empty({"auth_seq_id", 1});
atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
atom.set_value_if_empty({"label_alt_id", ""});
......@@ -2353,12 +2352,13 @@ branch &structure::extend_branch(const std::string &asym_id, std::vector<row_ini
atom.set_value("id", atom_id);
atom.set_value("label_asym_id", asym_id);
atom.set_value("auth_asym_id", asym_id);
atom.set_value("label_entity_id", tmp_entity_id);
atom.set_value({"auth_seq_id", sugarNum });
atom.set_value_if_empty({"group_PDB", "HETATM"});
atom.set_value_if_empty({"label_comp_id", compoundID});
atom.set_value_if_empty({"label_entity_id", tmp_entity_id});
atom.set_value_if_empty({"auth_comp_id", compoundID});
atom.set_value_if_empty({"auth_asym_id", asym_id});
atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
atom.set_value_if_empty({"label_alt_id", ""});
......
......@@ -58,6 +58,11 @@ int main(int argc, char* argv[])
structure.cleanup_empty_categories();
f.save(std::cout);
if (not f.is_valid())
throw std::runtime_error("Invalid");
f.save(std::cout);
}
catch (const std::exception& e)
{
......
......@@ -135,6 +135,10 @@ BOOST_AUTO_TEST_CASE(create_sugar_1)
BOOST_CHECK_EQUAL(branch.size(), 1);
BOOST_CHECK_EQUAL(branch[0].atoms().size(), nagAtoms.size());
BOOST_CHECK(file.is_valid());
file.save(gTestDir / "test-create_sugar_1.cif");
}
// --------------------------------------------------------------------
......@@ -170,12 +174,18 @@ BOOST_AUTO_TEST_CASE(create_sugar_2)
s.remove_branch(bH);
file.save(gTestDir / "test-create_sugar_2-0.cif");
BOOST_CHECK(file.is_valid());
auto &bN = s.create_branch(ai[0]);
s.extend_branch(bN.get_asym_id(), ai[1], 1, "O4");
BOOST_CHECK_EQUAL(bN.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose-(1-4)-2-acetamido-2-deoxy-beta-D-glucopyranose");
BOOST_CHECK_EQUAL(bN.size(), 2);
BOOST_CHECK(file.is_valid());
file.save(gTestDir / "test-create_sugar_2.cif");
BOOST_CHECK_NO_THROW(cif::mm::structure s2(file));
......@@ -205,6 +215,8 @@ BOOST_AUTO_TEST_CASE(delete_sugar_1)
BOOST_CHECK_EQUAL(bN.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose");
BOOST_CHECK_EQUAL(bN.size(), 1);
BOOST_CHECK(file.is_valid());
file.save(gTestDir / "test-create_sugar_3.cif");
BOOST_CHECK_NO_THROW(cif::mm::structure s2(file));
......
......@@ -1037,12 +1037,12 @@ _cat_2.desc
cat1.erase(cif::key("id") == 10);
BOOST_CHECK_EQUAL(cat1.size(), 2);
BOOST_CHECK_EQUAL(cat2.size(), 3); // TODO: Is this really what we want?
BOOST_CHECK_EQUAL(cat2.size(), 2); // TODO: Is this really what we want?
cat1.erase(cif::key("id") == 20);
BOOST_CHECK_EQUAL(cat1.size(), 1);
BOOST_CHECK_EQUAL(cat2.size(), 2); // TODO: Is this really what we want?
BOOST_CHECK_EQUAL(cat2.size(), 1); // TODO: Is this really what we want?
}
// --------------------------------------------------------------------
......
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