Commit faef95a8 by Maarten L. Hekkelman

new layout of symop table to work around compiler alignment issues

parent 25dfdd2f
......@@ -67,7 +67,7 @@ class Atom
Atom(const Atom& rhs);
// a special constructor to create symmetry copies
Atom(const Atom& rhs, const Point& symmmetry_location);
Atom(const Atom& rhs, const Point& symmmetry_location, const std::string& symmetry_operation);
~Atom();
......@@ -89,8 +89,8 @@ class Atom
const cif::Row getRowAniso() const;
// Atom symmetryCopy(const Point& d, const clipper::RTop_orth& rt);
// bool isSymmetryCopy() const;
// std::string symmetry() const;
bool isSymmetryCopy() const;
std::string symmetry() const;
// const clipper::RTop_orth& symop() const;
const Compound& comp() const;
......
......@@ -26,9 +26,89 @@
#pragma once
#include <cstdint>
#include <array>
namespace mmcif
{
// --------------------------------------------------------------------
struct Spacegroup
{
const char* name;
const char* xHM;
const char* Hall;
int nr;
};
extern const Spacegroup kSpaceGroups[];
extern const std::size_t kNrOfSpaceGroups;
// --------------------------------------------------------------------
struct SymopData
{
constexpr SymopData(const std::array<int,15>& data)
: m_packed((static_cast<uint64_t>(data[ 0]) & 0x03) << 34 bitor
(static_cast<uint64_t>(data[ 1]) & 0x03) << 32 bitor
(static_cast<uint64_t>(data[ 2]) & 0x03) << 30 bitor
(static_cast<uint64_t>(data[ 3]) & 0x03) << 28 bitor
(static_cast<uint64_t>(data[ 4]) & 0x03) << 26 bitor
(static_cast<uint64_t>(data[ 5]) & 0x03) << 24 bitor
(static_cast<uint64_t>(data[ 6]) & 0x03) << 22 bitor
(static_cast<uint64_t>(data[ 7]) & 0x03) << 20 bitor
(static_cast<uint64_t>(data[ 8]) & 0x03) << 18 bitor
(static_cast<uint64_t>(data[ 9]) & 0x07) << 15 bitor
(static_cast<uint64_t>(data[10]) & 0x07) << 12 bitor
(static_cast<uint64_t>(data[11]) & 0x07) << 9 bitor
(static_cast<uint64_t>(data[12]) & 0x07) << 6 bitor
(static_cast<uint64_t>(data[13]) & 0x07) << 3 bitor
(static_cast<uint64_t>(data[14]) & 0x07) << 0)
{
}
bool operator==(const SymopData& rhs) const
{
return m_packed == rhs.m_packed;
}
private:
friend struct SymopDataBlock;
const uint64_t kPackMask = (~0UL >> (64-36));
SymopData(uint64_t v)
: m_packed(v bitand kPackMask) {}
uint64_t m_packed;
};
struct SymopDataBlock
{
constexpr SymopDataBlock(int spacegroup, int rotational_number, const std::array<int,15>& rt_data)
: m_v((spacegroup & 0xffffULL) << 48 bitor
(rotational_number & 0xffULL) << 40 bitor
SymopData(rt_data).m_packed)
{
}
uint16_t spacegroup() const { return m_v >> 48; }
SymopData symop() const { return SymopData(m_v); }
uint8_t rotational_number() const { return (m_v >> 40) bitand 0xff; }
private:
uint64_t m_v;
};
static_assert(sizeof(SymopDataBlock) == sizeof(uint64_t), "Size of SymopData is wrong");
extern const SymopDataBlock kSymopNrTable[];
extern const std::size_t kSymopNrTableSize;
// --------------------------------------------------------------------
int GetSpacegroupNumber(std::string spacegroup); // alternative for clipper's parsing code
}
......@@ -1229,6 +1229,9 @@ void PDBFileParser::PreParseInput(std::istream& is)
{
std::cerr << "Dropped unsupported records: " << ba::join(dropped, ", ") << std::endl;
}
if (mData == nullptr)
throw std::runtime_error("Empty file?");
mRec = mData;
}
......@@ -1247,6 +1250,7 @@ void PDBFileParser::GetNextRecord()
void PDBFileParser::Match(const std::string& expected, bool throwIfMissing)
{
assert(mRec);
if (mRec->mName != expected)
{
if (throwIfMissing)
......
......@@ -216,13 +216,13 @@ struct AtomImpl
// mLocation -= d;
// }
AtomImpl(const AtomImpl& impl, const Point& loc)
AtomImpl(const AtomImpl& impl, const Point& loc, const std::string& sym_op)
: mFile(impl.mFile), mID(impl.mID), mType(impl.mType), mAtomID(impl.mAtomID)
, mCompID(impl.mCompID), mAsymID(impl.mAsymID), mSeqID(impl.mSeqID)
, mAltID(impl.mAltID), mLocation(loc), mRefcount(1)
, mRow(impl.mRow), mCompound(impl.mCompound), mRadius(impl.mRadius)
, mCachedProperties(impl.mCachedProperties)
, mSymmetryCopy(true)
, mSymmetryCopy(true), mSymmetryOperator(sym_op)
{
}
......@@ -378,6 +378,7 @@ struct AtomImpl
bool mSymmetryCopy = false;
bool mClone = false;
std::string mSymmetryOperator;
// clipper::RTop_orth mRTop;
// Point mD;
// int32_t mRTix;
......@@ -418,8 +419,8 @@ Atom Atom::clone() const
return Atom(mImpl_ ? new AtomImpl(*mImpl_) : nullptr);
}
Atom::Atom(const Atom& rhs, const Point& loc)
: mImpl_(new AtomImpl(*rhs.mImpl_, loc))
Atom::Atom(const Atom& rhs, const Point& loc, const std::string& sym_op)
: mImpl_(new AtomImpl(*rhs.mImpl_, loc, sym_op))
{
}
......@@ -629,6 +630,16 @@ void Atom::location(Point p)
// return clipper::Symop(impl()->mRTop).format() + "\n" + impl()->mRTop.format();
// }
bool Atom::isSymmetryCopy() const
{
return mImpl_->mSymmetryCopy;
}
std::string Atom::symmetry() const
{
return mImpl_->mSymmetryOperator;
}
// const clipper::RTop_orth& Atom::symop() const
// {
// return impl()->mRTop;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -53,7 +53,7 @@ int GetSpacegroupNumber(std::string spacegroup)
int result = 0;
const size_t N = sizeof(kSpaceGroups) / sizeof(Spacegroup);
const size_t N = kNrOfSpaceGroups;
int32_t L = 0, R = static_cast<int32_t>(N - 1);
while (L <= R)
{
......@@ -75,8 +75,9 @@ int GetSpacegroupNumber(std::string spacegroup)
// not found, see if we can find a match based on xHM name
if (result == 0)
{
for (auto& sp: kSpaceGroups)
for (size_t i = 0; i < kNrOfSpaceGroups; ++i)
{
auto& sp = kSpaceGroups[i];
if (sp.xHM == spacegroup)
{
result = sp.nr;
......
......@@ -350,13 +350,9 @@ int main()
// and $CLIBD/syminfo.lib using symop-map-generator,
// part of the PDB-REDO suite of programs.
struct Spacegroup
{
const char* name;
const char* xHM;
const char* Hall;
int nr;
} kSpaceGroups[] =
#include "cif++/Symmetry.hpp"
const Spacegroup kSpaceGroups[] =
{
)";
......@@ -390,35 +386,9 @@ struct Spacegroup
cout << R"(
};
union SymopData
{
struct
{
int rot_0_0:2;
int rot_0_1:2;
int rot_0_2:2;
int rot_1_0:2;
int rot_1_1:2;
int rot_1_2:2;
int rot_2_0:2;
int rot_2_1:2;
int rot_2_2:2;
unsigned int trn_0_0:3;
unsigned int trn_0_1:3;
unsigned int trn_1_0:3;
unsigned int trn_1_1:3;
unsigned int trn_2_0:3;
unsigned int trn_2_1:3;
};
uint64_t iv:36;
};
const size_t kNrOfSpaceGroups = sizeof(kSpaceGroups) / sizeof(Spacegroup);
struct SymopDataBlock
{
uint16_t spacegroupNr;
uint8_t rotationalNr;
SymopData rt;
} kSymopNrTable[] = {
const SymopDataBlock kSymopNrTable[] = {
)" << endl;
int spacegroupNr = 0;
......@@ -432,13 +402,17 @@ struct SymopDataBlock
spacegroupNr = sp;
cout << " { " << setw(3) << sp
<< ", " << setw(3) << o << ", { { ";
<< ", " << setw(3) << o << ", { ";
for (auto i: get<2>(sd))
cout << setw(2) << i << ',';
cout << " } } }," << endl;
cout << " } }," << endl;
}
cout << "};" << endl;
cout << R"(};
const size_t kSymopNrTableSize = sizeof(kSymopNrTable) / sizeof(SymopDataBlock);
)" << endl;
}
catch (const 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