chemfiles::Residue¶A Residue is a group of atoms belonging to the same logical unit. They can be molecules, amino-acids in a protein, monomers in polymers, etc.
Iterating over a Residue gives the indexes of the atoms in the associated Topology.
auto residue = Residue("CLU");
residue.add_atom(56);
residue.add_atom(22);
residue.add_atom(31);
std::vector<size_t> atoms;
for (auto atom: residue) {
atoms.push_back(atom);
}
assert(atoms == std::vector<size_t>({22, 31, 56}));
Public Functions
Residue(std::string name)¶Create a new residue with a given name and no residue id.
auto residue = Residue("ALA");
assert(residue.name() == "ALA");
assert(residue.id() == nullopt);
Residue(std::string name, uint64_t resid)¶Create a new residue with a given name and residue id resid.
auto residue = Residue("ALA", 456);
assert(residue.name() == "ALA");
assert(residue.id().value() == 456);
name() const¶Get the name of the residue
auto residue = Residue("FOO");
assert(residue.name() == "FOO");
id() const¶Get the residue identifier if it exists.
This function returna an chemfiles::optional value that is
close to C++17 std::optional.
auto residue = Residue("FOO");
assert(!residue.id());
residue = Residue("BAR", 33);
assert(residue.id());
assert(residue.id().value() == 33);
size() const¶Get the size of the residue, i.e. the number of atoms in this residue.
auto residue = Residue("FOO");
assert(residue.size() == 0);
residue.add_atom(2);
residue.add_atom(22);
residue.add_atom(42);
residue.add_atom(36);
assert(residue.size() == 4);
add_atom(size_t i)¶Add an atom with index i to this residue
If the atom is already in the residue, this does nothing.
auto residue = Residue("FOO");
assert(residue.size() == 0);
residue.add_atom(2);
residue.add_atom(22);
residue.add_atom(42);
residue.add_atom(36);
assert(residue.size() == 4);
residue.add_atom(36);
assert(residue.size() == 4);
contains(size_t i) const¶Check if the residue contains a given atom with index i
auto residue = Residue("FOO");
residue.add_atom(2);
residue.add_atom(22);
residue.add_atom(42);
residue.add_atom(36);
assert(residue.contains(22) == true);
assert(residue.contains(23) == false);