Loading...
Searching...
No Matches
Molecule Class Reference

A QObject derived molecule object with signals/slots.

`#include <avogadro/qtgui/molecule.h>`

Inheritance diagram for Molecule:

## Public Types

enum | MoleculeChange { NoChange = 0 , Atoms = 1 , Bonds = 2 , UnitCell = 4 , Selection = 8 , Layers = 16 , Properties = 32 , Constraints = 64 , Residues = 128 , NewCrystal = 256 , Added = 1024 , Removed = 2048 , Modified = 4096 , Moved = 8192 }
typedef Core::Molecule::AtomType | AtomType
typedef PersistentAtom< Molecule > | PersistentAtomType
typedef Core::Molecule::BondType | BondType
typedef PersistentBond< Molecule > | PersistentBondType
Public Types inherited from Molecule
using | AtomType = Atom
using | BondType = Bond
using | CustomElementMap = std::map<unsigned char, std::string>
using | ElementMask = std::bitset<element_count>

## Public Slots

void | emitChanged (unsigned int change)
| Force the molecule to emit the changed() signal.
void | emitUpdate () const
| Request an update through the update() signal.

## Signals

void | changed (unsigned int change) const
| Indicates that the molecule has changed.
void | update () const
| Request an update of the molecule. (e.g., re-compute properties).

## Public Member Functions

| Molecule (QObject *parent_=nullptr)
| ~Molecule () override
| Molecule (const Molecule &other)
| Molecule (const Core::Molecule &other)
Molecule & | operator= (const Molecule &other)
Molecule & | operator= (const Core::Molecule &other)
AtomType | addAtom (unsigned char atomicNumber) override
virtual AtomType | addAtom (unsigned char atomicNumber, Index uniqueId)
AtomType | addAtom (unsigned char number, Vector3 position3d, Index uniqueId=MaxIndex)
bool | removeAtom (Index index) override
| Remove the specified atom from the molecule.
bool | removeAtom (const AtomType &atom) override
| Remove the specified atom from the molecule.
AtomType | atomByUniqueId (Index uniqueId)
| Get the atom referenced by the `uniqueId`, the isValid method should be queried to ensure the id still referenced a valid atom.
Core::Array< Index > & | atomUniqueIds ()
BondType | addBond (const AtomType &a, const AtomType &b, unsigned char bondOrder=1) override
| Add a bond between the specified atoms.
BondType | addBond (Index atomId1, Index atomId2, unsigned char bondOrder=1) override
| Add a bond between the specified atoms.
void | addBonds (const Core::Array< std::pair< Index, Index > > &bonds, const Core::Array< unsigned char > &orders)
virtual BondType | addBond (const AtomType &a, const AtomType &b, unsigned char bondOrder, Index uniqueId)
| Add a bond between the specified atoms.
virtual BondType | addBond (Index atomId1, Index atomId2, unsigned char bondOrder, Index uniqueId)
| Add a bond between the specified atoms.
bool | removeBond (Index index) override
| Remove the specified bond.
bool | removeBond (const BondType &bond) override
| Remove the specified bond.
BondType | bondByUniqueId (Index uniqueId)
| Get the bond referenced by the `uniqueId`, the isValid method should be queried to ensure the id still referenced a valid bond.
Core::Array< Index > & | bondUniqueIds ()
Index | findAtomUniqueId (Index index) const
Index | findBondUniqueId (Index index) const
RWMolecule * | undoMolecule ()
QString | formattedFormula () const
| Get the formatted chemical formula for the molecule.
bool | isInteractive () const
void | swapBond (Index a, Index b)
void | swapAtom (Index a, Index b)
Index | atomUniqueId (const AtomType &atom) const
| Get the unique ID of the atom, this will uniquely reference the atom as long as it exists.
Index | atomUniqueId (Index atom) const
| Get the unique ID of the atom, this will uniquely reference the atom as long as it exists.
bool | removeBond (const AtomType &atom1, const AtomType &atom2) override
| Remove the specified bond.
bool | removeBond (Index atom1, Index atom2) override
| Remove the specified bond.
Index | bondUniqueId (const BondType &bond) const
| Get the unique ID of the bond, this will uniquely reference the bond as long as it exists.
Index | bondUniqueId (Index bond) const
| Get the unique ID of the bond, this will uniquely reference the bond as long as it exists.
Public Member Functions inherited from Molecule
| Molecule ()
| Molecule (const Molecule &other)
| Molecule (Molecule &&other) noexcept
Molecule & | operator= (const Molecule &other)
Molecule & | operator= (Molecule &&other) noexcept
void | readProperties (const Molecule &other)
void | setData (const std::string &name, const Variant &value)
Variant | data (const std::string &name) const
bool | hasData (const std::string &name) const
void | setDataMap (const VariantMap &map)
const VariantMap & | dataMap () const
VariantMap & | dataMap ()
MatrixX | spectra (const std::string &name) const
void | setSpectra (const std::string &name, const MatrixX &value)
std::set< std::string > | spectraTypes () const
void | setPartialCharges (const std::string &type, const MatrixX &value)
MatrixX | partialCharges (const std::string &type) const
std::set< std::string > | partialChargeTypes () const
Array< AtomHybridization > & | hybridizations ()
const Array< AtomHybridization > & | hybridizations () const
AtomHybridization | hybridization (Index atomId) const
bool | setHybridizations (const Core::Array< AtomHybridization > &hybs)
bool | setHybridization (Index atomId, AtomHybridization hybridization)
Array< signed char > & | formalCharges ()
const Array< signed char > & | formalCharges () const
signed char | formalCharge (Index atomId) const
bool | setFormalCharges (const Core::Array< signed char > &charges)
bool | setFormalCharge (Index atomId, signed char charge)
signed char | totalCharge () const
char | totalSpinMultiplicity () const
Array< unsigned short > & | isotopes ()
const Array< unsigned short > & | isotopes () const
unsigned short | isotope (Index atomId) const
bool | setIsotopes (const Core::Array< unsigned short > &isotopes)
bool | setIsotope (Index atomId, unsigned short isotope)
Array< Vector3ub > & | colors ()
const Array< Vector3ub > & | colors () const
Vector3ub | color (Index atomId) const
bool | setColors (const Core::Array< Vector3ub > &colors)
bool | setColor (Index atomId, Vector3ub color)
bool | setLayer (Index atomId, size_t layer)
size_t | layer (Index atomId) const
const Array< Vector2 > & | atomPositions2d () const
Array< Vector2 > & | atomPositions2d ()
Vector2 | atomPosition2d (Index atomId) const
bool | setAtomPositions2d (const Core::Array< Vector2 > &pos)
bool | setAtomPosition2d (Index atomId, const Vector2 &pos)
const Array< Vector3 > & | atomPositions3d () const
Array< Vector3 > & | atomPositions3d ()
Vector3 | atomPosition3d (Index atomId) const
bool | setAtomPositions3d (const Core::Array< Vector3 > &pos)
bool | setAtomPosition3d (Index atomId, const Vector3 &pos)
std::string | atomLabel (Index atomId) const
bool | setAtomLabel (Index atomId, const std::string &label)
const Core::Array< std::string > | atomLabels () const
bool | setAtomLabels (const Core::Array< std::string > &label)
void | setAtomSelected (Index atomId, bool selected)
bool | atomSelected (Index atomId) const
bool | isSelectionEmpty () const
const ElementMask | elements () const
AtomType | addAtom (unsigned char atomicNumber, Vector3 position3d)
virtual void | clearAtoms ()
AtomType | atom (Index index) const
virtual void | clearBonds ()
BondType | bond (Index index) const
BondType | bond (const AtomType &a, const AtomType &b) const
BondType | bond (Index atomId1, Index atomId2) const
std::string | bondLabel (Index bondIndex) const
bool | setBondLabel (Index bondIndex, const std::string &label)
const Core::Array< std::string > | bondLabels () const
bool | setBondLabels (const Core::Array< std::string > &label)
Mesh * | addMesh ()
| Add a mesh to the molecule.
Mesh * | mesh (Index index)
const Mesh * | mesh (Index index) const
Index | meshCount () const
void | clearMeshes ()
Cube * | addCube ()
| Add a cube to the molecule.
Cube * | cube (Index index)
const Cube * | cube (Index index) const
Index | cubeCount () const
void | clearCubes ()
bool | setActiveCubeIndex (Index index)
| Set the active cube index for volume rendering.
Index | activeCubeIndex () const
| Get the index of the active cube.
Cube * | activeCube ()
| Get the active cube for volume rendering.
const Cube * | activeCube () const
std::vector< Cube * > | cubes ()
| Get the cubes vector set (if present) for the molecule.
const std::vector< Cube * > | cubes () const
std::string | formula (const std::string &delimiter="", int showCountsOver=1) const
double | mass () const
double | monoisotopicMass () const
Vector3 | centerOfGeometry () const
Vector3 | centerOfMass () const
double | radius () const
std::pair< Vector3, Vector3 > | bestFitPlane () const
void | setBasisSet (BasisSet *basis)
BasisSet * | basisSet ()
const BasisSet * | basisSet () const
Array< double > | vibrationFrequencies () const
void | setVibrationFrequencies (const Array< double > &freq)
Array< double > | vibrationIRIntensities () const
void | setVibrationIRIntensities (const Array< double > &intensities)
Array< double > | vibrationRamanIntensities () const
void | setVibrationRamanIntensities (const Array< double > &intensities)
Array< Vector3 > | vibrationLx (int mode) const
void | setVibrationLx (const Array< Array< Vector3 > > &lx)
void | perceiveBondsSimple (const double tolerance=0.45, const double minDistance=0.32)
void | perceiveBondsFromResidueData ()
void | perceiveBondOrders ()
void | perceiveSubstitutedCations ()
size_t | coordinate3dCount () const
bool | setCoordinate3d (int coord)
Array< Vector3 > | coordinate3d (size_t index) const
bool | setCoordinate3d (const Array< Vector3 > &coords, size_t index)
void | clearCoordinate3d ()
void | estimateVelocities ()
Array< Vector3 > | velocities (int index) const
bool | setVelocities (const Array< Vector3 > &velocities, int index)
void | clearVelocities ()
bool | setTimeStep (double timestep, int index)
double | timeStep (int index, bool &status)
const Array< Vector3 > & | forceVectors () const
Array< Vector3 > & | forceVectors ()
Vector3 | forceVector (Index atomId) const
bool | setForceVectors (const Core::Array< Vector3 > &forces)
bool | setForceVector (Index atomId, const Vector3 &force)
Residue & | addResidue (std::string &name, Index &number, char &id)
void | addResidue (Residue &residue)
Residue & | residue (Index index)
const Residue & | residue (Index index) const
Array< Residue > & | residues ()
const Array< Residue > & | residues () const
Index | residueCount () const
std::string | residueLabel (Index residueIndex) const
bool | setResidueLabel (Index residueIndex, const std::string &label)
const Core::Array< std::string > | residueLabels () const
bool | setResidueLabels (const Core::Array< std::string > &label)
Index | atomCount () const
Index | atomCount (unsigned char atomicNumber) const
| Get the number of atoms in the molecule that match atomicNumber.
Index | bondCount () const
std::pair< Index, Index > | bondPair (Index bondId) const
bool | setBondPairs (const Array< std::pair< Index, Index > > &pairs)
const Array< std::pair< Index, Index > > & | bondPairs () const
const Array< unsigned char > & | bondOrders () const
const Graph & | graph () const
const Array< unsigned char > & | atomicNumbers () const
unsigned char | atomicNumber (Index atomId) const
bool | setBondOrders (const Array< unsigned char > &orders)
bool | setBondOrder (Index bondId, unsigned char order)
bool | hasCustomElements () const
bool | setBondPair (Index bondId, const std::pair< Index, Index > &pair)
unsigned char | bondOrder (Index bondId) const
bool | setAtomicNumbers (const Core::Array< unsigned char > &nums)
bool | setAtomicNumber (Index atomId, unsigned char atomicNumber)
std::map< unsigned char, size_t > | composition () const
std::map< std::string, size_t > | formulaComposition () const
Array< std::pair< Index, Index > > | getAtomBonds (Index index) const
Array< unsigned char > | getAtomOrders (Index index) const
bool | removeBonds (Index atom)
void | addBonds (const Array< std::pair< Index, Index > > &bonds, const Array< unsigned char > &orders)
void | swapBond (Index a, Index b)
void | swapAtom (Index a, Index b)
std::list< Index > | getAtomsAtLayer (size_t layer)
Layer & | layer ()
const Layer & | layer () const
void | boundingBox (Vector3 &boxMin, Vector3 &boxMax, const double radius=1.0) const
const CustomElementMap & | customElementMap () const
void | setCustomElementMap (const CustomElementMap &map)
Array< BondType > | bonds (const AtomType &a)
| Get all bonds to `a`.
Array< BondType > | bonds (Index a)
| Get all bonds to `a`.
Array< const BondType * > | bonds (Index a) const
| Get all bonds to `a`.
void | setUnitCell (UnitCell *uc)
UnitCell * | unitCell ()
const UnitCell * | unitCell () const
void | setHallNumber (unsigned short hallNumber)
unsigned short | hallNumber () const
void | addConstraint (Real Value, Index a, Index b, Index c=MaxIndex, Index d=MaxIndex)
void | addConstraint (Constraint &c)
void | removeConstraint (Index a, Index b, Index c=MaxIndex, Index d=MaxIndex)
void | clearConstraints ()
void | setConstraints (const std::vector< Core::Constraint > &constraints)
std::vector< Core::Constraint > & | constraints ()
const std::vector< Core::Constraint > & | constraints () const
void | setFrozenAtom (Index atomId, bool frozen)
bool | frozenAtom (Index atomId) const
bool | frozenAtomAxis (Index atomId, int axis) const
void | setFrozenAtomAxis (Index atomId, int axis, bool frozen)
Eigen::VectorXd | frozenAtomMask () const

## Additional Inherited Members

Static Public Member Functions inherited from Molecule
static std::pair< Vector3, Vector3 > | bestFitPlane (const Array< Vector3 > &pos)
static std::pair< Index, Index > | makeBondPair (const Index &a, const Index &b)
Protected Attributes inherited from Molecule
VariantMap | m_data
std::map< std::string, MatrixX > | m_partialCharges
| Sets of atomic partial charges.
std::map< std::string, MatrixX > | m_spectra
| Sets of spectra.
CustomElementMap | m_customElementMap
ElementMask | m_elements
Array< Vector2 > | m_positions2d
Array< Vector3 > | m_positions3d
Array< std::string > | m_atomLabels
Array< std::string > | m_bondLabels
Array< std::string > | m_residueLabels
Array< Array< Vector3 > > | m_coordinates3d
| Store conformers/trajectories.
Array< Array< Vector3 > > | m_velocities
| Store velocities.
Array< double > | m_timesteps
Array< AtomHybridization > | m_hybridizations
Array< signed char > | m_formalCharges
Array< unsigned short > | m_isotopes
| Store isotopes of the atoms.
Array< Vector3 > | m_forceVectors
Array< Vector3ub > | m_colors
Array< double > | m_vibrationFrequencies
Array< double > | m_vibrationIRIntensities
Array< double > | m_vibrationRamanIntensities
Array< Array< Vector3 > > | m_vibrationLx
std::vector< bool > | m_selectedAtoms
std::vector< Mesh * > | m_meshes
std::vector< Cube * > | m_cubes
Index | m_activeCubeIndex = 0
BasisSet * | m_basisSet
UnitCell * | m_unitCell
Array< Residue > | m_residues
unsigned short | m_hallNumber = 0
std::vector< Core::Constraint > | m_constraints
Eigen::VectorXd | m_frozenAtomMask

## Member Typedef Documentation

## AtomType

typedef Core::Molecule::AtomType AtomType

Typedef for Atom class.

## PersistentAtomType

typedef PersistentAtom<Molecule> PersistentAtomType

Typedef for PersistentAtom class.

## BondType

typedef Core::Molecule::BondType BondType

Typedef for Bond class.

## PersistentBondType

typedef PersistentBond<Molecule> PersistentBondType

Typedef for PersistentBond class.

## Member Enumeration Documentation

## MoleculeChange

enum MoleculeChange

Enumeration of change types that can be given.

Enumerator
NoChange | Useful for initializing MoleculeChange variables.
Atoms | Object types that can be changed.
NewCrystal | Indicates a new crystal structure (triggers space group fill).
Added | Operations that can affect the above types.

## Constructor & Destructor Documentation

## ~Molecule()

~Molecule | ( |  | ) |

override virtual

Destroys the molecule object.

Reimplemented from Molecule.

## Molecule() [1/2]

Molecule | ( | const Molecule & | other | ) |

copy constructor

## Molecule() [2/2]

Molecule | ( | const Core::Molecule & | other | ) |

copy constructor to copy data from base instance

## Member Function Documentation

## operator=() [1/2]

Molecule & operator= | ( | const Molecule & | other | ) |

Assignment operator

## operator=() [2/2]

Molecule & operator= | ( | const Core::Molecule & | other | ) |

Assignment operator to copy data from base instance

## addAtom() [1/2]

AtomType addAtom | ( | unsigned char | atomicNumber | ) |

override virtual

Add an atom with `atomicNumber` to the molecule.

Returns
  The atom created.

Reimplemented from Molecule.

## addAtom() [2/2]

virtual AtomType addAtom | ( | unsigned char | atomicNumber,
|  | Index | uniqueId )

virtual

Add an atom with `atomicNumber` and `uniqueId` to the molecule.

Returns
  The atom created. This can be invalid if the unique ID was already in use.

## removeAtom() [1/2]

bool removeAtom | ( | Index | index | ) |

override virtual

Parameters

  index | The index of the atom to be removed.

Returns
  True on success, false if the atom was not found.

Reimplemented from Molecule.

## removeAtom() [2/2]

bool removeAtom | ( | const AtomType & | atom | ) |

override virtual

Parameters

  atom | The atom to be removed.

Returns
  True on success, false if the atom was not found. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from Molecule.

## atomByUniqueId()

AtomType atomByUniqueId | ( | Index | uniqueId | ) |

Parameters

  uniqueId | The unique identifier for the atom.

Returns
  An Atom object, check it is valid before using it.

## atomUniqueId() [1/2]

Index atomUniqueId | ( | const AtomType & | atom | ) | const

Parameters

  atom | The atom to obtain the unique ID of.

Returns
  The unique identifier for the atom, MaxIndex if the atom is invalid or does not belong to this molecule.

## atomUniqueId() [2/2]

Index atomUniqueId | ( | Index | atom | ) | const

Parameters

  atom | The atom to obtain the unique ID of.

Returns
  The unique identifier for the atom, MaxIndex if the atom is invalid or does not belong to this molecule.

## addBond() [1/4]

BondType addBond | ( | const AtomType & | a,
|  | const AtomType & | b,
|  | unsigned char | bondOrder = 1 )

override virtual

Parameters

  a | The first atom in the bond.
  b | The second atom in the bond.
  bondOrder | The order of the bond.

Returns
  The bond created.

Reimplemented from Molecule.

## addBond() [2/4]

BondType addBond | ( | Index | atomId1,
|  | Index | atomId2,
|  | unsigned char | bondOrder = 1 )

override virtual

Parameters

  atomId1 | The index of the first atom in the bond.
  atomId2 | The index of the second atom in the bond.
  bondOrder | The order of the bond.

Returns
  The bond created.

Reimplemented from Molecule.

## addBond() [3/4]

virtual BondType addBond | ( | const AtomType & | a,
|  | const AtomType & | b,
|  | unsigned char | bondOrder,
|  | Index | uniqueId )

virtual

Parameters

  a | The first atom in the bond.
  b | The second atom in the bond.
  bondOrder | The order of the bond.
  uniqueId | The unique ID to use for the bond.

Returns
  The bond created. This can be invalid if the unique ID was already in use.

## addBond() [4/4]

virtual BondType addBond | ( | Index | atomId1,
|  | Index | atomId2,
|  | unsigned char | bondOrder,
|  | Index | uniqueId )

virtual

Parameters

  atomId1 | The index of the first atom in the bond.
  atomId2 | The index of the second atom in the bond.
  bondOrder | The order of the bond.
  uniqueId | The unique ID to use for the bond.

Returns
  The bond created. This can be invalid if the unique ID was already in use.

## removeBond() [1/4]

bool removeBond | ( | Index | index | ) |

override virtual

Parameters

  index | The index of the bond to be removed.

Returns
  True on success, false if the bond was not found.

Reimplemented from Molecule.

## removeBond() [2/4]

bool removeBond | ( | const BondType & | bond | ) |

override virtual

Parameters

  bond | The bond to be removed.

Returns
  True on success, false if the bond was not found. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from Molecule.

## removeBond() [3/4]

bool removeBond | ( | const AtomType & | atom1,
|  | const AtomType & | atom2 )

override virtual

Parameters

  atom1 | One atom in the bond.
  atom2 | The other atom in the bond.

Returns
  True on success, false if the bond was not found. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from Molecule.

## removeBond() [4/4]

bool removeBond | ( | Index | atom1,
|  | Index | atom2 )

override virtual

Parameters

  atom1 | One atom in the bond.
  atom2 | The other atom in the bond.

Returns
  True on success, false if the bond was not found. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from Molecule.

## bondByUniqueId()

BondType bondByUniqueId | ( | Index | uniqueId | ) |

Parameters

  uniqueId | The unique identifier for the bond.

Returns
  A Bond object, check it is valid before using it.

## bondUniqueId() [1/2]

Index bondUniqueId | ( | const BondType & | bond | ) | const

Parameters

  bond | The bond to obtain the unique ID of.

Returns
  The unique identifier for the bond, MaxIndex if the bond is invalid or does not belong to this molecule.

## bondUniqueId() [2/2]

Index bondUniqueId | ( | Index | bond | ) | const

Parameters

  bond | The bond to obtain the unique ID of.

Returns
  The unique identifier for the bond, MaxIndex if the bond is invalid or does not belong to this molecule.

## formattedFormula()

QString formattedFormula | ( |  | ) | const

Returns
  The formatted chemical formula in HTML format. This will include subscripts for atom counts and superscripts for charge and spin multiplicity.

## emitChanged

void emitChanged | ( | unsigned int | change | ) |

slot

Parameters

  change | See changed().

## changed

void changed | ( | unsigned int | change | ) | const

signal

Parameters

  change | Use the MoleculeChange enum to check what has changed.

The `change` variable indicates what has changed, i.e. if change & Atoms == true then atoms were changed in some way, and if change & Removed == true then one or more atoms were removed.

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

- qtgui/molecule.h