Gromacs  2024.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
#include "gmxpre.h"
#include "poscalc.h"
#include <cstring>
#include <algorithm>
#include <vector>
#include "gromacs/math/vec.h"
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/position.h"
#include "gromacs/trajectory/trajectoryframe.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "centerofmass.h"
+ Include dependency graph for poscalc.cpp:

Description

Implements gmx::PositionCalculationCollection and functions in poscalc.h.

Todo:
There is probably some room for optimization in the calculation of positions with bases. In particular, the current implementation may do a lot of unnecessary copying. The interface would need to be changed to make it possible to use the same output positions for several calculations.
Todo:
The current algorithm for setting up base calculations could be improved in cases when there are calculations that cannot use a common base but still overlap partially (e.g., with three calculations A, B, and C such that A could use both B and C as a base, but B and C cannot use the same base). Setting up the bases in an optimal manner in every possible situation can be quite difficult unless several bases are allowed for one calculation, but better heuristics could probably be implemented. For best results, the setup should probably be postponed (at least partially) to gmx_ana_poscalc_init_eval().
Author
Teemu Murtola teemu.nosp@m..mur.nosp@m.tola@.nosp@m.gmai.nosp@m.l.com

Classes

class  gmx::PositionCalculationCollection::Impl
 Private implementation class for PositionCalculationCollection. More...
 
struct  gmx_ana_poscalc_t
 Data structure for position calculation. More...
 

Functions

static e_index_t index_type_for_poscalc (e_poscalc_t type)
 Returns the partition type for a given position type. More...
 
PositionCalculationCollection::RequiredTopologyInfo gmx::anonymous_namespace{poscalc.cpp}::requiredTopologyInfo (e_poscalc_t type, int flags)
 Helper function for determining required topology information.
 
static void set_poscalc_maxindex (gmx_ana_poscalc_t *pc, gmx_ana_index_t *g, bool bBase)
 Initializes position calculation using the maximum possible input index. More...
 
static bool can_use_base (gmx_ana_poscalc_t *pc)
 Checks whether a position calculation should use a base at all. More...
 
static bool should_merge (gmx_ana_poscalc_t *pc1, gmx_ana_poscalc_t *pc2, gmx_ana_index_t *g1, gmx_ana_index_t *g)
 Checks whether two position calculations should use a common base. More...
 
static gmx_ana_poscalc_tcreate_simple_base (gmx_ana_poscalc_t *pc)
 Creates a static base for position calculation. More...
 
static void merge_to_base (gmx_ana_poscalc_t *base, gmx_ana_poscalc_t *pc)
 Merges a calculation into another calculation such that the new calculation can be used as a base. More...
 
static void merge_bases (gmx_ana_poscalc_t *tbase, gmx_ana_poscalc_t *mbase)
 Merges two bases into one. More...
 
static void setup_base (gmx_ana_poscalc_t *pc)
 Setups the static base calculation for a position calculation. More...
 
void gmx_ana_poscalc_set_flags (gmx_ana_poscalc_t *pc, int flags)
 Sets the flags for position calculation. More...
 
void gmx_ana_poscalc_set_maxindex (gmx_ana_poscalc_t *pc, gmx_ana_index_t *g)
 Sets the maximum possible input index group for position calculation. More...
 
void gmx_ana_poscalc_init_pos (gmx_ana_poscalc_t *pc, gmx_ana_pos_t *p)
 Initializes positions for position calculation output. More...
 
void gmx_ana_poscalc_free (gmx_ana_poscalc_t *pc)
 Frees the memory allocated for position calculation. More...
 
gmx::PositionCalculationCollection::RequiredTopologyInfo gmx_ana_poscalc_required_topology_info (gmx_ana_poscalc_t *pc)
 Returns true if the position calculation requires topology information. More...
 
void gmx_ana_poscalc_update (gmx_ana_poscalc_t *pc, gmx_ana_pos_t *p, gmx_ana_index_t *g, t_trxframe *fr, const t_pbc *pbc)
 Updates a single COM/COG structure for a frame. More...
 

Function Documentation

static bool can_use_base ( gmx_ana_poscalc_t pc)
static

Checks whether a position calculation should use a base at all.

Parameters
[in]pcPosition calculation data to check.
Returns
true if pc can use a base and gets some benefit out of it, false otherwise.
static gmx_ana_poscalc_t* create_simple_base ( gmx_ana_poscalc_t pc)
static

Creates a static base for position calculation.

Parameters
pcData structure to copy.
Returns
Pointer to a newly allocated base for pc.

Creates and returns a deep copy of pc, but clears the POS_DYNAMIC and POS_MASKONLY flags. The newly created structure is set as the base (gmx_ana_poscalc_t::sbase) of pc and inserted in the collection before pc.

void gmx_ana_poscalc_free ( gmx_ana_poscalc_t pc)

Frees the memory allocated for position calculation.

Parameters
pcPosition calculation data to be freed.

The pc pointer is invalid after the call.

void gmx_ana_poscalc_init_pos ( gmx_ana_poscalc_t pc,
gmx_ana_pos_t p 
)

Initializes positions for position calculation output.

Parameters
[in]pcPosition calculation data structure.
[out]pOutput positions.

Calls to gmx_ana_poscalc_update() using pc should use only positions initialized with this function. The p->g pointer is initialized to point to an internal group that contains the maximum index group set with gmx_ana_poscalc_set_maxindex().

gmx::PositionCalculationCollection::RequiredTopologyInfo gmx_ana_poscalc_required_topology_info ( gmx_ana_poscalc_t pc)

Returns true if the position calculation requires topology information.

Parameters
[in]pcPosition calculation data to query.
Returns
Which topology information pc requires for initialization and/or evaluation.
void gmx_ana_poscalc_set_flags ( gmx_ana_poscalc_t pc,
int  flags 
)

Sets the flags for position calculation.

Parameters
[in,out]pcPosition calculation data structure.
[in]flagsNew flags.

flags are added to the old flags. If calculation type is POS_ATOM, POS_MASS is automatically cleared. If both POS_DYNAMIC and POS_MASKONLY are provided, POS_DYNAMIC is cleared. If calculation type is not POS_RES or POS_MOL, POS_COMPLMAX and POS_COMPLWHOLE are automatically cleared.

void gmx_ana_poscalc_set_maxindex ( gmx_ana_poscalc_t pc,
gmx_ana_index_t g 
)

Sets the maximum possible input index group for position calculation.

Parameters
[in,out]pcPosition calculation data structure.
[in]gMaximum index group for the calculation.

Subsequent calls to gmx_ana_poscalc_update() should use only subsets of g for evaluation.

The topology should have been set for the collection of which pc is a member.

void gmx_ana_poscalc_update ( gmx_ana_poscalc_t pc,
gmx_ana_pos_t p,
gmx_ana_index_t g,
t_trxframe *  fr,
const t_pbc pbc 
)

Updates a single COM/COG structure for a frame.

Parameters
[in]pcPosition calculation data.
[in,out]pOutput positions, initialized previously with gmx_ana_poscalc_init_pos() using pc.
[in]gIndex group to use for the update.
[in]frCurrent frame.
[in]pbcPBC data, or NULL if no PBC should be used.

gmx_ana_poscalc_init_frame() should be called for each frame before calling this function.

static e_index_t index_type_for_poscalc ( e_poscalc_t  type)
static

Returns the partition type for a given position type.

Parameters
[in]typee_poscalc_t value to convert.
Returns
Corresponding e_indet_t.
static void merge_bases ( gmx_ana_poscalc_t tbase,
gmx_ana_poscalc_t mbase 
)
static

Merges two bases into one.

Parameters
[in,out]tbaseBase calculation to merge to.
[in]mbaseBase calculation to merge to tbase.

After the call, mbase has been freed and tbase is used as the base for all calculations that previously had mbase as their base. It is assumed that any overlap between tbase and mbase is in complete blocks, i.e., that the merge is possible.

static void merge_to_base ( gmx_ana_poscalc_t base,
gmx_ana_poscalc_t pc 
)
static

Merges a calculation into another calculation such that the new calculation can be used as a base.

Parameters
[in,out]baseBase calculation to merge to.
[in,out]pcPosition calculation to merge to base.

After the call, base can be used as a base for pc (or any calculation that used it as a base). It is assumed that any overlap between base and pc is in complete blocks, i.e., that the merge is possible.

static void set_poscalc_maxindex ( gmx_ana_poscalc_t pc,
gmx_ana_index_t g,
bool  bBase 
)
static

Initializes position calculation using the maximum possible input index.

Parameters
[in,out]pcPosition calculation data structure.
[in]gMaximum index group for the calculation.
[in]bBaseWhether pc will be used as a base or not.

bBase affects on how the pc->gmax field is initialized.

static void setup_base ( gmx_ana_poscalc_t pc)
static

Setups the static base calculation for a position calculation.

Parameters
[in,out]pcPosition calculation to setup the base for.
static bool should_merge ( gmx_ana_poscalc_t pc1,
gmx_ana_poscalc_t pc2,
gmx_ana_index_t g1,
gmx_ana_index_t g 
)
static

Checks whether two position calculations should use a common base.

Parameters
[in]pc1Calculation 1 to check for.
[in]pc2Calculation 2 to check for.
[in]g1Index group structure that contains the atoms from pc1.
[in,out]gWorking space, should have enough allocated memory to contain the intersection of the atoms in pc1 and pc2.
Returns
true if the two calculations should be merged to use a common base, false otherwise.