-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable use of CVs defined by PyTorch neural network models #570
base: master
Are you sure you want to change the base?
Conversation
Torchann1
CMAKE_CXX_STANDARD is less than 17
Hi, since we have one CI test working for the library, my only remaining concern would be avoiding routine conflicts with the build systems of the MD engines (see #570 (comment)). |
In the case that the `GMX_TORCH` CMake flag is enabled, propagate the compile flags to the Colvars build system to enable building of [pyTorch-based CVs](Colvars/colvars#570).
- Removed componentDisabled
The latest GROMACS test error is unrelated to Colvars: https://gitlab.com/gromacs/gromacs/-/issues/5204 |
Hi there! GROMACS 2025 runs without errors the See the outputs here: |
@giacomofiorin thanks for the work! |
@zwpku Yes, the reference files currently in that folder were produced came from another build, with a different version of libTorch. Would you expect this kind of difference? It is small, but it did exceed our threshold (1.0e-6 relative error). |
@giacomofiorin If I see correctly, the torch model in that test is simply the identity map and the CV is a dihedral angle. So I expect there should be little difference due to different versions of libTorch. Could it also be caused by some changes in the source code or in the config files of that test? I can try to build and examine the test on my local machine. |
This branch implements a class called
torchANN
, which allows to define cv components by loading pretrained PyTorch neural network models.Installation Steps
Download LibTorch. This package is required in order to enable the
torchann
class. First, download the code and unzip it.In this way, the library is uncompressed under the current directory. Let's say it is located at /path/to/libtorch.
Patch MD engine. This step is done as usual using the script update-colvars-code.sh. Enter the source code of Colvars package, and run:
Compilation. This step depends on the engine to be compiled.
NAMD: add "--with-colvars-torch --torch-prefix path/to/libtorch" to the argument of ./config
Assume packages that are required to build NAMD, e.g. charm, tcl/tcl-threaded, are already prepared.
Then, one can compile the NAMD package with the following commands:
An example of the command is:
and set the variable Torch_DIR in the file CMakeCache.txt. When a cpu version of libtorch library is used, it may
also be necessary to set MKL path to empty:
Alternatively, one could combine these steps in one command:
After that, run make and make install to compile and install the package.
The class has only been tested using simple neural network models (i.e. an autoencoder on alanine dipeptide), under NAMD and GROMACS engines. Feedbacks are welcome!
A (trivial) example
This Python script simply creates a model which is an identity map and save it to a file named identity.pt.
This file defines two CVs using torchann class taking other cv components (here dihedral angles) as inputs.