Skip to content
Open
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
4 changes: 2 additions & 2 deletions colvartools/poisson_integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ 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->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);
if (cvm::get_error()) { return -1; }
if (proxy->cvmodule->get_error()) { return -1; }

int itmax = 10000;
cvm::real err;
Expand Down
8 changes: 4 additions & 4 deletions colvartools/poisson_integrator_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ 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->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);
if (cvm::get_error()) { return -1; }
if (proxy->cvmodule->get_error()) { return -1; }

cvm::real err = 1.;
cvm::real tol = 1e-10;
Expand All @@ -28,10 +28,10 @@ int main (int argc, char *argv[]) {

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

if (ref.number_of_points() != fes.number_of_points()) {
cvm::error("Reference grid has wrong number of points: " + cvm::to_str(ref.number_of_points()) + "\n");
proxy->cvmodule->error("Reference grid has wrong number of points: " + cvm::to_str(ref.number_of_points()) + "\n");
return -1;
}

Expand Down
82 changes: 82 additions & 0 deletions gromacs/src/applied_forces/colvars/colvarproxygromacs.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
diff --git a/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp b/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp
index 76b350c611..e7cbe0dc28 100644
--- a/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp
+++ b/src/gromacs/applied_forces/colvars/colvarproxygromacs.cpp
@@ -117,23 +117,23 @@ ColvarProxyGromacs::ColvarProxyGromacs(const std::string& colvarsConfigString,
input_streams_[inputName] = new std::istringstream(content);
}

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


- colvars->cite_feature("GROMACS engine");
- colvars->cite_feature("Colvars-GROMACS interface");
+ cvmodule->cite_feature("GROMACS engine");
+ cvmodule->cite_feature("Colvars-GROMACS interface");

if (cvm::debug())
{
- cvm::log("Initializing the colvars proxy object.\n");
+ cvmodule->log("Initializing the colvars proxy object.\n");
}

int errorCode = colvarproxy::setup();
- errorCode |= colvars->read_config_string(colvarsConfigString);
- errorCode |= colvars->update_engine_parameters();
- errorCode |= colvars->setup_input();
+ errorCode |= cvmodule->read_config_string(colvarsConfigString);
+ errorCode |= cvmodule->update_engine_parameters();
+ errorCode |= cvmodule->setup_input();

if (errorCode != COLVARS_OK)
{
@@ -141,10 +141,10 @@ ColvarProxyGromacs::ColvarProxyGromacs(const std::string& colvarsConfigString,
}

// Citation Reporter
- cvm::log(std::string("\n") + colvars->feature_report(0) + std::string("\n"));
+ cvmodule->log(std::string("\n") + cvmodule->feature_report(0) + std::string("\n"));

// TODO get initial step number from MDModules
- // colvars->set_initial_step(static_cast<cvm::step_number>(0L));
+ // cvmodule->set_initial_step(static_cast<cvm::step_number>(0L));
}
}

@@ -196,7 +196,7 @@ int ColvarProxyGromacs::set_unit_system(std::string const& unitsIn, bool /*colva
{
if (unitsIn != "gromacs")
{
- cvm::error(
+ cvmodule->error(
"Specified unit system \"" + unitsIn
+ "\" is unsupported in Gromacs. Supported units are \"gromacs\" (nm, kJ/mol).\n");
return COLVARS_ERROR;
@@ -218,7 +218,7 @@ int ColvarProxyGromacs::check_atom_id(int atomNumber)
}
if ((aid < 0) || (aid >= gmxAtoms_.nr))
{
- cvm::error("Error: invalid atom number specified, " + cvm::to_str(atomNumber) + "\n",
+ cvmodule->error("Error: invalid atom number specified, " + cvm::to_str(atomNumber) + "\n",
COLVARS_INPUT_ERROR);
return COLVARS_INPUT_ERROR;
}
@@ -273,10 +273,10 @@ void ColvarProxyGromacs::updateAtomProperties(int index)

ColvarProxyGromacs::~ColvarProxyGromacs()
{
- if (colvars != nullptr)
+ if (cvmodule != nullptr)
{
- delete colvars;
- colvars = nullptr;
+ delete cvmodule;
+ cvmodule = nullptr;
}
}

94 changes: 94 additions & 0 deletions gromacs/src/applied_forces/colvars/colvarsforceprovider.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
diff --git a/src/gromacs/applied_forces/colvars/colvarsforceprovider.cpp b/src/gromacs/applied_forces/colvars/colvarsforceprovider.cpp
index 5860eed790..8a3232131c 100644
--- a/src/gromacs/applied_forces/colvars/colvarsforceprovider.cpp
+++ b/src/gromacs/applied_forces/colvars/colvarsforceprovider.cpp
@@ -201,7 +201,7 @@ ColvarsForceProvider::ColvarsForceProvider(const std::string& colvarsConfigStrin

if (doParsing_)
{
- colvars->setup_output();
+ cvmodule->setup_output();
}


@@ -258,7 +258,7 @@ ColvarsForceProvider::ColvarsForceProvider(const std::string& colvarsConfigStrin
{
if (stateToCheckpoint_.nColvarsAtoms_ != nColvarsAtoms)
{
- cvm::error(
+ cvmodule->error(
"Number of colvars atoms in the .cpt file differs from the one in .tpr "
"file");
}
@@ -271,8 +271,8 @@ ColvarsForceProvider::ColvarsForceProvider(const std::string& colvarsConfigStrin

int errorCode = colvarproxy::setup();
// Read input state file
- errorCode |= colvars->set_input_state_buffer(stateToCheckpoint_.colvarStateFile_);
- errorCode |= colvars->setup_input();
+ errorCode |= cvmodule->set_input_state_buffer(stateToCheckpoint_.colvarStateFile_);
+ errorCode |= cvmodule->setup_input();

if (errorCode != COLVARS_OK)
{
@@ -303,19 +303,19 @@ ColvarsForceProvider::ColvarsForceProvider(const std::string& colvarsConfigStrin

if (mpiComm.isMainRank() && cvm::debug())
{
- cvm::log("atoms_ids = " + cvm::to_str(atoms_ids) + "\n");
- cvm::log("atoms_refcount = " + cvm::to_str(atoms_refcount) + "\n");
- cvm::log("positions = " + cvm::to_str(atoms_positions) + "\n");
- cvm::log("total_forces = " + cvm::to_str(atoms_total_forces) + "\n");
- cvm::log("atoms_new_colvar_forces = " + cvm::to_str(atoms_new_colvar_forces) + "\n");
- cvm::log(cvm::line_marker);
+ cvmodule->log("atoms_ids = " + cvm::to_str(atoms_ids) + "\n");
+ cvmodule->log("atoms_refcount = " + cvm::to_str(atoms_refcount) + "\n");
+ cvmodule->log("positions = " + cvm::to_str(atoms_positions) + "\n");
+ cvmodule->log("total_forces = " + cvm::to_str(atoms_total_forces) + "\n");
+ cvmodule->log("atoms_new_colvar_forces = " + cvm::to_str(atoms_new_colvar_forces) + "\n");
+ cvmodule->log(cvmodule->line_marker);
log("Done initializing the colvars proxy object.\n");
}

if (mpiComm.isMainRank())
{
- cvm::log(cvm::line_marker);
- cvm::log("End colvars Initialization.\n\n");
+ cvmodule->log(cvmodule->line_marker);
+ cvmodule->log("End colvars Initialization.\n\n");
}
}

@@ -347,8 +347,10 @@ void ColvarsForceProvider::calculateForces(const ForceProviderInput& forceProvid
const rvec* xPointer = &(x.data()->as_vec());
const auto& box = forceProviderInput.box_;

- colvars->it = forceProviderInput.step_;
-
+ if (cvmodule) // Only one thread has a pointer to the module
+ {
+ cvmodule->it = forceProviderInput.step_; // 'it' is not a static class member anymore
+ }

// Eventually there needs to be an interface to update local data upon neighbor search
// We could check if by chance all atoms are in one node, and skip communication
@@ -389,9 +391,9 @@ void ColvarsForceProvider::calculateForces(const ForceProviderInput& forceProvid

biasEnergy = 0.0;
// Call the collective variable module to fill atoms_new_colvar_forces
- if (colvars->calc() != COLVARS_OK)
+ if (cvmodule->calc() != COLVARS_OK)
{
- cvm::error("Error calling colvars->calc()\n");
+ cvmodule->error("Error calling cvmodule->calc()\n");
}

// Copy the forces to C array for broadcasting
@@ -462,7 +464,7 @@ void ColvarsForceProvider::add_energy(cvm::real energy)
void ColvarsForceProvider::writeCheckpointData(MDModulesWriteCheckpointData checkpointWriting,
std::string_view moduleName)
{
- colvars->write_state_buffer(stateToCheckpoint_.colvarStateFile_);
+ cvmodule->write_state_buffer(stateToCheckpoint_.colvarStateFile_);
stateToCheckpoint_.writeState(checkpointWriting.builder_, moduleName);
}
15 changes: 15 additions & 0 deletions gromacs/src/applied_forces/colvars/colvarspreprocessor.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/gromacs/applied_forces/colvars/colvarspreprocessor.cpp b/src/gromacs/applied_forces/colvars/colvarspreprocessor.cpp
index 16c0f8ceba..c671eef78d 100644
--- a/src/gromacs/applied_forces/colvars/colvarspreprocessor.cpp
+++ b/src/gromacs/applied_forces/colvars/colvarspreprocessor.cpp
@@ -78,8 +78,8 @@ ColvarsPreProcessor::ColvarsPreProcessor(const std::string& colvarsConfigStrin
// Initialize t_pbc struct
set_pbc(&gmxPbc_, pbcType, box);

- cvm::log(cvm::line_marker);
- cvm::log("End colvars Initialization.\n\n");
+ cvmodule->log(cvmodule->line_marker);
+ cvmodule->log("End colvars Initialization.\n\n");
}

std::vector<RVec> ColvarsPreProcessor::getColvarsCoords()
66 changes: 33 additions & 33 deletions lammps/src/COLVARS/colvarproxy_lammps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ void colvarproxy_lammps::init()
version_int = get_version_from_string(COLVARPROXY_VERSION);

// create the colvarmodule instance
colvars = new colvarmodule(this);
cvmodule = new colvarmodule(this);

// Create instance of scripting interface
script = new colvarscript(this, colvars);
script = new colvarscript(this, cvmodule);

cvm::log("Using LAMMPS interface, version " + cvm::to_str(COLVARPROXY_VERSION) + ".\n");
cvmodule->log("Using LAMMPS interface, version " + cvm::to_str(COLVARPROXY_VERSION) + ".\n");

colvars->cite_feature("LAMMPS engine");
colvars->cite_feature("Colvars-LAMMPS interface");
cvmodule->cite_feature("LAMMPS engine");
cvmodule->cite_feature("Colvars-LAMMPS interface");

angstrom_value_ = _lmp->force->angstrom;
boltzmann_ = _lmp->force->boltz;
set_integration_timestep(_lmp->update->dt * _lmp->force->femtosecond);

if (_lmp->update->ntimestep != 0) {
colvars->set_initial_step(static_cast<cvm::step_number>(_lmp->update->ntimestep));
cvmodule->set_initial_step(static_cast<cvm::step_number>(_lmp->update->ntimestep));
}
}

Expand Down Expand Up @@ -94,9 +94,9 @@ int colvarproxy_lammps::setup()
{
int error_code = colvarproxy::setup();
set_integration_timestep(_lmp->update->dt * _lmp->force->femtosecond);
error_code |= colvars->update_engine_parameters();
error_code |= colvars->setup_input();
error_code |= colvars->setup_output();
error_code |= cvmodule->update_engine_parameters();
error_code |= cvmodule->setup_input();
error_code |= cvmodule->setup_output();
return error_code;
}

Expand All @@ -106,8 +106,8 @@ int colvarproxy_lammps::setup()

double colvarproxy_lammps::compute()
{
if (cvm::debug()) {
cvm::log(std::string(cvm::line_marker) +
if (cvmodule->debug()) {
cvmodule->log(std::string(cvmodule->line_marker) +
"colvarproxy_lammps step no. " +
cvm::to_str(_lmp->update->ntimestep) + " [first - last = " +
cvm::to_str(_lmp->update->beginstep) + " - " +
Expand All @@ -119,7 +119,7 @@ double colvarproxy_lammps::compute()
} else {
// Use the time step number from LAMMPS Update object
if (_lmp->update->ntimestep - previous_step == 1) {
colvarmodule::it++;
cvmodule->it++;
b_simulation_continuing = false;
} else {
// Cases covered by this condition:
Expand Down Expand Up @@ -152,9 +152,9 @@ double colvarproxy_lammps::compute()
boundaries_type = boundaries_unsupported;
}

if (cvm::debug()) {
cvm::log(std::string(cvm::line_marker) +
"colvarproxy_lammps, step no. " + cvm::to_str(colvarmodule::it) + "\n" +
if (cvmodule->debug()) {
cvmodule->log(std::string(cvmodule->line_marker) +
"colvarproxy_lammps, step no. " + cvm::to_str(cvmodule->it) + "\n" +
"Updating internal data.\n");
}

Expand All @@ -164,22 +164,22 @@ double colvarproxy_lammps::compute()

bias_energy = 0.0;

if (cvm::debug()) {
cvm::log("atoms_ids = " + cvm::to_str(atoms_ids) + "\n");
cvm::log("atoms_refcount = " + cvm::to_str(atoms_refcount) + "\n");
cvm::log("atoms_positions = " + cvm::to_str(atoms_positions) + "\n");
cvm::log("atoms_new_colvar_forces = " + cvm::to_str(atoms_new_colvar_forces) + "\n");
if (cvmodule->debug()) {
cvmodule->log("atoms_ids = " + cvm::to_str(atoms_ids) + "\n");
cvmodule->log("atoms_refcount = " + cvm::to_str(atoms_refcount) + "\n");
cvmodule->log("atoms_positions = " + cvm::to_str(atoms_positions) + "\n");
cvmodule->log("atoms_new_colvar_forces = " + cvm::to_str(atoms_new_colvar_forces) + "\n");
}

// Call the collective variable module
if (colvars->calc() != COLVARS_OK)
cvm::error("Error in the collective variables module.\n", COLVARS_ERROR);

if (cvm::debug()) {
cvm::log("atoms_ids = " + cvm::to_str(atoms_ids) + "\n");
cvm::log("atoms_refcount = " + cvm::to_str(atoms_refcount) + "\n");
cvm::log("atoms_positions = " + cvm::to_str(atoms_positions) + "\n");
cvm::log("atoms_new_colvar_forces = " + cvm::to_str(atoms_new_colvar_forces) + "\n");
if (cvmodule->calc() != COLVARS_OK)
cvmodule->error("Error in the collective variables module.\n", COLVARS_ERROR);

if (cvmodule->debug()) {
cvmodule->log("atoms_ids = " + cvm::to_str(atoms_ids) + "\n");
cvmodule->log("atoms_refcount = " + cvm::to_str(atoms_refcount) + "\n");
cvmodule->log("atoms_positions = " + cvm::to_str(atoms_positions) + "\n");
cvmodule->log("atoms_new_colvar_forces = " + cvm::to_str(atoms_new_colvar_forces) + "\n");
}

return bias_energy;
Expand Down Expand Up @@ -225,8 +225,8 @@ char const *colvarproxy_lammps::script_obj_to_str(unsigned char *obj)

std::vector<std::string> colvarproxy_lammps::script_obj_to_str_vector(unsigned char *obj)
{
if (cvm::debug()) {
cvm::log("Called colvarproxy_lammps::script_obj_to_str_vector().\n");
if (cvmodule->debug()) {
cvmodule->log("Called colvarproxy_lammps::script_obj_to_str_vector().\n");
}
std::string const input(reinterpret_cast<char *>(obj));
return LAMMPS_NS::utils::split_words(input); // :-)))
Expand All @@ -238,7 +238,7 @@ int colvarproxy_lammps::set_unit_system(std::string const &units_in, bool /*chec
{
std::string lmp_units = _lmp->update->unit_style;
if (units_in != lmp_units) {
cvm::error("Error: Specified unit system for Colvars \"" + units_in +
cvmodule->error("Error: Specified unit system for Colvars \"" + units_in +
"\" is incompatible with LAMMPS internal units (" + lmp_units + ").\n");
return COLVARS_ERROR;
}
Expand All @@ -251,12 +251,12 @@ int colvarproxy_lammps::check_atom_id(int atom_number)
{
int const aid = atom_number;

if (cvm::debug())
if (cvmodule->debug())
log("Adding atom " + cvm::to_str(atom_number) + " for collective variables calculation.\n");

// TODO add upper boundary check?
if ((aid < 0)) {
cvm::error("Error: invalid atom number specified, " +
cvmodule->error("Error: invalid atom number specified, " +
cvm::to_str(atom_number) + "\n", COLVARS_INPUT_ERROR);
return COLVARS_INPUT_ERROR;
}
Expand Down
Loading
Loading