Skip to content

Commit

Permalink
merge torchann squash
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang committed Oct 16, 2023
1 parent 7b12838 commit b3d7247
Show file tree
Hide file tree
Showing 20 changed files with 578 additions and 128 deletions.
1 change: 1 addition & 0 deletions doc/colvars-code-refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,5 @@ @article{White2014
% coordNum pairlist
% Custom functions (Lepton)
% Scripted functions (Tcl)
% torchANN colvar component
% --- END ---
12 changes: 12 additions & 0 deletions gromacs/cmake/gmxManageColvars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ function(gmx_include_colvars_headers)
target_include_directories(libgromacs PRIVATE ${PROJECT_SOURCE_DIR}/src/external/colvars)
endif()
endfunction()

function(gmx_set_colvars_torch)
find_package(Torch)
if (Torch_FOUND)
set_property(TARGET colvars PROPERTY CXX_STANDARD 17)
target_compile_definitions(colvars PRIVATE -DTORCH)
target_compile_options(colvars PRIVATE ${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS})
target_include_directories(colvars PRIVATE ${TORCH_INCLUDE_DIRS})
target_link_libraries(libgromacs PRIVATE "${TORCH_LIBRARIES}")
endif()
endfunction()

78 changes: 40 additions & 38 deletions gromacs/gromacs-2020.x.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ index 0911eb2a45..5530c1576a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -200,6 +200,9 @@ option(GMX_USE_OPENCL "Enable OpenCL acceleration" OFF)

option(GMX_INSTALL_LEGACY_API "Install legacy headers" OFF)

+include(gmxManageColvars)
+include(gmxManageLepton)
+
# The earliest version of the CUDA toolkit that supports c++14 is 9.0
set(REQUIRED_CUDA_VERSION 9.0)
set(REQUIRED_CUDA_COMPUTE_CAPABILITY 3.0)
diff --git a/src/gromacs/CMakeLists.txt b/src/gromacs/CMakeLists.txt
index 9249a7a08f..18b45ff01f 100644
index 9249a7a08f..ab5a927fb7 100644
--- a/src/gromacs/CMakeLists.txt
+++ b/src/gromacs/CMakeLists.txt
@@ -137,6 +137,12 @@ if (WIN32)
endif()
list(APPEND libgromacs_object_library_dependencies thread_mpi)

+# Add Colvars and Lepton targets, embed their object code in libgromacs
+gmx_manage_colvars()
+gmx_manage_lepton()
Expand All @@ -29,11 +29,13 @@ index 9249a7a08f..18b45ff01f 100644
configure_file(version.h.cmakein version.h)
if(GMX_INSTALL_LEGACY_API)
install(FILES
@@ -195,6 +201,8 @@ else()
@@ -195,6 +201,10 @@ else()
add_library(libgromacs ${LIBGROMACS_SOURCES})
endif()

+gmx_include_colvars_headers()
+
+gmx_set_colvars_torch()
+
# Add these contents first because linking their tests can take a lot
# of time, so we want lots of parallel work still available after
Expand All @@ -58,8 +60,8 @@ index 9c6cfe4213..ec2e64f61f 100644
+/* COLVARS : add a value of 1000 for Colvars support and
+ * prevent regular GROMACS to read colvars .cpt files */
+static const int cpt_version = cptv_Count - 1 + 1000;


const char* est_names[estNR] = { "FE-lambda",
@@ -1178,6 +1181,15 @@ static void do_cpt_header(XDR* xd, gmx_bool bRead, FILE* list, CheckpointHeaderC
{
Expand All @@ -75,12 +77,12 @@ index 9c6cfe4213..ec2e64f61f 100644
+ }
+
}

static int do_cpt_footer(XDR* xd, int file_version)
@@ -1909,6 +1921,35 @@ static int do_cpt_EDstate(XDR* xd, gmx_bool bRead, int nED, edsamhistory_t* EDst
return 0;
}

+/* This function stores the last whole configuration of the colvars atoms in the .cpt file */
+static int do_cpt_colvars(XDR* xd, gmx_bool bRead, int ecolvars, colvarshistory_t* colvarsstate, FILE* list)
+{
Expand Down Expand Up @@ -116,7 +118,7 @@ index 9c6cfe4213..ec2e64f61f 100644
@@ -2330,6 +2371,10 @@ void write_checkpoint(const char* fn,
swaphistory_t* swaphist = observablesHistory->swapHistory.get();
int eSwapCoords = (swaphist ? swaphist->eSwapCoords : eswapNO);

+ /* COLVARS */
+ colvarshistory_t* colvarshist = observablesHistory->colvarsHistory.get();
+ int ecolvars = (colvarshist ? colvarshist->n_atoms : 0);
Expand Down Expand Up @@ -145,7 +147,7 @@ index 9c6cfe4213..ec2e64f61f 100644
@@ -2802,6 +2849,17 @@ static void read_checkpoint(const char* fn,
cp_error();
}

+ if (headerContents->ecolvars != 0 && observablesHistory->colvarsHistory == nullptr)
+ {
+ observablesHistory->colvarsHistory = std::make_unique<colvarshistory_t>(colvarshistory_t{});
Expand All @@ -163,7 +165,7 @@ index 9c6cfe4213..ec2e64f61f 100644
@@ -2957,6 +3015,13 @@ static CheckpointHeaderContents read_checkpoint_data(t_fileio*
cp_error();
}

+ colvarshistory_t colvarshist = {};
+ ret = do_cpt_colvars(gmx_fio_getxdr(fp), TRUE, headerContents.ecolvars, &colvarshist, nullptr);
+ if (ret)
Expand All @@ -172,12 +174,12 @@ index 9c6cfe4213..ec2e64f61f 100644
+ }
+
ret = do_cpt_files(gmx_fio_getxdr(fp), TRUE, outputfiles, nullptr, headerContents.file_version);

if (ret)
@@ -3065,6 +3130,12 @@ void list_checkpoint(const char* fn, FILE* out)
ret = do_cpt_swapstate(gmx_fio_getxdr(fp), TRUE, headerContents.eSwapCoords, &swaphist, out);
}

+ if (ret == 0)
+ {
+ colvarshistory_t colvarshist = {};
Expand All @@ -198,7 +200,7 @@ index fb8f7268be..6feb181b30 100644
+ //! Colvars
+ int ecolvars;
};

/* Write a checkpoint to <fn>.cpt
diff --git a/src/gromacs/mdlib/energyoutput.cpp b/src/gromacs/mdlib/energyoutput.cpp
index f2532f3dfe..c761958854 100644
Expand All @@ -210,7 +212,7 @@ index f2532f3dfe..c761958854 100644
bEner_[F_ORIRESDEV] = (gmx_mtop_ftype_count(mtop, F_ORIRES) > 0);
- bEner_[F_COM_PULL] = ((ir->bPull && pull_have_potential(pull_work)) || ir->bRot);
+ bEner_[F_COM_PULL] = ((ir->bPull && pull_have_potential(pull_work)) || ir->bRot || ir->bColvars);

MdModulesEnergyOutputToDensityFittingRequestChecker mdModulesAddOutputToDensityFittingFieldRequest;
mdModulesNotifier.notifier_.notify(&mdModulesAddOutputToDensityFittingFieldRequest);
diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp
Expand All @@ -220,7 +222,7 @@ index f2528d78b4..7f91cac83d 100644
@@ -114,6 +114,8 @@
#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/sysinfo.h"

+#include "colvarproxy_gromacs.h"
+
using gmx::AtomLocality;
Expand All @@ -242,7 +244,7 @@ index f2528d78b4..7f91cac83d 100644
+
gmx::ForceProviderInput forceProviderInput(x, *mdatoms, t, box, *cr);
gmx::ForceProviderOutput forceProviderOutput(forceWithVirial, enerd);

diff --git a/src/gromacs/mdrun/legacymdrunoptions.h b/src/gromacs/mdrun/legacymdrunoptions.h
index 796e479490..8b20073b3b 100644
--- a/src/gromacs/mdrun/legacymdrunoptions.h
Expand All @@ -255,7 +257,7 @@ index 796e479490..8b20073b3b 100644
+ { efXVG, "-swap", "swapions", ffOPTWR },
+ { efDAT, "-colvars", "colvars", ffOPTRDMULT }, /* COLVARS */
+ { efDAT, "-colvars_restart", "colvars", ffOPTRD }, /* COLVARS */}};

//! Print a warning if any force is larger than this (in kJ/mol nm).
real pforce = -1;
diff --git a/src/gromacs/mdrun/replicaexchange.cpp b/src/gromacs/mdrun/replicaexchange.cpp
Expand All @@ -268,10 +270,10 @@ index 9ff4b3817d..eb31f1fa89 100644
exchange_rvecs(ms, b, state->v.rvec_array(), state->natoms);
+ exchange_rvecs(ms, b, state->xa_old_whole_colvars, state->n_colvars_atoms);
}

static void copy_state_serial(const t_state* src, t_state* dest)
diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp
index c2b3c088d7..bb38d44ab2 100644
index c2b3c088d7..7a5f2b05a4 100644
--- a/src/gromacs/mdrun/runner.cpp
+++ b/src/gromacs/mdrun/runner.cpp
@@ -115,6 +115,7 @@
Expand All @@ -285,7 +287,7 @@ index c2b3c088d7..bb38d44ab2 100644
@@ -156,6 +157,8 @@
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"

+#include "colvarproxy_gromacs.h"
+
#include "isimulator.h"
Expand All @@ -294,7 +296,7 @@ index c2b3c088d7..bb38d44ab2 100644
@@ -1536,6 +1539,51 @@ int Mdrunner::mdrunner()
MASTER(cr) ? globalState->x.rvec_array() : nullptr, filenames.size(),
filenames.data(), oenv, mdrunOptions.imdOptions, startingBehavior);

+ /* COLVARS */
+ if (opt2bSet("-colvars",filenames.size(), filenames.data()))
+ {
Expand Down Expand Up @@ -346,7 +348,7 @@ index c2b3c088d7..bb38d44ab2 100644
@@ -1654,6 +1702,16 @@ int Mdrunner::mdrunner()
free_membed(membed);
}

+ /* COLVARS */
+ if (inputrec->bColvars)
+ {
Expand Down Expand Up @@ -387,28 +389,28 @@ index 0000000000..ea69e03419
+
+#endif
diff --git a/src/gromacs/mdtypes/inputrec.h b/src/gromacs/mdtypes/inputrec.h
index 266670f3ef..f1d287d35d 100644
index 266670f3ef..86e4aa35d3 100644
--- a/src/gromacs/mdtypes/inputrec.h
+++ b/src/gromacs/mdtypes/inputrec.h
@@ -53,6 +53,8 @@ struct gmx_enfrot;
struct gmx_enfrotgrp;
struct pull_params_t;

+class colvarproxy_gromacs;
+
namespace gmx
{
class Awh;
@@ -587,6 +589,10 @@ struct t_inputrec // NOLINT (clang-analyzer-optin.performance.Padding)

//! KVT for storing simulation parameters that are not part of the mdp file.
std::unique_ptr<gmx::KeyValueTreeObject> internalParameters;
+
+ /* COLVARS */
+ gmx_bool bColvars = false; /* Do we do colvars calculations ? */
+ colvarproxy_gromacs *colvars_proxy = nullptr; /* The object for the colvars calculations */
};

int ir_optimal_nstcalcenergy(const t_inputrec* ir);
diff --git a/src/gromacs/mdtypes/observableshistory.cpp b/src/gromacs/mdtypes/observableshistory.cpp
index 0b5983a59c..57d851645a 100644
Expand All @@ -419,7 +421,7 @@ index 0b5983a59c..57d851645a 100644
#include "gromacs/mdtypes/pullhistory.h"
#include "gromacs/mdtypes/swaphistory.h"
+#include "gromacs/mdtypes/colvarshistory.h"

ObservablesHistory::ObservablesHistory() = default;
ObservablesHistory::~ObservablesHistory() = default;
diff --git a/src/gromacs/mdtypes/observableshistory.h b/src/gromacs/mdtypes/observableshistory.h
Expand All @@ -431,18 +433,18 @@ index d2ba1d820f..a5747139d7 100644
struct edsamhistory_t;
struct swaphistory_t;
+struct colvarshistory_t;

/*! \libinternal \brief Observables history, for writing/reading to/from checkpoint file
*/
@@ -76,6 +77,9 @@ struct ObservablesHistory
//! Ion/water position swapping history
std::unique_ptr<swaphistory_t> swapHistory;

+ //! Colvars
+ std::unique_ptr<colvarshistory_t> colvarsHistory;
+
ObservablesHistory();

~ObservablesHistory();
diff --git a/src/gromacs/mdtypes/state.cpp b/src/gromacs/mdtypes/state.cpp
index a949d589a3..957f7b7139 100644
Expand All @@ -456,7 +458,7 @@ index a949d589a3..957f7b7139 100644
+ ddp_count_cg_gl(0),
+ xa_old_whole_colvars(nullptr),
+ n_colvars_atoms(0)

{
// It would be nicer to initialize these with {} or {{0}} in the
diff --git a/src/gromacs/mdtypes/state.h b/src/gromacs/mdtypes/state.h
Expand All @@ -465,14 +467,14 @@ index a54bff29bb..8619c7935a 100644
+++ b/src/gromacs/mdtypes/state.h
@@ -257,6 +257,10 @@ public:
std::vector<int> cg_gl; //!< The global cg number of the local cgs

std::vector<double> pull_com_prev_step; //!< The COM of the previous step of each pull group
+
+ int n_colvars_atoms; //!< number of colvars atoms
+ rvec* xa_old_whole_colvars; //!< last whole positions of colvars atoms
+
};

#ifndef DOXYGEN
diff --git a/src/programs/mdrun/tests/refdata/MdrunTest_WritesHelp.xml b/src/programs/mdrun/tests/refdata/MdrunTest_WritesHelp.xml
index c2973bb1af..cb4d1da254 100644
Expand All @@ -496,6 +498,6 @@ index c2973bb1af..cb4d1da254 100644
+ Generic data file
+ -colvars_restart [&lt;.dat&gt;] (colvars.dat) (Opt.)
+ Generic data file

Options to specify output files:

Loading

0 comments on commit b3d7247

Please sign in to comment.