Commit eb50bee4 by Maarten L. Hekkelman

atom_type_traits changes

parent b6143f36
...@@ -270,6 +270,10 @@ class atom_type_traits ...@@ -270,6 +270,10 @@ class atom_type_traits
const SFData &wksf(int charge = 0) const; const SFData &wksf(int charge = 0) const;
const SFData &elsf() 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: private:
const struct atom_type_info *m_info; const struct atom_type_info *m_info;
}; };
......
...@@ -661,37 +661,6 @@ class branch : public std::vector<sugar> ...@@ -661,37 +661,6 @@ class branch : public std::vector<sugar>
std::string m_asym_id, m_entity_id; 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 enum class StructureOpenOptions
...@@ -699,7 +668,7 @@ enum class StructureOpenOptions ...@@ -699,7 +668,7 @@ enum class StructureOpenOptions
SkipHydrogen = 1 << 0 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); return static_cast<int>(a) bitand static_cast<int>(b);
} }
......
...@@ -112,12 +112,12 @@ class row : public std::vector<item_value> ...@@ -112,12 +112,12 @@ class row : public std::vector<item_value>
item_value* get(uint16_t ix) 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 const item_value* get(uint16_t ix) const
{ {
return ix < size() ? &at(ix) : nullptr; return ix < size() ? &data()[ix] : nullptr;
} }
private: private:
......
...@@ -1078,6 +1078,26 @@ bool atom_type_traits::is_metal(const std::string& symbol) ...@@ -1078,6 +1078,26 @@ bool atom_type_traits::is_metal(const std::string& symbol)
return result; 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 atom_type_traits::wksf(int charge) const -> const SFData&
{ {
auto type = m_info->type; auto type = m_info->type;
......
...@@ -51,7 +51,7 @@ class row_comparator ...@@ -51,7 +51,7 @@ class row_comparator
{ {
auto cv = cat.get_cat_validator(); 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); uint16_t ix = cat.add_column(k);
...@@ -78,13 +78,8 @@ class row_comparator ...@@ -78,13 +78,8 @@ class row_comparator
row_handle rhb(m_category, *b); row_handle rhb(m_category, *b);
int d = 0; 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 ka = rha[k].text();
std::string_view kb = rhb[k].text(); std::string_view kb = rhb[k].text();
...@@ -103,29 +98,30 @@ class row_comparator ...@@ -103,29 +98,30 @@ class row_comparator
row_handle rhb(m_category, *b); row_handle rhb(m_category, *b);
int d = 0, i = 0; int d = 0;
for (auto &c : m_comparator) auto ai = a.begin();
{
uint16_t k;
compareFunc f;
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(); std::string_view kb = rhb[k].text();
d = f(ka, kb); d = f(ka, kb);
if (d != 0) if (d != 0)
break; break;
++ai;
} }
return d; return d;
} }
private: private:
typedef std::function<int(std::string_view, std::string_view)> compareFunc; using compareFunc = std::function<int(std::string_view, std::string_view)>;
typedef std::tuple<uint16_t, compareFunc> key_comparator; using key_comparator = std::tuple<uint16_t, compareFunc>;
std::vector<key_comparator> m_comparator; std::vector<key_comparator> m_comparator;
category &m_category; category &m_category;
...@@ -139,13 +135,7 @@ class row_comparator ...@@ -139,13 +135,7 @@ class row_comparator
class category_index class category_index
{ {
public: public:
category_index(category *cat) category_index(category *cat);
: m_category(*cat)
, m_row_comparator(m_category)
, m_root(nullptr)
{
reconstruct();
}
~category_index() ~category_index()
{ {
...@@ -158,9 +148,6 @@ class category_index ...@@ -158,9 +148,6 @@ class category_index
void insert(row *r); void insert(row *r);
void erase(row *r); void erase(row *r);
// batch create
void reconstruct();
// reorder the row's and returns new head and tail // reorder the row's and returns new head and tail
std::tuple<row *, row *> reorder() std::tuple<row *, row *> reorder()
{ {
...@@ -241,7 +228,7 @@ class category_index ...@@ -241,7 +228,7 @@ class category_index
h->m_right->m_red = not h->m_right->m_red; 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; return h != nullptr and h->m_red;
} }
...@@ -342,6 +329,15 @@ class category_index ...@@ -342,6 +329,15 @@ class category_index
entry *m_root; 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 row *category_index::find(row *k) const
{ {
const entry *r = m_root; const entry *r = m_root;
...@@ -482,83 +478,6 @@ category_index::entry *category_index::erase(entry *h, row *k) ...@@ -482,83 +478,6 @@ category_index::entry *category_index::erase(entry *h, row *k)
return fix_up(h); 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 size_t category_index::size() const
{ {
std::stack<entry *> s; 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