File: colvarproxy_volmaps.h

package info (click to toggle)
lammps 20250204%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 474,368 kB
  • sloc: cpp: 1,060,070; python: 27,785; ansic: 8,956; f90: 7,254; sh: 6,044; perl: 4,171; fortran: 2,442; xml: 1,714; makefile: 1,352; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (128 lines) | stat: -rw-r--r-- 4,176 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -*- c++ -*-

#ifndef COLVARPROXY_VOLMAPS_H
#define COLVARPROXY_VOLMAPS_H


/// \brief Container of grid-based objects
class colvarproxy_volmaps {

public:

  /// Contructor
  colvarproxy_volmaps();

  /// Destructor
  virtual ~colvarproxy_volmaps();

  /// Clear volumetric map data
  int reset();

  /// Test whether this implementation can use volumetric maps as CVs
  virtual int check_volmaps_available();

  /// Create a slot for a volumetric map not requested yet
  int add_volmap_slot(int volmap_id);

  /// Request and prepare this volumetric map for use by Colvars
  /// \param volmap_id Numeric ID used by the MD engine
  /// \returns Index of the map in the colvarproxy arrays
  virtual int init_volmap_by_id(int volmap_id);

  /// Request and prepare this volumetric map for use by Colvars
  /// \param volmap_name Name used by the MD engine
  /// \returns Index of the map in the colvarproxy arrays
  virtual int init_volmap_by_name(char const *volmap_name);

  /// Check that the given volmap ID is valid (return COLVARS_OK if it is)
  /// \param volmap_id Numeric ID used by the MD engine
  /// \returns Error code
  virtual int check_volmap_by_id(int volmap_id);

  /// Check that the given volmap name is valid (return COLVARS_OK if it is)
  /// \param volmap_name Name used by the MD engine
  /// \returns Error code
  virtual int check_volmap_by_name(char const *volmap_name);

  /// Request and prepare this volumetric map for use by Colvars
  int init_volmap_by_name(std::string const &volmap_name);

  /// Check that the given volmap name is valid (return COLVARS_OK if it is)
  int check_volmap_by_name(std::string const &volmap_name);

  /// \brief Used by the CVC destructors
  virtual void clear_volmap(int index);

  /// Get the numeric ID of the given volumetric map (for the MD program)
  virtual int get_volmap_id_from_name(char const *volmap_name);

  /// Get the numeric ID of the given volumetric map (for the MD program)
  inline int get_volmap_id(int index) const
  {
    return volmaps_ids[index];
  }

  /// Read the current value of the volumetric map
  inline cvm::real get_volmap_value(int index) const
  {
    return volmaps_values[index];
  }

  /// Request that this force is applied to the given volumetric map
  inline void apply_volmap_force(int index, cvm::real const &new_force)
  {
    volmaps_new_colvar_forces[index] += new_force;
  }

  /// Re-weigh an atomic field (e.g. a colvar) by the value of a volumetric map
  /// \param flags Combination of flags
  /// \param volmap_id Numeric index of the map (no need to request it)
  /// \param atom_begin Iterator pointing to first atom
  /// \param atom_end Iterator pointing past the last atom
  /// \param value Pointer to location of total to increment
  /// \param atom_field Array of atomic field values (if NULL, ones are used)
  virtual int compute_volmap(int flags,
                             int volmap_id,
                             cvm::atom_iter atom_begin,
                             cvm::atom_iter atom_end,
                             cvm::real *value,
                             cvm::real *atom_field);

  /// Flags controlling what computation is done on the map
  enum {
    volmap_flag_null = 0,
    volmap_flag_gradients = 1,
    volmap_flag_use_atom_field = (1<<8)
  };

  /// Compute the root-mean-square of the applied forces
  void compute_rms_volmaps_applied_force();

  /// Compute the maximum norm among all applied forces
  void compute_max_volmaps_applied_force();

protected:

  /// \brief Array of numeric IDs of volumetric maps
  std::vector<int>          volmaps_ids;

  /// \brief Keep track of how many times each vol map is used by a
  /// separate colvar object
  std::vector<size_t>       volmaps_refcount;

  /// \brief Current values of the vol maps
  std::vector<cvm::real>    volmaps_values;

  /// \brief Forces applied from colvars, to be communicated to the MD
  /// integrator
  std::vector<cvm::real>    volmaps_new_colvar_forces;

  /// Root-mean-square of the the applied forces
  cvm::real volmaps_rms_applied_force_;

  /// Maximum norm among all applied forces
  cvm::real volmaps_max_applied_force_;
};


#endif