Compare commits

..

30 Commits

Author SHA1 Message Date
Maarten L. Hekkelman
b3dc38f2d8 update for WIN32 2023-11-02 14:12:17 +01:00
Maarten L. Hekkelman
6044d3dce3 Added cif::cell::get_volume() 2023-10-19 11:58:21 +02:00
Maarten L. Hekkelman
29446f2122 new cif::item constructors
version bump
2023-10-19 09:51:10 +02:00
Maarten L. Hekkelman
abb8673549 Better support for older cmake versions 2023-10-17 15:24:21 +02:00
Maarten L. Hekkelman
ffc8f9dcdf Better support for older cmake versions 2023-10-17 15:22:35 +02:00
Maarten L. Hekkelman
288b2bb720 update changelog 2023-10-17 12:23:59 +02:00
Maarten L. Hekkelman
fb3b7bda68 made data dir options more visible in cmake config
better error reporting in file::load
2023-10-10 13:39:13 +02:00
Maarten L. Hekkelman
6d5efe1cbd Merge branch 'trunk' of github.com:PDB-REDO/libcifpp into trunk 2023-09-26 14:40:44 +02:00
Maarten L. Hekkelman
1ceec22184 Better conversion from string to int 2023-09-26 14:40:38 +02:00
Maarten L. Hekkelman
951ff9b953 Better conversion from string to int 2023-09-26 14:39:26 +02:00
Maarten L. Hekkelman
641f06a7e7 sqrt is not constexpr on macOS 2023-09-22 09:37:15 +02:00
Maarten L. Hekkelman
915ba4ac21 describe download CCD 2023-09-18 10:49:08 +02:00
Maarten L. Hekkelman
824637d83f Update README.md, add link to documentation 2023-09-15 08:56:34 +02:00
Maarten L. Hekkelman
0871406fe3 Eigen dependency removed for clients
Typos fixed
Version bump
2023-09-14 16:03:00 +02:00
Maarten L. Hekkelman
1ad7e47b2e version bump, changelog 2023-09-14 12:53:07 +02:00
Maarten L. Hekkelman
f72a2c69d0 rename doxygen target 2023-09-14 11:14:38 +02:00
Maarten L. Hekkelman
84d9275cb8 update versionstring 2023-09-14 11:12:49 +02:00
Maarten L. Hekkelman
1b7c387c8b reintroduced get_terminal_width as an exported function 2023-09-14 09:52:52 +02:00
Maarten L. Hekkelman
2f1adbd22c clean up 2023-09-14 09:45:13 +02:00
Maarten L. Hekkelman
65031523a6 Merge branch 'trunk' of github.com:PDB-REDO/libcifpp into trunk 2023-09-14 09:15:07 +02:00
Maarten L. Hekkelman
02cc0fa0f6 Using CTest
Create docs/xml directory
2023-09-14 09:13:16 +02:00
Maarten L. Hekkelman
1e1afa023f Using CTest
Create docs/xml directory
2023-09-14 09:12:28 +02:00
Maarten L. Hekkelman
41f343c2cd Create the docs/xml directory in configure step 2023-09-13 17:01:43 +02:00
Maarten L. Hekkelman
a73c4deaca Revert changes in CMakeLists.txt for docs 2023-09-13 16:45:15 +02:00
Maarten L. Hekkelman
01a21aebc4 Fix install rules 2023-09-13 16:16:16 +02:00
Maarten L. Hekkelman
49434043f2 typo 2023-09-13 16:04:30 +02:00
Maarten L. Hekkelman
2e23877912 cleaning up a readthedocs.yaml file 2023-09-13 15:23:35 +02:00
Maarten L. Hekkelman
b737dd7df4 Even more documentation 2023-09-13 14:59:57 +02:00
Maarten L. Hekkelman
137ffaf768 Merge remote-tracking branch 'github/new-docs' into develop 2023-09-13 12:15:13 +02:00
Maarten L. Hekkelman
747c6d30d2 Added better support for std::optional in conditions 2023-09-13 12:14:04 +02:00
32 changed files with 654 additions and 261 deletions

View File

@@ -1,16 +1,16 @@
version: 2
build:
os: "ubuntu-22.04"
os: ubuntu-22.04
tools:
python: "3.11"
apt_packages:
- "doxygen"
- "cmake"
- doxygen
- cmake
jobs:
pre_build:
- "cmake -S . -B build -DBUILD_DOCUMENTATION=ON"
- "cmake --build build --target Doxygen"
- cmake -S . -B build -DBUILD_DOCUMENTATION=ON
- cmake --build build --target Doxygen
# Build from the docs/ directory with Sphinx
sphinx:

View File

@@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.16)
# set the project name
project(libcifpp VERSION 5.2.0 LANGUAGES CXX)
project(libcifpp VERSION 5.2.3 LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -36,6 +36,8 @@ include(CheckLibraryExists)
include(CMakePackageConfigHelpers)
include(CheckCXXSourceCompiles)
include(GenerateExportHeader)
include(CTest)
include(CMakeDependentOption)
set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)
@@ -49,11 +51,8 @@ elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
# Building shared libraries?
option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" OFF)
# Build documentation?
option(BUILD_DOC "Build the documentation" OFF)
option(BUILD_DOCUMENTATION "Build the documentation" OFF)
# We do not want to write an export file for all our symbols...
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
@@ -61,6 +60,14 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Optionally build a version to be installed inside CCP4
option(BUILD_FOR_CCP4 "Build a version to be installed in CCP4" OFF)
# Building shared libraries?
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
cmake_policy(SET CMP0127 NEW)
cmake_dependent_option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" OFF "NOT (BUILD_FOR_CCP4 AND WIN32)" ON)
else()
option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" OFF)
endif()
# Lots of code depend on the availability of the components.cif file
option(CIFPP_DOWNLOAD_CCD "Download the CCD file components.cif during installation" ON)
@@ -83,8 +90,6 @@ else()
endif()
# Unit tests
option(ENABLE_TESTING "Build test exectuables" OFF)
if(BUILD_FOR_CCP4)
if("$ENV{CCP4}" STREQUAL "" OR NOT EXISTS $ENV{CCP4})
message(FATAL_ERROR "A CCP4 built was requested but CCP4 was not sourced")
@@ -120,7 +125,8 @@ endif()
if(MSVC)
# make msvc standards compliant...
add_compile_options(/permissive-)
add_compile_options(/permissive- /bigobj)
add_link_options(/NODEFAULTLIB:library)
if(BUILD_SHARED_LIBS)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
@@ -292,11 +298,11 @@ set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(cifpp
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include;${PROJECT_BINARY_DIR};${EIGEN3_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include;${PROJECT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_link_libraries(cifpp PUBLIC Threads::Threads ZLIB::ZLIB Eigen3::Eigen ${CIFPP_REQUIRED_LIBRARIES})
target_link_libraries(cifpp PUBLIC Threads::Threads ZLIB::ZLIB ${CIFPP_REQUIRED_LIBRARIES} PRIVATE Eigen3::Eigen)
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_link_options(cifpp PRIVATE -undefined dynamic_lookup)
@@ -318,11 +324,12 @@ if(CIFPP_DOWNLOAD_CCD)
endif()
# Installation directories
set(CIFPP_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/libcifpp")
set(CIFPP_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/libcifpp" CACHE PATH "The directory where dictionary files are stored")
target_compile_definitions(cifpp PUBLIC DATA_DIR="${CIFPP_DATA_DIR}")
if(UNIX)
set(CIFPP_CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/libcifpp")
set(CIFPP_CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/libcifpp"
CACHE PATH "The directory where the update script stores new dictionary files")
target_compile_definitions(cifpp PUBLIC CACHE_DIR="${CIFPP_CACHE_DIR}")
set(CIFPP_ETC_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
@@ -338,7 +345,7 @@ install(TARGETS cifpp
if(MSVC AND BUILD_SHARED_LIBS)
install(
FILES $<TARGET_PDB_FILE:${PROJECT_NAME}>
FILES $<TARGET_PDB_FILE:cifpp>
DESTINATION ${CMAKE_INSTALL_LIBDIR}
OPTIONAL)
endif()
@@ -361,12 +368,6 @@ install(
COMPONENT Devel
)
install(
FILES ${PROJECT_BINARY_DIR}/cif++/exports.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cif++
COMPONENT Devel
)
install(FILES
${PROJECT_SOURCE_DIR}/rsrc/mmcif_ddl.dic
${PROJECT_SOURCE_DIR}/rsrc/mmcif_pdbx.dic
@@ -401,11 +402,10 @@ install(FILES
COMPONENT Devel
)
set(cifpp_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR})
set_target_properties(cifpp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION "${cifpp_MAJOR_VERSION}.${cifpp_MINOR_VERSION}"
INTERFACE_cifpp_MAJOR_VERSION ${cifpp_MAJOR_VERSION})
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
INTERFACE_cifpp_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set_property(TARGET cifpp APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING cifpp_MAJOR_VERSION
@@ -417,9 +417,7 @@ write_basic_package_version_file(
COMPATIBILITY AnyNewerVersion
)
if(ENABLE_TESTING)
enable_testing()
if(BUILD_TESTING)
find_package(Boost REQUIRED)
list(APPEND CIFPP_tests unit-v2 unit-3d format model rename-compound sugar spinner)
@@ -480,7 +478,7 @@ if(CIFPP_INSTALL_UPDATE_SCRIPT)
target_compile_definitions(cifpp PUBLIC CACHE_DIR="${CIFPP_CACHE_DIR}")
endif()
if(BUILD_DOC)
if(BUILD_DOCUMENTATION)
add_subdirectory(docs)
endif()

View File

@@ -1,10 +1,12 @@
libcifpp
========
# libcifpp
This library contains code to work with mmCIF and legacy PDB files.
Synopsis
--------
## Documentation
The documentation can be found at https://www.hekkelman.com/libcifpp-doc/
## Synopsis
```c++
// A simple program counting residues with an OXT atom
@@ -57,8 +59,14 @@ int main(int argc, char *argv[])
}
```
Requirements
------------
## Installation
You might be able to use libcifpp from a package manager used by your
OS distribution. But most likely this package will be out-of-date.
Therefore it is recommended to build *libcifpp* from code. It is not
hard to do.
### Requirements
The code for this library was written in C++17. You therefore need a
recent compiler to build it. For the development gcc 9.4 and clang 9.0
@@ -66,6 +74,7 @@ have been used as well as MSVC version 2019.
Other requirements are:
- [cmake](https://cmake.org) A build tool.
- [mrc](https://github.com/mhekkel/mrc), a resource compiler that
allows including data files into the executable making them easier to
install. Strictly speaking this is optional, but at the expense of
@@ -76,20 +85,20 @@ Other requirements are:
`libeigen3-dev`
- zlib, the development version of this library. On Debian/Ubuntu this
is the package `zlib1g-dev`.
- [boost](https://www.boost.org). The boost libraries are only needed if
you want to build the testing code.
- [boost](https://www.boost.org).
When building using MS Visual Studio, you will also need [libzeep](https://github.com/mhekkel/libzeep)
since MSVC does not yet provide a C++ template required by libcifpp.
Building
--------
The Boost libraries are only needed in case you want to build the test
code or if you are using GCC. That last condition is due to a long
standing bug in the implementation of std::regex. It simply crashes
on the regular expressions used in the mmcif_pdbx dictionary and so
we use the boost regex implementation instead.
This library uses [cmake](https://cmake.org). The usual way of building
and installing is to create a `build` directory and run cmake there.
### Building
On linux e.g. you would issue the following commands to build and install
libcifpp in your `$HOME/.local` folder:
Building the code is as simple as typing:
```console
git clone https://github.com/PDB-REDO/libcifpp.git --recurse-submodules
@@ -103,5 +112,9 @@ This checks out the source code from github, creates a new directory
where cmake stores its files. Run a configure, build the code and then
it installs the library and auxiliary files.
If you want to run the tests before installing, you should add `-DENABLE_TESTING=ON`
to the first cmake command.
Tests are created by default, and to test the code you can run:
```console
cmake --build build
ctest --test-dir build
```

View File

@@ -1,3 +1,20 @@
Version 5.2.3
- New constructors for cif::item, one taking std::optional values
and another taking only a name resulting in a value '.' (i.e. inapplicable).
- added cif::cell::get_volume
Version 5.2.2
- Remove dependency on Eigen3 for users of libcifpp
- Fix typos in documentation
- Do not build latex files in documentation
- Fixed conversion from string to integer, would fail on +2 e.g.
- sqrt is not constexpr, thus kGoldenRatio should be const, not constexpr
Version 5.2.1
- New versionstring module
- small fixes for generating documentation
- correctly setting SONAME
Version 5.2.0
- With lots of documentation
- Refactored coloured text output

View File

@@ -54,6 +54,10 @@ cmake_minimum_required(VERSION 3.15)
variables contained in the revision file.
#]=======================================================================]
# Record the location of this module now, not at the time the CMakeLists.txt
# is being processed
get_filename_component(_current_cmake_module_dir ${CMAKE_CURRENT_LIST_FILE} PATH)
# First locate a .git file or directory.
function(_get_git_dir _start_dir _variable)
@@ -233,7 +237,11 @@ function(write_version_header dir)
if(res EQUAL 0)
set(REVISION_STRING "${out}")
else()
message(STATUS "Git hash not found, does this project has a 'build' tag?")
endif()
else()
message(STATUS "Git hash not found")
endif()
# Check the revision string, if it matches we fill in the required info
@@ -255,141 +263,13 @@ function(write_version_header dir)
if(VERSION_STRING_OPTION_LIB_NAME)
set(VAR_PREFIX "${VERSION_STRING_OPTION_LIB_NAME}")
set(IDENT_PREFIX "${VERSION_STRING_OPTION_LIB_NAME}_")
set(BOOL_IS_MAIN "false")
else()
set(VAR_PREFIX "")
set(IDENT_PREFIX "")
set(BOOL_IS_MAIN "true")
endif()
# And finally, write out the header file
file(WRITE "${VERSION_STRING_DATA}/${file_name}.in" [[// This file was generated by VersionString.cmake
#pragma once
#include <ostream>
constexpr const char k@VAR_PREFIX@ProjectName[] = "@PROJECT_NAME@";
constexpr const char k@VAR_PREFIX@VersionNumber[] = "@PROJECT_VERSION@";
constexpr int k@VAR_PREFIX@BuildNumber = @BUILD_NUMBER@;
constexpr const char k@VAR_PREFIX@RevisionGitTag[] = "@REVISION_GIT_TAGREF@";
constexpr const char k@VAR_PREFIX@RevisionDate[] = "@REVISION_DATE_TIME@";
#ifndef VERSION_INFO_DEFINED
#define VERSION_INFO_DEFINED 1
namespace version_info_v1
{
class version_info_base
{
public:
static void write(std::ostream &os, bool verbose)
{
auto &s_head = head();
if (s_head != nullptr)
write(s_head, os, verbose);
}
protected:
version_info_base(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date)
: m_name(name)
, m_version(version)
, m_build_number(build_number)
, m_git_tag(git_tag)
, m_revision_date(revision_date)
{
auto &s_head = head();
m_next = s_head;
s_head = this;
}
static void write(const version_info_base *inst, std::ostream &os, bool verbose)
{
if (inst->m_next)
{
write(inst->m_next, os, verbose);
if (not verbose)
return;
os << '-' << std::endl;
}
os << inst->m_name << " version " << inst->m_version << std::endl;
if (verbose)
{
if (inst->m_build_number != 0)
{
os << "build: " << inst->m_build_number << ' ' << inst->m_revision_date << std::endl;
if (inst->m_git_tag[0] != 0)
os << "git tag: " << inst->m_git_tag << std::endl;
}
}
}
using version_info_ptr = version_info_base *;
static version_info_ptr &head()
{
static version_info_ptr s_head = nullptr;
return s_head;
}
const char *m_name;
const char *m_version;
int m_build_number;
const char *m_git_tag;
const char *m_revision_date;
version_info_base *m_next = nullptr;
};
template<typename T>
class version_info : public version_info_base
{
public:
using implementation_type = T;
version_info(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date)
: version_info_base(name, version, build_number, git_tag, revision_date)
{
}
struct register_object
{
register_object()
{
static implementation_type s_instance;
}
};
template<register_object&> struct reference_object;
static register_object s_registered_object;
static reference_object<s_registered_object> s_referenced_object;
};
template<typename T> typename version_info<T>::register_object version_info<T>::s_registered_object;
}
inline void write_version_string(std::ostream &os, bool verbose)
{
version_info_v1::version_info_base::write(os, verbose);
}
#endif
class version_info_@IDENT_PREFIX@impl : public version_info_v1::version_info<version_info_@IDENT_PREFIX@impl>
{
public:
version_info_@IDENT_PREFIX@impl()
: version_info(k@VAR_PREFIX@ProjectName, k@VAR_PREFIX@VersionNumber, k@VAR_PREFIX@BuildNumber, k@VAR_PREFIX@RevisionGitTag, k@VAR_PREFIX@RevisionDate)
{
}
};
]])
configure_file("${VERSION_STRING_DATA}/${file_name}.in" "${dir}/${file_name}" @ONLY)
configure_file("${_current_cmake_module_dir}/revision.hpp.in" "${dir}/${file_name}" @ONLY)
endfunction()

View File

@@ -11,7 +11,6 @@ include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(ZLIB REQUIRED)
find_dependency(Eigen3 REQUIRED)
if(MSVC)
find_dependency(zeep REQUIRED)

121
cmake/revision.hpp.in Normal file
View File

@@ -0,0 +1,121 @@
// This file was generated by VersionString.cmake
#pragma once
#include <ostream>
constexpr const char k@VAR_PREFIX@ProjectName[] = "@PROJECT_NAME@";
constexpr const char k@VAR_PREFIX@VersionNumber[] = "@PROJECT_VERSION@";
constexpr int k@VAR_PREFIX@BuildNumber = @BUILD_NUMBER@;
constexpr const char k@VAR_PREFIX@RevisionGitTag[] = "@REVISION_GIT_TAGREF@";
constexpr const char k@VAR_PREFIX@RevisionDate[] = "@REVISION_DATE_TIME@";
#ifndef VERSION_INFO_DEFINED
#define VERSION_INFO_DEFINED 1
namespace version_info_v1_1
{
class version_info_base
{
public:
static void write_version_string(std::ostream &os, bool verbose)
{
auto s_main = registered_main();
if (s_main != nullptr)
s_main->write(os, verbose);
if (verbose)
{
for (auto lib = registered_libraries(); lib != nullptr; lib = lib->m_next)
{
os << "-\n";
lib->write(os, verbose);
}
}
}
protected:
version_info_base(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date, bool is_main)
: m_name(name)
, m_version(version)
, m_build_number(build_number)
, m_git_tag(git_tag)
, m_revision_date(revision_date)
{
if (is_main)
registered_main() = this;
else
{
auto &s_head = registered_libraries();
m_next = s_head;
s_head = this;
}
}
void write(std::ostream &os, bool verbose)
{
os << m_name << " version " << m_version << '\n';
if (verbose)
{
if (m_build_number != 0)
{
os << "build: " << m_build_number << ' ' << m_revision_date << '\n';
if (m_git_tag[0] != 0)
os << "git tag: " << m_git_tag << '\n';
}
}
}
using version_info_ptr = version_info_base *;
static version_info_ptr &registered_main()
{
static version_info_ptr s_main = nullptr;
return s_main;
}
static version_info_ptr &registered_libraries()
{
static version_info_ptr s_head = nullptr;
return s_head;
}
const char *m_name;
const char *m_version;
int m_build_number;
const char *m_git_tag;
const char *m_revision_date;
version_info_base *m_next = nullptr;
};
template <typename T>
class version_info : public version_info_base
{
public:
using implementation_type = T;
version_info(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date, bool is_main)
: version_info_base(name, version, build_number, git_tag, revision_date, is_main)
{
}
};
} // namespace version_info_v1_1
inline void write_version_string(std::ostream &os, bool verbose)
{
version_info_v1_1::version_info_base::write_version_string(os, verbose);
}
#endif
const class version_info_@IDENT_PREFIX@impl : public version_info_v1_1::version_info<version_info_@IDENT_PREFIX@impl>
{
public:
version_info_@IDENT_PREFIX@impl()
: version_info(k@VAR_PREFIX@ProjectName, k@VAR_PREFIX@VersionNumber, k@VAR_PREFIX@BuildNumber, k@VAR_PREFIX@RevisionGitTag, k@VAR_PREFIX@RevisionDate, @BOOL_IS_MAIN@)
{
}
} s_version_info_@IDENT_PREFIX@instance;

View File

@@ -7,37 +7,42 @@ set(CIFPP_PUBLIC_HEADER_DIR ${PROJECT_SOURCE_DIR}/include)
file(GLOB_RECURSE CIFPP_PUBLIC_HEADERS ${CIFPP_PUBLIC_HEADER_DIR}/*.hpp)
set(DOXYGEN_INPUT_DIR ${CIFPP_PUBLIC_HEADER_DIR})
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml)
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/xml)
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/index.xml)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
#Replace variables inside @@ with the current values
# Replace variables inside @@ with the current values
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}) #Doxygen won't create this for us
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${DOXYGEN_OUTPUT_DIR}/xml
DEPENDS ${CIFPP_PUBLIC_HEADERS} ${DOXYFILE_OUT}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
COMMENT "Generating docs")
add_custom_command(
OUTPUT ${DOXYGEN_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${DOXYGEN_OUTPUT_DIR})
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${DOXYGEN_OUTPUT_DIR}
DEPENDS ${DOXYGEN_OUTPUT_DIR} ${CIFPP_PUBLIC_HEADERS} ${DOXYFILE_OUT}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
COMMENT "Generating docs")
add_custom_target("Doxygen-${PROJECT_NAME}" ALL DEPENDS ${DOXYGEN_INDEX_FILE})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_SOURCE_DIR}/conf.py @ONLY)
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
add_custom_target(Sphinx ALL
COMMAND
${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.${PROJECT_NAME}=${DOXYGEN_OUTPUT_DIR}/xml
${SPHINX_SOURCE} ${SPHINX_BUILD}
DEPENDS ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/api
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx")
add_custom_target("Sphinx-${PROJECT_NAME}" ALL
COMMAND ${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.${PROJECT_NAME}=${DOXYGEN_OUTPUT_DIR}
${SPHINX_SOURCE} ${SPHINX_BUILD}
DEPENDS ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/api
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sphinx/ DESTINATION ${CMAKE_INSTALL_DOCDIR} PATTERN .doctrees EXCLUDE)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sphinx/
DESTINATION ${CMAKE_INSTALL_DOCDIR}
PATTERN .doctrees EXCLUDE
PATTERN .buildinfo EXCLUDE)

View File

@@ -3,6 +3,7 @@ FILE_PATTERNS = *.hpp
STRIP_FROM_PATH = @DOXYGEN_INPUT_DIR@
RECURSIVE = YES
GENERATE_XML = YES
GENERATE_LATEX = NO
PREDEFINED += and=&& or=|| not=! CIFPP_EXPORT= HAVE_LIBCLIPPER=1
GENERATE_HTML = NO
GENERATE_TODOLIST = NO

View File

@@ -161,6 +161,50 @@ Returning a complete set if often not required, if you only want to have the fir
There are cases when you really need exactly one result. The :cpp:func:`cif::category::find1` can be used in that case, it will throw an exception if the query does not result in exactly one row.
NULL and ANY
------------
Sometimes items may be empty. The trouble is a bit that empty comes in two flavors: unknown and null. Null in *CIF* parlance means the item should not contain a value since it makes no sense in this case, the value stored in the file is a single dot character: ``'.'``. E.g. *atom_site* records may have a NULL value for label_seq_id for atoms that are part of a *non-polymer*.
The other empty value is indicated by a question mark character: ``'?'``. This means the value is simply unknown.
Both these are NULL in *libcifpp* conditions and can be searched for using :cpp:var:`cif::null`.
So you can search for:
.. code-block:: cpp
cif::condition c = "label_seq_id"_key == cif::null;
You might also want to look for a certain value and don't care in which item it is stored, in that case you can use :cpp:var:`cif::any`.
.. code-block:: cpp
cif::condition c = cif::any == "foo";
And in linked record you might have the items that have a value in both parent and child or both should be NULL. For that, you can request the value to return by find to be of type std::optional and then use that value to build the query. An example to explain this, let's find the location of the atom that is referenced as the first atom in a struct_conn record:
.. code-block:: cpp
// Take references to the two categories we need
auto struct_conn = db["struct_conn"];
auto atom_site = db["atom_site"];
// Loop over all rows in struct_conn taking only the values we need
// Note that the label_seq_id is returned as a std::optional<int>
// That means it may contain an integer or may be empty
for (const auto &[asym1, seqid1, authseqid1, atomid1] :
struct_conn.rows<std::string,std::optional<int>,std::string,std::string,std::string>(
"ptnr1_label_asym_id", "ptnr1_label_seq_id", "ptnr1_auth_seq_id", "ptnr1_label_atom_id"
))
{
// Find the location of the first atom
cif::point p1 = atom_site.find1<float,float,float>(
"label_asym_id"_key == asym1 and "label_seq_id"_key == seqid1 and "auth_seq_id"_key == authseqid1 and "label_atom_id"_key == atomid1,
"cartn_x", "cartn_y", "cartn_z");
}
Validation
----------

49
docs/bitsandpieces.rst Normal file
View File

@@ -0,0 +1,49 @@
Bits & Pieces
=============
The *libcifpp* library offers some extra code that makes the life of developers a bit easier.
gzio
----
To work with compressed data files a *std::streambuf* implemenation was added based on the code in `gxrio <https://github.com/mhekkel/gxrio>`_. This allows you to read and write compressed data streams transparently.
When working with files you can use :cpp:class:`cif::gzio::ifstream` and :cpp:class:`cif::gzio::ofstream`. The selection of whether to use compression or not is based on the file extension. If it is ``.gz`` gzip compression is used:
.. code-block:: cpp
cif::gzio::ifstream file("my-file.txt.gz");
std::string line;
while (std::getline(file, line))
std::cout << line << '\n';
Writing is equally easy:
.. code-block:: cpp
cif::gzio::ofstream file("/tmp/output.txt.gz");
file << "Hello, world!";
file.close();
You can also use the :cpp:class:`cif::gzio::istream` and feed it a *std::streambuf* object that may or may not contain compressed data. In that case the first bytes of the input are sniffed and if it is gzip compressed data, decompression will be done.
A progress bar
--------------
Applications based on *libcifpp* may have a longer run time. To give some feedback to the user running your application in a terminal you can use the :cpp:class:`cif::progress_bar`. This class will display an ASCII progress bar along with optional status messages, but only if output is to a real TTY (terminal).
A progress bar is also shown only if the duration is more than two seconds. To avoid having flashing progress bars for short actions.
The progress bar uses an internal progress counter that starts at zero and ends when the max value has been reached after which it will be removed from the screen. Updating this internal progress counter can be done by adding a number of steps calling :cpp:func:`cif::progress_bar::consumed` or by setting the exact value for the counter by calling :cpp:func:`cif::progress_bar::progress`.
Colouring output
----------------
It is also nice to emphasise some output in the terminal by using colours. For this you can create output manipulators using :cpp:func:`cif::coloured`. To write a string in white, and bold letters on a red background you can do:
.. code-block:: cpp
using namespace cif::colour;
std::cout << cif::coloured("Hello, world!", white, red, bold) << '\n';

33
docs/compound.rst Normal file
View File

@@ -0,0 +1,33 @@
Chemical Compounds
==================
The data in *CIF* and *mmCIF* files often describes the structure of some chemical compounds. The structure is recorded in the categories *atom_site* and friends. Records in these categories refer to chemical compounds using a compound ID. This compound ID is the ID field of the *chem_comp* category. For all of the known compounds in the PDB there is an entry in the Chemical Compounds Dictionary or `CCD <https://www.wwpdb.org/data/ccd>`_. If *libcifpp* was properly installed you have a copy of this file somewhere on your disk. And if you have installed the update scripts, a fresh version of this file will be retrieved weekly.
As an alternative to CCD there are the monomer library files from `CCP4 <https://www.ccp4.ac.uk/>`_. These contain somewhat different data but the overlap is good enough for usage in *libcifpp*.
Information about compounds is captured in the :cpp:class:`cif::compound`. An instance of a compound object for a certain compound ID can be obtained by using the singleton :cpp:class:`cif::compound_factory`.
If the compound you want to use is not available in the CCD or in CCP4, you can add that information yourself. For this you can use the method :cpp:func:`cif::compound_factory::push_dictionary`.
So, given that we have CCD, CCP4 monomer library and used defined compound definitions, what will you get when you try to retrieve such a compound by ID? The answer is, the factory has a stack of compound generators. The first thrown on the stack is the one for a CCD file (*components.cif*) if it can be found. Then, if the *CLIBD_MON* environmental variable is defined, a generator for monomer library files is added to the stack. And then all generators for files you added using *push_dictionary* are added in order. The generators are searched in the reverse order in which they were added to see if it creates a compound object for the ID. If no compound was created at all, nullptr is returned.
Updating CCD
------------
The CCD data is stored in a single file called *components.cif* and can be downloaded from `CCD <https://www.wwpdb.org/data/ccd>`_.
As can be read in the section on resources (:doc:`/resources`) files in libcifpp are loaded in a specific order. If the CCD datafile was downloaded during installation, a copy can be found in the directory */usr/share/libcifpp/* (if you installed in */usr*). This is a static file and will not be updated until the next installation of libcifpp.
When configuring libcifpp, you can specify the *CIFPP_INSTALL_UPDATE_SCRIPT* option, as in:
.. code-block:: console
cmake -S . -B build -DCIFPP_INSTALL_UPDATE_SCRIPT=ON # ... more options?
This will install a script named *update-libcifpp-data* in */etc/cron.weekly* or */etc/periodic/weekly*. This file uses a config file named */etc/libcifpp.conf* which you then need to edit. In this config file the following line needs to be uncommented:
.. code-block:: console
# update=true
After that, the update script will weekly download the latest components.cif file to */var/cache/libcifpp*.

View File

@@ -36,8 +36,11 @@ Using *libcifpp* is easy, if you are familiar with modern C++:
self
basics.rst
compound.rst
model.rst
resources.rst
symmetry.rst
bitsandpieces.rst
api/library_root.rst
genindex.rst

36
docs/model.rst Normal file
View File

@@ -0,0 +1,36 @@
Molecular Model
===============
Theoretically it is possible to get along with only the classes *cif::file*, *cif::datablock* and *cif::category*. But to keep your data complete and valid you then have to update lots of categories for all but the simplest manipulations. For this *libcifpp* comes with a higher level API modelling atoms, residues, monomers, polymers and complete structures in their respective classes.
Note that these classes only work properly if you are using *mmCIF* files and have an mmcif_pdbx dictionary available, either compiled in using `mrc <https://github.com/mhekkel/mrc.git>`_ or installed in the proper location.
.. note::
This part of *libcifpp* is the least developed part. What is available should work but functionality should eventually be extended.
Atom
----
The :cpp:class:`cif::mm::atom` is a lightweight proxy class giving access to the data stored in *atom_site* and *atom_site_anisotrop*. It only caches the most often used item data and every modification is directly written back into the *mmCIF* categories.
Atoms can be copied by value with low cost. The atom class only contains a pointer to an implementation that is reference counted.
Residue, Monomer and Polymer
----------------------------
The :cpp:class:`cif::mm::residue`, :cpp:class:`cif::mm::monomer` and :cpp:class:`cif::mm::polymer` implement what you'd expect. A monomer is a residue that is part of a polymer and thus has a sequence number and siblings.
Sugars & Branches
-----------------
There are also classes for modelling sugars and sugar branches. You can create sugar branches
Structure
---------
The :cpp:class:`cif::mm::structure` can be used to load one of the models from an *mmCIF* file. By default the first model is loaded. (Multiple models are often only available files containing structures defined using NMR).
A structure holds a reference to a *cif::datablock* and retrieves its data from this datablock and writes any modification back into that datablock.
One of the most useful parts of the structure class is the ability to create and modify residues. This updates related *chem_comp* and *entity* categories as well.

View File

@@ -20,6 +20,20 @@ Matrix
Although Quaternions are the preferred way of doing rotations, not every manipulation is a rotation and thus we need a matrix class as well. Matrices and their operations are encoded as matrix_expressions in *libcifpp* allowing the compiler to generate very fast code. See the :ref:`file_cif++_matrix.hpp` for what is on offer.
Crystals
--------
The *CIF* and *mmCIF* were initially developed to store crystallographic information on structures. Apart from coordinates and the chemical information the crystallographic information is important. This information can be split into two parts, a unit cell and a set of :ref:`symmetry-ops` making up a spacegroup. The spacegroup number and name are stored in the *symmetry* category. The corresponding symmetry operations can be obtained in *libcifpp* by using the :cpp:class:`cif::spacegroup`. The cell is stored in the category *cell* and likewise can be loaded using the :cpp:class:`cif::cell`. Together these two classes make up a crystal and so we have a :cpp:class:`cif::crystal` which contains both. You can easily create such a crystal object by passing the datablock containing the data to the constructor. As in:
.. code:: cpp
// Load the file
cif::file f("1cbs.cif.gz");
auto &db = f.front();
cif::crystal c(db);
.. _symmetry-ops:
Symmetry operations
-------------------
@@ -31,21 +45,28 @@ To give an idea how this works, here's a piece of code copied from one of the un
.. code:: cpp
using namespace cif::literals;
// Load the file
cif::file f(gTestDir / "2bi3.cif.gz");
// Simply assume we can use the first datablock
auto &db = f.front();
cif::mm::structure s(db);
// Load the crystal information
cif::crystal c(db);
// Take references to the two categories we need
auto struct_conn = db["struct_conn"];
auto atom_site = db["atom_site"];
// Loop over all rows in struct_conn taking only the values we need
for (const auto &[
asym1, seqid1, authseqid1, atomid1, symm1,
asym2, seqid2, authseqid2, atomid2, symm2,
dist] : struct_conn.find<
std::string,int,std::string,std::string,std::string,
std::string,int,std::string,std::string,std::string,
std::string,std::optional<int>,std::string,std::string,std::string,
std::string,std::optional<int>,std::string,std::string,std::string,
float>(
cif::key("ptnr1_symmetry") != "1_555" or cif::key("ptnr2_symmetry") != "1_555",
"ptnr1_label_asym_id", "ptnr1_label_seq_id", "ptnr1_auth_seq_id", "ptnr1_label_atom_id", "ptnr1_symmetry",
@@ -53,25 +74,35 @@ To give an idea how this works, here's a piece of code copied from one of the un
"pdbx_dist_value"
))
{
auto &r1 = s.get_residue(asym1, seqid1, authseqid1);
auto &r2 = s.get_residue(asym2, seqid2, authseqid2);
// Find the location of the first atom
cif::point p1 = atom_site.find1<float,float,float>(
"label_asym_id"_key == asym1 and "label_seq_id"_key == seqid1 and "auth_seq_id"_key == authseqid1 and "label_atom_id"_key == atomid1,
"cartn_x", "cartn_y", "cartn_z");
auto a1 = r1.get_atom_by_atom_id(atomid1);
auto a2 = r2.get_atom_by_atom_id(atomid2);
// Find the location of the second atom
cif::point p2 = atom_site.find1<float,float,float>(
"label_asym_id"_key == asym2 and "label_seq_id"_key == seqid2 and "auth_seq_id"_key == authseqid2 and "label_atom_id"_key == atomid2,
"cartn_x", "cartn_y", "cartn_z");
auto sa1 = c.symmetry_copy(a1.get_location(), cif::sym_op(symm1));
auto sa2 = c.symmetry_copy(a2.get_location(), cif::sym_op(symm2));
// Calculate the position of the first atom using the symmetry operator defined in struct_conn
auto sa1 = c.symmetry_copy(p1, cif::sym_op(symm1));
BOOST_TEST(cif::distance(sa1, sa2) == dist);
// Calculate the position of the second atom using the symmetry operator defined in struct_conn
auto sa2 = c.symmetry_copy(p2, cif::sym_op(symm2));
auto pa1 = a1.get_location();
// The distance between these symmetry atoms should be equal to the distance in the struct_conn record
assert(cif::distance(sa1, sa2) == dist);
const auto &[d, p, so] = c.closest_symmetry_copy(pa1, a2.get_location());
// And to show how you can obtain the closest symmetry copy of an atom near another one:
// here we request the symmetry copy of p2 that lies closest to p1
const auto &[d, p, so] = c.closest_symmetry_copy(p1, p2);
BOOST_TEST(p.m_x == sa2.m_x);
BOOST_TEST(p.m_y == sa2.m_y);
BOOST_TEST(p.m_z == sa2.m_z);
// And that should of course be equal to the location in struct_conn for p2
assert(p.m_x == sa2.m_x);
assert(p.m_y == sa2.m_y);
assert(p.m_z == sa2.m_z);
BOOST_TEST(d == dist);
BOOST_TEST(so.string() == symm2);
// Distance and symmetry operator string should also be the same
assert(d == dist);
assert(so.string() == symm2);
}

View File

@@ -48,6 +48,9 @@
/// may also be generated from the CCP4 monomer library.
///
/// Note that the information in CCP4 and CCD is not equal.
///
/// See also :doc:`/compound` for more information.
namespace cif
{

View File

@@ -1061,6 +1061,19 @@ inline condition operator!=(const key &key, const empty_type &)
return condition(new detail::key_is_not_empty_condition_impl(key.m_item_tag));
}
/**
* @brief Create a condition to search any column for a value @a v if @a v contains a value
* compare to null if not.
*/
template <typename T>
condition operator==(const key &key, const std::optional<T> &v)
{
if (v.has_value())
return condition(new detail::key_equals_condition_impl({ key.m_item_tag, *v }));
else
return condition(new detail::key_is_empty_condition_impl(key.m_item_tag));
}
/**
* @brief Operator to create a boolean opposite of the condition in @a rhs
*/

View File

@@ -28,7 +28,6 @@
#include <list>
#include "cif++/exports.hpp"
#include "cif++/datablock.hpp"
#include "cif++/parser.hpp"

View File

@@ -26,8 +26,6 @@
#pragma once
#include "cif++/exports.hpp"
#include <string>
#include <vector>

View File

@@ -51,14 +51,51 @@ namespace cif
{
// --------------------------------------------------------------------
/// \brief item is a transient class that is used to pass data into rows
/// but it also takes care of formatting data.
/** @brief item is a transient class that is used to pass data into rows
* but it also takes care of formatting data.
*
*
*
* The class cif::item is often used implicitly when creating a row in a category
* using the emplace function.
*
* @code{.cpp}
* cif::category cat("my-cat");
* cat.emplace({
* { "item-1", 1 }, // <- stores an item with value 1
* { "item-2", 1.0, 2 }, // <- stores an item with value 1.00
* { "item-3", std::optional<int>() }, // <- stores an item with value ?
* { "item-4", std::make_optional<int>(42) }, // <- stores an item with value 42
* { "item-5" } // <- stores an item with value .
* });
*
* std::cout << cat << '\n';
* @endcode
*
* Will result in:
*
* @code{.txt}
* _my-cat.item-1 1
* _my-cat.item-2 1.00
* _my-cat.item-3 ?
* _my-cat.item-4 42
* _my-cat.item-5 .
* @endcode
*/
class item
{
public:
/// \brief Default constructor, empty item
item() = default;
/// \brief constructor for an item with name \a name and as
/// content the character '.', i.e. an inapplicable value.
item(std::string_view name)
: m_name(name)
, m_value({ '.' })
{
}
/// \brief constructor for an item with name \a name and as
/// content a single character string with content \a value
item(std::string_view name, char value)
@@ -68,7 +105,7 @@ class item
}
/// \brief constructor for an item with name \a name and as
/// content a the formatted floating point value \a value with
/// content the formatted floating point value \a value with
/// precision \a precision
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
item(std::string_view name, const T &value, int precision)
@@ -110,7 +147,7 @@ class item
}
/// \brief constructor for an item with name \a name and as
/// content a the formatted integral value \a value
/// content the formatted integral value \a value
template <typename T, std::enable_if_t<std::is_integral_v<T> and not std::is_same_v<T, bool>, int> = 0>
item(const std::string_view name, const T &value)
: m_name(name)
@@ -127,7 +164,7 @@ class item
}
/// \brief constructor for an item with name \a name and as
/// content a the formatted boolean value \a value
/// content the formatted boolean value \a value
template <typename T, std::enable_if_t<std::is_same_v<T, bool>, int> = 0>
item(const std::string_view name, const T &value)
: m_name(name)
@@ -143,6 +180,37 @@ class item
{
}
/// \brief constructor for an item with name \a name and as
/// content the optional value \a value
template <typename T>
item(const std::string_view name, const std::optional<T> &value)
: m_name(name)
{
if (value.has_value())
{
item tmp(name, *value);
std::swap(tmp.m_value, m_value);
}
else
m_value.assign("?");
}
/// \brief constructor for an item with name \a name and as
/// content the formatted floating point value \a value with
/// precision \a precision
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
item(std::string_view name, const std::optional<T> &value, int precision)
: m_name(name)
{
if (value.has_value())
{
item tmp(name, *value, precision);
std::swap(tmp.m_value, m_value);
}
else
m_value.assign("?");
}
/** @cond */
item(const item &rhs) = default;
item(item &&rhs) noexcept = default;
@@ -287,7 +355,7 @@ struct item_handle
/**
* @brief Assign value @a value to the item referenced
*
*
* @tparam T Type of the value
* @param value The value
* @return reference to this item_handle
@@ -459,9 +527,12 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
{
auto txt = ref.text();
std::from_chars_result r = selected_charconv<value_type>::from_chars(txt.data(), txt.data() + txt.size(), result);
auto b = txt.data();
auto e = txt.data() + txt.size();
if (r.ec != std::errc())
std::from_chars_result r = (b + 1 < e and *b == '+' and std::isdigit(b[1])) ? selected_charconv<value_type>::from_chars(b + 1, e, result) : selected_charconv<value_type>::from_chars(b, e, result);
if (r.ec != std::errc() or r.ptr != e)
{
result = {};
if (cif::VERBOSE)
@@ -470,6 +541,8 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
std::cerr << "Attempt to convert " << std::quoted(txt) << " into a number\n";
else if (r.ec == std::errc::result_out_of_range)
std::cerr << "Conversion of " << std::quoted(txt) << " into a type that is too small\n";
else
std::cerr << "Not a valid number " << std::quoted(txt) << '\n';
}
}
}
@@ -489,9 +562,12 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
{
value_type v = {};
std::from_chars_result r = selected_charconv<value_type>::from_chars(txt.data(), txt.data() + txt.size(), v);
auto b = txt.data();
auto e = txt.data() + txt.size();
if (r.ec != std::errc())
std::from_chars_result r = (b + 1 < e and *b == '+' and std::isdigit(b[1])) ? selected_charconv<value_type>::from_chars(b + 1, e, v) : selected_charconv<value_type>::from_chars(b, e, v);
if (r.ec != std::errc() or r.ptr != e)
{
if (cif::VERBOSE)
{
@@ -499,6 +575,8 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
std::cerr << "Attempt to convert " << std::quoted(txt) << " into a number\n";
else if (r.ec == std::errc::result_out_of_range)
std::cerr << "Conversion of " << std::quoted(txt) << " into a type that is too small\n";
else
std::cerr << "Not a valid number " << std::quoted(txt) << '\n';
}
result = 1;
}

View File

@@ -1031,17 +1031,17 @@ class structure
/// \brief Create a new and empty (sugar) branch
branch &create_branch();
/// \brief Create a new (sugar) branch with one first NAG containing atoms constructed from \a atoms
branch &create_branch(std::vector<row_initializer> atoms);
// /// \brief Create a new (sugar) branch with one first NAG containing atoms constructed from \a atoms
// branch &create_branch(std::vector<row_initializer> atoms);
/// \brief Extend an existing (sugar) branch identified by \a asymID with one sugar containing atoms constructed from \a atom_info
///
/// \param asym_id The asym id of the branch to extend
/// \param atom_info Array containing the info for the atoms to construct for the new sugar
/// \param link_sugar The sugar to link to, note: this is the sugar number (1 based)
/// \param link_atom The atom id of the atom linked in the sugar
branch &extend_branch(const std::string &asym_id, std::vector<row_initializer> atom_info,
int link_sugar, const std::string &link_atom);
// /// \brief Extend an existing (sugar) branch identified by \a asymID with one sugar containing atoms constructed from \a atom_info
// ///
// /// \param asym_id The asym id of the branch to extend
// /// \param atom_info Array containing the info for the atoms to construct for the new sugar
// /// \param link_sugar The sugar to link to, note: this is the sugar number (1 based)
// /// \param link_atom The atom id of the atom linked in the sugar
// branch &extend_branch(const std::string &asym_id, std::vector<row_initializer> atom_info,
// int link_sugar, const std::string &link_atom);
/// \brief Remove \a branch
void remove_branch(branch &branch);

View File

@@ -26,8 +26,6 @@
#pragma once
#include "cif++/exports.hpp"
#include <array>
#include <cmath>
#include <complex>
@@ -882,7 +880,7 @@ class spherical_dots
spherical_dots()
{
constexpr double
const double
kGoldenRatio = (1 + std::sqrt(5.0)) / 2;
auto p = m_points.begin();

View File

@@ -397,6 +397,8 @@ class cell
float get_beta() const { return m_beta; } ///< return angle beta
float get_gamma() const { return m_gamma; } ///< return angle gamma
float get_volume() const; ///< return the calculated volume for this cell
matrix3x3<float> get_orthogonal_matrix() const { return m_orthogonal; } ///< return the matrix to use to transform coordinates from fractional to orthogonal
matrix3x3<float> get_fractional_matrix() const { return m_fractional; } ///< return the matrix to use to transform coordinates from orthogonal to fractional

View File

@@ -77,6 +77,9 @@ extern CIFPP_EXPORT int VERBOSE;
/// return the git 'build' number
std::string get_version_nr();
/// return the width of the current output terminal, or 80 if it cannot be determined
uint32_t get_terminal_width();
// --------------------------------------------------------------------
namespace colour

View File

@@ -182,17 +182,17 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name)
void file::load(const std::filesystem::path &p)
{
gzio::ifstream in(p);
if (not in.is_open())
throw std::runtime_error("Could not open file '" + p.string() + '\'');
try
{
gzio::ifstream in(p);
if (not in.is_open())
throw std::runtime_error("Could not open file " + p.string());
load(in);
}
catch (const std::exception &)
{
throw_with_nested(std::runtime_error("Error reading file " + p.string()));
throw_with_nested(std::runtime_error("Error reading file '" + p.string() + '\''));
}
}

View File

@@ -2840,7 +2840,8 @@ void reconstruct_pdbx(datablock &db)
if (db.get("atom_site") == nullptr)
throw std::runtime_error("Cannot reconstruct PDBx file, atom data missing");
assert(false);
throw std::runtime_error("not implemented yet");
}
} // namespace pdbx

View File

@@ -80,6 +80,22 @@ void cell::init()
m_fractional = inverse(m_orthogonal);
}
float cell::get_volume() const
{
auto alpha = (m_alpha * kPI) / 180;
auto beta = (m_beta * kPI) / 180;
auto gamma = (m_gamma * kPI) / 180;
auto cos_alpha = std::cos(alpha);
auto cos_beta = std::cos(beta);
auto cos_gamma = std::cos(gamma);
auto vol = m_a * m_b * m_c;
vol *= std::sqrt(1.0f - cos_alpha * cos_alpha - cos_beta * cos_beta - cos_gamma * cos_gamma + 2.0f * cos_alpha * cos_beta * cos_gamma);
return vol;
}
// --------------------------------------------------------------------
sym_op::sym_op(std::string_view s)

View File

@@ -43,11 +43,6 @@
#include <sstream>
#include <thread>
#if not defined(_WIN32)
#include <sys/ioctl.h>
#include <termios.h>
#endif
namespace fs = std::filesystem;
// --------------------------------------------------------------------
@@ -88,6 +83,8 @@ uint32_t get_terminal_width()
#else
#include <sys/ioctl.h>
#include <termios.h>
#include <limits.h>
uint32_t get_terminal_width()

BIN
test/.1juh.cif.gz.swp Normal file

Binary file not shown.

View File

@@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(clr_1)
{
using namespace cif::colour;
std::cout << "Hello, " << cif::coloured("world!", white, red, regular) << '\n'
std::cout << "Hello, " << cif::coloured("world!", white, red, cif::colour::regular) << '\n'
<< "Hello, " << cif::coloured("world!", white, red, bold) << '\n'
<< "Hello, " << cif::coloured("world!", black, red) << '\n'
<< "Hello, " << cif::coloured("world!", white, green) << '\n'

View File

@@ -527,14 +527,14 @@ BOOST_AUTO_TEST_CASE(symm_2bi3_1a, *utf::tolerance(0.1f))
cif::crystal c(db);
auto struct_conn = db["struct_conn"];
auto atom_site = db["struct_conn"];
auto atom_site = db["atom_site"];
for (const auto &[
asym1, seqid1, authseqid1, atomid1, symm1,
asym2, seqid2, authseqid2, atomid2, symm2,
dist] : struct_conn.find<
std::string,int,std::string,std::string,std::string,
std::string,int,std::string,std::string,std::string,
std::string,std::optional<int>,std::string,std::string,std::string,
std::string,std::optional<int>,std::string,std::string,std::string,
float>(
cif::key("ptnr1_symmetry") != "1_555" or cif::key("ptnr2_symmetry") != "1_555",
"ptnr1_label_asym_id", "ptnr1_label_seq_id", "ptnr1_auth_seq_id", "ptnr1_label_atom_id", "ptnr1_symmetry",
@@ -565,8 +565,6 @@ BOOST_AUTO_TEST_CASE(symm_2bi3_1a, *utf::tolerance(0.1f))
}
}
BOOST_AUTO_TEST_CASE(symm_3bwh_1, *utf::tolerance(0.1f))
{
cif::file f(gTestDir / "3bwh.cif.gz");
@@ -588,4 +586,16 @@ BOOST_AUTO_TEST_CASE(symm_3bwh_1, *utf::tolerance(0.1f))
BOOST_TEST(d == distance(a1.get_location(), p));
}
}
}
}
BOOST_AUTO_TEST_CASE(volume_3bwh_1, *utf::tolerance(0.1f))
{
cif::file f(gTestDir / "1juh.cif.gz");
auto &db = f.front();
cif::crystal c(db);
BOOST_CHECK_EQUAL(c.get_cell().get_volume(), 741009.625f);
}

View File

@@ -150,6 +150,31 @@ BOOST_AUTO_TEST_CASE(cc_2)
}
}
BOOST_AUTO_TEST_CASE(cc_3)
{
cif::category c("foo");
c.emplace({
{ "f-1", 1 },
{ "f-2", "-1" },
{ "f-3", "+1" },
{ "f-4", " 1" },
{ "f-5", " +1" },
{ "f-6", "1 " },
});
auto row = c.front();
BOOST_CHECK_EQUAL(row["f-1"].as<int>(), 1);
BOOST_CHECK_EQUAL(row["f-2"].as<int>(), -1);
BOOST_CHECK_EQUAL(row["f-3"].as<int>(), 1);
// BOOST_CHECK_THROW(row["f-4"].as<int>(), std::exception);
// BOOST_CHECK_THROW(row["f-5"].as<int>(), std::exception);
// BOOST_CHECK_THROW(row["f-6"].as<int>(), std::exception);
BOOST_CHECK_EQUAL(row["f-4"].as<int>(), 0);
BOOST_CHECK_EQUAL(row["f-5"].as<int>(), 0);
BOOST_CHECK_EQUAL(row["f-6"].as<int>(), 0);
}
BOOST_AUTO_TEST_CASE(item_1)
{
using namespace cif;
@@ -179,6 +204,26 @@ BOOST_AUTO_TEST_CASE(item_1)
BOOST_CHECK(ci3.empty());
}
BOOST_AUTO_TEST_CASE(item_2)
{
using namespace cif;
cif::item i0("test1");
BOOST_CHECK(i0.value() == ".");
cif::item i1("test1", std:: optional<float>());
BOOST_CHECK(i1.value() == "?");
cif::item i2("test1", std::make_optional<float>(1));
BOOST_CHECK(i2.value() == "1");
cif::item i3("test1", std::optional<float>(), 2);
BOOST_CHECK(i3.value() == "?");
cif::item i4("test1", std::make_optional<float>(1), 2);
BOOST_CHECK(i4.value() == "1.00");
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(r_1)