# HarmonicBondForce Class Reference

This class implements an interaction between pairs of particles that varies harmonically with the distance between them. More...

`#include <HarmonicBondForce.h>`

Inheritance diagram for HarmonicBondForce:

List of all members.

## Classes

class | BondInfo
| This is an internal class used to record information about a bond.

## Public Member Functions

| HarmonicBondForce ()
| Create a HarmonicBondForce.
int | getNumBonds () const
| Get the number of harmonic bond stretch terms in the potential function.
int | addBond (int particle1, int particle2, double length, double k)
| Add a bond term to the force field.
void | getBondParameters (int index, int &particle1, int &particle2, double &length, double &k) const
| Get the force field parameters for a bond term.
void | setBondParameters (int index, int particle1, int particle2, double length, double k)
| Set the force field parameters for a bond term.
void | updateParametersInContext (Context &context)
| Update the per-bond parameters in a Context to match those stored in this Force object.

## Protected Member Functions

ForceImpl * | createImpl () const
| When a Context is created, it invokes this method on each Force in the System.

## Detailed Description

This class implements an interaction between pairs of particles that varies harmonically with the distance between them.

To use it, create a HarmonicBondForce object then call addBond() once for each bond. After a bond has been added, you can modify its force field parameters by calling setBondParameters(). This will have no effect on Contexts that already exist unless you call updateParametersInContext().

## Constructor & Destructor Documentation

HarmonicBondForce | ( |  | ) |

Create a HarmonicBondForce.

## Member Function Documentation

int addBond | ( | int | particle1,
|  | int | particle2,
|  | double | length,
|  | double | k |
| ) |  |  |

Add a bond term to the force field.

Parameters:

  | particle1 | the index of the first particle connected by the bond
  | particle2 | the index of the second particle connected by the bond
  | length | the equilibrium length of the bond, measured in nm
  | k | the harmonic force constant for the bond, measured in kJ/mol/nm^2

Returns:
  the index of the bond that was added

ForceImpl* createImpl | ( |  | ) | const`[protected, virtual]`

When a Context is created, it invokes this method on each Force in the System.

It should create a new ForceImpl object which can be used by the context for calculating forces. The ForceImpl will be deleted automatically when the Context is deleted.

Implements Force.

void getBondParameters | ( | int | index,
|  | int & | particle1,
|  | int & | particle2,
|  | double & | length,
|  | double & | k |
| ) |  |  | const

Get the force field parameters for a bond term.

Parameters:

  | index | the index of the bond for which to get parameters
  | particle1 | the index of the first particle connected by the bond
  | particle2 | the index of the second particle connected by the bond
  | length | the equilibrium length of the bond, measured in nm
  | k | the harmonic force constant for the bond, measured in kJ/mol/nm^2

int getNumBonds | ( |  | ) | const`[inline]`

Get the number of harmonic bond stretch terms in the potential function.

void setBondParameters | ( | int | index,
|  | int | particle1,
|  | int | particle2,
|  | double | length,
|  | double | k |
| ) |  |  |

Set the force field parameters for a bond term.

Parameters:

  | index | the index of the bond for which to set parameters
  | particle1 | the index of the first particle connected by the bond
  | particle2 | the index of the second particle connected by the bond
  | length | the equilibrium length of the bond, measured in nm
  | k | the harmonic force constant for the bond, measured in kJ/mol/nm^2

void updateParametersInContext | ( | Context & | context | ) |

Update the per-bond parameters in a Context to match those stored in this Force object.

This method provides an efficient method to update certain parameters in an existing Context without needing to reinitialize it. Simply call setBondParameters() to modify this object's parameters, then call updateParametersInState() to copy them over to the Context.

The only information this method updates is the values of per-bond parameters. The set of particles involved in a bond cannot be changed, nor can new bonds be added.

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

- HarmonicBondForce.h