Avogadro::Core::Constraint#

class Constraint#

Constraints for optimization / dynamics.

This class represents a distance, angle, or torsional constraint / restraint during optimization or dynamics. More technically, these are implemented as stiff harmonic oscillators restraining a particular atom set towards the value.

Author

Geoffrey R. Hutchison

Distances are stored in Angstrom and angles / torsions in degrees, matching what the user sees in the property tables and constraint dialog. Energy calculators convert angular values to radians internally, so the angular force constants are in kJ/mol/radian^2.

Public Types

enum Type#

Values:

enumerator None#
enumerator DistanceConstraint#
enumerator AngleConstraint#
enumerator TorsionConstraint#
enumerator OutOfPlaneConstraint#
enumerator UnknownConstraint#

Public Functions

inline Constraint(Index a, Index b, Index c = MaxIndex, Index d = MaxIndex, Real value = 0.0)#

Constructor, results in a zero distance constraint

Parameters:
  • aAtom index of the first atom of the constraint

  • bAtom index of the second atom of the constraint

  • cAtom index of the third atom (for angles or torsions) or MaxIndex

  • dAtom index of the fourth atom (for torsion constraints) or MaxIndex

  • value – The value of the constraint, either Angstrom for distance or degrees for angles and torsions

inline void set(Index a, Index b, Index c = MaxIndex, Index d = MaxIndex, Real value = 0.0)#

Set the constraint

Parameters:
  • aAtom index of the first atom of the constraint

  • bAtom index of the second atom of the constraint

  • cAtom index of the third atom (for angles or torsions) or MaxIndex

  • dAtom index of the fourth atom (for torsion constraints) or MaxIndex

  • value – The value of the constraint, either Angstrom for distance or degrees for angles and torsions

inline void setValue(Real value)#

Set the constraint value (distance, angle, dihedral)

Parameters:

value – The value of the constraint, either Angstrom for distance or degrees for angles and torsions

inline Real value() const#
Returns:

the constraint value

inline std::tuple<Index, Index, Index, Index> atoms() const#
Returns:

the atoms in the constraint as a tuple

inline Index aIndex() const#
Returns:

the atom index from the constraint or MaxIndex

inline Index bIndex() const#
inline Index cIndex() const#
inline Index dIndex() const#
inline Real k() const#
Returns:

the harmonic force constant, either kJ/mol/Angstrom^2 for a distance restraint or kJ/mol/radian^2 for an angular one. If no force constant has been set explicitly, a type-appropriate default is used &#8212; the two have different units and cannot share a value.

inline void setK(Real k)#
inline Constraint::Type type() const#
Returns:

the type of constraint

inline void setType(Constraint::Type type) const#

Set the type of constraint. An explicit type survives later set() calls, since it cannot always be inferred from the atom indices &#8212; an out-of-plane constraint has the same four indices as a torsion. Pass None to go back to inferring the type from the indices.

Parameters:

type – The type of constraint

Public Static Attributes

static constexpr Real DefaultDistanceK = 41840.0#

Default force constant for distance restraints, in kJ/mol/Angstrom^2

static constexpr Real DefaultAngularK = 10000.0#

Default force constant for angular restraints, in kJ/mol/radian^2

Protected Attributes

Index m_aIndex = MaxIndex#
Index m_bIndex = MaxIndex#
Index m_cIndex = MaxIndex#
Index m_dIndex = MaxIndex#
Real m_value = 0.0#
Real m_k = DefaultDistanceK#
bool m_kSet = false#
mutable Constraint::Type m_type = None#
mutable bool m_typeExplicit = false#