Skip to content

Commit

Permalink
Add+test code to load supn_context PDBs from names
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Aug 26, 2015
1 parent 11d97b5 commit 8fc3709
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
54 changes: 54 additions & 0 deletions source/superposition/superposition_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@

#include "superposition_context.h"

#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/range/algorithm_ext/for_each.hpp>

#include "alignment/alignment_context.h"
#include "common/algorithm/transform_build.h"
#include "exception/invalid_argument_exception.h"
#include "file/pdb/pdb.h"
#include "file/pdb/pdb_atom.h"
#include "file/pdb/pdb_residue.h"
#include "options/options_block/data_dirs_options_block.h"
#include "superposition/io/superposition_io.h"

using namespace cath;
using namespace cath::align;
using namespace cath::common;
using namespace cath::file;
using namespace cath::opts;
using namespace cath::sup;
using namespace cath::sup::detail;
using namespace std;

using boost::filesystem::path;
using boost::log::trivial::severity_level;
using boost::property_tree::json_parser::write_json;
using boost::property_tree::ptree;
Expand Down Expand Up @@ -95,6 +100,55 @@ const alignment & superposition_context::get_alignment_cref() const {
return *any_alignment;
}

/// \brief Setter for the PDBs
///
/// \pre arg_pdbs.size() == get_num_entries( *this ) else this throws an invalid_argument_exception
void superposition_context::set_pdbs(const pdb_list &arg_pdbs ///< The PDBs to set
) {
if ( arg_pdbs.size() != get_num_entries( *this ) ) {
BOOST_THROW_EXCEPTION(invalid_argument_exception(
"Unable to load " + to_string( arg_pdbs.size() )
+ " pdbs into superposition context of superposition with " + to_string( get_num_entries( *this ) )
+ " entries"
));
}
pdbs = arg_pdbs;
}

/// \brief Get the number of entries in the specified superposition_context
///
/// \relates superposition_context
size_t cath::sup::get_num_entries(const superposition_context &arg_superposition_context ///< The superposition_context to query
) {
return arg_superposition_context.get_superposition_cref().get_num_entries();
}

/// \brief Load the specified superposition_context's PDBs using its names and the specified data_dirs_options_block
///
/// \relates superposition_context
void cath::sup::load_pdbs_from_names(superposition_context &arg_supn_context, ///< The superposition_context for which the PDBs should be loaded based on its names
const data_dirs_options_block &arg_data_dirs ///< The data_dirs_options_block with which to convert names into PDB filenames
) {
arg_supn_context.set_pdbs(
transform_build<pdb_vec>(
arg_supn_context.get_names_cref(),
[&] (const string &name) {
return read_pdb_file( find_file( arg_data_dirs, data_file::PDB, name ) );
}
)
);
}

/// \brief Return a copy of the specified superposition_context with the PDBs loaded using its names and the specified data_dirs_options_block
///
/// \relates superposition_context
superposition_context cath::sup::load_pdbs_from_names_copy(superposition_context arg_supn_context, ///< The superposition_context from which the copy should be taken with the PDBs loaded based on its names
const data_dirs_options_block &arg_data_dirs ///< The data_dirs_options_block with which to convert names into PDB filenames
) {
load_pdbs_from_names( arg_supn_context, arg_data_dirs );
return arg_supn_context;
}

/// \brief TODOCUMENT
///
/// \relates superposition_context
Expand Down
11 changes: 11 additions & 0 deletions source/superposition/superposition_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "superposition/superposition.h"

namespace cath { namespace align { class alignment_context; } }
namespace cath { namespace opts { class data_dirs_options_block; } }

namespace cath {
namespace sup {
Expand Down Expand Up @@ -65,8 +66,18 @@ namespace cath {
const superposition & get_superposition_cref() const;
bool has_alignment() const;
const align::alignment & get_alignment_cref() const;

void set_pdbs(const file::pdb_list &);
};

size_t get_num_entries(const superposition_context &);

void load_pdbs_from_names(superposition_context &,
const opts::data_dirs_options_block &);

superposition_context load_pdbs_from_names_copy(superposition_context,
const opts::data_dirs_options_block &);

align::alignment_context make_alignment_context(const superposition_context &);

void save_to_ptree(boost::property_tree::ptree &,
Expand Down
33 changes: 25 additions & 8 deletions source/superposition/superposition_context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@
#include "file/pdb/pdb_atom.h"
#include "file/pdb/pdb_list.h"
#include "file/pdb/pdb_residue.h"
#include "options/options_block/data_dirs_options_block.h"
#include "structure/geometry/coord_list.h"
#include "superposition/superposition_context.h"
#include "test/global_test_constants.h"

using namespace cath::file;
using namespace cath::geom;
using namespace cath::opts;
using namespace cath::sup;

namespace cath {
namespace test {

/// \brief The superposition_context_test_suite_fixture to assist in testing superposition_context
struct superposition_context_test_suite_fixture {
struct superposition_context_test_suite_fixture : protected global_test_constants {
protected:
~superposition_context_test_suite_fixture() noexcept = default;

coord_list coord_list_1{ { coord{ 1.0, 0.0, 0.0 }, coord{ 2.0, 0.0, 0.0 } } };
coord_list coord_list_2{ { coord{ 0.0, -1.0, 0.0 }, coord{ 0.0, -2.0, 0.0 } } };
superposition the_sup = create_pairwise_superposition( coord_list_1, coord_list_2 );
superposition_context the_sup_con{
const coord_list coord_list_1{ { coord{ 1.0, 0.0, 0.0 }, coord{ 2.0, 0.0, 0.0 } } };
const coord_list coord_list_2{ { coord{ 0.0, -1.0, 0.0 }, coord{ 0.0, -2.0, 0.0 } } };
const superposition the_sup = create_pairwise_superposition( coord_list_1, coord_list_2 );
const superposition_context the_sup_con {
pdb_list{ pdb_vec{ 2, pdb{} } },
str_vec { "name_a", "name_b" },
str_vec { "1c0pA01", "1hdoA00" },
the_sup
};
};
Expand All @@ -54,16 +57,30 @@ namespace cath {

BOOST_FIXTURE_TEST_SUITE(superposition_context_test_suite, cath::test::superposition_context_test_suite_fixture)

BOOST_AUTO_TEST_CASE(load_pdbs_from_names_copy_leaves_orig_empty_pdbs) {
const auto loaded_sup_con = load_pdbs_from_names_copy( the_sup_con, build_data_dirs_options_block_of_dir( TEST_SOURCE_DATA_DIR() ) );
BOOST_REQUIRE_EQUAL( the_sup_con.get_pdbs_cref().size(), 2 );
BOOST_CHECK_EQUAL ( the_sup_con.get_pdbs_cref()[ 0 ].get_num_residues(), 0 );
BOOST_CHECK_EQUAL ( the_sup_con.get_pdbs_cref()[ 1 ].get_num_residues(), 0 );
}

BOOST_AUTO_TEST_CASE(load_pdbs_from_names_copy_sets_two_pdbs_with_199_and_205_residues) {
const auto loaded_sup_con = load_pdbs_from_names_copy( the_sup_con, build_data_dirs_options_block_of_dir( TEST_SOURCE_DATA_DIR() ) );
BOOST_REQUIRE_EQUAL( loaded_sup_con.get_pdbs_cref().size(), 2 );
BOOST_CHECK_EQUAL ( loaded_sup_con.get_pdbs_cref()[ 0 ].get_num_residues(), 199 );
BOOST_CHECK_EQUAL ( loaded_sup_con.get_pdbs_cref()[ 1 ].get_num_residues(), 205 );
}

BOOST_AUTO_TEST_CASE(to_json_string_works_for_example_sup_con) {
BOOST_CHECK_EQUAL(
to_json_string( the_sup_con, false ),
R"({"entries":[{"name":"name_a","transformation":{"translation":)"
R"({"entries":[{"name":"1c0pA01","transformation":{"translation":)"
R"({"x":"0","y":"0","z":"0"},)"
R"("rotation":)"
R"([["1","0","0"],)"
R"(["0","1","0"],)"
R"(["0","0","1"])"
R"(]}},{"name":"name_b","transformation":{"translation":)"
R"(]}},{"name":"1hdoA00","transformation":{"translation":)"
R"({"x":"0","y":"0","z":"0"},)"
R"("rotation":)"
R"([["0","-1","0"],)"
Expand Down

0 comments on commit 8fc3709

Please sign in to comment.