diff --git a/.github/workflows/backend-template.yml b/.github/workflows/backend-template.yml index 7f0d6b6b0..6f08cf0b9 100644 --- a/.github/workflows/backend-template.yml +++ b/.github/workflows/backend-template.yml @@ -25,6 +25,10 @@ on: description: "Name of the branch of the backend repository" required: true type: string + container_name: + description: "Name of the container used to build on" + required: true + type: string vmd_plugins_repo: description: "Name of the VMD plugins repository" required: false @@ -71,7 +75,7 @@ jobs: with: path: | ~/.ccache - ~/ccache_CentOS7-devel + ~/ccache_${{ inputs.container_name }} key: ${{ runner.os }}-build-${{ inputs.backend_name }}-${{ github.sha }} restore-keys: | ${{ runner.os }}-build-${{ inputs.backend_name }}- @@ -82,7 +86,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.apptainer - key: Linux-x86_64-containers-build-2022-10-11 + key: Linux-x86_64-containers-build-2023-07-20 - name: Checkout OpenMM (for Lepton library) uses: actions/checkout@v3 @@ -122,29 +126,30 @@ jobs: wget https://github.com/apptainer/apptainer/releases/download/v1.0.3/apptainer_1.0.3_amd64.deb sudo apt-get -y install ./apptainer_1.0.3_amd64.deb - - name: Get container image of backends' dependencies + - name: Get container images for build dependencies shell: bash working-directory: devel-tools run: | - # Pull CentOS 7 container used to build backends + # Pull all containers used to build backends # (contains build tools, OpenMPI, FFTW, Tcl/Tk and Charm++) apptainer remote status SylabsCloud || apptainer remote add --no-login SylabsCloud cloud.sylabs.io apptainer remote use SylabsCloud apptainer pull CentOS7-devel.sif library://giacomofiorin/default/colvars_development:centos7 + apptainer pull CentOS9-devel.sif library://giacomofiorin/default/colvars_development:centos9 - name : Get spiff shell: bash working-directory: devel-tools - run: sudo cp -f $(apptainer exec CentOS7-devel.sif ./get_spiff) /usr/local/bin + run: sudo cp -f $(apptainer exec ${{ inputs.container_name }}.sif ./get_spiff) /usr/local/bin - name: Update and build ${{ inputs.backend_name }} shell: bash env: OPENMM_SOURCE: ${{ github.workspace }}/openmm-source run: | - apptainer exec devel-tools/CentOS7-devel.sif ./update-colvars-code.sh -f ${{ inputs.backend_name }}-source - CCACHE_DIR=~/ccache_CentOS7-devel \ - apptainer exec devel-tools/CentOS7-devel.sif \ + apptainer exec devel-tools/${{ inputs.container_name }}.sif ./update-colvars-code.sh -f ${{ inputs.backend_name }}-source + CCACHE_DIR=~/ccache_${{ inputs.container_name }} \ + apptainer exec devel-tools/${{ inputs.container_name }}.sif \ bash ${{ inputs.path_compile_script }} ${{ inputs.backend_name }}-source @@ -157,7 +162,7 @@ jobs: shell: bash working-directory: ${{ inputs.test_lib_directory }} run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ + apptainer exec ${{github.workspace}}/devel-tools/${{ inputs.container_name }}.sif \ ./run_tests.sh ${{github.workspace}}/${{ inputs.backend_name }}-source/${{ inputs.rpath_exe }} 0??_* - name: Save failed library test artifact @@ -172,7 +177,7 @@ jobs: shell: bash working-directory: ${{ inputs.test_interface_directory }} run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ + apptainer exec ${{github.workspace}}/devel-tools/${{ inputs.container_name }}.sif \ ./run_tests.sh ${{github.workspace}}/${{ inputs.backend_name }}-source/${{ inputs.rpath_exe }} - name: Save failed interface test artifact diff --git a/.github/workflows/test-backends.yml b/.github/workflows/test-backends.yml index 62e10e7b4..266972893 100644 --- a/.github/workflows/test-backends.yml +++ b/.github/workflows/test-backends.yml @@ -26,6 +26,7 @@ jobs: backend_name: LAMMPS backend_repo: lammps/lammps backend_repo_ref: develop + container_name: CentOS7-devel path_compile_script: devel-tools/compile-lammps.sh test_lib_directory: lammps/tests/library test_interface_directory: lammps/tests/interface @@ -43,6 +44,7 @@ jobs: backend_name: NAMD backend_repo: Colvars/namd backend_repo_ref: master + container_name: CentOS7-devel path_compile_script: devel-tools/compile-namd.sh test_lib_directory: namd/tests/library test_interface_directory: namd/tests/interface @@ -68,6 +70,7 @@ jobs: # Interface tests disabled until map variables are merged into NAMD3 # test_interface_directory: namd/tests/interface rpath_exe: Linux-x86_64-g++.multicore/namd3 + container_name: CentOS7-devel secrets: # Choice of license by UIUC prevents sharing the code, hence the secret private_key: ${{ secrets.PULL_NAMD_KEY }} @@ -84,6 +87,7 @@ jobs: backend_name: VMD backend_repo: Colvars/vmd backend_repo_ref: master + container_name: CentOS7-devel # Special variable for VMD test case since it's the only one # which needs to checkout 2 repos vmd_plugins_repo: Colvars/vmd-plugins @@ -103,6 +107,7 @@ jobs: backend_name: GROMACS-2020 backend_repo: gromacs/gromacs backend_repo_ref: release-2020 + container_name: CentOS7-devel path_compile_script: devel-tools/compile-gromacs.sh test_lib_directory: gromacs/tests/library # Gromacs need to be compiled in double precision to pass the tests @@ -116,6 +121,7 @@ jobs: backend_name: GROMACS-2021 backend_repo: gromacs/gromacs backend_repo_ref: release-2021 + container_name: CentOS9-devel path_compile_script: devel-tools/compile-gromacs.sh test_lib_directory: gromacs/tests/library rpath_exe: install/bin/gmx_d @@ -128,6 +134,7 @@ jobs: backend_name: GROMACS-2022 backend_repo: gromacs/gromacs backend_repo_ref: release-2022 + container_name: CentOS9-devel path_compile_script: devel-tools/compile-gromacs.sh test_lib_directory: gromacs/tests/library rpath_exe: install/bin/gmx_d diff --git a/.github/workflows/test-library.yml b/.github/workflows/test-library.yml index 23fd0e834..3b81d5050 100644 --- a/.github/workflows/test-library.yml +++ b/.github/workflows/test-library.yml @@ -33,7 +33,7 @@ jobs: - name: Install build dependencies for library run: | - sudo apt-get -y install ccache tcl8.6-dev + sudo apt -y install ccache tcl8.6-dev clang - name: Test build recipes run: bash devel-tools/check_build_recipes @@ -48,7 +48,7 @@ jobs: exit 1 fi - - name: Build and test library with CMake + - name: Build and test library (GCC) env: CCACHE: ccache run: cmake -P devel-tools/build_test_library.cmake @@ -63,6 +63,14 @@ jobs: exit 1 fi + - name: Build and test library (Clang) + env: + CMAKE_BUILD_DIR: build-clang + CCACHE: ccache + CXX: clang++ + CC: clang + run: cmake -P devel-tools/build_test_library.cmake + - name: Build library with debug flags enabled env: CCACHE: ccache @@ -88,7 +96,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.apptainer - key: Linux-x86_64-containers-build-doc-2022-09-03 + key: Linux-x86_64-containers-build-doc-2023-07-19 - name: Install Apptainer shell: bash @@ -102,7 +110,7 @@ jobs: run: | apptainer remote status SylabsCloud || apptainer remote add --no-login SylabsCloud cloud.sylabs.io apptainer remote use SylabsCloud - apptainer pull Fedora35-texlive.sif library://giacomofiorin/default/colvars_development:fedora35_texlive + apptainer pull texlive.sif library://giacomofiorin/default/colvars_development:texlive - name: Checkout website repository uses: actions/checkout@v3 @@ -115,7 +123,7 @@ jobs: env: COLVARSDIR: ${{ github.workspace }} FORCE: 1 # Ignore error if branch isn't master - run: apptainer exec ${COLVARSDIR}/devel-tools/Fedora35-texlive.sif make + run: apptainer exec ${COLVARSDIR}/devel-tools/texlive.sif make codeql: @@ -174,7 +182,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.apptainer - key: Linux-x86_64-containers-build-2022-10-11 + key: Linux-x86_64-containers-build-2023-07-20 - name: Get small downloadable packages uses: actions/checkout@v3 @@ -196,8 +204,9 @@ jobs: apptainer remote status SylabsCloud || apptainer remote add --no-login SylabsCloud cloud.sylabs.io apptainer remote use SylabsCloud apptainer pull CentOS7-devel.sif library://giacomofiorin/default/colvars_development:centos7 + apptainer pull CentOS9-devel.sif library://giacomofiorin/default/colvars_development:centos9 - - name: GCC 4.8, C++11 + - name: GCC 4.8, C++11 (CentOS 7) env: CXX_STANDARD: 11 CXX: g++ @@ -207,29 +216,7 @@ jobs: apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 8, C++17 - env: - CXX_STANDARD: 17 - CXX: g++ - CXX_VERSION: 8 - CC: gcc - run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ - scl enable devtoolset-${CXX_VERSION} -- \ - cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - - name: GCC 11, C++20 - env: - CXX_STANDARD: 20 - CXX: g++ - CXX_VERSION: 11 - CC: gcc - run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ - scl enable devtoolset-${CXX_VERSION} -- \ - cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - - name: Clang 3.4, C++11 + - name: Clang 3.4, C++11 (CentOS 7) env: CXX_STANDARD: 11 CXX: clang++ @@ -239,7 +226,7 @@ jobs: apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: Clang 7, C++17 + - name: Clang 7, C++17 (CentOS 7) env: CXX_STANDARD: 17 CXX: clang++ @@ -250,29 +237,29 @@ jobs: scl enable llvm-toolset-${CXX_VERSION} -- \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 11, C++17 + - name: GCC 8, C++14 (CentOS 7) env: - CXX_STANDARD: 17 + CXX_STANDARD: 14 CXX: g++ - CXX_VERSION: 11 + CXX_VERSION: 8 CC: gcc run: | apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ scl enable devtoolset-${CXX_VERSION} -- \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 10, C++17 + - name: GCC 8, C++17 (CentOS 7) env: CXX_STANDARD: 17 CXX: g++ - CXX_VERSION: 10 + CXX_VERSION: 8 CC: gcc run: | apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ scl enable devtoolset-${CXX_VERSION} -- \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 9, C++14 + - name: GCC 9, C++14 (CentOS 7) env: CXX_STANDARD: 14 CXX: g++ @@ -283,49 +270,109 @@ jobs: scl enable devtoolset-${CXX_VERSION} -- \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 8, C++14 + - name: GCC 10, C++17 (CentOS 7) env: - CXX_STANDARD: 14 + CXX_STANDARD: 17 CXX: g++ - CXX_VERSION: 8 + CXX_VERSION: 10 CC: gcc run: | apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ scl enable devtoolset-${CXX_VERSION} -- \ cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 8, C++11 + + - name: GCC 11, C++11 (CentOS 9) env: CXX_STANDARD: 11 CXX: g++ - CXX_VERSION: 8 + CXX_VERSION: 11 CC: gcc run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ - scl enable devtoolset-${CXX_VERSION} -- \ - cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 7, C++14 + - name: GCC 11, C++14 (CentOS 9) env: CXX_STANDARD: 14 CXX: g++ - CXX_VERSION: 7 + CXX_VERSION: 11 CC: gcc run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ - scl enable devtoolset-${CXX_VERSION} -- \ - cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + + - name: GCC 11, C++17 (CentOS 9) + env: + CXX_STANDARD: 17 + CXX: g++ + CXX_VERSION: 11 + CC: gcc + run: | + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake - - name: GCC 7, C++11 + - name: GCC 11, C++20 (CentOS 9) + env: + CXX_STANDARD: 20 + CXX: g++ + CXX_VERSION: 11 + CC: gcc + run: | + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + + - name: GCC 12, C++11 (CentOS 9) env: CXX_STANDARD: 11 CXX: g++ - CXX_VERSION: 7 + CXX_VERSION: 12 CC: gcc run: | - apptainer exec ${{github.workspace}}/devel-tools/CentOS7-devel.sif \ - scl enable devtoolset-${CXX_VERSION} -- \ - cmake3 -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + scl enable gcc-toolset-12 -- \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + + - name: GCC 12, C++20 (CentOS 9) + env: + CXX_STANDARD: 20 + CXX: g++ + CXX_VERSION: 12 + CC: gcc + run: | + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + scl enable gcc-toolset-12 -- \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + + - name: Clang 16, C++11 (CentOS 9) + env: + CXX_STANDARD: 11 + CXX: clang++ + CXX_VERSION: 16 + CC: clang + run: | + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + + - name: Clang 16, C++17 (CentOS 9) + env: + CXX_STANDARD: 17 + CXX: clang++ + CXX_VERSION: 16 + CC: clang + run: | + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake + + - name: Clang 16, C++20 (CentOS 9) + env: + CXX_STANDARD: 20 + CXX: clang++ + CXX_VERSION: 16 + CC: clang + run: | + apptainer exec ${{github.workspace}}/devel-tools/CentOS9-devel.sif \ + cmake -D CMAKE_CXX_STANDARD=${CXX_STANDARD} -P devel-tools/build_test_library.cmake build-linux-x86_64-sun: @@ -340,7 +387,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.apptainer - key: Linux-x86_64-containers-build-2022-10-11 + key: Linux-x86_64-containers-build-2023-07-20 - name: Checkout Sun compiler (Oracle Developer Studio) uses: actions/checkout@v3 @@ -370,6 +417,7 @@ jobs: apptainer remote status SylabsCloud || apptainer remote add --no-login SylabsCloud cloud.sylabs.io apptainer remote use SylabsCloud apptainer pull CentOS7-devel.sif library://giacomofiorin/default/colvars_development:centos7 + apptainer pull CentOS9-devel.sif library://giacomofiorin/default/colvars_development:centos9 - name: Build library with Sun compiler (Oracle Developer Studio) shell: bash diff --git a/colvartools/plot_colvars_traj.py b/colvartools/plot_colvars_traj.py index b396b70e0..00f3e42ab 100644 --- a/colvartools/plot_colvars_traj.py +++ b/colvartools/plot_colvars_traj.py @@ -3,7 +3,7 @@ # Invoke this script with --help for documentation. # Download link: https://github.com/Colvars/colvars/blob/master/colvartools/plot_colvars_traj.py?raw=true -# This version was modified on: 2022-09-12 +# This version was modified on: 2023-07-13 # Contact: giacomo.fiorin@gmail.com from __future__ import print_function @@ -143,6 +143,8 @@ def _parse_comment_line(self, line): self._keys = new_keys # Find the boundaries of each column for i in range(1, len(self._keys)): + if (self._keys[i] not in self._colvars): + self._colvars[self._keys[i]] = Colvar_traj(self._keys[i]) if i == 1: pos = line.find(' '+self._keys[i]+' ') else: @@ -152,7 +154,6 @@ def _parse_comment_line(self, line): self._end[self._keys[i-1]] = pos self._end[self._keys[-1]] = -1 - def _parse_line(self, line, dict_buffer): """ Read in a data line from a colvars.traj file @@ -226,10 +227,8 @@ def read_files(self, filenames, list_variables=False, last_step = step for key in dict_buffer: - if (key not in self._colvars): - self._colvars[key] = Colvar_traj(key) - self._colvars[key]._set_num_dimensions(dict_buffer[key]['dimension']) cv = self._colvars[key] + cv._set_num_dimensions(dict_buffer[key]['dimension']) cv._step = np.concatenate((cv.steps, dict_buffer[key]['cv_step']), axis=0) cv._colvar = np.concatenate((cv.values, dict_buffer[key]['cv_values']), axis=0) f.close() diff --git a/devel-tools/compile-namd.sh b/devel-tools/compile-namd.sh index d1dc3ae28..6f206b64a 100755 --- a/devel-tools/compile-namd.sh +++ b/devel-tools/compile-namd.sh @@ -72,7 +72,14 @@ EOF cmd+=(--tcl-prefix ${TCL_HOME:-/usr}) cmd+=(--with-fftw3 --fftw-prefix ${FFTW_HOME:-/usr}) - cmd+=(--with-python) + + local python_version=$(python3 --version 2> /dev/null | cut -d' ' -f 2) + python_version=${python_version%.*} + if [ "x${python_version}" == "x3.6" ] || [ "x${python_version}" == "x3.7" ] || \ + [ "x${python_version}" == "x3.8" ] ; then + # Currently does not build with >= 3.9 API + cmd+=(--with-python) + fi eval ${cmd[@]} diff --git a/devel-tools/containers/CentOS7-devel.def b/devel-tools/containers/CentOS7-devel.def new file mode 100644 index 000000000..16aaf68bc --- /dev/null +++ b/devel-tools/containers/CentOS7-devel.def @@ -0,0 +1,49 @@ +BootStrap: library +From: centos:7 + + +%help + Development environment for CentOS 7 + + +%post + yum -y update + yum -y install epel-release centos-release-scl + yum -y install \ + redhat-lsb-core "@Development Tools" \ + ncurses which bc man-db vim emacs screen tmux \ + gcc gcc-c++ gcc-gfortran glibc-static libstdc++-static clang cppcheck \ + autoconf automake cvs git git-cvs cvsps subversion mercurial \ + rh-git227 devtoolset-{7..11} llvm-toolset-7 cmake3 ccache ninja \ + doxygen \ + openmpi-devel fftw-devel tcl-devel \ + python-{devel,virtualenv} numpy scipy tkinter \ + python3-{devel,tkinter} python36-{virtualenv,numpy,scipy} \ + rh-python38-python-{devel,tkinter,numpy,scipy} \ + boost169-devel \ + ncurses-devel \ + rlwrap \ + tk-devel fltk-devel \ + sqlite-devel netcdf-devel expat-devel hdf5-devel tng-devel \ + mesa-dri-drivers mesa-libGL-devel libglvnd-devel \ + libXi-devel libXinerama-devel libpng-devel \ + xfce4-terminal \ + texlive-latex texlive-epstopdf texlive-pdftex latex2html \ + texlive-graphics texlive-metafont \ + texlive-collection-latexrecommended texlive-collection-fontsrecommended + + # Build Charm++ + umask 022 + git clone --single-branch --depth=1 -b v7.0.0 https://github.com/UIUC-PPL/charm.git /opt/charm && \ + cd /opt/charm && \ + ./build charm++ mpi-linux-x86_64 -j\$(nproc) --with-production && \ + ./build charm++ multicore-linux-x86_64 -j\$(nproc) --with-production && \ + ./build charm++ netlrts-linux-x86_64 -j\$(nproc) --with-production + + # Load Git 2.27 + cat > /etc/profile.d/git.sh < /// \brief Communication between colvars and LAMMPS /// (implementation of \link colvarproxy \endlink) diff --git a/C_fortran/colvarproxy_C_interface.h b/misc_interfaces/C_fortran/colvarproxy_C_interface.h similarity index 100% rename from C_fortran/colvarproxy_C_interface.h rename to misc_interfaces/C_fortran/colvarproxy_C_interface.h diff --git a/C_fortran/colvars.py b/misc_interfaces/C_fortran/colvars.py similarity index 100% rename from C_fortran/colvars.py rename to misc_interfaces/C_fortran/colvars.py diff --git a/C_fortran/fortran_test.f90 b/misc_interfaces/C_fortran/fortran_test.f90 similarity index 100% rename from C_fortran/fortran_test.f90 rename to misc_interfaces/C_fortran/fortran_test.f90 diff --git a/python/colvars.py b/misc_interfaces/python/colvars.py similarity index 100% rename from python/colvars.py rename to misc_interfaces/python/colvars.py diff --git a/tests/stubs/colvarproxy_stub.cpp b/misc_interfaces/stubs/colvarproxy_stub.cpp similarity index 100% rename from tests/stubs/colvarproxy_stub.cpp rename to misc_interfaces/stubs/colvarproxy_stub.cpp diff --git a/tests/stubs/colvarproxy_stub.h b/misc_interfaces/stubs/colvarproxy_stub.h similarity index 100% rename from tests/stubs/colvarproxy_stub.h rename to misc_interfaces/stubs/colvarproxy_stub.h diff --git a/src/colvarbias.cpp b/src/colvarbias.cpp index 18969fc53..97c0c40e4 100644 --- a/src/colvarbias.cpp +++ b/src/colvarbias.cpp @@ -462,17 +462,15 @@ std::string const colvarbias::get_state_params() const } -int colvarbias::set_state_params(std::string const &conf) +int colvarbias::check_matching_state(std::string const &conf) { - matching_state = false; - std::string check_name = ""; colvarparse::get_keyval(conf, "name", check_name, std::string(""), colvarparse::parse_silent); if (check_name.size() == 0) { - cvm::error("Error: \""+bias_type+"\" block within the restart file " - "has no identifiers.\n", COLVARS_INPUT_ERROR); + return cvm::error("Error: \""+bias_type+"\" block within the state file " + "has no identifiers.\n", COLVARS_INPUT_ERROR); } if (check_name != this->name) { @@ -480,11 +478,17 @@ int colvarbias::set_state_params(std::string const &conf) cvm::log("Ignoring state of bias \""+check_name+ "\": this bias is named \""+name+"\".\n"); } - return COLVARS_OK; + matching_state = false; + } else { + matching_state = true; } - matching_state = true; + return COLVARS_OK; +} + +int colvarbias::set_state_params(std::string const &conf) +{ colvarparse::get_keyval(conf, "step", state_file_step, cvm::step_absolute(), colvarparse::parse_silent); @@ -515,41 +519,42 @@ std::ostream & colvarbias::write_state(std::ostream &os) std::istream & colvarbias::read_state(std::istream &is) { - std::streampos const start_pos = is.tellg(); + auto const start_pos = is.tellg(); std::string key, brace, conf; if ( !(is >> key) || !(key == state_keyword || key == bias_type) || !(is >> brace) || !(brace == "{") || !(is >> colvarparse::read_block("configuration", &conf)) || - (set_state_params(conf) != COLVARS_OK) ) { + (check_matching_state(conf) != COLVARS_OK) ) { cvm::error("Error: in reading state configuration for \""+bias_type+ "\" bias \""+ this->name+"\" at position "+ cvm::to_str(static_cast(is.tellg()))+ " in stream.\n", COLVARS_INPUT_ERROR); is.clear(); - is.seekg(start_pos, std::ios::beg); + is.seekg(start_pos); is.setstate(std::ios::failbit); return is; } - if (matching_state == false) { - // This state is not for this bias - is.seekg(start_pos, std::ios::beg); + if (!matching_state) { + // No errors reading, but this state is not for this bias; rewind + is.seekg(start_pos); return is; } cvm::log("Restarting "+bias_type+" bias \""+name+"\" from step number "+ cvm::to_str(state_file_step)+".\n"); - if (!read_state_data(is)) { + if ((set_state_params(conf) != COLVARS_OK) || !read_state_data(is)) { cvm::error("Error: in reading state data for \""+bias_type+"\" bias \""+ this->name+"\" at position "+ cvm::to_str(static_cast(is.tellg()))+ " in stream.\n", COLVARS_INPUT_ERROR); + auto state = is.rdstate(); is.clear(); - is.seekg(start_pos, std::ios::beg); - is.setstate(std::ios::failbit); + is.seekg(start_pos); + is.setstate(state); } is >> brace; diff --git a/src/colvarbias.h b/src/colvarbias.h index e865902be..de7b04b51 100644 --- a/src/colvarbias.h +++ b/src/colvarbias.h @@ -133,6 +133,9 @@ class colvarbias /// Write the values of specific mutable properties to a string virtual std::string const get_state_params() const; + /// Check the name of the bias vs. the given string, set the matching_state flag accordingly + int check_matching_state(std::string const &conf); + /// Read the values of specific mutable properties from a string virtual int set_state_params(std::string const &state_conf); diff --git a/src/colvarcomp.cpp b/src/colvarcomp.cpp index abe522a24..151a25569 100644 --- a/src/colvarcomp.cpp +++ b/src/colvarcomp.cpp @@ -43,6 +43,22 @@ colvar::cvc::cvc(std::string const &conf) } +int colvar::cvc::update_description() +{ + if (name.size() > 0) { + description = "cvc " + name; + } else { + description = "unnamed cvc"; + } + if (function_type.size() > 0) { + description += " of type \"" + function_type + "\""; + } else { + description += " of unset type"; + } + return COLVARS_OK; +} + + int colvar::cvc::set_function_type(std::string const &type) { function_type = type; @@ -53,6 +69,8 @@ int colvar::cvc::set_function_type(std::string const &type) function_types.push_back(function_type); } } + update_description(); + for (size_t i = function_types.size()-1; i > 0; i--) { cvm::main()->cite_feature(function_types[i]+" colvar component"+ " (derived from "+function_types[i-1]+")"); @@ -74,11 +92,6 @@ int colvar::cvc::init(std::string const &conf) } if (get_keyval(conf, "name", name, name)) { - if (name.size() > 0) { - description = "cvc \"" + name + "\" of type " + function_type; - } else { - description = "unnamed cvc"; - } if ((name != old_name) && (old_name.size() > 0)) { cvm::error("Error: cannot rename component \""+old_name+ "\" after initialization (new name = \""+name+"\")", @@ -86,6 +99,7 @@ int colvar::cvc::init(std::string const &conf) name = old_name; } } + update_description(); get_keyval(conf, "componentCoeff", sup_coeff, sup_coeff); get_keyval(conf, "componentExp", sup_np, sup_np); @@ -314,7 +328,7 @@ int colvar::cvc::init_dependencies() { int colvar::cvc::setup() { - description = "cvc " + name; + update_description(); return COLVARS_OK; } diff --git a/src/colvarcomp.h b/src/colvarcomp.h index c89143bc0..e475d815c 100644 --- a/src/colvarcomp.h +++ b/src/colvarcomp.h @@ -278,6 +278,9 @@ class colvar::cvc protected: + /// Update the description string based on name and type + int update_description(); + /// Record the type of this class as well as those it is derived from std::vector function_types; diff --git a/src/colvarcomp_combination.cpp b/src/colvarcomp_combination.cpp index 7d5079701..974cc870c 100644 --- a/src/colvarcomp_combination.cpp +++ b/src/colvarcomp_combination.cpp @@ -33,22 +33,8 @@ colvar::linearCombination::linearCombination(std::string const &conf): cvc(conf) " expects one or more nesting components.\n"); return; } else { - // TODO: Maybe we can add an option to allow mixing scalar and vector types, - // but that's a bit complicated so we just require a consistent type - // of nesting CVs. x.type(cv[0]->value()); x.reset(); - for (size_t i_cv = 1; i_cv < cv.size(); ++i_cv) { - const auto type_i = cv[i_cv]->value().type(); - if (type_i != x.type()) { - cvm::error("Error: the type of sub-CVC " + cv[i_cv]->name + - " is " + colvarvalue::type_desc(type_i) + ", which is " - "different to the type of the first sub-CVC. Currently " - "only sub-CVCs of the same type are supported to be " - "nested.\n"); - return; - } - } } use_explicit_gradients = true; for (size_t i_cv = 0; i_cv < cv.size(); ++i_cv) { @@ -317,7 +303,8 @@ void colvar::customColvar::apply_force(colvarvalue const &force) { } } else { const colvarvalue& current_cv_value = cv[i_cv]->value(); - colvarvalue cv_force(current_cv_value.type()); + colvarvalue cv_force(current_cv_value); + cv_force.reset(); const cvm::real factor_polynomial = getPolynomialFactorOfCVGradient(i_cv); for (size_t j_elem = 0; j_elem < current_cv_value.size(); ++j_elem) { for (size_t c = 0; c < x.size(); ++c) { diff --git a/src/colvars_version.h b/src/colvars_version.h index d0f63e717..0aa4e60d1 100644 --- a/src/colvars_version.h +++ b/src/colvars_version.h @@ -1,3 +1,3 @@ #ifndef COLVARS_VERSION -#define COLVARS_VERSION "2023-07-21" +#define COLVARS_VERSION "2023-08-21" #endif diff --git a/src/colvarvalue.h b/src/colvarvalue.h index 9ab8dbe31..6bc7a57c7 100644 --- a/src/colvarvalue.h +++ b/src/colvarvalue.h @@ -120,7 +120,8 @@ class colvarvalue { /// number and always behaves like it unless you change its type colvarvalue(); - /// Constructor from a type specification + /// Constructor from a type flag (note: type_vector also needs the vector length to be set) + /// \param[in] vti Value of the \link Type \endlink enum colvarvalue(Type const &vti); /// Copy constructor from real base type diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index e86a6228d..cfcade4d9 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -1,4 +1,4 @@ -set(COLVARS_STUBS_DIR ${COLVARS_SOURCE_DIR}/tests/stubs/) +set(COLVARS_STUBS_DIR ${COLVARS_SOURCE_DIR}/misc_interfaces/stubs/) add_library(colvars_stubs OBJECT ${COLVARS_STUBS_DIR}/colvarproxy_stub.cpp) target_include_directories(colvars_stubs PRIVATE ${COLVARS_SOURCE_DIR}/src) diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index f4653cb2b..e2804ae75 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -17,7 +17,7 @@ endif() # Last test requires the stubs proxy add_executable(read_xyz_traj read_xyz_traj.cpp) -set(COLVARS_STUBS_DIR ${COLVARS_SOURCE_DIR}/tests/stubs/) +set(COLVARS_STUBS_DIR ${COLVARS_SOURCE_DIR}/misc_interfaces/stubs/) target_link_libraries(read_xyz_traj PRIVATE colvars colvars_stubs) target_include_directories(read_xyz_traj PRIVATE ${COLVARS_SOURCE_DIR}/src) target_include_directories(read_xyz_traj PRIVATE ${COLVARS_STUBS_DIR}) diff --git a/update-colvars-code.sh b/update-colvars-code.sh index 8c9a9ea80..8932391de 100755 --- a/update-colvars-code.sh +++ b/update-colvars-code.sh @@ -1,6 +1,8 @@ #!/bin/bash # -*- sh-basic-offset: 2; sh-indentation: 2; -*- +set -e + # Script to update a NAMD, VMD, LAMMPS or GROMACS source tree with the latest Colvars # version. @@ -363,7 +365,7 @@ then condcopy "${source}/namd/lepton/Makefile.namd" \ "${target}/lepton/Makefile.namd" - if ! grep -q lepton/Makefile.namd "${target}/lepton/Makefile.namd" ; then + if ! grep -q lepton/Makefile.namd "${target}/Makefile" ; then patch -p1 -N -d ${target} < namd/Makefile.patch fi