Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
colvarmodule::atom_group::group_force_object Class Reference

A helper class for applying forces on an atom group in a way that is aware of the fitting group. NOTE: you are encouraged to use get_group_force_object() to get an instance of group_force_object instead of constructing directly. More...

#include <colvaratoms.h>

Collaboration diagram for colvarmodule::atom_group::group_force_object:
Collaboration graph
[legend]

Public Member Functions

 group_force_object (cvm::atom_group *ag)
 Constructor of group_force_object. More...
 
 ~group_force_object ()
 Destructor of group_force_object.
 
void add_atom_force (size_t i, const cvm::rvector &force)
 Apply force to atom i. More...
 

Private Member Functions

void apply_force_with_fitting_group ()
 

Private Attributes

cvm::atom_groupm_ag
 
cvm::atom_groupm_group_for_fit
 
bool m_has_fitting_force
 

Detailed Description

A helper class for applying forces on an atom group in a way that is aware of the fitting group. NOTE: you are encouraged to use get_group_force_object() to get an instance of group_force_object instead of constructing directly.

Constructor & Destructor Documentation

◆ group_force_object()

cvm::atom_group::group_force_object::group_force_object ( cvm::atom_group ag)

Constructor of group_force_object.

Parameters
agThe pointer to the atom group that forces will be applied on.

Member Function Documentation

◆ add_atom_force()

void cvm::atom_group::group_force_object::add_atom_force ( size_t  i,
const cvm::rvector force 
)

Apply force to atom i.

Parameters
iThe i-th of atom in the atom group.
forceThe force being added to atom i.

The function can be used as follows,

// In your colvar::cvc::apply_force() loop of a component:
auto ag_force = atoms->get_group_force_object();
for (ia = 0; ia < atoms->size(); ia++) {
const cvm::rvector f = compute_force_on_atom_ia();
ag_force.add_atom_force(ia, f);
}
std::vector< cvm::atom > atoms
Array of atom objects.
Definition: colvaratoms.h:242
vector of real numbers with three components
Definition: colvartypes.h:727

There are actually two scenarios under the hood: (i) If the atom group does not have a fitting group, then the force is added to atom i directly; (ii) If the atom group has a fitting group, the force on atom i will just be temporary stashed into ag->group_forces. At the end of the loop of apply_force(), the destructor ~group_force_object() will be called, which then call apply_force_with_fitting_group(). The forces on the main group will be rotated back by multiplying ag->group_forces with the inverse rotation. The forces on the fitting group (if enableFitGradients is on) will be calculated by calling calc_fit_forces.


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