Commit a29e3e8d by Maarten L. Hekkelman

create symop table

parent dd5df1bb
......@@ -30,6 +30,26 @@ endif()
option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Only try to recreate SymOpTable_data.hpp if CCP4 is known
option(CCP4 "The location where ccp4 is installed" "")
if(DEFINED CCP4 AND EXISTS ${CCP4})
set(CCP4 $ENV{CCP4})
set(CLIBD ${CCP4}/lib/data)
elseif(NOT DEFINED CCP4 AND DEFINED $ENV{CCP4} AND EXISTS $ENV{CCP4})
set(CCP4 $ENV{CCP4})
set(CLIBD ${CCP4}/lib/data)
endif()
if(EXISTS "${CCP4}")
option(RECREATE_SYMOP_DATA "Recreate SymOp data table in case it is out of date" ON)
if(RECREATE_SYMOP_DATA AND NOT EXISTS "${CLIBD}/syminfo.lib")
message(FATAL_ERROR "Symop data table recreation requested, but file syminfo.lib was not found in ${CLIBD}")
endif()
else()
message("Not trying to recreate SymOpTable_data.hpp since CCP4 is not defined")
endif()
# set(CMAKE_DEBUG_POSTFIX d)
if(MSVC)
......@@ -128,6 +148,27 @@ include_directories(${CMAKE_BINARY_DIR} PRIVATE)
string(TIMESTAMP BUILD_DATE_TIME "%Y-%m-%dT%H:%M:%SZ" UTC)
configure_file("${CMAKE_SOURCE_DIR}/src/revision.hpp.in" "${CMAKE_BINARY_DIR}/revision.hpp" @ONLY)
# SymOp data table
if(RECREATE_SYMOP_DATA)
# The tool to create the table
add_executable(symop-map-generator "${CMAKE_SOURCE_DIR}/tools/symop-map-generator.cpp")
target_link_libraries(symop-map-generator Threads::Threads ${Boost_LIBRARIES})
set($ENV{CLIBD} ${CLIBD})
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/src/SymOpTable_data.hpp
COMMAND $<TARGET_FILE:symop-map-generator> ${CLIBD}/syminfo.lib ${CMAKE_SOURCE_DIR}/src/SymOpTable_data.hpp
)
add_custom_target(
OUTPUT ${CMAKE_SOURCE_DIR}/src/SymOpTable_data.hpp
DEPENDS symop-map-generator "$ENV{CLIBD}/syminfo.lib"
)
endif()
# Sources
set(project_sources
......@@ -166,7 +207,7 @@ set(project_headers
${PROJECT_SOURCE_DIR}/include/cif++/TlsParser.hpp
)
add_library(cifpp ${project_sources} ${project_headers})
add_library(cifpp ${project_sources} ${project_headers} ${PROJECT_SOURCE_DIR}/src/SymOpTable_data.hpp)
set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(cifpp
......@@ -352,11 +393,11 @@ if(CIFPP_BUILD_TESTS)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Run${CIFPP_TEST}.touch
COMMAND $<TARGET_FILE:${CIFPP_TEST}>
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test)
add_test(NAME ${CIFPP_TEST}
COMMAND $<TARGET_FILE:${CIFPP_TEST}>
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test)
endforeach()
endif()
......
......@@ -48,13 +48,11 @@
#include "cif++/Cif++Export.hpp"
#if _MSC_VER
# pragma warning (disable : 4355) // this is used in Base Initializer list
# pragma warning (disable : 4996) // unsafe function or variable
# pragma warning (disable : 4996) // unsafe function or variable (strcpy e.g.)
# pragma warning (disable : 4068) // unknown pragma
# pragma warning (disable : 4996) // stl copy()
# pragma warning (disable : 4800) // BOOL conversion
# pragma warning (disable : 4100) // unreferenced formal parameter
# pragma warning (disable : 4101) // unreferenced local variable
# define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING 1
#endif
namespace cif
......
......@@ -30,7 +30,7 @@
#include "cif++/Symmetry.hpp"
#include "cif++/CifUtils.hpp"
#include "SymOpTable_data.cpp"
#include "SymOpTable_data.hpp"
namespace mmcif
{
......
......@@ -12,18 +12,29 @@ namespace po = boost::program_options;
int main(int argc, char* argv[])
{
cif::VERBOSE = 3;
mmcif::CompoundFactory::instance().pushDictionary("RXA.cif");
mmcif::File f("../examples/1cbs.cif.gz");
mmcif::Structure structure(f);
try
{
if (std::filesystem::exists("../data/components.cif"))
cif::addFileResource("components.cif", "../data/components.cif");
mmcif::CompoundFactory::instance().pushDictionary("RXA.cif");
mmcif::File f("../examples/1cbs.cif.gz");
mmcif::Structure structure(f);
auto &res = structure.getResidue("B", "REA");
structure.changeResidue(res, "RXA", {});
auto &res = structure.getResidue("B", "REA");
structure.changeResidue(res, "RXA", {});
structure.cleanupEmptyCategories();
structure.cleanupEmptyCategories();
f.file().save(std::cout);
f.file().save(std::cout);
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
return 0;
}
......@@ -26,6 +26,7 @@
#include <cassert>
#include <array>
#include <iostream>
#include <iomanip>
#include <fstream>
......@@ -33,9 +34,12 @@
#include <map>
#include <filesystem>
#include <boost/program_options.hpp>
#include <cstdlib>
namespace fs = std::filesystem;
namespace po = boost::program_options;
std::regex kNameRx(R"(^(\d+) +(\d+) +(\d+) +(\S+) +(\S+) +(\S+) +'([^']+)'( +'([^']+)')?(?: +!.+)?$)");
......@@ -185,18 +189,42 @@ int main(int argc, char* const argv[])
try
{
if (argc != 2)
throw std::runtime_error("Usage: symom-map-generator <outputfile>");
po::options_description visible_options("symop-map-generator symlib-file output-file");
visible_options.add_options()
( "help,h", "Display help message" )
( "verbose,v", "Verbose output") ;
po::options_description hidden_options("hidden options");
hidden_options.add_options()
( "input,i", po::value<std::string>(), "Input file")
( "output,o", po::value<std::string>(), "Output file");
po::options_description cmdline_options;
cmdline_options.add(visible_options).add(hidden_options);
po::positional_options_description p;
p.add("input", 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("input") == 0 or vm.count("output") == 0 or vm.count("help"))
{
std::cerr << visible_options << std::endl;
exit(vm.count("help") == 0);
}
fs::path input(vm["input"].as<std::string>());
fs::path output(vm["output"].as<std::string>());
tmpFile = output.parent_path() / (output.filename().string() + ".tmp");
tmpFile = argv[1] + ".tmp"s;
std::ofstream out(tmpFile);
if (not out.is_open())
throw std::runtime_error("Failed to open output file");
const char* CLIBD = getenv("CLIBD");
if (CLIBD == nullptr)
throw std::runtime_error("CCP4 not sourced");
// --------------------------------------------------------------------
......@@ -216,15 +244,13 @@ int main(int argc, char* const argv[])
std::map<int,SymInfoBlock> symInfo;
int symopnr, mysymnr = 10000;
std::ifstream file(CLIBD + "/syminfo.lib"s);
std::ifstream file(input);
if (not file.is_open())
throw std::runtime_error("Could not open syminfo.lib file");
enum class State { skip, spacegroup } state = State::skip;
std::string line;
std::string Hall;
std::vector<std::string> old;
const std::regex rx(R"(^symbol +(Hall|xHM|old) +'(.+?)'(?: +'(.+?)')?$)"),
rx2(R"(symbol ccp4 (\d+))");;
......@@ -383,7 +409,7 @@ const size_t kSymopNrTableSize = sizeof(kSymopNrTable) / sizeof(SymopDataBlock);
)" << std::endl;
out.close();
fs::rename(tmpFile, argv[1]);
fs::rename(tmpFile, output);
}
catch (const std::exception& ex)
{
......
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