Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion colvartools/poisson_integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ int main (int argc, char *argv[]) {
}

colvarproxy *proxy = new colvarproxy();
proxy->colvars = new colvarmodule(proxy); // This could be omitted if we used the colvarproxy_stub class
proxy->colvars = new colvarmodule(); // This could be omitted if we used the colvarproxy_stub class
proxy->colvars->init(proxy);

std::string gradfile (argv[1]);
std::shared_ptr<colvar_grid_gradient> grad_ptr = std::make_shared<colvar_grid_gradient>(gradfile);
Expand Down
3 changes: 2 additions & 1 deletion colvartools/poisson_integrator_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ int main (int argc, char *argv[]) {
}

colvarproxy *proxy = new colvarproxy();
proxy->colvars = new colvarmodule(proxy); // This could be omitted if we used the colvarproxy_stub class
proxy->colvars = new colvarmodule(); // This could be omitted if we used the colvarproxy_stub class
proxy->colvars->init(proxy);

std::string gradfile (argv[1]);
std::shared_ptr<colvar_grid_gradient> grad_ptr = std::make_shared<colvar_grid_gradient>(gradfile);
Expand Down
24 changes: 24 additions & 0 deletions gromacs/src/applied_forces/colvars/colvarproxygromacs.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp b/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp
index 76b350c611..e0eaedfd61 100644
--- a/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp
+++ b/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp
@@ -79,9 +79,6 @@ ColvarProxyGromacs::ColvarProxyGromacs(const std::string& colvarsConfigString,
// Retrieve masses and charges from input file
updated_masses_ = updated_charges_ = true;

- // User-scripted forces are not available in GROMACS
- have_scripts = false;
-
angstrom_value_ = 0.1;

// From Gnu units
@@ -117,7 +114,8 @@ ColvarProxyGromacs::ColvarProxyGromacs(const std::string& colvarsConfigString,
input_streams_[inputName] = new std::istringstream(content);
}

- colvars = new colvarmodule(this);
+ colvars = new colvarmodule();
+ colvars->init(this);
cvm::log(cvm::line_marker);
cvm::log("Start colvars Initialization.");

3 changes: 2 additions & 1 deletion lammps/src/COLVARS/colvarproxy_lammps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void colvarproxy_lammps::init()
version_int = get_version_from_string(COLVARPROXY_VERSION);

// create the colvarmodule instance
colvars = new colvarmodule(this);
colvars = new colvarmodule();
colvars->init(this);

// Create instance of scripting interface
script = new colvarscript(this, colvars);
Expand Down
3 changes: 2 additions & 1 deletion misc_interfaces/C_fortran/colvarproxy_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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);
colvars = new colvarmodule();
colvars->init(this);
colvars->log("This is the Module speaking.");
}

Expand Down
3 changes: 2 additions & 1 deletion misc_interfaces/stubs/colvarproxy_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ colvarproxy_stub::colvarproxy_stub()
// both fields are taken from data structures already available
updated_masses_ = updated_charges_ = true;

colvars = new colvarmodule(this);
colvars = new colvarmodule();
colvars->init(this);
cvm::log("Using minimal testing interface.\n");

colvars->cv_traj_freq = 0; // I/O will be handled explicitly
Expand Down
18 changes: 18 additions & 0 deletions namd/src/ComputeMgr.C.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/src/ComputeMgr.C b/src/ComputeMgr.C
index 96cbb387..343111b5 100644
--- a/src/ComputeMgr.C
+++ b/src/ComputeMgr.C
@@ -1082,8 +1082,11 @@ ComputeMgr::createComputes(ComputeMap *map)
masterServerObject->addClient(new GlobalMasterMisc());
if ( simParams->freeEnergyOn )
masterServerObject->addClient(new GlobalMasterFreeEnergy());
- if ( simParams->colvarsOn )
- masterServerObject->addClient(new GlobalMasterColvars());
+ if ( simParams->colvarsOn ) {
+ auto *m = new GlobalMasterColvars();
+ masterServerObject->addClient(m);
+ m->init();
+ }

}

13 changes: 13 additions & 0 deletions namd/src/GlobalMaster.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/GlobalMaster.h b/src/GlobalMaster.h
index bb27f2ee..373913c5 100644
--- a/src/GlobalMaster.h
+++ b/src/GlobalMaster.h
@@ -81,6 +81,8 @@ class GlobalMaster {
protected:
GlobalMaster();

+ virtual void init() {}
+
/* This will be called after the pointers to lists below have been
initialized correctly by processData. It should perform any
required caluation and update the atom/force lists. */
8 changes: 7 additions & 1 deletion namd/src/GlobalMasterColvars.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
#include "colvarproxy_namd.h"


GlobalMasterColvars::GlobalMasterColvars() : proxy(new colvarproxy_namd(this)) {}
GlobalMasterColvars::GlobalMasterColvars() {}

void GlobalMasterColvars::init()
{
proxy.reset(new colvarproxy_namd());
proxy->init(this);
}

GlobalMasterColvars::~GlobalMasterColvars() { reset(); }

Expand Down
2 changes: 2 additions & 0 deletions namd/src/GlobalMasterColvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class GlobalMasterColvars : public GlobalMaster {

~GlobalMasterColvars();

void init() override;

void reset();

void calculate() override;
Expand Down
27 changes: 14 additions & 13 deletions namd/src/colvarproxy_namd.C
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
#include "colvarproxy_namd_version.h"


colvarproxy_namd::colvarproxy_namd(GlobalMasterColvars *gm)
: globalmaster(gm)
colvarproxy_namd::colvarproxy_namd()
{
engine_name_ = "NAMD";
#if CMK_SMP && USE_CKLOOP
Expand All @@ -63,7 +62,6 @@ colvarproxy_namd::colvarproxy_namd(GlobalMasterColvars *gm)
}
#endif
first_timestep = true;
globalmaster->requestTotalForcePublic(total_force_requested);

boltzmann_ = 0.001987191;

Expand All @@ -75,9 +73,6 @@ colvarproxy_namd::colvarproxy_namd(GlobalMasterColvars *gm)
if (cvm::debug())
iout << "Info: initializing the colvars proxy object.\n" << endi;

// find the configuration file, if provided
StringList *config = Node::Object()->configList->find("colvarsConfig");

// find the input state file
StringList *input_restart = Node::Object()->configList->find("colvarsInput");
colvarproxy_io::set_input_prefix(input_restart ? input_restart->data : "");
Expand Down Expand Up @@ -110,15 +105,25 @@ colvarproxy_namd::colvarproxy_namd(GlobalMasterColvars *gm)
}

init_atoms_map();
}


int colvarproxy_namd::init(GlobalMasterColvars *gm)
{
globalmaster = gm;

// initialize module: this object will be the communication proxy
colvars = new colvarmodule(this);
colvars = new colvarmodule();
colvars->init(this);

cvm::log("Using NAMD interface, version "+
cvm::to_str(COLVARPROXY_VERSION)+".\n");
colvars->cite_feature("NAMD engine");
colvars->cite_feature("Colvars-NAMD interface");

// find the configuration file, if provided
StringList *config = Node::Object()->configList->find("colvarsConfig");

errno = 0;
for ( ; config; config = config->next ) {
add_config("configfile", config->data);
Expand All @@ -134,12 +139,6 @@ colvarproxy_namd::colvarproxy_namd(GlobalMasterColvars *gm)
// save to Node for Tcl script access
Node::Object()->colvars = colvars;

#ifdef NAMD_TCL
have_scripts = true;
#else
have_scripts = false;
#endif

if (simparams->firstTimestep != 0) {
colvars->set_initial_step(static_cast<cvm::step_number>(simparams->firstTimestep));
}
Expand All @@ -156,6 +155,8 @@ colvarproxy_namd::colvarproxy_namd(GlobalMasterColvars *gm)

if (cvm::debug())
iout << "Info: done initializing the colvars proxy object.\n" << endi;

return COLVARS_OK;
}


Expand Down
6 changes: 5 additions & 1 deletion namd/src/colvarproxy_namd.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ class colvarproxy_namd : public colvarproxy {

void init_tcl_pointers() override;

colvarproxy_namd(GlobalMasterColvars *gm);
colvarproxy_namd();
~colvarproxy_namd();

/// Initialize Colvars module and interface with GlobalMaster
int init(GlobalMasterColvars *gm);

int setup() override;

int reset() override;

/// Get the target temperature from the NAMD thermostats supported so far
Expand Down
8 changes: 6 additions & 2 deletions src/colvarmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace {
}


colvarmodule::colvarmodule(colvarproxy *proxy_in)
colvarmodule::colvarmodule()
{
depth_s = 0;
log_level_ = 10;
Expand All @@ -109,8 +109,12 @@ colvarmodule::colvarmodule(colvarproxy *proxy_in)

usage_ = new usage();
usage_->cite_feature("Colvars module");
}


if (proxy != NULL) {
void colvarmodule::init(colvarproxy *proxy_in)
{
if (proxy) {
// TODO relax this error to handle multiple molecules in VMD
// once the module is not static anymore
cvm::error("Error: trying to allocate the collective "
Expand Down
10 changes: 4 additions & 6 deletions src/colvarmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,12 @@ static inline real acos(real const &x)
size_t size() const;

/// Constructor
/// \param Pointer to instance of the proxy class (communicate with engine)
colvarmodule(colvarproxy *proxy);

private:

/// Cannot initialize the main object without a proxy
colvarmodule();

/// Initialize interface with proxy and other complex objects
/// \param Pointer to instance of the proxy class (communicate with engine)
void init(colvarproxy *proxy);

public:

/// Destructor
Expand Down
10 changes: 3 additions & 7 deletions src/colvarproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,14 @@ int colvarproxy_smp::smp_unlock()



colvarproxy_script::colvarproxy_script()
{
script = NULL;
have_scripts = false;
}
colvarproxy_script::colvarproxy_script() {}


colvarproxy_script::~colvarproxy_script()
{
if (script != NULL) {
if (script) {
delete script;
script = NULL;
script = nullptr;
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/colvarproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,7 @@ class colvarproxy_script {

/// Pointer to the scripting interface object
/// (does not need to be allocated in a new interface)
colvarscript *script;

/// Do we have a scripting interface?
bool have_scripts;
colvarscript *script = nullptr;

/// Run a user-defined colvar forces script
virtual int run_force_callback();
Expand Down
3 changes: 2 additions & 1 deletion src/colvarscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ int tcl_colvars_vmd_init(Tcl_Interp *interp, int molid);
extern "C" {
int Colvars_Init(Tcl_Interp *interp) {
colvarproxy *proxy = new colvarproxy();
colvarmodule *colvars = new colvarmodule(proxy);
colvarmodule *colvars = new colvarmodule();
colvars->init(proxy);
proxy->set_tcl_interp(interp);
proxy->colvars = colvars;
Tcl_CreateObjCommand(interp, "cv", tcl_run_colvarscript_command,
Expand Down
3 changes: 2 additions & 1 deletion tests/functional_gpu/run_colvars_test_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class colvarproxy_stub_gpu : public colvarproxy {
return COLVARS_NOT_IMPLEMENTED;
}
void init_cvm() {
colvars = new colvarmodule(this);
colvars = new colvarmodule();
colvars->init(this);
cvm::log("Using minimal CUDA testing interface.\n");

colvars->cv_traj_freq = 0; // I/O will be handled explicitly
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/embedded_tcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
int main(int argc, char *argv[]) {

colvarproxy *proxy = new colvarproxy();
proxy->colvars = new colvarmodule(proxy);
proxy->colvars = new colvarmodule();
proxy->colvars->init(proxy);

int res = proxy->tcl_run_script("puts \"\n(Tcl) Tcl script running successfully using embedded interpreter.\"");

Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/file_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
int main(int argc, char *argv[]) {

colvarproxy *proxy = new colvarproxy();
proxy->colvars = new colvarmodule(proxy);
proxy->colvars = new colvarmodule();
proxy->colvars->init(proxy);

proxy->backup_file("nonexistent.txt");
proxy->remove_file("nonexistent.txt");
Expand Down
10 changes: 3 additions & 7 deletions vmd/src/colvarproxy_vmd.C
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,14 @@ colvarproxy_vmd::colvarproxy_vmd(Tcl_Interp *interp, VMDApp *v, int molid)
// both fields are taken from data structures already available
updated_masses_ = updated_charges_ = true;

// Do we have scripts?
// For now colvars depend on Tcl, but this may not always be the case
// in the future
#if defined(VMDTCL)
have_scripts = true;
// Need to set this before constructing colvarmodule, which creates colvarscript object
set_tcl_interp(interp);
#else
have_scripts = false;
#endif

colvars = new colvarmodule(this);
colvars = new colvarmodule();
colvars->init(this);

cvm::log("Using VMD interface, version "+
cvm::to_str(COLVARPROXY_VERSION)+".\n");

Expand Down
Loading