Chemical Data Processing Library Python API - Version 1.4.0
Classes | Public Member Functions | Static Public Member Functions | Properties | List of all members
CDPL.Chem.Molecule Class Reference

Abstract base class representing a mutable molecular graph that owns and manages its atoms and bonds. More...

+ Inheritance diagram for CDPL.Chem.Molecule:

Classes

class  AtomSequence
 
class  BondSequence
 

Public Member Functions

None __init__ ()
 Initializes the Molecule instance.
 
None reserveMemoryForAtoms (int num_atoms)
 Reserves memory for num_atoms atoms. More...
 
None reserveMemoryForBonds (int num_bonds)
 Reserves memory for num_bonds bonds. More...
 
None clear ()
 Removes all atoms and bonds and clears all properties of the molecule.
 
Atom addAtom ()
 Creates a new atom and adds it to the molecule. More...
 
Bond addBond (int atom1_idx, int atom2_idx)
 Creates a new or returns an already existing bond between the atoms specified by atom1_idx and atom2_idx. More...
 
None removeAtom (int idx)
 Removes the atom at the specified index. More...
 
None removeBond (int idx)
 Removes the bond at the specified index. More...
 
None copy (Molecule mol)
 Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecule mol. More...
 
None copy (MolecularGraph molgraph)
 Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecular graph molgraph. More...
 
None append (Molecule mol)
 Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol. More...
 
None append (MolecularGraph molgraph)
 Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecular graph molgraph. More...
 
None remove (MolecularGraph molgraph)
 Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule instance. More...
 
Molecule assign (Molecule mol)
 Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecule mol. More...
 
Molecule assign (MolecularGraph molgraph)
 Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecular graph molgraph. More...
 
AtomSequence getAtoms ()
 
BondSequence getBonds ()
 
None invokeCopyPostprocessingFunctions (MolecularGraph src_molgraph)
 Invokes all registered copy postprocessing functions on this molecule with src_molgraph as the source molecular graph. More...
 
Atom getAtom (int idx)
 Returns a reference to the atom at index idx. More...
 
bool containsAtom (Atom atom)
 Tells whether the specified atom is part of the atom sequence. More...
 
int getAtomIndex (Atom atom)
 Returns the index of the specified atom. More...
 
int getNumAtoms ()
 Returns the number of atoms. More...
 
None orderAtoms (BoolAtom2Functor func)
 Orders the atoms according to criteria implemented by the provided atom comparison function. More...
 
Entity3D getEntity (int idx)
 Returns a reference to the entity at index idx. More...
 
int getNumEntities ()
 Returns the number of stored Chem.Entity3D objects. More...
 
Bond getBond (int idx)
 Returns a reference to the bond at index idx. More...
 
bool containsBond (Bond bond)
 Tells whether the specified bond is part of the bond sequence. More...
 
None orderBonds (BoolBond2Functor func)
 Orders the bonds according to criteria implemented by the provided bond comparison function. More...
 
int getBondIndex (Bond bond)
 Returns the index of the specified bond. More...
 
int getNumBonds ()
 Returns the number of bonds. More...
 
tuple __getstate__ ()
 
Molecule __iadd__ (Molecule mol)
 Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol. More...
 
Molecule __iadd__ (MolecularGraph molgraph)
 Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecular graph molgraph. More...
 
Molecule __isub__ (MolecularGraph molgraph)
 Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule instance. More...
 
Base.Any __getitem__ (Base.LookupKey key)
 
bool __contains__ (Base.LookupKey key)
 Returns the result of the membership test operation key in self. More...
 
bool __contains__ (Bond bond)
 Returns the result of the membership test operation bond in self. More...
 
bool __contains__ (Atom atom)
 Returns the result of the membership test operation atom in self. More...
 
None __setitem__ (Base.LookupKey key, Base.Any value)
 
bool __delitem__ (Base.LookupKey key)
 
int __len__ ()
 
- Public Member Functions inherited from CDPL.Chem.MolecularGraph
MolecularGraph clone ()
 Creates a deep copy of the molecular graph. More...
 
- Public Member Functions inherited from CDPL.Chem.AtomContainer
Atom __getitem__ (int idx)
 
- Public Member Functions inherited from CDPL.Chem.Entity3DContainer
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
- Public Member Functions inherited from CDPL.Chem.BondContainer
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
Bond __getitem__ (int idx)
 
- Public Member Functions inherited from CDPL.Base.PropertyContainer
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
int getNumProperties ()
 Returns the number of property entries. More...
 
Any getPropertyOrDefault (LookupKey key, Any def_value)
 
list getPropertyKeys ()
 
list getPropertyValues ()
 
list getProperties ()
 Returns a reference to itself. More...
 
None setProperty (LookupKey key, Any value)
 
bool removeProperty (LookupKey key)
 Clears the value of the property specified by key. More...
 
Any getProperty (LookupKey key, bool throw_=False)
 Returns the value of the property specified by key. More...
 
bool isPropertySet (LookupKey key)
 Tells whether or not a value has been assigned to the property specified by key. More...
 
None clearProperties ()
 Clears all property values.
 
None addProperties (PropertyContainer cntnr)
 Adds the property value entries in the PropertyContainer instance cntnr. More...
 
None copyProperties (PropertyContainer cntnr)
 Replaces the current set of properties by a copy of the entries in cntnr. More...
 
None swap (PropertyContainer cntnr)
 Exchanges the properties of this container with the properties of the container cntnr. More...
 
Any __getitem__ (LookupKey key)
 Returns the value of the property specified by key. More...
 
bool __contains__ (LookupKey key)
 Returns the result of the membership test operation key in self. More...
 
None __setitem__ (LookupKey key, Any value)
 
bool __delitem__ (LookupKey key)
 

Static Public Member Functions

None registerCopyPostprocessingFunction (VoidMoleculeMolecularGraphFunctor func)
 Registers a new copy postprocessing function in the global registry. More...
 

Properties

 atoms = property(getAtoms)
 
 bonds = property(getBonds)
 
- Properties inherited from CDPL.Chem.MolecularGraph
 atoms = property(getAtoms)
 
 bonds = property(getBonds)
 
- Properties inherited from CDPL.Chem.AtomContainer
 numAtoms = property(getNumAtoms)
 
- Properties inherited from CDPL.Chem.Entity3DContainer
 objectID = property(getObjectID)
 
 numEntities = property(getNumEntities)
 
- Properties inherited from CDPL.Chem.BondContainer
 objectID = property(getObjectID)
 
 numBonds = property(getNumBonds)
 
- Properties inherited from CDPL.Base.PropertyContainer
 objectID = property(getObjectID)
 
 propertyKeys = property(getPropertyKeys)
 
 propertyValues = property(getPropertyValues)
 
 properties = property(getProperties)
 
 numProperties = property(getNumProperties)
 

Detailed Description

Abstract base class representing a mutable molecular graph that owns and manages its atoms and bonds.

Extends the Chem.MolecularGraph interface with editing methods (addAtom(), addBond(), removeAtom(), removeBond(), copy(), append(), remove()) and supports a global registry of copy postprocessing functions invoked after copying/append operations to properly transform properties referencing atoms and bonds of the source molecular graph.

Member Function Documentation

◆ reserveMemoryForAtoms()

None CDPL.Chem.Molecule.reserveMemoryForAtoms ( int  num_atoms)

Reserves memory for num_atoms atoms.

Allows implementors to speed up the creation of molecules with a known large number of atoms.

Parameters
num_atomsThe expected number of atoms for which memory shall be allocated in advance.

◆ reserveMemoryForBonds()

None CDPL.Chem.Molecule.reserveMemoryForBonds ( int  num_bonds)

Reserves memory for num_bonds bonds.

Allows implementors to speed up the creation of molecules with a known large number of bonds.

Parameters
num_bondsThe expected number of bonds for which memory shall be allocated in advance.

◆ addAtom()

Atom CDPL.Chem.Molecule.addAtom ( )

Creates a new atom and adds it to the molecule.

Note that this method does not create any bonds - the returned atom is always unconnected.

Returns
A reference to the newly created atom.

◆ addBond()

Bond CDPL.Chem.Molecule.addBond ( int  atom1_idx,
int  atom2_idx 
)

Creates a new or returns an already existing bond between the atoms specified by atom1_idx and atom2_idx.

If a bond between the specified atoms already exists then the existing bond will be returned. If a bond does not yet exist, a new bond will be created. The atom specified by atom1_idx becomes the start atom and the atom specified by atom2_idx the end atom of the newly created bond.

Parameters
atom1_idxThe zero-based index of the first atom of the bond.
atom2_idxThe zero-based index of the second atom of the bond.
Returns
A reference to the newly created or already existing bond between the specified atoms.
Exceptions
Base.IndexErrorif atom1_idx and/or atom2_idx is not in the range [0, getNumAtoms()).

◆ removeAtom()

None CDPL.Chem.Molecule.removeAtom ( int  idx)

Removes the atom at the specified index.

If the specified atom is connected to any other atoms of the molecule then the connecting bonds will also be removed.

Parameters
idxThe index of the atom to remove.
Exceptions
Base.IndexErrorif idx is not in the range [0, getNumAtoms()).

◆ removeBond()

None CDPL.Chem.Molecule.removeBond ( int  idx)

Removes the bond at the specified index.

Parameters
idxThe zero-based index of the bond to remove.
Exceptions
Base.IndexErrorif idx is not in the range [0, getNumBonds()).

◆ copy() [1/2]

None CDPL.Chem.Molecule.copy ( Molecule  mol)

Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecule mol.

Parameters
molThe molecule to copy.

Reimplemented in CDPL.Chem.BasicMolecule.

◆ copy() [2/2]

None CDPL.Chem.Molecule.copy ( MolecularGraph  molgraph)

Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecular graph molgraph.

Parameters
molgraphThe molecular graph providing the atoms, bonds and properties to copy.

Reimplemented in CDPL.Chem.BasicMolecule.

◆ append() [1/2]

None CDPL.Chem.Molecule.append ( Molecule  mol)

Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol.

Parameters
molThe molecule providing the atoms and bonds to append.
Note
Does not affect any properties.

Reimplemented in CDPL.Chem.BasicMolecule.

◆ append() [2/2]

None CDPL.Chem.Molecule.append ( MolecularGraph  molgraph)

Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecular graph molgraph.

Parameters
molgraphThe molecular graph providing the atoms and bonds to append.
Note
Does not affect any properties.

Reimplemented in CDPL.Chem.BasicMolecule.

◆ remove()

None CDPL.Chem.Molecule.remove ( MolecularGraph  molgraph)

Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule instance.

Parameters
molgraphThe molecular graph specifying the atoms and bonds to remove.
Note
Does not affect any properties if this != &molgraph.

◆ assign() [1/2]

Molecule CDPL.Chem.Molecule.assign ( Molecule  mol)

Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecule mol.

Internally calls copy() to perform the actual work.

Parameters
molThe molecule to copy.
Returns
self

Reimplemented in CDPL.Chem.BasicMolecule.

◆ assign() [2/2]

Molecule CDPL.Chem.Molecule.assign ( MolecularGraph  molgraph)

Replaces the current set of atoms, bonds and properties by a copy of the atoms, bonds and properties of the molecular graph molgraph.

Internally calls copy() to perform the actual work.

Parameters
molgraphThe Chem.MolecularGraph instance providing the atoms and bonds to copy.
Returns
self

Reimplemented in CDPL.Chem.BasicMolecule.

◆ registerCopyPostprocessingFunction()

None CDPL.Chem.Molecule.registerCopyPostprocessingFunction ( VoidMoleculeMolecularGraphFunctor  func)
static

Registers a new copy postprocessing function in the global registry.

Registered functions are invoked in registration order typically after copy/append operations that populate a Chem.Molecule instance with atoms and bonds from a source Chem.MolecularGraph instance.

Parameters
funcThe callback function to register.

◆ invokeCopyPostprocessingFunctions()

None CDPL.Chem.Molecule.invokeCopyPostprocessingFunctions ( MolecularGraph  src_molgraph)

Invokes all registered copy postprocessing functions on this molecule with src_molgraph as the source molecular graph.

Parameters
src_molgraphThe source molecular graph that provided the copied atoms and bonds.

◆ getAtom()

Atom CDPL.Chem.Molecule.getAtom ( int  idx)

Returns a reference to the atom at index idx.

Parameters
idxThe zero-based index of the atom to return.
Returns
A reference to the atom at the specified index.
Exceptions
Base.IndexErrorif idx is not in the range [0, getNumAtoms()).

Reimplemented from CDPL.Chem.MolecularGraph.

◆ containsAtom()

bool CDPL.Chem.Molecule.containsAtom ( Atom  atom)

Tells whether the specified atom is part of the atom sequence.

Parameters
atomThe atom to look for.
Returns
True if atom is part of the sequence, and False otherwise.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getAtomIndex()

int CDPL.Chem.Molecule.getAtomIndex ( Atom  atom)

Returns the index of the specified atom.

Parameters
atomThe atom for which to return the index.
Returns
The zero-based index of the specified atom.
Exceptions
Base.ItemNotFoundif the specified atom could not be found.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getNumAtoms()

int CDPL.Chem.Molecule.getNumAtoms ( )

Returns the number of atoms.

Returns
The number of atoms.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ orderAtoms()

None CDPL.Chem.Molecule.orderAtoms ( BoolAtom2Functor  func)

Orders the atoms according to criteria implemented by the provided atom comparison function.

Parameters
funcThe atom comparison function implementing the applied ordering criteria.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getEntity()

Entity3D CDPL.Chem.Molecule.getEntity ( int  idx)

Returns a reference to the entity at index idx.

Forwards to getAtom() and exists to satisfy the Chem.Entity3DContainer interface.

Parameters
idxThe zero-based entity index.
Returns
A reference to the entity at the specified index.
Exceptions
Base.IndexErrorif idx is not in the range [0, getNumAtoms()).

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getNumEntities()

int CDPL.Chem.Molecule.getNumEntities ( )

Returns the number of stored Chem.Entity3D objects.

Forwards to getNumAtoms() and exists to satisfy the Chem.Entity3DContainer interface.

Returns
The number of contained atoms.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getBond()

Bond CDPL.Chem.Molecule.getBond ( int  idx)

Returns a reference to the bond at index idx.

Parameters
idxThe zero-based index of the bond to return.
Returns
A reference to the bond at the specified index.
Exceptions
Base.IndexErrorif idx is not in the range [0, getNumBonds()).

Reimplemented from CDPL.Chem.MolecularGraph.

◆ containsBond()

bool CDPL.Chem.Molecule.containsBond ( Bond  bond)

Tells whether the specified bond is part of the bond sequence.

Parameters
bondThe bond to look for.
Returns
True if bond is part of the sequence, and False otherwise.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ orderBonds()

None CDPL.Chem.Molecule.orderBonds ( BoolBond2Functor  func)

Orders the bonds according to criteria implemented by the provided bond comparison function.

Parameters
funcThe bond comparison function implementing the applied ordering criteria.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getBondIndex()

int CDPL.Chem.Molecule.getBondIndex ( Bond  bond)

Returns the index of the specified bond.

Parameters
bondThe bond for which to return the index.
Returns
The zero-based index of the specified bond.
Exceptions
Base.ItemNotFoundif the specified bond could not be found.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ getNumBonds()

int CDPL.Chem.Molecule.getNumBonds ( )

Returns the number of bonds.

Returns
The number of bonds.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ __iadd__() [1/2]

Molecule CDPL.Chem.Molecule.__iadd__ ( Molecule  mol)

Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecule mol.

Internally calls append() to perform the actual work.

Parameters
molThe molecule providing the atoms and bonds to append.
Returns
self

Reimplemented in CDPL.Chem.BasicMolecule.

◆ __iadd__() [2/2]

Molecule CDPL.Chem.Molecule.__iadd__ ( MolecularGraph  molgraph)

Extends the current set of atoms and bonds by a copy of the atoms and bonds of the molecular graph molgraph.

Internally calls append() to perform the actual work.

Parameters
molgraphThe Chem.MolecularGraph instance providing the atoms and bonds to append.
Returns
self

Reimplemented in CDPL.Chem.BasicMolecule.

◆ __isub__()

Molecule CDPL.Chem.Molecule.__isub__ ( MolecularGraph  molgraph)

Removes atoms and bonds referenced by the molecular graph molgraph that are part of this Molecule instance.

Internally calls remove() to perform the actual work.

Parameters
molgraphThe Chem.MolecularGraph instance specifying the atoms and bonds to remove.
Returns
self

◆ __contains__() [1/3]

bool CDPL.Chem.Molecule.__contains__ ( Base.LookupKey  key)

Returns the result of the membership test operation key in self.

Parameters
keyThe value to test for membership.
Returns
The result of the membership test operation.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ __contains__() [2/3]

bool CDPL.Chem.Molecule.__contains__ ( Bond  bond)

Returns the result of the membership test operation bond in self.

Parameters
bondThe value to test for membership.
Returns
The result of the membership test operation.

Reimplemented from CDPL.Chem.MolecularGraph.

◆ __contains__() [3/3]

bool CDPL.Chem.Molecule.__contains__ ( Atom  atom)

Returns the result of the membership test operation atom in self.

Parameters
atomThe value to test for membership.
Returns
The result of the membership test operation.

Reimplemented from CDPL.Chem.MolecularGraph.