Topology¶
-
class Topology¶
A topology contains the definition of all the atoms in the system, as well as the liaisons between the particles (bonds, angles, dihedrals, …) and the residues.
Only the atoms and the bonds are stored, the angles, dihedrals and impropers are automaticaly deduced from the bonds.
It is also possible to iterate over a
Topology
, yielding all the atoms in the system.Public Functions
-
Topology() = default¶
Construct a new empty topology
-
inline Atom &operator[](size_t index)¶
Get a reference to the atom at the position
index
.- Parameters:
index – the atomic index
- Throws:
OutOfBounds – if
index
is greater thansize()
-
inline const Atom &operator[](size_t index) const¶
Get a const reference to the atom at the position
index
.- Parameters:
index – the atomic index
- Throws:
OutOfBounds – if
index
is greater thansize()
-
void add_atom(Atom atom)¶
Add an
atom
at the end of this topology.- Parameters:
atom – the new atom to add
-
void remove(size_t i)¶
Delete the atom at index
i
in this topology, as well as all the bonds involving this atom.This function modify the index of all the atoms after
i
, and modify the bond list accordingly.- Parameters:
i – the index of the atom to remove
- Throws:
OutOfBounds – if
i
is greater than size()
-
void add_bond(size_t atom_i, size_t atom_j, Bond::BondOrder bond_order = Bond::UNKNOWN)¶
Add a bond in the system, between the atoms at index
atom_i
andatom_j
.- Parameters:
atom_i – the index of the first atom in the bond
atom_j – the index of the second atom in the bond
bond_order – the bond order for the bond added
- Throws:
OutOfBounds – if
atom_i
oratom_j
are greater thansize()
Error – if
atom_i == atom_j
, as this is an invalid bond
-
void remove_bond(size_t atom_i, size_t atom_j)¶
Remove a bond in the system, between the atoms at index
atom_i
andatom_j
.If the bond does not exist, this does nothing.
- Parameters:
atom_i – the index of the first atom in the bond
atom_j – the index of the second atom in the bond
- Throws:
OutOfBounds – if
atom_i
oratom_j
are greater thansize()
-
Bond::BondOrder bond_order(size_t atom_i, size_t atom_j) const¶
Get the bond order for the given bond
If the bond does not exist, this will thrown an Error.
- Parameters:
atom_i – the index of the first atom in the bond
atom_j – the index of the second atom in the bond
- Throws:
OutOfBounds – if
atom_i
oratom_j
are greater thansize()
Error – if no bond between
atom_i
andatom_j
exists.
-
inline size_t size() const¶
Get the number of atoms in the topology
-
void resize(size_t size)¶
Resize the topology to hold
size
atoms, adding new atoms as needed.If the new number of atoms is bigger than the old one, pre-existing atoms are conserved.
If the new size if smaller than the old one, all atoms and connectivity elements after the new size are removed.
- Parameters:
size – the new size of the topology
-
void reserve(size_t size)¶
Allocate memory in the frame to be able to store data for
size
atoms.This function does not change the actual number of atoms in the topology, and should be used as an optimisation.
- Parameters:
size – the number of elements to reserve memory for
-
const std::vector<Bond> &bonds() const¶
Get the bonds in the system
The bonds are sorted according to
operator<(const Bond&, const Bond&)
, which mean it is possible to look for a bond in the list using a binary search (std::lower_bound
).
-
const std::vector<Bond::BondOrder> &bond_orders() const¶
Get the bond orders in the system.
The bond orders are sorted so that the index of each bond is the same as its index in the array returned by
Topology::bonds
. This means that the bond order forTopology::bonds()[index]
would be given bybond_orders()[index]
.
-
const std::vector<Angle> &angles() const¶
Get the angles in the system
The angles are sorted according to
operator<(const Angle&, const Angle&)
, which mean it is possible to look for an angle in the list using a binary search (std::lower_bound
).
-
const std::vector<Dihedral> &dihedrals() const¶
Get the dihedral angles in the system
The dihedrals are sorted according to
operator<(const Dihedral&, const Dihedral&)
, which mean it is possible to look for a dihedral in the list using a binary search (std::lower_bound
).
-
const std::vector<Improper> &impropers() const¶
Get the improper dihedral angles in the system
The impropers are sorted according to
operator<(const Improper&, const Improper&)
, which mean it is possible to look for an improper in the list using a binary search (std::lower_bound
).
-
inline void clear_bonds()¶
Remove all bonding information in the topology (bonds, angles and dihedrals)
-
void add_residue(Residue residue)¶
Add a
residue
to this topology.- Parameters:
residue – the residue to add to this topology
- Throws:
chemfiles::Error – if any atom in the
residue
is already in another residue in this topology. In that case, the topology is not modified.
-
bool are_linked(const Residue &first, const Residue &second) const¶
Check if two residues are linked together, i.e. if there is a bond between one atom in the
first
residue and one atom in thesecond
one. Both residues should be in this topology.The two residues are the same (
first == second
), this function returnstrue
.
-
optional<const Residue&> residue_for_atom(size_t index) const¶
Get the residue containing the atom at the given
index
.If no residue contains this atom, this function returns
nullopt
.
-
Topology() = default¶
Connectivity elements¶
-
class Bond¶
The
Bond
class ensure a canonical representation of a bond two atoms.This class implements all the comparison operators, as well as indexing.
Public Types
-
enum BondOrder¶
Stores the type of bond.
Values:
-
enumerator SINGLE¶
Single bond.
-
enumerator DOUBLE¶
Double bond.
-
enumerator TRIPLE¶
Triple bond.
-
enumerator QUADRUPLE¶
Quadruplet bond.
-
enumerator QUINTUPLET¶
Quintuplet bond.
-
enumerator DOWN¶
Single bond direction from first atom to second is ‘down’. Used for cis-trans isomers.
-
enumerator UP¶
Single bond direction from first atom to second is ‘up’. Used for cis-trans isomers.
-
enumerator DATIVE_R¶
Dative bond where the electrons are localized to the first atom.
-
enumerator DATIVE_L¶
Dative bond where the electrons are localized to the second atom.
-
enumerator AMIDE¶
Amide bond (C(=O)-NH)
-
enumerator AROMATIC¶
Aromatic bond (for example the ring bonds in benzene)
-
enumerator SINGLE¶
Public Functions
-
size_t operator[](size_t i) const¶
Get the index of the
i
th atom (i == 0
ori == 1
) in the bond.- Throws:
OutOfBounds – if
i
is not 0 or 1
-
enum BondOrder¶
-
class Angle¶
The
Angle
class ensure a canonical representation of an angle between three atoms.An angle is formed by two consecutive bonds:
| i k | | \ / | | j |
This class implements all the comparison operators, as well as indexing.
Public Functions
-
Angle(size_t i, size_t j, size_t k)¶
Create a new
Angle
containing the atomsi
,j
andk
.- Throws:
Error – if
i == j
,j == k
ori == k
-
size_t operator[](size_t i) const¶
Get the index of the
i
th atom (i == 0
,i == 1
ori == 2
) in the angle.- Throws:
OutOfBounds – if
i
is not 0, 1 or 2
-
Angle(size_t i, size_t j, size_t k)¶
-
class Dihedral¶
The
Dihedral
class ensure a canonical representation of a dihedral angle between four atoms.A dihedral angle is formed by three consecutive bonds:
| i k | | \ / \ | | j m |
This class implements all the comparison operators, as well as indexing.
Public Functions
-
Dihedral(size_t i, size_t j, size_t k, size_t m)¶
Create a new
Dihedral
containing the atomsi
,j
,k
andm
.- Throws:
Error – if any of
i
,j
,k
,m
has the same value as another
-
size_t operator[](size_t i) const¶
Get the index of the
i
th atom (i
can be 0, 1, 2 or 3) in the dihedral.- Throws:
OutOfBounds – if
i
is not 0, 1, 2 or 3.
-
Dihedral(size_t i, size_t j, size_t k, size_t m)¶
-
class Improper¶
The
Improper
class ensure a canonical representation of an improper dihedral angle between four atoms.An improper dihedral angle is formed by three bonds around a central atom:
| i k | | \ / | | j | | | | | m |
This class implements all the comparison operators, as well as indexing.
The second atom of the improper is always the central atom.
Public Functions
-
Improper(size_t i, size_t j, size_t k, size_t m)¶
Create a new
Improper
containing the atomsi
,j
,k
andm
.j
must be the central atom of the improper.- Throws:
Error – if any of
i
,j
,k
,m
has the same value as another
-
size_t operator[](size_t i) const¶
Get the index of the
i
th atom (i
can be 0, 1, 2 or 3) in the improper.- Throws:
OutOfBounds – if
i
is not 0, 1, 2 or 3.
-
Improper(size_t i, size_t j, size_t k, size_t m)¶