forked from Colvars/colvars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolvarcomp_volmaps.cpp
125 lines (101 loc) · 3.51 KB
/
colvarcomp_volmaps.cpp
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
// -*- c++ -*-
// This file is part of the Collective Variables module (Colvars).
// The original version of Colvars and its updates are located at:
// https://github.com/Colvars/colvars
// Please update all Colvars source files before making any changes.
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.
#include "colvarmodule.h"
#include "colvarvalue.h"
#include "colvar.h"
#include "colvarcomp.h"
colvar::map_total::map_total()
{
set_function_type("mapTotal");
x.type(colvarvalue::type_scalar);
}
int colvar::map_total::init(std::string const &conf)
{
int error_code = cvc::init(conf);
colvarproxy *proxy = cvm::main()->proxy;
get_keyval(conf, "mapName", volmap_name, volmap_name);
get_keyval(conf, "mapID", volmap_id, volmap_id);
register_param("mapID", reinterpret_cast<void *>(&volmap_id));
cvm::main()->cite_feature("Volumetric map-based collective variables");
if ((volmap_name.size() > 0) && (volmap_id >= 0)) {
error_code |=
cvm::error("Error: mapName and mapID are mutually exclusive.\n", COLVARS_INPUT_ERROR);
}
// Parse optional group
atoms = parse_group(conf, "atoms", true);
if (atoms) {
// Using internal selection
if (volmap_name.size()) {
error_code |= proxy->check_volmap_by_name(volmap_name);
}
if (volmap_id >= 0) {
error_code |= proxy->check_volmap_by_id(volmap_id);
}
} else {
// Using selection from the MD engine
if (volmap_name.size()) {
volmap_index = proxy->init_volmap_by_name(volmap_name);
}
if (volmap_id >= 0) {
volmap_index = proxy->init_volmap_by_id(volmap_id);
}
error_code |= (volmap_index >= 0) ? COLVARS_OK : COLVARS_INPUT_ERROR;
}
if (get_keyval(conf, "atomWeights", atom_weights, atom_weights)) {
if (!atoms) {
error_code |= cvm::error("Error: weights can only be assigned when atoms "
"are selected explicitly in Colvars.\n",
COLVARS_INPUT_ERROR);
} else {
if (atoms->size() != atom_weights.size()) {
error_code |= cvm::error("Error: if defined, the number of weights ("+
cvm::to_str(atom_weights.size())+
") must equal the number of atoms ("+
cvm::to_str(atoms->size())+
").\n", COLVARS_INPUT_ERROR);
}
}
}
if (volmap_name.size() > 0) {
volmap_id = proxy->get_volmap_id_from_name(volmap_name.c_str());
}
return error_code;
}
void colvar::map_total::calc_value()
{
colvarproxy *proxy = cvm::main()->proxy;
int flags = is_enabled(f_cvc_gradient) ? colvarproxy::volmap_flag_gradients :
colvarproxy::volmap_flag_null;
if (atoms != NULL) {
// Compute the map inside Colvars
x.real_value = 0.0;
cvm::real *w = NULL;
if (atom_weights.size() > 0) {
flags |= colvarproxy::volmap_flag_use_atom_field;
w = &(atom_weights[0]);
}
proxy->compute_volmap(flags, volmap_id, atoms->begin(), atoms->end(),
&(x.real_value), w);
} else {
// Get the externally computed value
x.real_value = proxy->get_volmap_value(volmap_index);
}
}
void colvar::map_total::calc_gradients()
{
// Computed in calc_value() or by the MD engine
}
void colvar::map_total::apply_force(colvarvalue const &force)
{
if (atoms) {
cvc::apply_force(force);
} else {
colvarproxy *proxy = cvm::main()->proxy;
proxy->apply_volmap_force(volmap_index, force.real_value);
}
}