Residue¶
-
class Residue¶
A
Residueis 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
Residuegives the indexes of the atoms in the associatedTopology.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
-
explicit Residue(std::string name)¶
Create a new residue with a given
nameand no residue id.auto residue = Residue("ALA"); assert(residue.name() == "ALA"); assert(residue.id() == nullopt);
-
Residue(std::string name, int64_t resid)¶
Create a new residue with a given
nameand residue idresid.auto residue = Residue("ALA", 456); assert(residue.name() == "ALA"); assert(residue.id().value() == 456);
-
inline const std::string &name() const¶
Get the name of the residue.
auto residue = Residue("FOO"); assert(residue.name() == "FOO");
-
inline optional<int64_t> id() const¶
Get the residue identifier, or
nulloptif it does not exist.auto residue = Residue("FOO"); assert(!residue.id()); residue = Residue("BAR", 33); assert(residue.id()); assert(residue.id().value() == 33);
-
inline size_t 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);
-
void add_atom(size_t i)¶
Add an atom with index
ito this residueIf 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 contains(size_t i) const¶
Check if the residue contains a given atom with index
iauto 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);
-
inline const property_map &properties() const¶
Get the map of properties asociated with this residue. This map might be iterated over to list the properties of the residue, or directly accessed.
auto frame = Frame(); frame.set("a string", "the lazy fox"); frame.set("a number", 122); // Iterator over properties in the frame for (auto it: frame.properties()) { if (it.first == "a string") { assert(it.second.as_string() == "the lazy fox"); } else if (it.first == "a number") { assert(it.second.as_double() == 122); } }
-
inline void set(std::string name, Property value)¶
Set an arbitrary
Propertyfor this residue with the givennameandvalue. If a property with this name already exist, it is replaced with the new value.auto residue = Residue("ALA"); residue.set("first", "alanine group"); residue.set("second", 42.5); assert(residue.get("second")->as_double() == 42.5); assert(residue.get("first")->as_string() == "alanine group"); // Typed access to properties assert(residue.get<Property::STRING>("first").value() == "alanine group"); assert(!residue.get<Property::BOOL>("first")); assert(!residue.get("non-existant property")); // Override the "first" property residue.set("first", false); assert(residue.get("first")->as_bool() == false);
-
inline optional<const Property&> get(const std::string &name) const¶
Get the
Propertywith the givennamefor this residue if it exists.If no property with the given
nameis found, this function returnsnullopt.auto residue = Residue("ALA"); residue.set("first", "alanine group"); residue.set("second", 42.5); assert(residue.get("second")->as_double() == 42.5); assert(residue.get("first")->as_string() == "alanine group"); // Typed access to properties assert(residue.get<Property::STRING>("first").value() == "alanine group"); assert(!residue.get<Property::BOOL>("first")); assert(!residue.get("non-existant property")); // Override the "first" property residue.set("first", false); assert(residue.get("first")->as_bool() == false);
-
template<Property::Kind kind>
inline optional<typename property_metadata<kind>::type> get(const std::string &name) const¶ Get the
Propertywith the givennamefor this residue if it exists, and check that it has the requiredkind.If no property with the given
nameis found, this function returnsnullopt.If a property with the given
nameis found, but has a different kind, this function emits a warning and returnsnullopt.auto residue = Residue("ALA"); residue.set("first", "alanine group"); residue.set("second", 42.5); assert(residue.get("second")->as_double() == 42.5); assert(residue.get("first")->as_string() == "alanine group"); // Typed access to properties assert(residue.get<Property::STRING>("first").value() == "alanine group"); assert(!residue.get<Property::BOOL>("first")); assert(!residue.get("non-existant property")); // Override the "first" property residue.set("first", false); assert(residue.get("first")->as_bool() == false);
-
explicit Residue(std::string name)¶