Commit eb50bee4 by Maarten L. Hekkelman

atom_type_traits changes

parent b6143f36
......@@ -270,6 +270,10 @@ class atom_type_traits
const SFData &wksf(int charge = 0) const;
const SFData &elsf() const;
// Clipper doesn't like atoms with charges that do not have a scattering factor. And
// rightly so, but we need to know in advance if this is the case
bool has_sf(int charge) const;
private:
const struct atom_type_info *m_info;
};
......
......@@ -661,37 +661,6 @@ class branch : public std::vector<sugar>
std::string m_asym_id, m_entity_id;
};
// // --------------------------------------------------------------------
// // file is a reference to the data stored in e.g. the cif file.
// // This object is not copyable.
// class File : public file
// {
// public:
// File() {}
// // File(const std::filesystem::path &path)
// // {
// // load(path);
// // }
// // File(const char *data, size_t length)
// // {
// // load(data, length);
// // }
// File(const File &) = delete;
// File &operator=(const File &) = delete;
// // void load(const std::filesystem::path &p) override;
// // void save(const std::filesystem::path &p) override;
// // using file::load;
// // using file::save;
// datablock &data() { return front(); }
// };
// --------------------------------------------------------------------
enum class StructureOpenOptions
......@@ -699,7 +668,7 @@ enum class StructureOpenOptions
SkipHydrogen = 1 << 0
};
inline bool operator&(StructureOpenOptions a, StructureOpenOptions b)
constexpr inline bool operator&(StructureOpenOptions a, StructureOpenOptions b)
{
return static_cast<int>(a) bitand static_cast<int>(b);
}
......
......@@ -112,12 +112,12 @@ class row : public std::vector<item_value>
item_value* get(uint16_t ix)
{
return ix < size() ? &at(ix) : nullptr;
return ix < size() ? &data()[ix] : nullptr;
}
const item_value* get(uint16_t ix) const
{
return ix < size() ? &at(ix) : nullptr;
return ix < size() ? &data()[ix] : nullptr;
}
private:
......
......@@ -1078,6 +1078,26 @@ bool atom_type_traits::is_metal(const std::string& symbol)
return result;
}
bool atom_type_traits::has_sf(int charge) const
{
auto type = m_info->type;
if (type == D)
type = H;
bool result = false;
for (auto& sf: data::kWKSFData)
{
if (sf.symbol == type and sf.charge == charge)
{
result = true;
break;
}
}
return result;
}
auto atom_type_traits::wksf(int charge) const -> const SFData&
{
auto type = m_info->type;
......
......@@ -51,7 +51,7 @@ class row_comparator
{
auto cv = cat.get_cat_validator();
for (auto k : cv->m_keys)
for (auto &k : cv->m_keys)
{
uint16_t ix = cat.add_column(k);
......@@ -78,13 +78,8 @@ class row_comparator
row_handle rhb(m_category, *b);
int d = 0;
for (auto &c : m_comparator)
for (const auto &[k, f] : m_comparator)
{
uint16_t k;
compareFunc f;
std::tie(k, f) = c;
std::string_view ka = rha[k].text();
std::string_view kb = rhb[k].text();
......@@ -103,29 +98,30 @@ class row_comparator
row_handle rhb(m_category, *b);
int d = 0, i = 0;
for (auto &c : m_comparator)
{
uint16_t k;
compareFunc f;
int d = 0;
auto ai = a.begin();
std::tie(k, f) = c;
for (const auto &[k, f] : m_comparator)
{
assert(ai != a.end());
std::string_view ka = a[i++].value();
std::string_view ka = ai->value();
std::string_view kb = rhb[k].text();
d = f(ka, kb);
if (d != 0)
break;
++ai;
}
return d;
}
private:
typedef std::function<int(std::string_view, std::string_view)> compareFunc;
typedef std::tuple<uint16_t, compareFunc> key_comparator;
using compareFunc = std::function<int(std::string_view, std::string_view)>;
using key_comparator = std::tuple<uint16_t, compareFunc>;
std::vector<key_comparator> m_comparator;
category &m_category;
......@@ -139,13 +135,7 @@ class row_comparator
class category_index
{
public:
category_index(category *cat)
: m_category(*cat)
, m_row_comparator(m_category)
, m_root(nullptr)
{
reconstruct();
}
category_index(category *cat);
~category_index()
{
......@@ -158,9 +148,6 @@ class category_index
void insert(row *r);
void erase(row *r);
// batch create
void reconstruct();
// reorder the row's and returns new head and tail
std::tuple<row *, row *> reorder()
{
......@@ -241,7 +228,7 @@ class category_index
h->m_right->m_red = not h->m_right->m_red;
}
bool is_red(entry *h) const
constexpr bool is_red(entry *h) const
{
return h != nullptr and h->m_red;
}
......@@ -342,6 +329,15 @@ class category_index
entry *m_root;
};
category_index::category_index(category *cat)
: m_category(*cat)
, m_row_comparator(m_category)
, m_root(nullptr)
{
for (auto r : m_category)
insert(r.get_row());
}
row *category_index::find(row *k) const
{
const entry *r = m_root;
......@@ -482,83 +478,6 @@ category_index::entry *category_index::erase(entry *h, row *k)
return fix_up(h);
}
void category_index::reconstruct()
{
delete m_root;
m_root = nullptr;
for (auto r : m_category)
insert(r.get_row());
// maybe reconstruction can be done quicker by using the following commented code.
// however, I've not had the time to think of a way to set the red/black flag correctly in that case.
// std::vector<row*> rows;
// transform(mCat.begin(), mCat.end(), backInserter(rows),
// [](Row r) -> row* { assert(r.mData); return r.mData; });
//
// assert(std::find(rows.begin(), rows.end(), nullptr) == rows.end());
//
// // don't use sort here, it will run out of the stack of something.
// // quicksort is notorious for using excessive recursion.
// // Besides, most of the time, the data is ordered already anyway.
//
// stable_sort(rows.begin(), rows.end(), [this](row* a, row* b) -> bool { return this->mComp(a, b) < 0; });
//
// for (size_t i = 0; i < rows.size() - 1; ++i)
// assert(mComp(rows[i], rows[i + 1]) < 0);
//
// deque<entry*> e;
// transform(rows.begin(), rows.end(), back_inserter(e),
// [](row* r) -> entry* { return new entry(r); });
//
// while (e.size() > 1)
// {
// deque<entry*> ne;
//
// while (not e.empty())
// {
// entry* a = e.front();
// e.pop_front();
//
// if (e.empty())
// ne.push_back(a);
// else
// {
// entry* b = e.front();
// b->mLeft = a;
//
// assert(mComp(a->mRow, b->mRow) < 0);
//
// e.pop_front();
//
// if (not e.empty())
// {
// entry* c = e.front();
// e.pop_front();
//
// assert(mComp(b->mRow, c->mRow) < 0);
//
// b->mRight = c;
// }
//
// ne.push_back(b);
//
// if (not e.empty())
// {
// ne.push_back(e.front());
// e.pop_front();
// }
// }
// }
//
// swap (e, ne);
// }
//
// assert(e.size() == 1);
// mRoot = e.front();
}
size_t category_index::size() const
{
std::stack<entry *> s;
......
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