Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
59 changes: 59 additions & 0 deletions namd/Make.depends.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
diff --git a/Make.depends b/Make.depends
index 994b3914..1d54373f 100644
--- a/Make.depends
+++ b/Make.depends
@@ -6398,6 +6398,45 @@ obj/GlobalMasterTMD.o: \
src/fitrms.h \
src/Debug.h
$(CXX) $(CXXFLAGS) $(COPTO)obj/GlobalMasterTMD.o $(COPTC) src/GlobalMasterTMD.C
+obj/GlobalMasterColvars.o: \
+ obj/.exists \
+ src/GlobalMasterColvars.C \
+ src/Controller.h \
+ src/common.h \
+ src/Vector.h \
+ src/Tensor.h \
+ src/Lattice.h \
+ src/NamdTypes.h \
+ src/CudaRecord.h \
+ src/HipDefines.h \
+ src/ResizeArray.h \
+ src/ResizeArrayRaw.h \
+ src/fstream_namd.h \
+ src/DataExchanger.h \
+ src/main.h \
+ inc/DataExchanger.decl.h \
+ src/Pointer.h \
+ src/GlobalMaster.h \
+ src/GlobalMasterColvars.h \
+ src/colvarproxy_namd.h \
+ src/colvarproxy_namd_version.h \
+ src/SimParameters.h \
+ src/imd.h \
+ src/MGridforceParams.h \
+ src/GroupRestraintsParam.h \
+ src/Random.h \
+ src/ConfigList.h \
+ colvars/src/colvarmodule.h \
+ colvars/src/colvarproxy.h \
+ colvars/src/colvarmodule.h \
+ colvars/src/colvartypes.h \
+ colvars/src/colvarproxy_io.h \
+ colvars/src/colvarproxy_replicas.h \
+ colvars/src/colvarproxy_system.h \
+ colvars/src/colvarproxy_tcl.h \
+ colvars/src/colvarproxy_volmaps.h \
+ colvars/src/colvarvalue.h
+ $(CXX) $(CXXFLAGS) $(COPTO)obj/GlobalMasterColvars.o $(COPTC) src/GlobalMasterColvars.C
obj/Matrix4Symmetry.o: \
obj/.exists \
src/Matrix4Symmetry.C \
@@ -6637,6 +6676,8 @@ obj/colvarproxy_namd.o: \
src/MStream.h \
plugins/include/molfile_plugin.h \
plugins/include/vmdplugin.h \
+ src/GlobalMasterColvars.h \
+ src/GlobalMaster.h \
src/GridForceGrid.inl \
src/PDB.h \
src/parm.h \
19 changes: 9 additions & 10 deletions namd/Makefile.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
diff --git a/Makefile b/Makefile
index fb23fcac..541fe8ca 100644
index 960f7718..85126dff 100644
--- a/Makefile
+++ b/Makefile
@@ -446,7 +446,7 @@ CXXMICFLAGS = $(CXXBASEFLAGS) $(CXXOPTS) $(CXXMICOPTS)
CXXTHREADFLAGS = $(CXXBASEFLAGS) $(CXXTHREADOPTS)
CXXSIMPARAMFLAGS = $(CXXBASEFLAGS) $(CXXSIMPARAMOPTS)
CXXNOALIASFLAGS = $(CXXBASEFLAGS) $(CXXNOALIASOPTS)
-COLVARSCXXFLAGS = $(CXXBASEFLAGS) $(CXXOPTS) $(COPTI)$(LEPTONINCDIR) -DLEPTON -DLEPTON_USE_STATIC_LIBRARIES
+COLVARSCXXFLAGS = $(CXXBASEFLAGS) $(CXXOPTS) $(COPTI)$(LEPTONINCDIR) -DLEPTON -DLEPTON_USE_STATIC_LIBRARIES $(EXTRACOLVARSFLAGS)
GXXFLAGS = $(CXXBASEFLAGS) -DNO_STRSTREAM_H
CFLAGS = $(COPTI)$(SRCDIR) $(TCL) $(COPTS) $(RELEASE) $(EXTRADEFINES) $(TRACEOBJDEF)
PLUGINGCCFLAGS = $(COPTI)$(PLUGINSRCDIR) $(COPTI)$(PLUGININCDIR) $(COPTD)STATIC_PLUGIN
@@ -231,6 +231,7 @@ OBJS = \
$(DSTDIR)/GlobalMasterTcl.o \
$(DSTDIR)/GlobalMasterSMD.o \
$(DSTDIR)/GlobalMasterTMD.o \
+ $(DSTDIR)/GlobalMasterColvars.o \
$(DSTDIR)/Matrix4Symmetry.o \
$(DSTDIR)/GlobalMasterSymmetry.o \
$(DSTDIR)/GlobalMasterFreeEnergy.o \
59 changes: 0 additions & 59 deletions namd/config.patch
Original file line number Diff line number Diff line change
@@ -1,59 +0,0 @@
diff --git a/config b/config
Comment thread
giacomofiorin marked this conversation as resolved.
index ddf9f860..4148d87c 100755
--- a/config
+++ b/config
@@ -57,6 +57,8 @@ function error_syntax {
echo ' --cuda-dlink arch=<arch>,code=<code> (for cuFFT, may be repeated)'
echo ' --with-cuda-profiling (enables CUDA profiling with NVTX)'
echo ' --with-rocm-profiling (enables ROCm profiling with ROCtracer API)'
+ echo ' --with-colvars-torch (enables torchann in Colvars)'
+ echo ' --torch-prefix <directory containing libTorch>'
echo ''
if [ -n "${PRINT_ARCH_LIST+set}" ]; then
ARCH_PAT=''
@@ -152,6 +154,7 @@ function error_exists {
use_mkl=0
use_cuda=0
use_hip=0
+ use_colvars_torch=0
use_cuda_prof=0
use_rocm_prof=0
use_memopt=0
@@ -257,6 +260,19 @@ function error_exists {
ARCH_SUFFIX_ARG=$ARCH_SUFFIX_ARG-$1
;;

+ --with-colvars-torch)
+ use_colvars_torch=1
+ ;;
+
+ --torch-prefix)
+ shift
+ if [ ! -d "$1" ]; then
+ echo "ERROR: No such directory $1"
+ error_syntax
+ fi
+ TORCH_PREFIX=$1
+ ;;
+
--with-debug)
use_debug=1
;;
@@ -1015,7 +1031,16 @@ function error_exists {
if [ -n "$CC_OPTS" ]; then
echo "COPTS = $CC_OPTS" >> Make.config
fi
-
+ if (( "$use_colvars_torch" )); then
+ echo "TORCHDIR = $TORCH_PREFIX" >> Make.config
+ echo 'TORCHINCFLAGS = $(COPTI)$(TORCHDIR)/include $(COPTI)$(TORCHDIR)/include/torch/csrc/api/include' >> Make.config
+ echo 'EXTRACOLVARSFLAGS = -std=c++17 -DCOLVARS_TORCH $(TORCHINCFLAGS)' >> Make.config
+ if [[ $use_cuda && -f "${TORCH_PREFIX}/lib/libtorch_cuda.so" ]]; then
+ echo 'EXTRALINKLIBS = -Wl,-rpath,$(TORCHDIR)/lib -L$(TORCHDIR)/lib -ltorch -ltorch_cpu -lc10 -ltorch_cuda -lc10_cuda' >> Make.config
+ else
+ echo 'EXTRALINKLIBS = -Wl,-rpath,$(TORCHDIR)/lib -L$(TORCHDIR)/lib -ltorch -ltorch_cpu -lc10' >> Make.config
+ fi
+ fi

if (( $use_debug )); then
echo 'CXXOPTS = -g' >> Make.config
14 changes: 14 additions & 0 deletions namd/src/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
Comment thread
giacomofiorin marked this conversation as resolved.
Language: Cpp
ColumnLimit: 100
UseTab: Never
TabWidth: 2
IndentWidth: 2
ObjCBlockIndentWidth: 2
PenaltyBreakAssignment: 2
AccessModifierOffset: -2
BreakBeforeBraces: WebKit
EmptyLineAfterAccessModifier: Leave
NamespaceIndentation: None
MaxEmptyLinesToKeep: 2
...
31 changes: 31 additions & 0 deletions namd/src/GlobalMasterColvars.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// -*- c++ -*-

#include "GlobalMaster.h"
#include "GlobalMasterColvars.h"
#include "colvarproxy_namd.h"


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

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

void GlobalMasterColvars::calculate() { proxy->calculate(); }


void GlobalMasterColvars::reset()
{
// Unrequest all positions, total forces, etc from NAMD
modifyRequestedAtoms().clear();
modifyForcedAtoms().clear();
modifyAppliedForces().clear();

modifyRequestedGroups().clear();
modifyGroupForces().clear();

#if NAMD_VERSION_NUMBER >= 34471681
modifyRequestedGridObjects().clear();
modifyGridObjForces().clear();
#endif

requestTotalForce(false);
}
155 changes: 155 additions & 0 deletions namd/src/GlobalMasterColvars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#ifndef GLOBALMASTERCOLVARS_H
#define GLOBALMASTERCOLVARS_H

#include <memory>

#include "GlobalMaster.h"


class colvarproxy_namd;

class GlobalMasterColvars : public GlobalMaster {
public:

GlobalMasterColvars();

~GlobalMasterColvars();

void reset();

void calculate() override;

inline void requestTotalForcePublic(bool yesno = true)
{
requestTotalForce(yesno);
}

inline AtomIDList &modifyRequestedAtomsPublic()
{
return modifyRequestedAtoms();
}

inline AtomIDList &modifyForcedAtomsPublic()
{
return modifyForcedAtoms();
}

inline ForceList &modifyAppliedForcesPublic()
{
return modifyAppliedForces();
}

inline ResizeArray<AtomIDList> &modifyRequestedGroupsPublic()
{
return modifyRequestedGroups();
}

inline ForceList &modifyGroupForcesPublic()
{
return modifyGroupForces();
}

inline IntList &modifyRequestedGridObjectsPublic()
{
return modifyRequestedGridObjects();
}

inline BigRealList &modifyGridObjForcesPublic()
{
return modifyGridObjForces();
}

inline AtomIDList::const_iterator getAtomIdBeginPublic()
{
return getAtomIdBegin();
}

inline AtomIDList::const_iterator getAtomIdEndPublic()
{
return getAtomIdEnd();
}

inline PositionList::const_iterator getAtomPositionBeginPublic()
{
return getAtomPositionBegin();
}

inline PositionList::const_iterator getGroupPositionBeginPublic()
{
return getGroupPositionBegin();
}

inline PositionList::const_iterator getGroupPositionEndPublic()
{
return getGroupPositionEnd();
}

inline ForceList::const_iterator getGroupTotalForceBeginPublic()
{
return getGroupTotalForceBegin();
}

inline ForceList::const_iterator getGroupTotalForceEndPublic()
{
return getGroupTotalForceEnd();
}

inline IntList::const_iterator getGridObjIndexBeginPublic()
{
return getGridObjIndexBegin();
}

inline IntList::const_iterator getGridObjIndexEndPublic()
{
return getGridObjIndexEnd();
}

inline BigRealList::const_iterator getGridObjValueBeginPublic()
{
return getGridObjValueBegin();
}

inline BigRealList::const_iterator getGridObjValueEndPublic()
{
return getGridObjValueEnd();
}

inline AtomIDList::const_iterator getForceIdBeginPublic()
{
return getForceIdBegin();
}

inline AtomIDList::const_iterator getForceIdEndPublic()
{
return getForceIdEnd();
}

inline ForceList::const_iterator getTotalForcePublic()
{
return getTotalForce();
}

inline void addReductionEnergyPublic(int reductionTag, BigReal energy)
{
addReductionEnergy(reductionTag, energy);
}

inline Lattice const *get_lattice() const
{
return lattice;
}

protected:

std::unique_ptr<colvarproxy_namd> proxy;
};


namespace {
// Constants used for profiling CkLoop calls
constexpr int32_t GLOBAL_MASTER_CKLOOP_CALC_ITEM = 2000;
constexpr int32_t GLOBAL_MASTER_CKLOOP_CALC_BIASES = 2001;
constexpr int32_t GLOBAL_MASTER_CKLOOP_CALC_SCRIPTED_BIASES = 2002;
}

#endif
Loading