Skip to content

Commit

Permalink
Add+test sup-to-json-file option (not functional)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Aug 28, 2015
1 parent a72cd2f commit d78439d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <boost/optional.hpp>

#include "common/clone/make_uptr_clone.h"
#include "exception/not_implemented_exception.h"
#include "options/outputter/superposition_outputter/ostream_superposition_outputter.h"
#include "options/outputter/superposition_outputter/pdb_file_superposition_outputter.h"
#include "options/outputter/superposition_outputter/pdb_files_superposition_outputter.h"
Expand All @@ -47,6 +48,7 @@ const string superposition_output_options_block::PO_SUP_TO_STDOUT ( "sup-to-s
const string superposition_output_options_block::PO_SUP_TO_PYMOL ( "sup-to-pymol" );
const string superposition_output_options_block::PO_PYMOL_PROGRAM ( "pymol-program" );
const string superposition_output_options_block::PO_SUP_TO_PYMOL_FILE( "sup-to-pymol-file" );
const string superposition_output_options_block::PO_SUP_TO_JSON_FILE ( "sup-to-json-file" );

const string superposition_output_options_block::DEFAULT_PYMOL_PROGRAM( "pymol" );

Expand All @@ -69,7 +71,8 @@ void superposition_output_options_block::do_add_visible_options_to_description(o
(PO_SUP_TO_STDOUT.c_str(), bool_switch(&sup_to_stdout)->default_value(false), "Print the superposed structures to stdout, separated using faked chain codes" )
(PO_SUP_TO_PYMOL.c_str(), bool_switch(&sup_to_pymol )->default_value(false), "Start up PyMOL for viewing the superposition" )
(PO_PYMOL_PROGRAM.c_str(), value<path>(&pymol_program)->default_value(DEFAULT_PYMOL_PROGRAM), "Use arg as the PyMOL executable for viewing; may optionally include the full path" )
(PO_SUP_TO_PYMOL_FILE.c_str(), value<path>(&sup_to_pymol_file), "Write the superposition to a PyMOL script arg\n(Recommended filename extension: .pml)" );
(PO_SUP_TO_PYMOL_FILE.c_str(), value<path>(&sup_to_pymol_file), "Write the superposition to a PyMOL script arg\n(Recommended filename extension: .pml)" )
(PO_SUP_TO_JSON_FILE.c_str(), value<path>(&json_file), "Write the superposition to JSON superposition file\n(Recommended filename extension: .sup_json)" );
}

opt_str superposition_output_options_block::do_invalid_string() const {
Expand All @@ -88,6 +91,9 @@ opt_str superposition_output_options_block::do_invalid_string() const {
if (!get_sup_to_pymol_file().empty() && !is_acceptable_output_file(get_sup_to_pymol_file())) {
return "Not a valid superposition PyMOL output file:\"" + get_sup_to_pymol_file().string() + "\"";
}
if (!get_json_file().empty() && !is_acceptable_output_file(get_json_file())) {
return "Not a valid superposition JSON output file:\"" + get_json_file().string() + "\"";
}

return none;
}
Expand Down Expand Up @@ -122,6 +128,11 @@ path superposition_output_options_block::get_sup_to_pymol_file() const {
return sup_to_pymol_file;
}

/// TODOCUMENT
path superposition_output_options_block::get_json_file() const {
return json_file;
}

superposition_outputter_list superposition_output_options_block::get_superposition_outputters(const display_spec &arg_display_spec ///< TODOCUMENT
) const {
superposition_outputter_list superposition_outputters;
Expand All @@ -140,6 +151,9 @@ superposition_outputter_list superposition_output_options_block::get_superpositi
if ( ! get_sup_to_pymol_file().empty() ) {
superposition_outputters.push_back( pymol_file_superposition_outputter( get_sup_to_pymol_file(), arg_display_spec ) );
}
if ( ! get_json_file().empty() ) {
BOOST_THROW_EXCEPTION(not_implemented_exception("Not yet implemented a JSON superposition outputter"));
}

return superposition_outputters;
}
Expand Down
11 changes: 11 additions & 0 deletions source/options/options_block/superposition_output_options_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ namespace cath { namespace opts { class superposition_outputter; } }
namespace cath { namespace opts { class superposition_outputter_list; } }
namespace cath { class display_spec; }

namespace superposition_output_options_block_test_suite { struct parses_option_for_to_json_file; }
namespace superposition_output_options_block_test_suite { struct unparsed_has_no_json_file; }

namespace cath {
namespace opts {

/// \brief TODOCUMENT
class superposition_output_options_block final : public options_block {
private:
friend struct superposition_output_options_block_test_suite::parses_option_for_to_json_file;
friend struct superposition_output_options_block_test_suite::unparsed_has_no_json_file;

using super = options_block;

static const std::string PO_SUP_FILE;
Expand All @@ -45,6 +51,7 @@ namespace cath {
static const std::string PO_SUP_TO_PYMOL;
static const std::string PO_PYMOL_PROGRAM;
static const std::string PO_SUP_TO_PYMOL_FILE;
static const std::string PO_SUP_TO_JSON_FILE;

static const std::string DEFAULT_PYMOL_PROGRAM;

Expand All @@ -54,6 +61,7 @@ namespace cath {
bool sup_to_pymol;
boost::filesystem::path sup_to_pymol_file;
boost::filesystem::path pymol_program;
boost::filesystem::path json_file;

virtual std::unique_ptr<options_block> do_clone() const override final;
virtual std::string do_get_block_name() const override final;
Expand All @@ -66,10 +74,13 @@ namespace cath {
bool get_sup_to_pymol() const;
boost::filesystem::path get_pymol_program() const;
boost::filesystem::path get_sup_to_pymol_file() const;
boost::filesystem::path get_json_file() const;

public:
virtual ~superposition_output_options_block() noexcept = default;

/// \todo Consider adding a sister get_superposition_outputters() for getting non-display outputters
/// without having to specify a display_spec
superposition_outputter_list get_superposition_outputters(const display_spec &) const;
bool outputs_to_stdout() const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@

#include <boost/test/auto_unit_test.hpp>

#include "display/display_spec/display_spec.h"
#include "exception/not_implemented_exception.h"
#include "options/options_block/options_block_tester.h"
#include "options/options_block/superposition_output_options_block.h"
#include "options/outputter/superposition_outputter/superposition_outputter.h"
#include "options/outputter/superposition_outputter/superposition_outputter_list.h"

using namespace cath;
using namespace cath::common;
using namespace cath::opts;

using boost::filesystem::path;

namespace cath {
namespace test {

/// \brief The superposition_output_options_block_test_suite_fixture to assist in testing superposition_output_options_block
struct superposition_output_options_block_test_suite_fixture {
struct superposition_output_options_block_test_suite_fixture : protected options_block_tester {
protected:
~superposition_output_options_block_test_suite_fixture() noexcept = default;
};
Expand All @@ -34,9 +47,26 @@ namespace cath {

BOOST_FIXTURE_TEST_SUITE(superposition_output_options_block_test_suite, cath::test::superposition_output_options_block_test_suite_fixture)

/// \brief TODOCUMENT
BOOST_AUTO_TEST_CASE(basic) {
BOOST_CHECK( true );
BOOST_AUTO_TEST_CASE(unparsed_has_no_json_file) {
BOOST_CHECK( superposition_output_options_block{}.get_json_file().empty() );
}

BOOST_AUTO_TEST_CASE(parses_option_for_to_json_file) {
const auto parsed_block = parse_into_options_block_copy(
superposition_output_options_block{},
{ "--sup-to-json-file", "the_filename" }
);
BOOST_CHECK_EQUAL( parsed_block.get_json_file(), path( "the_filename" ) );
}

BOOST_AUTO_TEST_CASE(option_for_to_json_file_not_yet_implemented_outputter) {
const auto parsed_block = parse_into_options_block_copy(
superposition_output_options_block{},
{ "--sup-to-json-file", "the_filename" }
);
BOOST_REQUIRE_THROW( parsed_block.get_superposition_outputters( display_spec{ "", false, false, false, false } ), not_implemented_exception );
BOOST_WARN_MESSAGE( false, "Currently testing for not_implemented_exception on attempt to use JSON superposition outputter" );
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit d78439d

Please sign in to comment.