235 std::cerr <<
"Usage symop-map-generator <input-file> <output-file>" << std::endl;
239 fs::path input(argv[1]);
240 fs::path output(argv[2]);
242 tmpFile = output.parent_path() / (output.filename().string() +
".tmp");
244 std::ofstream out(tmpFile);
245 if (not out.is_open())
246 throw std::runtime_error(
"Failed to open output file");
251 std::vector<std::tuple<int,int,std::array<int,15>>> data;
263 std::map<int,SymInfoBlock> symInfo;
264 int symopnr, mysymnr = 10000;
266 std::ifstream file(input);
267 if (not file.is_open())
268 throw std::runtime_error(
"Could not open syminfo.lib file");
270 enum class State { skip, spacegroup } state = State::skip;
274 const std::regex rx(R
"(^symbol +(Hall|xHM|old) +'(.+?)'(?: +'(.+?)')?$)"), 275 rx2(R"(symbol ccp4 (\d+))");; 277 SymInfoBlock cur = {}; 279 std::vector<std::array<int,15>> symops, cenops; 281 while (getline(file, line))
286 if (line ==
"begin_spacegroup")
288 state = State::spacegroup;
295 case State::spacegroup:
298 if (std::regex_match(line, m, rx))
306 else if (m[1] ==
"xHM")
308 else if (m[1] ==
"Hall")
311 else if (regex_match(line, m, rx2))
317 else if (line.compare(0, 6,
"symop ") == 0)
320 symops.emplace_back(p.
parse(line.substr(6)));
322 else if (line.compare(0, 6,
"cenop ") == 0)
325 cenops.emplace_back(p.
parse(line.substr(6)));
327 else if (line ==
"end_spacegroup")
329 for (
auto& cenop: cenops)
331 for (
auto symop: symops)
335 data.emplace_back(cur.nr, symopnr, symop);
340 symInfo.emplace(cur.nr, cur);
353 sort(data.begin(), data.end());
357 out << R
"(// This file was generated from $CLIBD/symop.lib 358 // and $CLIBD/syminfo.lib using symop-map-generator, 359 // part of the PDB-REDO suite of programs. 361 #include "cif++/symmetry.hpp" 366 const space_group kSpaceGroups[] = 370 std::vector<std::tuple<std::string,int,std::string,std::string>> spacegroups; 372 for (
auto& [nr, info]: symInfo)
374 spacegroups.emplace_back(info.old[0], nr, info.xHM, info.Hall);
375 if (info.old[1].empty() ==
false)
376 spacegroups.emplace_back(info.old[1], nr, info.xHM, info.Hall);
379 sort(spacegroups.begin(), spacegroups.end());
381 for (
auto [old, nr, xHM, Hall]: spacegroups)
383 old =
'"' + old +
'"' + std::string(20 - old.length(),
' ');
384 xHM =
'"' + xHM +
'"' + std::string(30 - xHM.length(),
' ');
386 for (std::string::size_type p = Hall.length(); p > 0; --p)
388 if (Hall[p - 1] ==
'"')
389 Hall.insert(p - 1,
"\\", 1);
392 Hall =
'"' + Hall +
'"' + std::string(40 - Hall.length(),
' ');
394 out <<
"\t{ " << old <<
", " << xHM <<
", " << Hall <<
", " << nr <<
" }," << std::endl;
400 const size_t kNrOfSpaceGroups = sizeof(kSpaceGroups) / sizeof(space_group); 402 const symop_datablock kSymopNrTable[] = { 405 int spacegroupNr = 0;
409 std::tie(sp, o, std::ignore) = sd;
411 if (sp > spacegroupNr)
412 out <<
" // " << symInfo[sp].xHM << std::endl;
415 out <<
" { " << std::setw(3) << sp
416 <<
", " << std::setw(3) << o <<
", { ";
417 for (
auto&
i: std::get<2>(sd))
418 out << std::setw(2) <<
i <<
',';
419 out <<
" } }," << std::endl;
424 const size_t kSymopNrTableSize = sizeof(kSymopNrTable) / sizeof(symop_datablock); 430 fs::rename(tmpFile, output); 432 catch (
const std::exception& ex)
434 std::cerr << std::endl
435 <<
"Program terminated due to error:" << std::endl
436 << ex.what() << std::endl;
std::array< int, 15 > parse(const std::string &s)
std::array< int, 15 > move_symop(std::array< int, 15 > symop, const std::array< int, 15 > &cenop)
void sort(struct DCEL_T *dcel)