Commit e9e1a22c by Maarten L. Hekkelman

Removed boost dependency

parent 8d05920e
[submodule "libconfig"]
path = libconfig
url = https://github.com/mhekkel/libconfig.git
[submodule "date"]
path = date
url = https://github.com/HowardHinnant/date.git
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this # 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer # list of conditions and the following disclaimer
# 2. Redistributions in binary form must reproduce the above copyright notice, # 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation # this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution. # and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
...@@ -37,6 +37,7 @@ include(CMakePackageConfigHelpers) ...@@ -37,6 +37,7 @@ include(CMakePackageConfigHelpers)
include(Dart) include(Dart)
include(FindFilesystem) include(FindFilesystem)
include(GenerateExportHeader) include(GenerateExportHeader)
include(AddGitSubmodule)
set(CXX_EXTENSIONS OFF) set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
...@@ -47,24 +48,25 @@ find_package(Filesystem REQUIRED) ...@@ -47,24 +48,25 @@ find_package(Filesystem REQUIRED)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
elseif(MSVC) elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif() endif()
if(NOT "$ENV{CCP4}" STREQUAL "") if(NOT "$ENV{CCP4}" STREQUAL "")
set(CCP4 $ENV{CCP4}) set(CCP4 $ENV{CCP4})
list(PREPEND CMAKE_MODULE_PATH "${CCP4}/Lib") list(PREPEND CMAKE_MODULE_PATH "${CCP4}/Lib")
list(APPEND CMAKE_PREFIX_PATH ${CCP4}) list(APPEND CMAKE_PREFIX_PATH ${CCP4})
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CCP4}) set(CMAKE_INSTALL_PREFIX ${CCP4})
endif() endif()
endif() endif()
if(MSVC) if(MSVC)
# make msvc standards compliant... # make msvc standards compliant...
add_compile_options(/permissive-) add_compile_options(/permissive-)
macro(get_WIN32_WINNT version) macro(get_WIN32_WINNT version)
if (WIN32 AND CMAKE_SYSTEM_VERSION) if(WIN32 AND CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION}) set(ver ${CMAKE_SYSTEM_VERSION})
string(REPLACE "." "" ver ${ver}) string(REPLACE "." "" ver ${ver})
string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver}) string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
...@@ -118,14 +120,22 @@ set(CMAKE_THREAD_PREFER_PTHREAD) ...@@ -118,14 +120,22 @@ set(CMAKE_THREAD_PREFER_PTHREAD)
set(THREADS_PREFER_PTHREAD_FLAG) set(THREADS_PREFER_PTHREAD_FLAG)
find_package(Threads) find_package(Threads)
# Note: use -DBoost_USE_STATIC_LIBS=ON to use boost static libraries
find_package(cifpp 5.0.0 REQUIRED) find_package(cifpp 5.0.0 REQUIRED)
find_package(pdbxpp 5.0.0) find_package(pdbxpp 5.0.0)
find_package(Boost COMPONENTS date_time program_options)
# The DSSP code is in a separate library, optionally to be used by others find_package(date)
if(NOT date_FOUND)
add_git_submodule(date EXCLUDE_FROM_ALL)
endif()
find_package(libconfig)
if(NOT libconfig_FOUND)
add_git_submodule(libconfig EXCLUDE_FROM_ALL)
endif()
# The DSSP code is in a separate library, optionally to be used by others
add_library(dssp_library OBJECT ${PROJECT_SOURCE_DIR}/src/DSSP.cpp) add_library(dssp_library OBJECT ${PROJECT_SOURCE_DIR}/src/DSSP.cpp)
target_link_libraries(dssp_library cifpp::cifpp pdbxpp::pdbxpp) target_link_libraries(dssp_library cifpp::cifpp pdbxpp::pdbxpp)
...@@ -136,18 +146,17 @@ add_executable(mkdssp ...@@ -136,18 +146,17 @@ add_executable(mkdssp
$<TARGET_OBJECTS:dssp_library>) $<TARGET_OBJECTS:dssp_library>)
target_include_directories(mkdssp PRIVATE ${CMAKE_BINARY_DIR}) target_include_directories(mkdssp PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(mkdssp PRIVATE dssp_library cifpp::cifpp pdbxpp::pdbxpp Boost::date_time Boost::program_options) target_link_libraries(mkdssp PRIVATE dssp_library cifpp::cifpp pdbxpp::pdbxpp date::date libconfig::libconfig)
if(USE_RSRC) if(USE_RSRC)
mrc_target_resources(mkdssp ${CIFPP_SHARE_DIR}/mmcif_pdbx.dic) mrc_target_resources(mkdssp ${CIFPP_SHARE_DIR}/mmcif_pdbx.dic)
endif() endif()
install(TARGETS ${PROJECT_NAME} install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${BIN_INSTALL_DIR} RUNTIME DESTINATION ${BIN_INSTALL_DIR}
) )
# manual # manual
if(UNIX) if(UNIX)
install(FILES doc/mkdssp.1 install(FILES doc/mkdssp.1
DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man1) DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man1)
...@@ -159,38 +168,39 @@ if(EXISTS "${CCP4}/html") ...@@ -159,38 +168,39 @@ if(EXISTS "${CCP4}/html")
endif() endif()
# test # test
if(ENABLE_TESTING)
add_executable(dssp-unit-test ${PROJECT_SOURCE_DIR}/test/dssp-unit-test.cpp ${PROJECT_SOURCE_DIR}/src/dssp_wrapper.cpp)
add_executable(dssp-unit-test ${PROJECT_SOURCE_DIR}/test/dssp-unit-test.cpp ${PROJECT_SOURCE_DIR}/src/dssp_wrapper.cpp) if(USE_RSRC)
mrc_target_resources(dssp-unit-test ${CIFPP_SHARE_DIR}/mmcif_pdbx.dic)
if(USE_RSRC) endif()
mrc_target_resources(dssp-unit-test ${CIFPP_SHARE_DIR}/mmcif_pdbx.dic)
endif()
target_include_directories(dssp-unit-test PRIVATE target_include_directories(dssp-unit-test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
) )
target_link_libraries(dssp-unit-test dssp_library cifpp::cifpp pdbxpp::pdbxpp Boost::date_time) target_link_libraries(dssp-unit-test dssp_library cifpp::cifpp pdbxpp::pdbxpp date::date)
if(MSVC) if(MSVC)
# Specify unwind semantics so that MSVC knowns how to handle exceptions # Specify unwind semantics so that MSVC knowns how to handle exceptions
target_compile_options(dssp-unit-test PRIVATE /EHsc) target_compile_options(dssp-unit-test PRIVATE /EHsc)
endif() endif()
enable_testing() enable_testing()
add_test(NAME dssp-unit-test COMMAND $<TARGET_FILE:dssp-unit-test> -- ${PROJECT_SOURCE_DIR}/test) add_test(NAME dssp-unit-test COMMAND $<TARGET_FILE:dssp-unit-test> -- ${PROJECT_SOURCE_DIR}/test)
endif()
option(DSSP_BUILD_INSTALLER "Build an installer" OFF) option(DSSP_BUILD_INSTALLER "Build an installer" OFF)
if(DSSP_BUILD_INSTALLER) if(DSSP_BUILD_INSTALLER)
include(InstallRequiredSystemLibraries) include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
# NSIS options # NSIS options
set(CPACK_NSIS_MODIFY_PATH ON) set(CPACK_NSIS_MODIFY_PATH ON)
# configuration done, include CPack # configuration done, include CPack
include(CPack) include(CPack)
endif() endif()
cmake_minimum_required(VERSION 3.19)
function(add_git_submodule dir)
# add a Git submodule directory to CMake, assuming the
# Git submodule directory is a CMake project.
#
# Usage: in CMakeLists.txt
#
# include(AddGitSubmodule.cmake)
# add_git_submodule(mysubmod_dir)
find_package(Git REQUIRED)
if(NOT EXISTS ${dir}/CMakeLists.txt)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${dir}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY)
endif()
add_subdirectory(${dir} ${ARGV})
endfunction(add_git_submodule)
\ No newline at end of file
Subproject commit 22ceabf205d8d678710a43154da5a06b701c5830
Subproject commit 606fd039f2c70632e144b9eb9f6e6796e933b728
/*- /*-
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
* *
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute * Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer * list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
...@@ -29,37 +29,32 @@ ...@@ -29,37 +29,32 @@
#endif #endif
#include <exception> #include <exception>
#include <iostream>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iostream>
#include <cfg.hpp>
#include <gxrio.hpp> #include <gxrio.hpp>
#include <pdbx++.hpp> #include <pdbx++.hpp>
#include <boost/format.hpp>
#include <boost/date_time/gregorian/formatters.hpp>
#include "DSSP.hpp" #include "DSSP.hpp"
#include <boost/program_options.hpp>
#include "dssp_wrapper.hpp" #include "dssp_wrapper.hpp"
#include "revision.hpp" #include "revision.hpp"
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace po = boost::program_options;
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// recursively print exception whats: // recursively print exception whats:
void print_what (const std::exception& e) void print_what(const std::exception &e)
{ {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
try try
{ {
std::rethrow_if_nested(e); std::rethrow_if_nested(e);
} }
catch (const std::exception& nested) catch (const std::exception &nested)
{ {
std::cerr << " >> "; std::cerr << " >> ";
print_what(nested); print_what(nested);
...@@ -68,102 +63,78 @@ void print_what (const std::exception& e) ...@@ -68,102 +63,78 @@ void print_what (const std::exception& e)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
int d_main(int argc, const char* argv[]) int d_main(int argc, const char *argv[])
{ {
using namespace std::literals; using namespace std::literals;
po::options_description visible_options(argv[0] + " [options] input-file [output-file]"s); auto &config = cfg::config::instance();
visible_options.add_options()
("dict", po::value<std::vector<std::string>>(), config.init(
"Dictionary file containing restraints for residues in this specific target, can be specified multiple times.") cfg::make_option<std::string>("output-format", "Output format, can be either 'dssp' for classic DSSP or 'mmcif' for annotated mmCIF. The default is chosen based on the extension of the output file, if any."),
("output-format", po::value<std::string>(), "Output format, can be either 'dssp' for classic DSSP or 'mmcif' for annotated mmCIF. The default is chosen based on the extension of the output file, if any.") cfg::make_option<short>("min-pp-stretch", 3, "Minimal number of residues having PSI/PHI in range for a PP helix, default is 3"),
("min-pp-stretch", po::value<short>(), "Minimal number of residues having PSI/PHI in range for a PP helix, default is 3") cfg::make_option("write-other", "If set, write the type OTHER for loops, default is to leave this out"),
("write-other", "If set, write the type OTHER for loops, default is to leave this out")
// cfg::make_option("components", po::value<std::string, "Location of the components.cif file from CCD")
// ("components", po::value<std::string>(), "Location of the components.cif file from CCD") // cfg::make_option("extra-compounds", po::value<std::string, "File containing residue information for extra compounds in this specific target, should be either in CCD format or a CCP4 restraints file")
// ("extra-compounds", po::value<std::string>(), "File containing residue information for extra compounds in this specific target, should be either in CCD format or a CCP4 restraints file") cfg::make_option<std::string>("mmcif-dictionary", "Path to the mmcif_pdbx.dic file to use instead of default"),
("mmcif-dictionary", po::value<std::string>(), "Path to the mmcif_pdbx.dic file to use instead of default")
cfg::make_option("help,h", "Display help message"),
("help,h", "Display help message") cfg::make_option("version", "Print version"),
("version", "Print version") cfg::make_option("verbose,v", "verbose output"),
("verbose,v", "verbose output")
; cfg::make_hidden_option<int>("debug,d", "Debug level (for even more verbose output)"));
po::options_description hidden_options("hidden options"); config.parse(argc, argv);
hidden_options.add_options()
("xyzin,i", po::value<std::string>(), "coordinates file")
("output,o", po::value<std::string>(), "Output to this file")
("debug,d", po::value<int>(), "Debug level (for even more verbose output)")
// ("compounds", po::value<std::string>(), "Location of the components.cif file from CCD, alias")
;
po::options_description cmdline_options;
cmdline_options.add(visible_options).add(hidden_options);
po::positional_options_description p;
p.add("xyzin", 1);
p.add("output", 1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
po::notify(vm);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
if (vm.count("version")) if (config.has("version"))
{ {
write_version_string(std::cout, vm.count("verbose")); write_version_string(std::cout, config.has("verbose"));
exit(0); exit(0);
} }
if (vm.count("help")) if (config.has("help"))
{ {
std::cerr << visible_options << std::endl; std::cerr << "Usage: mkdssp [options] input-file [output-file]" << std::endl
<< std::endl
<< config << std::endl;
exit(0); exit(0);
} }
if (vm.count("xyzin") == 0) if (config.operands().empty())
{ {
std::cerr << "Input file not specified" << std::endl; std::cerr << "Input file not specified" << std::endl;
exit(1); exit(1);
} }
if (vm.count("output-format") and vm["output-format"].as<std::string>() != "dssp" and vm["output-format"].as<std::string>() != "mmcif") if (config.has("output-format") and config.get<std::string>("output-format") != "dssp" and config.get<std::string>("output-format") != "mmcif")
{ {
std::cerr << "Output format should be one of 'dssp' or 'mmcif'" << std::endl; std::cerr << "Output format should be one of 'dssp' or 'mmcif'" << std::endl;
exit(1); exit(1);
} }
cif::VERBOSE = vm.count("verbose") != 0; cif::VERBOSE = config.count("verbose");
if (vm.count("debug")) if (config.has("debug"))
cif::VERBOSE = vm["debug"].as<int>(); cif::VERBOSE = config.get<int>("debug");
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Load extra CCD definitions, if any // Load extra CCD definitions, if any
// if (vm.count("compounds")) // if (config.has("compounds"))
// cif::add_file_resource("components.cif", vm["compounds"].as<std::string>()); // cif::add_file_resource("components.cif", config.get<std::string>("compounds"));
// else if (vm.count("components")) // else if (config.has("components"))
// cif::add_file_resource("components.cif", vm["components"].as<std::string>()); // cif::add_file_resource("components.cif", config.get<std::string>("components"));
// if (vm.count("extra-compounds"))
// mmcif::CompoundFactory::instance().pushDictionary(vm["extra-compounds"].as<std::string>());
// And perhaps a private mmcif_pdbx dictionary
if (vm.count("mmcif-dictionary")) // if (config.has("extra-compounds"))
cif::add_file_resource("mmcif_pdbx.dic", vm["mmcif-dictionary"].as<std::string>()); // mmcif::CompoundFactory::instance().pushDictionary(config.get<std::string>("extra-compounds"));
// if (vm.count("dict")) // And perhaps a private mmcif_pdbx dictionary
// { if (config.has("mmcif-dictionary"))
// for (auto dict: vm["dict"].as<std::vector<std::string>>()) cif::add_file_resource("mmcif_pdbx.dic", config.get<std::string>("mmcif-dictionary"));
// mmcif::CompoundFactory::instance().pushDictionary(dict);
// }
gxrio::ifstream in(vm["xyzin"].as<std::string>()); gxrio::ifstream in(config.operands().front());
if (not in.is_open()) if (not in.is_open())
{ {
std::cerr << "Could not open file" << std::endl; std::cerr << "Could not open file" << std::endl;
...@@ -180,19 +151,21 @@ int d_main(int argc, const char* argv[]) ...@@ -180,19 +151,21 @@ int d_main(int argc, const char* argv[])
// -------------------------------------------------------------------- // --------------------------------------------------------------------
short pp_stretch = 3; short pp_stretch = 3;
if (vm.count("min-pp-stretch")) if (config.has("min-pp-stretch"))
pp_stretch = vm["min-pp-stretch"].as<short>(); pp_stretch = config.get<short>("min-pp-stretch");
bool writeOther = vm.count("write-other"); bool writeOther = config.has("write-other");
std::string fmt; std::string fmt;
if (vm.count("output-format")) if (config.has("output-format"))
fmt = vm["output-format"].as<std::string>(); fmt = config.get<std::string>("output-format");
fs::path output;
if (config.operands().size() > 1)
output = config.operands()[1];
if (fmt.empty() and vm.count("output")) if (fmt.empty() and not output.empty())
{ {
fs::path output = vm["output"].as<std::string>();
if (output.extension() == ".gz" or output.extension() == ".xz") if (output.extension() == ".gz" or output.extension() == ".xz")
output = output.stem(); output = output.stem();
...@@ -204,9 +177,8 @@ int d_main(int argc, const char* argv[]) ...@@ -204,9 +177,8 @@ int d_main(int argc, const char* argv[])
dssp::DSSP dssp(f.front(), 1, pp_stretch, fmt == "dssp"); dssp::DSSP dssp(f.front(), 1, pp_stretch, fmt == "dssp");
if (vm.count("output")) if (not output.empty())
{ {
fs::path output = vm["output"].as<std::string>();
gxrio::ofstream out(output); gxrio::ofstream out(output);
if (not out.is_open()) if (not out.is_open())
...@@ -227,13 +199,13 @@ int d_main(int argc, const char* argv[]) ...@@ -227,13 +199,13 @@ int d_main(int argc, const char* argv[])
else else
annotateDSSP(f.front(), dssp, writeOther, std::cout); annotateDSSP(f.front(), dssp, writeOther, std::cout);
} }
return 0; return 0;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
int main(int argc, const char* argv[]) int main(int argc, const char *argv[])
{ {
int result = 0; int result = 0;
...@@ -244,7 +216,7 @@ int main(int argc, const char* argv[]) ...@@ -244,7 +216,7 @@ int main(int argc, const char* argv[])
#endif #endif
result = d_main(argc, argv); result = d_main(argc, argv);
} }
catch (const std::exception& ex) catch (const std::exception &ex)
{ {
print_what(ex); print_what(ex);
exit(1); exit(1);
......
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