5#ifndef GEMMI_SELECT_HPP_
6#define GEMMI_SELECT_HPP_
24 bool inverted =
false;
27 std::string
str()
const {
30 return inverted ?
"!" + list : list;
33 bool has(
const std::string& name)
const {
37 return inverted ? !found : found;
43 bool has(
char flag)
const {
46 bool invert = (pattern[0] ==
'!');
47 bool found = (pattern.find(flag, invert ? 1 : 0) != std::string::npos);
48 return invert ? !found : found;
60 std::string
str()
const;
63 if (seqnum != *seqid.
num)
64 return seqnum < *seqid.
num ? -1 : 1;
65 if (icode !=
'*' && icode != seqid.
icode)
66 return icode < seqid.
icode ? -1 : 1;
80 else if (property ==
'b')
89 std::string
str()
const;
114 return mdl == 0 || mdl == model.
num;
117 return chain_ids.
has(chain.
name);
127 return atom_names.
has(a.
name) &&
131 std::all_of(atom_inequalities.begin(), atom_inequalities.end(),
135 return (cra.
chain ==
nullptr || matches(*cra.
chain)) &&
137 (cra.
atom ==
nullptr || matches(*cra.
atom));
141 return {*
this,
st.models};
144 return {*
this, model.
chains};
150 return {*
this, residue.
atoms};
157 for (
Residue& res : chain.residues) {
159 for (
Atom& atom : res.atoms) {
161 return {&chain, &res, &atom};
165 return {
nullptr,
nullptr,
nullptr};
169 for (
Model& model :
st.models) {
170 CRA cra = first_in_model(model);
172 return {&model, cra};
174 return {
nullptr, {
nullptr,
nullptr,
nullptr}};
188 residue_flags.
pattern = pattern;
205 for (
auto&
child :
t.children())
207 remove_selected(
child);
209 [&](
typename T::child_type& c) { return c.children().empty(); });
212 if (atom_names.
all && elements.empty() && altlocs.
all &&
213 atom_flags.
pattern.empty() && atom_inequalities.empty())
221 vector_remove_if(
t.children(), [&](
typename T::child_type& c) { return !matches(c); });
222 for (
auto&
child :
t.children())
223 remove_not_selected(
child);
Data structures to store macromolecular structure models.
void vector_remove_if(std::vector< T > &v, F &&condition)
bool is_in_list(const std::string &name, const std::string &list, char sep=',')
Represents atom site in macromolecular structure (~100 bytes).
std::vector< Residue > residues
std::vector< Chain > chains
std::vector< Atom > atoms
bool matches(const Atom &a) const
bool has(char flag) const
bool has(const std::string &name) const
int compare(const SeqId &seqid) const
Selection & set_atom_flags(const std::string &pattern)
std::vector< AtomInequality > atom_inequalities
FilterProxy< Selection, Atom > atoms(Residue &residue) const
bool matches(const Residue &res) const
T copy_selection(const T &orig) const
Selection(const std::string &cid)
bool matches(const Chain &chain) const
bool matches(const Structure &) const
bool matches(const Model &model) const
CRA first_in_model(Model &model) const
FilterProxy< Selection, Residue > residues(Chain &chain) const
void remove_not_selected(T &t) const
std::pair< Model *, CRA > first(Structure &st) const
void add_matching_children(const T &orig, T &target) const
FilterProxy< Selection, Model > models(Structure &st) const
void add_matching_children(const Atom &, Atom &) const
Selection & set_residue_flags(const std::string &pattern)
std::vector< char > elements
void remove_not_selected(Atom &) const
bool matches(const Atom &a) const
FilterProxy< Selection, Chain > chains(Model &model) const
void remove_selected(T &t) const
bool matches(const CRA &cra) const
std::array< char, 6 > et_flags
void remove_selected(Residue &res) const