Commit fb59adcf by Maarten L. Hekkelman

Fix symmetry rotational numbers

parent 4acca8a3
......@@ -191,12 +191,12 @@ if(CIFPP_RECREATE_SYMOP_DATA)
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/src/symop_table_data.hpp
COMMAND $<TARGET_FILE:symop-map-generator> $ENV{CLIBD}/syminfo.lib ${PROJECT_SOURCE_DIR}/src/symop_table_data.hpp
COMMAND $<TARGET_FILE:symop-map-generator> $ENV{CLIBD}/syminfo.lib $ENV{CLIBD}/symop.lib ${PROJECT_SOURCE_DIR}/src/symop_table_data.hpp
)
add_custom_target(
OUTPUT ${PROJECT_SOURCE_DIR}/src/symop_table_data.hpp
DEPENDS symop-map-generator "$ENV{CLIBD}/syminfo.lib"
DEPENDS symop-map-generator "$ENV{CLIBD}/syminfo.lib" "$ENV{CLIBD}/symop.lib"
)
endif()
......
......@@ -60,21 +60,21 @@ extern CIFPP_EXPORT const std::size_t kNrOfSpaceGroups;
struct symop_data
{
constexpr symop_data(const std::array<int, 15> &data)
: m_packed((data[0] & 0x03ULL) << 34 bitor
(data[1] & 0x03ULL) << 32 bitor
(data[2] & 0x03ULL) << 30 bitor
(data[3] & 0x03ULL) << 28 bitor
(data[4] & 0x03ULL) << 26 bitor
(data[5] & 0x03ULL) << 24 bitor
(data[6] & 0x03ULL) << 22 bitor
(data[7] & 0x03ULL) << 20 bitor
(data[8] & 0x03ULL) << 18 bitor
(data[9] & 0x07ULL) << 15 bitor
(data[10] & 0x07ULL) << 12 bitor
(data[11] & 0x07ULL) << 9 bitor
(data[12] & 0x07ULL) << 6 bitor
(data[13] & 0x07ULL) << 3 bitor
(data[14] & 0x07ULL) << 0)
: m_packed((data[0] bitand 0x03ULL) << 34 bitor
(data[1] bitand 0x03ULL) << 32 bitor
(data[2] bitand 0x03ULL) << 30 bitor
(data[3] bitand 0x03ULL) << 28 bitor
(data[4] bitand 0x03ULL) << 26 bitor
(data[5] bitand 0x03ULL) << 24 bitor
(data[6] bitand 0x03ULL) << 22 bitor
(data[7] bitand 0x03ULL) << 20 bitor
(data[8] bitand 0x03ULL) << 18 bitor
(data[9] bitand 0x07ULL) << 15 bitor
(data[10] bitand 0x07ULL) << 12 bitor
(data[11] bitand 0x07ULL) << 9 bitor
(data[12] bitand 0x07ULL) << 6 bitor
(data[13] bitand 0x07ULL) << 3 bitor
(data[14] bitand 0x07ULL) << 0)
{
}
......@@ -88,24 +88,35 @@ struct symop_data
return m_packed < rhs.m_packed;
}
std::array<int, 15> data() const
inline constexpr int unpack3(int offset) const
{
int result = (m_packed >> offset) bitand 0x03;
return result == 3 ? -1 : result;
}
inline constexpr int unpack7(int offset) const
{
return (m_packed >> offset) bitand 0x07;
}
constexpr std::array<int, 15> data() const
{
return {
static_cast<int>(m_packed >> 34) bitand 0x03,
static_cast<int>(m_packed >> 32) bitand 0x03,
static_cast<int>(m_packed >> 30) bitand 0x03,
static_cast<int>(m_packed >> 28) bitand 0x03,
static_cast<int>(m_packed >> 26) bitand 0x03,
static_cast<int>(m_packed >> 24) bitand 0x03,
static_cast<int>(m_packed >> 22) bitand 0x03,
static_cast<int>(m_packed >> 20) bitand 0x03,
static_cast<int>(m_packed >> 18) bitand 0x03,
static_cast<int>(m_packed >> 15) bitand 0x07,
static_cast<int>(m_packed >> 12) bitand 0x07,
static_cast<int>(m_packed >> 9) bitand 0x07,
static_cast<int>(m_packed >> 6) bitand 0x07,
static_cast<int>(m_packed >> 3) bitand 0x07,
static_cast<int>(m_packed >> 0) bitand 0x07,
unpack3(34),
unpack3(32),
unpack3(30),
unpack3(28),
unpack3(26),
unpack3(24),
unpack3(22),
unpack3(20),
unpack3(18),
unpack7(15),
unpack7(12),
unpack7(9),
unpack7(6),
unpack7(3),
unpack7(0)
};
}
......@@ -125,8 +136,8 @@ struct symop_data
struct symop_datablock
{
constexpr symop_datablock(int spacegroup, int rotational_number, const std::array<int, 15> &rt_data)
: m_v((spacegroup & 0xffffULL) << 48 bitor
(rotational_number & 0xffULL) << 40 bitor
: m_v((spacegroup bitand 0xffffULL) << 48 bitor
(rotational_number bitand 0xffULL) << 40 bitor
symop_data(rt_data).m_packed)
{
}
......
......@@ -34,7 +34,7 @@ namespace cif
{
// --------------------------------------------------------------------
// Unfortunately, clipper has a different numbering scheme than PDB
// Unfortunately, clipper has a different numbering scheme than CCP4
// for rotation numbers. So we created a table to map those.
// Perhaps a bit over the top, but hey....
......
......@@ -27,6 +27,7 @@
#include <cassert>
#include <array>
#include <charconv>
#include <iostream>
#include <iomanip>
#include <fstream>
......@@ -169,7 +170,7 @@ class SymopParser
}
Token m_lookahead;
int m_nr;
int m_nr = -1;
std::string m_s;
std::string::const_iterator m_p, m_e;
......@@ -230,14 +231,15 @@ int main(int argc, char* const argv[])
try
{
if (argc != 3)
if (argc != 4)
{
std::cerr << "Usage symop-map-generator <input-file> <output-file>" << std::endl;
std::cerr << "Usage symop-map-generator <syminfo.lib-file> <symop.lib-file> < <output-file>" << std::endl;
exit(1);
}
fs::path input(argv[1]);
fs::path output(argv[2]);
fs::path syminfolib(argv[1]);
fs::path symoplib(argv[2]);
fs::path output(argv[3]);
tmpFile = output.parent_path() / (output.filename().string() + ".tmp");
......@@ -261,22 +263,51 @@ int main(int argc, char* const argv[])
};
std::map<int,SymInfoBlock> symInfo;
int symopnr = 0, mysymnr = 10000;
std::ifstream file(input);
std::ifstream file(symoplib);
if (not file.is_open())
throw std::runtime_error("Could not open symop.lib file");
std::string line;
int sgnr = 0;
int rnr = 0;
while (getline(file, line))
{
if (line.empty())
continue;
if (std::isdigit(line[0])) // start of new spacegroup
{
auto r = std::from_chars(line.data(), line.data() + line.length(), sgnr);
if (r.ec != std::errc())
throw std::runtime_error("Error parsing symop.lib file");
rnr = 1;
continue;
}
if (not std::isspace(line[0]) or sgnr == 0)
throw std::runtime_error("Error parsing symop.lib file");
SymopParser p;
data.emplace_back(sgnr, rnr, p.parse(line));
++rnr;
}
file.close();
file.open(syminfolib);
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;
const std::regex rx(R"(^symbol +(Hall|xHM|old) +'(.+?)'(?: +'(.+?)')?$)"),
rx2(R"(symbol ccp4 (\d+))");;
SymInfoBlock cur = {};
std::vector<std::array<int,15>> symops, cenops;
// std::vector<std::array<int,15>> symops, cenops;
while (getline(file, line))
{
......@@ -284,12 +315,7 @@ int main(int argc, char* const argv[])
{
case State::skip:
if (line == "begin_spacegroup")
{
state = State::spacegroup;
symopnr = 1;
++mysymnr;
cur = { mysymnr };
}
break;
case State::spacegroup:
......@@ -314,34 +340,34 @@ int main(int argc, char* const argv[])
if (nr != 0)
cur.nr = nr;
}
else if (line.compare(0, 6, "symop ") == 0)
{
SymopParser p;
symops.emplace_back(p.parse(line.substr(6)));
}
else if (line.compare(0, 6, "cenop ") == 0)
{
SymopParser p;
cenops.emplace_back(p.parse(line.substr(6)));
}
// else if (line.compare(0, 6, "symop ") == 0)
// {
// SymopParser p;
// symops.emplace_back(p.parse(line.substr(6)));
// }
// else if (line.compare(0, 6, "cenop ") == 0)
// {
// SymopParser p;
// cenops.emplace_back(p.parse(line.substr(6)));
// }
else if (line == "end_spacegroup")
{
for (auto& cenop: cenops)
{
for (auto symop: symops)
{
symop = move_symop(symop, cenop);
// for (auto& cenop: cenops)
// {
// for (auto symop: symops)
// {
// symop = move_symop(symop, cenop);
data.emplace_back(cur.nr, symopnr, symop);
++symopnr;
}
}
// data.emplace_back(cur.nr, symopnr, symop);
// ++symopnr;
// }
// }
symInfo.emplace(cur.nr, cur);
state = State::skip;
symops.clear();
cenops.clear();
// symops.clear();
// cenops.clear();
}
break;
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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