Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions colvartools/poisson_integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ int main (int argc, char *argv[]) {
proxy->cvmodule = new colvarmodule(proxy); // This could be omitted if we used the colvarproxy_stub class

std::string gradfile (argv[1]);
std::shared_ptr<colvar_grid_gradient> grad_ptr = std::make_shared<colvar_grid_gradient>(gradfile);
std::shared_ptr<colvar_grid_gradient> grad_ptr = std::make_shared<colvar_grid_gradient>(proxy->cvmodule, gradfile);
if (proxy->cvmodule->get_error()) { return -1; }

int itmax = 10000;
cvm::real err;
cvm::real tol = 1e-8;

colvargrid_integrate fes(grad_ptr);
colvargrid_integrate fes(proxy->cvmodule, grad_ptr);
fes.set_div();
fes.integrate(itmax, tol, err);
fes.set_zero_minimum();
Expand Down
6 changes: 3 additions & 3 deletions colvartools/poisson_integrator_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ int main (int argc, char *argv[]) {
proxy->cvmodule = new colvarmodule(proxy); // This could be omitted if we used the colvarproxy_stub class

std::string gradfile (argv[1]);
std::shared_ptr<colvar_grid_gradient> grad_ptr = std::make_shared<colvar_grid_gradient>(gradfile);
std::shared_ptr<colvar_grid_gradient> grad_ptr = std::make_shared<colvar_grid_gradient>(proxy->cvmodule, gradfile);
if (proxy->cvmodule->get_error()) { return -1; }

cvm::real err = 1.;
cvm::real tol = 1e-10;

colvargrid_integrate fes(grad_ptr);
colvargrid_integrate fes(proxy->cvmodule, grad_ptr);
fes.set_div();

// Load reference
colvar_grid_scalar ref(gradfile + ".ref");
colvar_grid_scalar ref(proxy->cvmodule, gradfile + ".ref");
if (proxy->cvmodule->get_error()) { return -1; }

if (ref.number_of_points() != fes.number_of_points()) {
Expand Down
4 changes: 2 additions & 2 deletions misc_interfaces/C_fortran/C_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ int main() {

// Cannot yet call colvarscript without language interface
unsigned char cmd[][256] = {"", "version" };
run_colvarscript_command(1, (unsigned char **)(cmd));
const char *res = get_colvarscript_result();
run_colvarscript_command(proxy, 1, (unsigned char **)(cmd));
const char *res = get_colvarscript_result(proxy);
printf("Colvarscript claims it runs version %s\n", res);
return 0;
}
2 changes: 1 addition & 1 deletion misc_interfaces/C_fortran/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COLVARS_LIB = ../../src/libcolvars.a
COLVARS_SRC_DIR = ../../src
IF_OBJ = colvarproxy_C.o

CXXFLAGS := -std=c++11 -pedantic -g -O2 -fPIC
CXXFLAGS := -std=c++17 -pedantic -g -O2 -fPIC

.PHONY: default $(COLVARS_LIB)

Expand Down
4 changes: 2 additions & 2 deletions misc_interfaces/C_fortran/colvarproxy_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ static colvarproxy* unique_colvarproxy_object;
colvarproxy_C::colvarproxy_C()
{
std::cerr << "This is the colvarproxy_C constructor at address " << this << std::endl;
colvars = new colvarmodule(this);
cvmodule->log("This is the Module speaking.");
cvmodule = new colvarmodule(this);
cvmodule->log_static("This is the Module speaking.");
}

colvarproxy_C::~colvarproxy_C()
Expand Down
4 changes: 2 additions & 2 deletions misc_interfaces/C_fortran/colvarproxy_C_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void call_proxy_member(void *proxy);
// Functions of this type should define a complete interface
// This could be based on colvarscript

int run_colvarscript_command(int objc, unsigned char *const objv[]);
const char * get_colvarscript_result();
int run_colvarscript_command(void *proxy_in, int objc, unsigned char *const objv[]);
const char * get_colvarscript_result(void *proxy_in);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ifeq ($(CXX),)
CXX := g++
endif
ifeq ($(CXXFLAGS),)
CXXFLAGS := -std=c++11 -pedantic -g -O2 -fPIC
CXXFLAGS := -std=c++17 -pedantic -g -O2 -fPIC
ifneq ($(CXX),"CC")
CXXFLAGS += -Wall
endif
Expand Down
12 changes: 6 additions & 6 deletions src/colvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "colvars_memstream.h"
#include "colvarcomp_torchann.h"

std::map<std::string, std::function<colvar::cvc *()>> colvar::global_cvc_map =
std::map<std::string, std::function<colvar::cvc *()>>();
std::map<std::string, std::function<colvar::cvc *(colvarmodule *cvmodule_in)>> colvar::global_cvc_map =
std::map<std::string, std::function<colvar::cvc *(colvarmodule *cvmodule_in)>>();

std::map<std::string, std::string> colvar::global_cvc_desc_map =
std::map<std::string, std::string>();
Expand Down Expand Up @@ -821,8 +821,8 @@ template <typename def_class_name>
void colvar::add_component_type(char const *def_description, char const *def_config_key)
{
if (global_cvc_map.count(def_config_key) == 0) {
global_cvc_map[def_config_key] = []() {
return new def_class_name();
global_cvc_map[def_config_key] = [](colvarmodule *cvmodule_in) {
return new def_class_name(cvmodule_in);
};
global_cvc_desc_map[def_config_key] = std::string(def_description);
}
Expand All @@ -844,7 +844,7 @@ int colvar::init_components_type(const std::string& conf, const char* def_config
"a new \""+std::string(def_config_key)+"\" component"+
(cvm::debug() ? ", with configuration:\n"+def_conf
: ".\n"));
cvc *cvcp = global_cvc_map[def_config_key]();
cvc *cvcp = global_cvc_map[def_config_key](cvmodule);
if (!cvcp) {
return cvmodule->error("Error: in creating object of type \"" + std::string(def_config_key) +
"\".\n",
Expand Down Expand Up @@ -1990,7 +1990,7 @@ void colvar::update_extended_Lagrangian()
// [O] leap to v_(i+1/2) (10c)
if (is_enabled(f_cv_Langevin)) {
colvarvalue rnd(x);
rnd.set_random();
rnd.set_random(this->cvmodule);
// ext_sigma has been computed at init time according to (10c)
v_ext = cvm::exp(- 1.0 * dt * ext_gamma) * v_ext + ext_sigma * rnd / ext_mass;
}
Expand Down
4 changes: 2 additions & 2 deletions src/colvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ class colvar : public colvardeps {
class map_total;

/// A global mapping of cvc names to the cvc constructors
static const std::map<std::string, std::function<colvar::cvc *()>> &get_global_cvc_map()
static const std::map<std::string, std::function<colvar::cvc *(colvarmodule *cvmodule_in)>> &get_global_cvc_map()
{
return global_cvc_map;
}
Expand Down Expand Up @@ -705,7 +705,7 @@ class colvar : public colvardeps {
#endif

/// A global mapping of cvc names to the cvc constructors
static std::map<std::string, std::function<colvar::cvc *()>> global_cvc_map;
static std::map<std::string, std::function<colvar::cvc *(colvarmodule *cvmodule_in)>> global_cvc_map;

/// A global mapping of cvc names to the corresponding descriptions
static std::map<std::string, std::string> global_cvc_desc_map;
Expand Down
7 changes: 4 additions & 3 deletions src/colvaratoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ cvm::atom_group::simple_atom cvm::atom_group::init_atom_from_proxy(
/*.grad = */{0, 0, 0}};
}

cvm::atom_group::atom_group():
cvm::atom_group::atom_group(colvarmodule* cvmodule_in):
colvardeps(cvmodule_in),
b_dummy(false),
fitting_group(nullptr),
noforce(false), b_user_defined_fit(false),
Expand All @@ -108,7 +109,7 @@ cvm::atom_group::atom_group():
init();
}

cvm::atom_group::atom_group(char const *key_in): atom_group() {
cvm::atom_group::atom_group(char const *key_in, colvarmodule* cvmodule_in): atom_group(cvmodule_in) {
key = std::string(key_in);
init();
}
Expand Down Expand Up @@ -837,7 +838,7 @@ int cvm::atom_group::parse_fitting_options(std::string const &group_conf) {
return COLVARS_INPUT_ERROR;
}
cvmodule->log("Within atom group \""+key+"\":\n");
fitting_group = new atom_group("fittingGroup");
fitting_group = new atom_group("fittingGroup", cvmodule);
if (fitting_group->parse(fitting_group_conf) == COLVARS_OK) {
fitting_group->check_keywords(fitting_group_conf, "fittingGroup");
if (cvmodule->get_error()) {
Expand Down
4 changes: 2 additions & 2 deletions src/colvaratoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class cvm::atom_group: public colvardeps {
* @attention Will call \p init_dependencies() to initialize the
* dependency tree.
*/
atom_group();
atom_group(colvarmodule* cvmodule_in);
/**
* @brief Create a group object, assign a name to it
*/
atom_group(char const *key_in);
atom_group(char const *key_in, colvarmodule* cvmodule_in);
/**
* @brief Destructor
*
Expand Down
4 changes: 2 additions & 2 deletions src/colvaratoms_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ void colvaratoms_gpu::do_feature_side_effects_gpu(
break;
}
case colvardeps::f_ag_rotate: {
rot_gpu.init();
rot_gpu.init(this->cvmodule);
break;
}
}
Expand All @@ -948,7 +948,7 @@ int colvaratoms_gpu::setup_rotation(const cvm::atom_group* cpu_atoms) {
error_code |= p->reallocate_device(&gpu_buffers.d_ref_pos, cpu_atoms->ref_pos.size());
error_code |=p->copy_HtoD(cpu_atoms->ref_pos.data(), gpu_buffers.d_ref_pos, cpu_atoms->ref_pos.size());
error_code |=p->copy_HtoD(&cpu_atoms->ref_pos_cog, gpu_buffers.d_ref_pos_cog, 1);
rot_gpu.init();
rot_gpu.init(this->cvmodule);
return error_code;
}

Expand Down
12 changes: 6 additions & 6 deletions src/colvarbias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ int colvarbias::init(std::string const &conf)
std::string biasing_force_scaling_factors_in_filename;
get_keyval(conf, "scaledBiasingForceFactorsGrid",
biasing_force_scaling_factors_in_filename, std::string());
biasing_force_scaling_factors = new colvar_grid_scalar(colvars);
biasing_force_scaling_factors = new colvar_grid_scalar(cvmodule, colvars);
error_code |= biasing_force_scaling_factors->read_multicol(biasing_force_scaling_factors_in_filename,
"grid file");
biasing_force_scaling_factors_bin.assign(num_variables(), 0);
Expand Down Expand Up @@ -278,8 +278,8 @@ int colvarbias::reset()
}


colvarbias::colvarbias()
: has_data(false)
colvarbias::colvarbias(colvarmodule* cvmodule_in)
: colvardeps(cvmodule_in), has_data(false)
{}


Expand Down Expand Up @@ -810,7 +810,7 @@ std::ostream & colvarbias::write_traj(std::ostream &os)
}


colvarbias_ti::colvarbias_ti(char const *key)
colvarbias_ti::colvarbias_ti(colvarmodule* cvmodule_in, char const *key): colvardeps(cvmodule_in), colvarbias(cvmodule_in)
{
colvarproxy *proxy = cvmodule->proxy;
provide(f_cvb_calc_ti_samples);
Expand Down Expand Up @@ -891,8 +891,8 @@ int colvarbias_ti::init_grids()
ti_system_forces[icv].is_derivative();
ti_system_forces[icv].reset();
}
ti_count.reset(new colvar_grid_count(colvars, grid_conf));
ti_avg_forces.reset(new colvar_grid_gradient(colvars, ti_count));
ti_count.reset(new colvar_grid_count(cvmodule, colvars, grid_conf));
ti_avg_forces.reset(new colvar_grid_gradient(cvmodule, colvars, ti_count));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/colvarbias.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class colvarbias
protected:

/// Default constructor
colvarbias();
colvarbias(colvarmodule* cvmodule_in);

/// Copy constructor
colvarbias(colvarbias &);
Expand Down Expand Up @@ -336,7 +336,7 @@ class colvar_grid_count;
class colvarbias_ti : public virtual colvarbias {
public:

colvarbias_ti(char const *key);
colvarbias_ti(colvarmodule* cvmodule_in, char const *key);
virtual ~colvarbias_ti();

virtual int init(std::string const &conf);
Expand Down
54 changes: 27 additions & 27 deletions src/colvarbias_abf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "colvars_memstream.h"

colvarbias_abf::colvarbias_abf(colvarmodule *cvmodule_in, char const *key)
: colvarbias(cvmodule_in, key),
: colvardeps(cvmodule_in), colvarbias(cvmodule_in, key),
b_UI_estimator(false),
b_CZAR_estimator(false),
pabf_freq(0),
Expand Down Expand Up @@ -181,16 +181,16 @@ int colvarbias_abf::init(std::string const &conf)
std::string grid_conf;
key_lookup(conf, "grid", &grid_conf);

samples.reset(new colvar_grid_count(colvars, grid_conf));
samples.reset(new colvar_grid_count(cvmodule, colvars, grid_conf));
}
gradients.reset(new colvar_grid_gradient(colvars, samples)); // Also use samples as template for sizes
gradients.reset(new colvar_grid_gradient(cvmodule, colvars, samples)); // Also use samples as template for sizes

gradients->full_samples = full_samples;
gradients->min_samples = min_samples;

if (shared_on) {
local_samples.reset(new colvar_grid_count(colvars, samples));
local_gradients.reset(new colvar_grid_gradient(colvars, local_samples));
local_samples.reset(new colvar_grid_count(cvmodule, colvars, samples));
local_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, local_samples));
}

// Data for eABF z-based estimator
Expand All @@ -204,11 +204,11 @@ int colvarbias_abf::init(std::string const &conf)
colvarparse::parse_silent);

z_bin.assign(num_variables(), 0);
z_samples.reset(new colvar_grid_count(colvars, samples));
z_samples.reset(new colvar_grid_count(cvmodule, colvars, samples));
z_samples->request_actual_value();
z_gradients.reset(new colvar_grid_gradient(colvars, z_samples));
z_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, z_samples));
z_gradients->request_actual_value();
czar_gradients.reset(new colvar_grid_gradient(colvars, nullptr, samples));
czar_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, nullptr, samples));
}

get_keyval(conf, "integrate", b_integrate, num_variables() <= 3); // Integrate for output if d<=3
Expand All @@ -218,12 +218,12 @@ int colvarbias_abf::init(std::string const &conf)
cvmodule->error("Error: cannot integrate free energy in dimension > 3.\n");
return COLVARS_ERROR;
}
pmf.reset(new colvargrid_integrate(colvars, gradients));
pmf.reset(new colvargrid_integrate(cvmodule, colvars, gradients));
if (b_CZAR_estimator) {
czar_pmf.reset(new colvargrid_integrate(colvars, czar_gradients));
czar_pmf.reset(new colvargrid_integrate(cvmodule, colvars, czar_gradients));
}
if (shared_on) {
local_pmf.reset(new colvargrid_integrate(colvars, local_gradients));
local_pmf.reset(new colvargrid_integrate(cvmodule, colvars, local_gradients));
}
// Parameters for integrating initial (and final) gradient data
get_keyval(conf, "integrateMaxIterations", integrate_iterations, 10000, colvarparse::parse_silent);
Expand All @@ -237,10 +237,10 @@ int colvarbias_abf::init(std::string const &conf)
if (b_CZAR_estimator && shared_on && cvmodule->proxy->replica_index() == 0) {
// The pointers below are used for outputting CZAR data
// Allocate grids for collected global data, on replica 0 only
global_z_samples.reset(new colvar_grid_count(colvars, samples));
global_z_gradients.reset(new colvar_grid_gradient(colvars, global_z_samples));
global_czar_gradients.reset(new colvar_grid_gradient(colvars, nullptr, samples));
global_czar_pmf.reset(new colvargrid_integrate(colvars, global_czar_gradients));
global_z_samples.reset(new colvar_grid_count(cvmodule, colvars, samples));
global_z_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, global_z_samples));
global_czar_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, nullptr, samples));
global_czar_pmf.reset(new colvargrid_integrate(cvmodule, colvars, global_czar_gradients));
} else {
// otherwise they are just aliases for the local CZAR grids
global_z_samples = z_samples;
Expand All @@ -253,11 +253,11 @@ int colvarbias_abf::init(std::string const &conf)
// This used to be only if "shared" was defined,
// but now we allow calling share externally (e.g. from Tcl).
if (b_CZAR_estimator) {
z_samples_in.reset(new colvar_grid_count(colvars, samples));
z_gradients_in.reset(new colvar_grid_gradient(colvars, z_samples_in));
z_samples_in.reset(new colvar_grid_count(cvmodule, colvars, samples));
z_gradients_in.reset(new colvar_grid_gradient(cvmodule, colvars, z_samples_in));
}
last_samples.reset(new colvar_grid_count(colvars, samples));
last_gradients.reset(new colvar_grid_gradient(colvars, last_samples));
last_samples.reset(new colvar_grid_count(cvmodule, colvars, samples));
last_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, last_samples));
// Any data collected after now is new for shared ABF purposes
shared_last_step = cvmodule->step_absolute();

Expand Down Expand Up @@ -555,9 +555,9 @@ int colvarbias_abf::replica_share() {
if (!local_samples) {
// We arrive here if sharing has just been enabled by a script
// in which case local arrays have not been initialized yet
local_samples.reset(new colvar_grid_count(colvars, samples));
local_gradients.reset(new colvar_grid_gradient(colvars, local_samples));
local_pmf.reset(new colvargrid_integrate(colvars, local_gradients));
local_samples.reset(new colvar_grid_count(cvmodule, colvars, samples));
local_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, local_samples));
local_pmf.reset(new colvargrid_integrate(cvmodule, colvars, local_gradients));
}
// Calculate the delta gradient and count for the local replica
last_gradients->delta_grid(*gradients);
Expand Down Expand Up @@ -675,10 +675,10 @@ int colvarbias_abf::replica_share_CZAR() {
// We arrive here if sharing has just been enabled by a script
// Allocate grids for collective data, on replica 0 only
// overriding CZAR grids that are equal to local ones by default
global_z_samples.reset(new colvar_grid_count(colvars, samples));
global_z_gradients.reset(new colvar_grid_gradient(colvars, global_z_samples));
global_czar_gradients.reset(new colvar_grid_gradient(colvars, nullptr, samples));
global_czar_pmf.reset(new colvargrid_integrate(colvars, global_czar_gradients));
global_z_samples.reset(new colvar_grid_count(cvmodule, colvars, samples));
global_z_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, global_z_samples));
global_czar_gradients.reset(new colvar_grid_gradient(cvmodule, colvars, nullptr, samples));
global_czar_pmf.reset(new colvargrid_integrate(cvmodule, colvars, global_czar_gradients));
}

// Start with data from replica 0
Expand Down Expand Up @@ -886,7 +886,7 @@ int colvarbias_abf::read_gradients_samples()
// Therefore the czar_gradients grid is not linked to a sampling grid
// Here we define a temporary czar_gradients grid linked to z_samples,
// to correctly average input gradients if overlapping
czar_gradients_in.reset(new colvar_grid_gradient(colvars, z_samples));
czar_gradients_in.reset(new colvar_grid_gradient(cvmodule, colvars, z_samples));
}

for ( size_t i = 0; i < input_prefix.size(); i++ ) {
Expand Down
Loading