Residue class

class 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

chemfiles::ResidueResidue(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);

chemfiles::ResidueResidue(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);

const std::string &chemfiles::Residuename() const

Get the name of the residue

auto residue = Residue("FOO");
assert(residue.name() == "FOO");

optional<uint64_t> chemfiles::Residueid() 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_t chemfiles::Residuesize() 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);

void chemfiles::Residueadd_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);

bool chemfiles::Residuecontains(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);

void chemfiles::Residueset(std::string name, Property value)

Set an arbitrary Property for this residue with the given name and value. If a property with this name already exist, it is replaced with the new value.

auto residue = Residue("ALA");

residue.set("first", "this is an alanine group");
residue.set("second", 42.5);

assert(residue.get("second")->as_double() == 42.5);
assert(residue.get("first")->as_string() == "this is an alanine group");

assert(!residue.get("non-existant property"));

// Override the "first" property
residue.set("first", false);
assert(residue.get("first")->as_bool() == false);

optional<const Property&> chemfiles::Residueget(const std::string &name) const

Get the Property with the given name for this residue if it exists.

If no property with the given name is found, this function returns nullopt.

This function returns an chemfiles::optional value that is close to C++17 std::optional.

auto residue = Residue("ALA");

residue.set("first", "this is an alanine group");
residue.set("second", 42.5);

assert(residue.get("second")->as_double() == 42.5);
assert(residue.get("first")->as_string() == "this is an alanine group");

assert(!residue.get("non-existant property"));

// Override the "first" property
residue.set("first", false);
assert(residue.get("first")->as_bool() == false);