NuriKit v0.1.0b2
Loading...
Searching...
No Matches
nuri::MoleculeMutator Class Reference

A class to mutate a molecule. More...

#include <nuri/core/molecule.h>

Public Member Functions

 MoleculeMutator (Molecule &mol)
 Construct a new MoleculeMutator object.
 MoleculeMutator ()=delete
 MoleculeMutator (const MoleculeMutator &)=delete
MoleculeMutatoroperator= (const MoleculeMutator &)=delete
 MoleculeMutator (MoleculeMutator &&) noexcept=default
MoleculeMutatoroperator= (MoleculeMutator &&) noexcept=default
 ~MoleculeMutator () noexcept
int add_atom (const AtomData &atom)
 Add an atom to the molecule.
int add_atom (AtomData &&atom) noexcept
 Add an atom to the molecule.
int add_atom (const Molecule::Atom &atom)
 Add an atom to the molecule.
void mark_atom_erase (int atom_idx)
 Mark an atom to be erased.
void mark_atom_erase (Molecule::Atom atom)
 Mark an atom to be erased.
void clear_atoms () noexcept
 Clear all atoms and bonds of the molecule.
std::pair< int, bool > register_bond (int src, int dst, const BondData &bond)
 Register a bond to be added to the molecule.
std::pair< int, bool > register_bond (int src, int dst, BondData &&bond) noexcept
 Register a bond to be added to the molecule.
std::pair< int, bool > register_bond (int src, int dst, Molecule::Bond bond)
 Register a bond to be added to the molecule.
void mark_bond_erase (int bid)
 Mark a bond to be erased.
void mark_bond_erase (int src, int dst)
 Mark a bond to be erased.
void mark_bond_erase (Molecule::Atom src, Molecule::Atom dst)
 Mark a bond to be erased.
void clear_bonds () noexcept
 Clear all bonds of the molecule.
void clear () noexcept
 Clear the molecule.
void finalize () noexcept
 Finalize the mutation.
Moleculemol () noexcept
const Moleculemol () const noexcept

Detailed Description

A class to mutate a molecule.

Atom addition is directly applied to the molecule, but bond addition and atom/bond erasure are delayed until the finalize() method is called. This is because bulk bond addition is more efficient than individual bond addition, and atom erasure might change the atom indices of the remaining atoms, resulting in unexpected behavior if the mutation is not applied in the correct order. The finalize() method applies the mutations in the following order:

  1. Add registered bonds.
  2. Erase marked bonds.
  3. Erase marked atoms.

If finalize() method is not explicitly called, the destructor will automatically call it.

Conformers of molecules will resize to the new number of atoms also at the finalize() call. Currently, there is no way to specify the new positions of the added atoms. Assign the new positions manually after the mutation if necessary.

Note
Having multiple instances of this class for the same molecule might result in an inconsistent state.

Constructor & Destructor Documentation

◆ MoleculeMutator() [1/4]

nuri::MoleculeMutator::MoleculeMutator ( Molecule & mol)
inline

Construct a new MoleculeMutator object.

Parameters
molThe molecule to mutate.

◆ MoleculeMutator() [2/4]

nuri::MoleculeMutator::MoleculeMutator ( )
delete

◆ MoleculeMutator() [3/4]

nuri::MoleculeMutator::MoleculeMutator ( const MoleculeMutator & )
delete

◆ MoleculeMutator() [4/4]

nuri::MoleculeMutator::MoleculeMutator ( MoleculeMutator && )
defaultnoexcept

◆ ~MoleculeMutator()

nuri::MoleculeMutator::~MoleculeMutator ( )
inlinenoexcept

Member Function Documentation

◆ add_atom() [1/3]

int nuri::MoleculeMutator::add_atom ( AtomData && atom)
inlinenoexcept

Add an atom to the molecule.

Parameters
atomThe data of the atom to add.
Returns
The index of the added atom.

◆ add_atom() [2/3]

int nuri::MoleculeMutator::add_atom ( const AtomData & atom)
inline

Add an atom to the molecule.

Parameters
atomThe data of the atom to add.
Returns
The index of the added atom.

◆ add_atom() [3/3]

int nuri::MoleculeMutator::add_atom ( const Molecule::Atom & atom)
inline

Add an atom to the molecule.

Parameters
atomAn atom to add.
Returns
The index of the added atom.

◆ clear()

void nuri::MoleculeMutator::clear ( )
noexcept

Clear the molecule.

◆ clear_atoms()

void nuri::MoleculeMutator::clear_atoms ( )
noexcept

Clear all atoms and bonds of the molecule.

◆ clear_bonds()

void nuri::MoleculeMutator::clear_bonds ( )
noexcept

Clear all bonds of the molecule.

◆ finalize()

void nuri::MoleculeMutator::finalize ( )
noexcept

Finalize the mutation.

Note
The mutator internally calls discard() after applying changes. Thus, successive calls to finalize() have no effect.
See also
Molecule::sanitize()

This will effectively call Molecule::update_topology(), if any atoms or bonds are added or removed.

◆ mark_atom_erase() [1/2]

void nuri::MoleculeMutator::mark_atom_erase ( int atom_idx)
inline

Mark an atom to be erased.

Parameters
atom_idxIndex of the atom to erase, after all additions.
Note
The behavior is undefined if the atom index is out of range at the moment of calling finalize().

◆ mark_atom_erase() [2/2]

void nuri::MoleculeMutator::mark_atom_erase ( Molecule::Atom atom)
inline

Mark an atom to be erased.

Parameters
atomAn atom to erase.
Note
The behavior is undefined if the atom does not belong to the molecule.

◆ mark_bond_erase() [1/3]

void nuri::MoleculeMutator::mark_bond_erase ( int bid)
inline

Mark a bond to be erased.

Parameters
bidThe index of the bond to erase.
Note
The behavior is undefined if the index is out of range.

◆ mark_bond_erase() [2/3]

void nuri::MoleculeMutator::mark_bond_erase ( int src,
int dst )

Mark a bond to be erased.

Parameters
srcIndex of the source atom of the bond.
dstIndex of the destination atom of the bond.
Note
The behavior is undefined if any of the atom indices is out of range. This is a no-op if the bond does not exist.

◆ mark_bond_erase() [3/3]

void nuri::MoleculeMutator::mark_bond_erase ( Molecule::Atom src,
Molecule::Atom dst )
inline

Mark a bond to be erased.

Parameters
srcThe source atom of the bond.
dstThe destination atom of the bond.
Note
The behavior is undefined if any of the atom does not belong to the molecule. This is a no-op if the bond does not exist.

◆ mol() [1/2]

const Molecule & nuri::MoleculeMutator::mol ( ) const
inlinenoexcept

◆ mol() [2/2]

Molecule & nuri::MoleculeMutator::mol ( )
inlinenoexcept

◆ operator=() [1/2]

MoleculeMutator & nuri::MoleculeMutator::operator= ( const MoleculeMutator & )
delete

◆ operator=() [2/2]

MoleculeMutator & nuri::MoleculeMutator::operator= ( MoleculeMutator && )
defaultnoexcept

◆ register_bond() [1/3]

std::pair< int, bool > nuri::MoleculeMutator::register_bond ( int src,
int dst,
BondData && bond )
noexcept

Register a bond to be added to the molecule.

Parameters
srcIndex of the source atom of the bond.
dstIndex of the destination atom of the bond.
bondThe data of the bond to add.
Returns
A pair of (tentative bond index, will be added). The tentative bond index is the index of the bond if it is added (before any erasure is applied), or the index of the existing bond if it is not added. The data of the existing bond is not modified.
Note
The behavior is undefined if any of the atom indices is out of range, or if src == dst.

◆ register_bond() [2/3]

std::pair< int, bool > nuri::MoleculeMutator::register_bond ( int src,
int dst,
const BondData & bond )

Register a bond to be added to the molecule.

Parameters
srcIndex of the source atom of the bond.
dstIndex of the destination atom of the bond.
bondThe data of the bond to add.
Returns
A pair of (tentative bond index, will be added). The tentative bond index is the index of the bond if it is added (before any erasure is applied), or the index of the existing bond if it is not added. The data of the existing bond is not modified.
Note
The behavior is undefined if any of the atom indices is out of range, or if src == dst.

◆ register_bond() [3/3]

std::pair< int, bool > nuri::MoleculeMutator::register_bond ( int src,
int dst,
Molecule::Bond bond )
inline

Register a bond to be added to the molecule.

Parameters
srcIndex of the source atom of the bond.
dstIndex of the destination atom of the bond.
bondThe bond to copy the data from.
Returns
A pair of (tentative bond index, will be added). The tentative bond index is the index of the bond if it is added (before any erasure is applied), or the index of the existing bond if it is not added. The data of the existing bond is not modified.
Note
The behavior is undefined if any of the atom indices is out of range, or if src == dst.

The documentation for this class was generated from the following file: