Compare commits

...

5 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
14 changed files with 155 additions and 51 deletions

View File

@@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.16)
# set the project name
project(libcifpp VERSION 5.2.2 LANGUAGES CXX)
project(libcifpp VERSION 5.2.3 LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -61,8 +61,12 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
option(BUILD_FOR_CCP4 "Build a version to be installed in CCP4" OFF)
# Building shared libraries?
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)
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)
@@ -121,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")
@@ -293,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 ${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)
@@ -340,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()

View File

@@ -1,3 +1,8 @@
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

View File

@@ -237,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

View File

@@ -29,7 +29,7 @@ class version_info_base
{
for (auto lib = registered_libraries(); lib != nullptr; lib = lib->m_next)
{
os << '-' << std::endl;
os << "-\n";
lib->write(os, verbose);
}
}
@@ -55,15 +55,15 @@ class version_info_base
void write(std::ostream &os, bool verbose)
{
os << m_name << " version " << m_version << std::endl;
os << m_name << " version " << m_version << '\n';
if (verbose)
{
if (m_build_number != 0)
{
os << "build: " << m_build_number << ' ' << m_revision_date << std::endl;
os << "build: " << m_build_number << ' ' << m_revision_date << '\n';
if (m_git_tag[0] != 0)
os << "git tag: " << m_git_tag << std::endl;
os << "git tag: " << m_git_tag << '\n';
}
}
}
@@ -100,25 +100,8 @@ class version_info : public version_info_base
: version_info_base(name, version, build_number, git_tag, revision_date, is_main)
{
}
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;
} // namespace version_info_v1_1
inline void write_version_string(std::ostream &os, bool verbose)
@@ -128,11 +111,11 @@ inline void write_version_string(std::ostream &os, bool verbose)
#endif
class version_info_@IDENT_PREFIX@impl : public version_info_v1_1::version_info<version_info_@IDENT_PREFIX@impl>
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

@@ -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
@@ -462,9 +530,7 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
auto b = txt.data();
auto e = txt.data() + txt.size();
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);
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)
{
@@ -499,9 +565,7 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
auto b = txt.data();
auto e = txt.data() + txt.size();
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);
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)
{

View File

@@ -26,8 +26,6 @@
#pragma once
#include "cif++/exports.hpp"
#include <array>
#include <cmath>
#include <complex>

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

@@ -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)

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

@@ -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

@@ -204,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)