AvogadroLibs 1.98.1
|
The RWMolecule class is an editable molecule class that automatically populates an undo stack. More...
#include <avogadro/qtgui/rwmolecule.h>
Classes | |
class | UndoCommand |
Public Types | |
typedef RWAtom | AtomType |
typedef PersistentAtom< RWMolecule > | PersistentAtomType |
typedef RWBond | BondType |
typedef PersistentBond< RWMolecule > | PersistentBondType |
Public Slots | |
void | emitChanged (unsigned int change) |
Force the molecule to emit the changed() signal. | |
Signals | |
void | changed (unsigned int change) |
Indicates that the molecule has changed. | |
Public Member Functions | |
RWMolecule (Molecule &mol, QObject *parent=nullptr) | |
Molecule & | molecule () |
const Molecule & | molecule () const |
AtomType | addAtom (unsigned char atomicNumber, bool usingPositions=true) |
AtomType | addAtom (unsigned char atomicNumber, const Vector3 &position3d) |
AtomType | atom (Index atomId) const |
AtomType | atomByUniqueId (Index atomUId) const |
Index | atomCount () const |
Index | atomCount (unsigned char atomicNumber) const |
void | clearAtoms () |
void | adjustHydrogens (Index atomId) |
void | adjustHydrogens (const Core::Array< Index > &atomIds) |
const Core::Array< unsigned char > & | atomicNumbers () const |
unsigned char | atomicNumber (Index atomId) const |
bool | setAtomicNumbers (const Core::Array< unsigned char > &nums) |
bool | setAtomicNumber (Index atomId, unsigned char atomicNumber) |
const Core::Array< Vector3 > & | atomPositions3d () const |
Vector3 | atomPosition3d (Index atomId) const |
bool | setAtomPositions3d (const Core::Array< Vector3 > &pos, const QString &undoText=tr("Change Atom Positions")) |
bool | setAtomPosition3d (Index atomId, const Vector3 &pos, const QString &undoText=tr("Change Atom Position")) |
std::string | label (Index atomId) const |
bool | setLabel (Index atomId, const std::string &label, const QString &undoText=tr("Change Atom Label")) |
void | setAtomSelected (Index atomId, bool selected, const QString &undoText=tr("Change Selection")) |
bool | atomSelected (Index atomId) const |
bool | setAtomPosition2d (Index, const Vector2 &) |
Vector2 | atomPosition2d (Index) |
const Core::Array< Vector2 > & | atomPositions2d () const |
Core::AtomHybridization | hybridization (Index atomId) const |
bool | setHybridization (Index atomId, Core::AtomHybridization hyb) |
signed char | formalCharge (Index atomId) const |
bool | setFormalCharge (Index atomId, signed char charge) |
Vector3ub | color (Index atomId) const |
bool | setColor (Index atomId, Vector3ub color) |
bool | setLayer (Index atomId, size_t layer) |
size_t | layer (Index atomId) const |
BondType | bond (Index bondId) const |
BondType | bond (Index atom1, Index atom2) const |
BondType | bond (const AtomType &atom1, const AtomType &atom2) const |
BondType | bondByUniqueId (Index bondUid) const |
Index | bondUniqueId (Index bondId) const |
Index | bondUniqueId (const BondType &bond) const |
Index | bondCount () const |
void | clearBonds () |
Core::Array< BondType > | bonds (const AtomType &atom) const |
Core::Array< BondType > | bonds (const Index &atomId) const |
const Core::Array< unsigned char > & | bondOrders () const |
unsigned char | bondOrder (Index bondId) const |
bool | setBondOrders (const Core::Array< unsigned char > &orders) |
bool | setBondOrder (Index bondId, unsigned char order) |
const Core::Array< std::pair< Index, Index > > & | bondPairs () const |
std::pair< Index, Index > | bondPair (Index bondId) const |
bool | setBondPairs (const Core::Array< std::pair< Index, Index > > &pairs) |
bool | setBondPair (Index bondId, const std::pair< Index, Index > &pair) |
void | addUnitCell () |
void | removeUnitCell () |
void | modifyMolecule (const Molecule &newMolecule, Molecule::MoleculeChanges changes, const QString &undoText=QStringLiteral("Modify Molecule")) |
void | appendMolecule (const Molecule &addMolecule, const QString &undoText=QStringLiteral("Append Molecule")) |
void | editUnitCell (Matrix3 cellMatrix, Core::CrystalTools::Options opts) |
void | wrapAtomsToCell () |
void | rotateCellToStandardOrientation () |
void | setCellVolume (double newVolume, Core::CrystalTools::Options options) |
void | buildSupercell (unsigned int a, unsigned int b, unsigned int c) |
void | niggliReduceCell () |
bool | reduceCellToPrimitive (double cartTol=1e-5) |
bool | conventionalizeCell (double cartTol=1e-5) |
bool | symmetrizeCell (double cartTol=1e-5) |
bool | fillUnitCell (unsigned short hallNumber, double cartTol=1e-5) |
bool | reduceCellToAsymmetricUnit (unsigned short hallNumber, double cartTol=1e-5) |
void | beginMergeMode (const QString &undoName=QStringLiteral("Draw")) |
void | endMergeMode () |
void | setInteractive (bool b) |
Begin or end an interactive edit. | |
bool | isInteractive () const |
const Core::Array< Vector3 > & | forceVectors () const |
bool | setForceVector (Index atomId, const Vector3 &pos, const QString &undoText=QStringLiteral("Change Force Vectors")) |
Index | atomUniqueId (Index atomId) const |
Index | atomUniqueId (const AtomType &atom) const |
bool | removeAtom (Index atomId) |
bool | removeAtom (const AtomType &atom) |
BondType | addBond (Index atom1, Index atom2, unsigned char order=1) |
BondType | addBond (const AtomType &atom1, const AtomType &atom2, unsigned char order=1) |
bool | removeBond (Index bondId) |
bool | removeBond (const BondType &bond) |
bool | removeBond (Index atom1, Index atom2) |
bool | removeBond (const AtomType &atom1, const AtomType &atom2) |
QUndoStack & | undoStack () |
const QUndoStack & | undoStack () const |
Protected Member Functions | |
Index | findAtomUniqueId (Index atomId) const |
Index | findBondUniqueId (Index bondId) const |
Protected Attributes | |
Molecule & | m_molecule |
m_molecule still stored all data, this class acts upon it and builds an undo/redo stack that can be used to offer undo and redo. | |
bool | m_interactive |
QUndoStack | m_undoStack |
This class implements the molecule API and composes a QUndoStack (undoStack()). New undo commands are automatically generated and push each time a non-const method is called.
An interactive mode is supported that causes "noisy" commands, such as atom position changes, to be merged into a single command, saving memory keeping the stack usable during interactive editing of the molecule. Use setInteractive(bool) to toggle interactive mode.
Similarly, multiple sequences of commands can be compressed into a single named action using the QUndoStack's macro capability. Call undoStack().beginMacro(tr("User Description Of Change")) to begin a macro, and undoStack().endMacro() when finished.
typedef PersistentAtom<RWMolecule> PersistentAtomType |
Typedef for PersistentAtom class.
typedef PersistentBond<RWMolecule> PersistentBondType |
Typedef for PersistentBond class.
|
explicit |
Construct a molecule with the atoms/bonds of mol.
AtomType addAtom | ( | unsigned char | atomicNumber, |
bool | usingPositions = true |
||
) |
Add a new atom to the molecule.
atomicNumber | The atomic number of the new atom. |
usingPositions | Whether or not to use positions for this atom. Default is true. Set to false if the atom will not be using coordinates. |
AtomType addAtom | ( | unsigned char | atomicNumber, |
const Vector3 & | position3d | ||
) |
Add a new atom to the molecule and set its position.
atomicNumber | The atomic number of the new atom. |
position3d | The position of the atom. |
RWMolecule::AtomType atom | ( | Index | atomId | ) | const |
Obtain an atom object.
atomId | The index of the atom to return. |
RWMolecule::AtomType atomByUniqueId | ( | Index | atomUId | ) | const |
Obtain an atom object from it's unique id.
atomUId | The unique of the requested atom. |
Index atomUniqueId | ( | Index | atomId | ) | const |
Index atomUniqueId | ( | const AtomType & | atom | ) | const |
Index atomCount | ( | ) | const |
Index atomCount | ( | unsigned char | atomicNumber | ) | const |
bool removeAtom | ( | Index | atomId | ) |
Delete the specified atom from this molecule.
bool removeAtom | ( | const AtomType & | atom | ) |
Delete the specified atom from this molecule.
void clearAtoms | ( | ) |
Delete all atoms from this molecule.
void adjustHydrogens | ( | Index | atomId | ) |
Adjust hydrogens for an atom.
atomId | The index of the atom. |
void adjustHydrogens | ( | const Core::Array< Index > & | atomIds | ) |
Adjust hydrogens for multiple atoms.
atomIds | The indices for the atoms. |
const Core::Array< unsigned char > & atomicNumbers | ( | ) | const |
unsigned char atomicNumber | ( | Index | atomId | ) | const |
Get the atomic number for the requested atom.
atomId | The index of the atom. |
bool setAtomicNumbers | ( | const Core::Array< unsigned char > & | nums | ) |
Replace the current array of atomic numbers.
nums | The new atomic number array. Must be of length atomCount(). |
bool setAtomicNumber | ( | Index | atomId, |
unsigned char | atomicNumber | ||
) |
Set the atomic number of a single atom.
atomId | The index of the atom to modify. |
atomicNumber | The new atomic number. |
const Core::Array< Vector3 > & atomPositions3d | ( | ) | const |
Vector3 atomPosition3d | ( | Index | atomId | ) | const |
Get the 3D position of a single atom.
atomId | The index of the atom. |
bool setAtomPositions3d | ( | const Core::Array< Vector3 > & | pos, |
const QString & | undoText = tr("Change Atom Positions") |
||
) |
Replace the current array of 3D atomic coordinates.
pos | The new coordinate array. Must be of length atomCount(). |
undoText | The undo text to be displayed for undo commands. |
bool setAtomPosition3d | ( | Index | atomId, |
const Vector3 & | pos, | ||
const QString & | undoText = tr("Change Atom Position") |
||
) |
Set the 3D position of a single atom.
atomId | The index of the atom to modify. |
pos | The new position of the atom. |
undoText | The undo text to be displayed for undo commands. |
void setAtomSelected | ( | Index | atomId, |
bool | selected, | ||
const QString & | undoText = tr("Change Selection") |
||
) |
Set whether the specified atom is selected or not.
bool atomSelected | ( | Index | atomId | ) | const |
Query whether the supplied atom index has been selected.
Core::AtomHybridization hybridization | ( | Index | atomId | ) | const |
Get the hybridization for the requested atom.
atomId | The index of the atom. |
bool setHybridization | ( | Index | atomId, |
Core::AtomHybridization | hyb | ||
) |
Set the hybridization of a single atom.
atomId | The index of the atom to modify. |
hyb | The new hybridization. |
signed char formalCharge | ( | Index | atomId | ) | const |
Get the formal charge for the requested atom.
atomId | The index of the atom. |
bool setFormalCharge | ( | Index | atomId, |
signed char | charge | ||
) |
Set the formal charge of a single atom.
atomId | The index of the atom to modify. |
charge | The new formal charge. |
Vector3ub color | ( | Index | atomId | ) | const |
Get the color for the requested atom.
atomId | The index of the atom. |
bool setColor | ( | Index | atomId, |
Vector3ub | color | ||
) |
Set the color of a single atom.
atomId | The index of the atom to modify. |
color | The new color. |
BondType addBond | ( | Index | atom1, |
Index | atom2, | ||
unsigned char | order = 1 |
||
) |
Create a new bond in the molecule.
atom1 | The first atom in the bond. |
atom2 | The second order in the bond. |
order | The bond order. |
RWMolecule::BondType addBond | ( | const AtomType & | atom1, |
const AtomType & | atom2, | ||
unsigned char | order = 1 |
||
) |
Create a new bond in the molecule.
atom1 | The first atom in the bond. |
atom2 | The second order in the bond. |
order | The bond order. |
RWMolecule::BondType bond | ( | Index | bondId | ) | const |
Get a bond object.
bondId | The index of the requested bond. |
BondType bond | ( | Index | atom1, |
Index | atom2 | ||
) | const |
Get a bond object.
atom1 | The index of one atom in the bond. |
atom2 | The index of the other atom in bond. |
RWMolecule::BondType bond | ( | const AtomType & | atom1, |
const AtomType & | atom2 | ||
) | const |
Get a bond object.
atom1 | One atom in the bond. |
atom2 | The other atom in bond. |
RWMolecule::BondType bondByUniqueId | ( | Index | bondUid | ) | const |
Get a bond object from its unique id.
bondUid | The unique id of the bond. |
Index bondUniqueId | ( | Index | bondId | ) | const |
Get the unique id of a bond.
bondId | The index of the requested bond. |
Index bondUniqueId | ( | const BondType & | bond | ) | const |
Get the unique id of a bond.
bond | The requested bond object. |
Index bondCount | ( | ) | const |
bool removeBond | ( | Index | bondId | ) |
Remove the requested bond.
bool removeBond | ( | const BondType & | bond | ) |
Remove the requested bond.
bool removeBond | ( | Index | atom1, |
Index | atom2 | ||
) |
Remove the requested bond.
Remove the requested bond.
void clearBonds | ( | ) |
Remove all bonds from the molecule.
Core::Array< RWMolecule::BondType > bonds | ( | const AtomType & | atom | ) | const |
Find bonds connected to an atom.
atom | The atom of interest. |
Core::Array< RWMolecule::BondType > bonds | ( | const Index & | atomId | ) | const |
Find bonds connected to an atom.
atomId | The index for the atom of interest. |
const Core::Array< unsigned char > & bondOrders | ( | ) | const |
unsigned char bondOrder | ( | Index | bondId | ) | const |
Get the order of a bond.
bondId | The id of the bond. |
bool setBondOrders | ( | const Core::Array< unsigned char > & | orders | ) |
Replace the current array of bond orders.
orders | The new array. |
bool setBondOrder | ( | Index | bondId, |
unsigned char | order | ||
) |
Set the order of a bond in the molecule.
bondId | The bond's index. |
order | The new order of the bond. |
const Core::Array< std::pair< Index, Index > > & bondPairs | ( | ) | const |
std::pair< Index, Index > bondPair | ( | Index | bondId | ) | const |
Get the set of bonded atoms corresponding to bondId.
bondId | The index of the requested bond. |
bool setBondPairs | ( | const Core::Array< std::pair< Index, Index > > & | pairs | ) |
Replace the current array of bonded atoms.
pairs | The array. |
bool setBondPair | ( | Index | bondId, |
const std::pair< Index, Index > & | pair | ||
) |
Set the bonded atoms for a bond.
bondId | The bond to modify. |
pair | The new bond pair. |
void addUnitCell | ( | ) |
Add a default unit cell to the molecule. Does nothing if there already is a unit cell. Changes are emitted.
void removeUnitCell | ( | ) |
Remove the unit cell from the molecule. Does nothing if there is no unit cell. Changes are emitted.
void modifyMolecule | ( | const Molecule & | newMolecule, |
Molecule::MoleculeChanges | changes, | ||
const QString & | undoText = QStringLiteral("Modify Molecule") |
||
) |
Generic edit that changes the current molecule to be newMolecule. Also sets the text for the undo command to be undoText. Changes are emitted.
newMolecule | The new molecule to be set. |
changes | The changes to be emitted. |
undoText | The text description for the undo command. |
void appendMolecule | ( | const Molecule & | addMolecule, |
const QString & | undoText = QStringLiteral("Append Molecule") |
||
) |
Generic edit that adds newMolecule to the current molecule. Also sets the text for the undo command to be undoText. Changes are emitted.
addMolecule | The new molecule to be set. |
undoText | The text description for the undo command. |
void editUnitCell | ( | Matrix3 | cellMatrix, |
Core::CrystalTools::Options | opts | ||
) |
Edit the unit cell by replacing the current cell matrix with a new cell matrix. Changes are emitted.
cellMatrix | The new cell matrix to be set. |
opts | If TransformAtoms is specified, the atoms in molecule are adjusted so that their fractional (lattice) coordinates are preserved. This option is ignored if the input molecule has no unit cell. |
void wrapAtomsToCell | ( | ) |
Wrap atoms to the unit cell. Changes are emitted.
void rotateCellToStandardOrientation | ( | ) |
Rotate cell to standard orientation. Changes are emitted.
void setCellVolume | ( | double | newVolume, |
Core::CrystalTools::Options | options | ||
) |
Scale a cell's volume. Changes are emitted.
newVolume | The new volume to be set. |
options | If CrystalTools::TransformAtoms is set, then the atoms will be transformed during the scaling. |
void buildSupercell | ( | unsigned int | a, |
unsigned int | b, | ||
unsigned int | c | ||
) |
Build a supercell. Changes are emitted.
a | The final number of units along the A vector (at least 1). |
b | The final number of units along the B vector (at least 1). |
c | The final number of units along the C vector (at least 1). |
void niggliReduceCell | ( | ) |
Perform a Niggli reduction on the cell. Changes are emitted.
bool reduceCellToPrimitive | ( | double | cartTol = 1e-5 | ) |
Use spglib to reduce the cell to its primitive form. Changes are emitted.
cartTol | Cartesian tolerance for primitive reduction. |
bool conventionalizeCell | ( | double | cartTol = 1e-5 | ) |
Use spglib to convert the cell to its conventional form. Changes are emitted.
cartTol | Cartesian tolerance for conventionalization. |
bool symmetrizeCell | ( | double | cartTol = 1e-5 | ) |
Use spglib to symmetrize the cell. Changes are emitted.
cartTol | Cartesian tolerance for symmetrization. |
bool fillUnitCell | ( | unsigned short | hallNumber, |
double | cartTol = 1e-5 |
||
) |
Fill unit cell using transforms for the space group. Changes are emitted.
hallNumber | The hall number to be used for transforming the cell. |
cartTol | Cartesian tolerance for comparing atom positions. |
bool reduceCellToAsymmetricUnit | ( | unsigned short | hallNumber, |
double | cartTol = 1e-5 |
||
) |
Use transforms to reduce a cell to its asymmetric unit. Changes are emitted.
hallNumber | The hall number to be used for obtaining the transforms. |
cartTol | Cartesian tolerance for comparing atom positions. |
void beginMergeMode | ( | const QString & | undoName = QStringLiteral("Draw") | ) |
Call this function when you wish to merge all undo commands. It turns on interactive mode to merge similar undo commands in a series (in order to save space), and it uses QUndoStack's beginMacro() to merge dissimilar undo commands together. You must call endMergeMode() to end the merging section (undo and redo are unavailable while merge mode is on).
undoName | The name of the undo command |
void endMergeMode | ( | ) |
Call this function when you wish merge mode to end. This will turn off interactive mode, and it will call QUndoStack's endMacro(). All of the undo commands pushed between beginMergeMode() and endMergeMode() will be merged into one undo command. beginMergeMode() should have been called before this is called.
void setInteractive | ( | bool | b | ) |
If enabled, certain undo operations will be merged together. For instance, an editor dragging an atom through space in response to mouse movement will only generate a single undo command containing the initial and final positions and discard the intermediate states. If disabled, each intermediate action will appear in the undo log.
bool isInteractive | ( | ) | const |
QUndoStack & undoStack | ( | ) |
const QUndoStack & undoStack | ( | ) | const |
const Core::Array< Vector3 > & forceVectors | ( | ) | const |
Returns a vector of forces for the atoms in the molecule.
bool setForceVector | ( | Index | atomId, |
const Vector3 & | pos, | ||
const QString & | undoText = QStringLiteral("Change Force Vectors") |
||
) |
Replace the current array of force vectors.
pos | The new force vector array. Must be of length atomCount(). |
undoText | The undo text to be displayed for undo commands. |
|
slot |
change | See changed(). |
|
signal |
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.