### Run muParser Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/muparser/Install.txt Navigate to the samples directory and execute the example binary to test the installation. ```bash cd samples/example1 ./example1 ``` -------------------------------- ### Install Project Rules Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/googlemock/CMakeLists.txt Defines the installation rules for the project. ```cmake install_project(gmock gmock_main) ``` -------------------------------- ### Install muParser Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/muparser/Install.txt Compile and install the muParser library and its components. 'sudo' is required for system-wide installation. ```bash make [sudo*] make install [sudo*] ldconfig ``` -------------------------------- ### Install gmxapi from Local Source Archive Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Download the gmxapi source distribution and install it from the local archive file. This is an alternative to installing directly from PyPI. ```bash pip download gmxapi pip install gmxapi-.tar.gz ``` -------------------------------- ### Configure and install pkg-config file Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/muparser/CMakeLists.txt Sets up variables and installs the .pc file for system-wide package discovery. ```cmake set(PACKAGE_NAME muparser) if(ENABLE_WIDE_CHAR) set(PKG_CONFIG_FLAGS "-D_UNICODE") endif(ENABLE_WIDE_CHAR) configure_file( muparser.pc.in ${CMAKE_BINARY_DIR}/muparser.pc @ONLY ) install( FILES ${CMAKE_BINARY_DIR}/muparser.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig EXCLUDE_FROM_ALL ) ``` -------------------------------- ### Install CMake and Pybind11 Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Install essential build tools required by the gmxapi installer. ```bash pip install --upgrade cmake pybind11 ``` -------------------------------- ### Set up Python virtual environment and install dependencies Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst This command sequence sets up a Python virtual environment, activates it, ensures pip is up-to-date, and installs the mpi4py package. This is a prerequisite for installing gmxapi. ```bash python3 -m venv $HOME/myvenv . $HOME/myvenv/bin/activate python -m ensurepip --default-pip pip install --upgrade pip setuptools wheel pip install mpi4py ``` -------------------------------- ### Install and Run Black Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/dev-manual/code-formatting.rst Install the Black formatter and run it using the repository's configuration file. ```bash pip install black black --config .black.toml . ``` -------------------------------- ### Build OpenMP Examples Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/tng_io/src/tests/CMakeLists.txt Configures the build to include OpenMP support for examples if found. ```cmake if(TNG_BUILD_EXAMPLES) find_package(OpenMP) if(OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") add_executable(md_openmp md_openmp.c) target_link_libraries(md_openmp tng_io ${OpenMP_LIBS}) if(UNIX) target_link_libraries(md_openmp m) endif() set_property(TARGET md_openmp PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) set_property(TARGET md_openmp APPEND PROPERTY COMPILE_DEFINITIONS TNG_BUILD_OPENMP_EXAMPLES) add_executable(md_openmp_util md_openmp_util.c) target_link_libraries(md_openmp_util tng_io ${OpenMP_LIBS}) if(UNIX) target_link_libraries(md_openmp_util m) endif() set_property(TARGET md_openmp_util PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) set_property(TARGET md_openmp_util APPEND PROPERTY COMPILE_DEFINITIONS TNG_BUILD_OPENMP_EXAMPLES) add_executable(tng_parallel_read tng_parallel_read.c) target_link_libraries(tng_parallel_read tng_io) if(UNIX) target_link_libraries(tng_parallel_read m) endif() set_property(TARGET tng_parallel_read PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) set_property(TARGET tng_parallel_read APPEND PROPERTY COMPILE_DEFINITIONS TNG_BUILD_OPENMP_EXAMPLES) endif() add_executable(tng_io_read_pos tng_io_read_pos.c) target_link_libraries(tng_io_read_pos tng_io) if(UNIX) target_link_libraries(tng_io_read_pos m) endif() if(HAVE_INTTYPES_H) set_property(TARGET tng_io_read_pos APPEND PROPERTY COMPILE_DEFINITIONS USE_STD_INTTYPES_H=1) endif() set_property(TARGET tng_io_read_pos PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) add_executable(tng_io_read_pos_util tng_io_read_pos_util.c) target_link_libraries(tng_io_read_pos_util tng_io) if(UNIX) target_link_libraries(tng_io_read_pos_util m) endif() if(HAVE_INTTYPES_H) set_property(TARGET tng_io_read_pos_util APPEND PROPERTY COMPILE_DEFINITIONS USE_STD_INTTYPES_H=1) endif() set_property(TARGET tng_io_read_pos_util PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) if(TNG_BUILD_FORTRAN) # This does not work due to a bug in CMake. Remove lines below if no fortran compiler is found. enable_language(Fortran OPTIONAL) if(${CMAKE_Fortran_COMPILER_WORKS}) get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME) if (Fortran_COMPILER_NAME STREQUAL "gfortran") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer ${OpenMP_C_FLAGS} -std=legacy -cpp -ffixed-line-length-none") endif() if(OPENMP_FOUND) ``` -------------------------------- ### Include Sphinx Macros and Setup Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/CMakeLists.txt Includes necessary Sphinx macros and initializes the Sphinx setup for documentation generation. ```cmake include(SphinxMacros.cmake) gmx_init_sphinx_setup(${SPHINX_INPUT_DIR}) ``` -------------------------------- ### Download and Install gmxapi from Source Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Use these commands to download the package to a directory and install it without index lookups. ```bash pip download --destination-directory DIR . # Build and install from the source directory. pip install --no-index --find-links=DIR . ``` -------------------------------- ### Build and Install GoogleTest Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/googletest/README.md Compiles the generated build scripts and installs the resulting binaries to the system. ```bash make sudo make install # Install in /usr/local/ by default ``` -------------------------------- ### Install gmxapi from Source Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Installs the package from the local GROMACS source repository. ```shell cd python_packaging/gmxapi pip install -r requirements.txt pip install . ``` -------------------------------- ### Install template files Source: https://gitlab.com/gromacs/gromacs/-/blob/main/share/template/CMakeLists.txt Defines installation rules for the template source files, README, and CMake helper files. ```cmake install(FILES CMakeLists.txt.template DESTINATION ${GMX_INSTALL_GMXDATADIR}/template RENAME CMakeLists.txt COMPONENT development) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/README template.cpp Makefile.pkg DESTINATION ${GMX_INSTALL_GMXDATADIR}/template COMPONENT development) install(FILES cmake/FindGROMACS.cmake DESTINATION ${GMX_INSTALL_GMXDATADIR}/template/cmake COMPONENT development) ``` -------------------------------- ### Install Copying File Source: https://gitlab.com/gromacs/gromacs/-/blob/main/CMakeLists.txt Installs the COPYING file to the data destination. This is typically necessary for binary distributions. ```cmake #COPYING file: Only necessary for binary distributions. #Simpler to always install. install(FILES COPYING DESTINATION ${GMX_INSTALL_GMXDATADIR} COMPONENT data) ``` -------------------------------- ### Install OpenCL utility and kernel files Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/gromacs/CMakeLists.txt Deploys OpenCL headers and kernel source files to the installation directory when GMX_GPU_OPENCL is enabled. ```cmake if(GMX_GPU_OPENCL) # Install the utility headers file(GLOB OPENCL_INSTALLED_FILES gpu_utils/vectype_ops.clh gpu_utils/device_utils.clh ) install(FILES ${OPENCL_INSTALLED_FILES} DESTINATION ${GMX_INSTALL_OCLDIR}/gromacs/gpu_utils COMPONENT libraries) file(GLOB OPENCL_INSTALLED_FILES pbcutil/ishift.h ) install(FILES ${OPENCL_INSTALLED_FILES} DESTINATION ${GMX_INSTALL_OCLDIR}/gromacs/pbcutil COMPONENT libraries) # Install the NBNXM source and headers file(GLOB OPENCL_INSTALLED_FILES nbnxm/constants.h ) install(FILES ${OPENCL_INSTALLED_FILES} DESTINATION ${GMX_INSTALL_OCLDIR}/gromacs/nbnxm COMPONENT libraries) file(GLOB OPENCL_INSTALLED_FILES nbnxm/opencl/nbnxm_ocl_kernels.cl nbnxm/opencl/nbnxm_ocl_kernel.clh nbnxm/opencl/nbnxm_ocl_kernel_pruneonly.clh nbnxm/opencl/nbnxm_ocl_kernels.clh nbnxm/opencl/nbnxm_ocl_kernels_fastgen.clh nbnxm/opencl/nbnxm_ocl_kernels_fastgen_add_twincut.clh nbnxm/opencl/nbnxm_ocl_kernel_utils.clh nbnxm/opencl/nbnxm_ocl_consts.h ) install(FILES ${OPENCL_INSTALLED_FILES} DESTINATION ${GMX_INSTALL_OCLDIR}/gromacs/nbnxm/opencl COMPONENT libraries) # Install the PME source and headers file(GLOB OPENCL_INSTALLED_FILES ewald/pme_spread.clh ewald/pme_solve.clh ewald/pme_gather.clh ewald/pme_gpu_calculate_splines.clh ewald/pme_program.cl ewald/pme_gpu_types.h ) install(FILES ${OPENCL_INSTALLED_FILES} DESTINATION ${GMX_INSTALL_OCLDIR}/gromacs/ewald COMPONENT libraries) endif() ``` -------------------------------- ### Install Python documentation dependencies Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/dev-manual/documentation-generation.rst Install the required Python packages for building the full documentation set. ```bash pip install -r python_packaging/gmxapi/requirements.txt ``` -------------------------------- ### Install gmxapi Python package Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst After setting up the environment and sourcing the Gromacs installation, this command installs the gmxapi package from PyPI. Use --no-cache-dir to ensure a fresh build. ```bash . /path/to/gromacs/bin/GMXRC pip install --no-cache-dir gmxapi ``` -------------------------------- ### Offline Installation via Wheels Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Commands to download or build wheels for offline installation. ```shell # Remove any locally cached (previously built) wheels. pip cache remove gmxapi # Download gmxapi and dependencies from pypi. pip wheel --wheel-dir DIR gmxapi # or, using package source from the GROMACS repository cd python_packaging/gmxapi pip wheel --wheel-dir DIR . # Later, install. pip install --no-index --find-links=DIR DIR/gmxapi*whl ``` -------------------------------- ### PDB File Format Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/reference-manual/file-formats.rst Example of a PDB file structure showing atom records with coordinates and occupancy/temperature factors. ```text ATOM 1 H1 LYS 1 14.260 6.590 34.480 1.00 0.00 ATOM 2 H2 LYS 1 13.760 5.000 34.340 1.00 0.00 ATOM 3 N LYS 1 14.090 5.850 33.800 1.00 0.00 ATOM 4 H3 LYS 1 14.920 5.560 33.270 1.00 0.00 ... ... ``` -------------------------------- ### Force Field Include File Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/reference-manual/topologies/topology-file-formats.rst Example content of a force field .itp file, showing preprocessor definitions and the [ defaults ] directive. ```text #define _FF_AMBER #define _FF_AMBER99 [ defaults ] ; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ 1 2 yes 0.5 0.8333 #include "ffnonbonded.itp" #include "ffbonded.itp" ``` -------------------------------- ### Register NbLib Setup Tests Source: https://gitlab.com/gromacs/gromacs/-/blob/main/api/nblib/tests/CMakeLists.txt Configures the NbLib setup test executable and registers it as an integration test. ```cmake set(testname "NbLibSetupTests") set(exename "nblib-setup-test") gmx_add_gtest_executable( ${exename} HARDWARE_DETECTION CPP_SOURCE_FILES # files with code for tests box.cpp interactions.cpp particletype.cpp pbcholder.cpp molecules.cpp nbnxmsetup.cpp topology.cpp virials.cpp ) target_link_libraries(${exename} PRIVATE mdrun_test_infrastructure) target_link_libraries(${exename} PRIVATE nblib_test_infrastructure nblib) target_include_directories(${exename} PRIVATE ${PROJECT_SOURCE_DIR}/api) gmx_register_gtest_test(${testname} ${exename} INTEGRATION_TEST) add_dependencies(nblib-tests ${exename}) ``` -------------------------------- ### Fallback Target: INSTALL Guide Unavailable Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/CMakeLists.txt This target is created when Sphinx is not available, informing the user that the INSTALL guide cannot be built. ```cmake add_custom_target(install-guide COMMAND ${CMAKE_COMMAND} -E echo "INSTALL cannot be built because Sphinx expected minimum version ${EXPECTED_SPHINX_VERSION} is not available" VERBATIM) ``` -------------------------------- ### Example pkg-config file content Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/pkgconfig.md A sample .pc file structure for GoogleTest. ```text libdir=/usr/lib64 includedir=/usr/include Name: gtest Description: GoogleTest (without main() function) Version: 1.11.0 URL: https://github.com/google/googletest Libs: -L${libdir} -lgtest -lpthread Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread ``` -------------------------------- ### UnitTest::start_timestamp Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/reference/testing.md Gets the time of the test program start, in milliseconds from the start of the UNIX epoch. ```APIDOC ## UnitTest::start_timestamp ### Description Gets the time of the test program start, in ms from the start of the UNIX epoch. ### Method `TimeInMillis UnitTest::start_timestamp() const` ``` -------------------------------- ### Initialize Input Options for Analysis Tool Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/doxygen/user/analysistemplate.md Sets up options for the analysis tool, including description, output file name, selections, and a cutoff value. Requires topology information. ```cpp void AnalysisTemplate::initOptions(gmx::TrajectoryAnalysisSettings& settings) { settings.setToolDescription("Example trajectory analysis tool."); settings.addOutputFileOption("o", 'o', "output.dat", "Output file name."); settings.addSelectionOption("sel", 's', "all", "Atoms to analyze."); settings.addOption("cutoff", 'c', "0.5", "Cutoff distance.", &cutoff_); settings.setRequiresTopology(true); } ``` -------------------------------- ### TestSuite::start_timestamp Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/reference/testing.md Gets the time of the test suite start, in ms from the start of the UNIX epoch. ```APIDOC ## TestSuite::start_timestamp ### Description Gets the time of the test suite start, in ms from the start of the UNIX epoch. ### Method `TimeInMillis TestSuite::start_timestamp() const` ``` -------------------------------- ### Notify MDModulesNotifier in Mdrunner Setup Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/doxygen/lib/mdmodules.md Trigger notifications from the MDModulesNotifier during the Mdrunner setup phase. This example shows how to call the notify method with a callback argument. ```C++ YourCallbackSignature argument(); mdModules_.notifier().notifier_.notify(argument); ``` -------------------------------- ### Get muParser linker flags Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/muparser/Install.txt Use pkg-config to retrieve the necessary linker flags for linking against the installed muParser library. ```bash pkg-config muparser --libs ``` -------------------------------- ### Get muParser compiler flags Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/muparser/Install.txt Use pkg-config to retrieve the necessary compiler flags for linking against the installed muParser library. ```bash pkg-config muparser --cflags ``` -------------------------------- ### Minimalist Test Event Listener Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/advanced.md A basic implementation of a test event listener that prints messages when a test starts, ends, or a test assertion results in a failure or success. ```c++ class MinimalistPrinter : public testing::EmptyTestEventListener { // Called before a test starts. void OnTestStart(const testing::TestInfo& test_info) override { printf("*** Test %s.%s starting.\n", test_info.test_suite_name(), test_info.name()); } // Called after a failed assertion or a SUCCESS(). void OnTestPartResult(const testing::TestPartResult& test_part_result) override { printf("%s in %s:%d\n%s\n", test_part_result.failed() ? "*** Failure" : "Success", test_part_result.file_name(), test_part_result.line_number(), test_part_result.summary()); } // Called after a test ends. void OnTestEnd(const testing::TestInfo& test_info) override { printf("*** Test %s.%s ending.\n", test_info.test_suite_name(), test_info.name()); } }; ``` -------------------------------- ### Set Example Files Directory Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/tng_io/src/tests/CMakeLists.txt Defines a preprocessor macro for the directory containing test files. ```cmake add_definitions(-DTNG_EXAMPLE_FILES_DIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/example_files/") ``` -------------------------------- ### Install gmxapi with CMake Hints Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Uses configuration settings to define the root path and provide a CMake cache file for build hints. ```shell pip install gmxapi \ --config-settings=cmake.define.gmxapi_ROOT=${UNIQUE_PREFIX} \ --config-settings=cmake.args=-C${UNIQUE_PREFIX}/share/cmake/gromacs${SUFFIX}/gromacs-hints${SUFFIX}.cmake ``` -------------------------------- ### Basic mdrun with MPI and OpenMP Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/user-guide/mdrun-performance.rst Starts mdrun with a specified number of MPI ranks and OpenMP threads per rank. Suitable for setups where CPU cores are evenly distributed across ranks for threading. ```bash mpirun -np 20 gmx_mpi mdrun -ntomp 4 -gputasks 00 ``` -------------------------------- ### Per-Test-Suite Setup and Teardown Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/advanced.md Demonstrates how to declare and define static members and SetUpTestSuite/TearDownTestSuite methods for sharing resources across tests in a fixture. Ensure proper cleanup in TearDownTestSuite to prevent memory leaks, especially with derived classes. ```C++ class FooTest : public testing::Test { protected: // Per-test-suite set-up. // Called before the first test in this test suite. // Can be omitted if not needed. static void SetUpTestSuite() { shared_resource_ = new ...; // If `shared_resource_` is **not deleted** in `TearDownTestSuite()`, // reallocation should be prevented because `SetUpTestSuite()` may be called // in subclasses of FooTest and lead to memory leak. // // if (shared_resource_ == nullptr) { // shared_resource_ = new ...; // } } // Per-test-suite tear-down. // Called after the last test in this test suite. // Can be omitted if not needed. static void TearDownTestSuite() { delete shared_resource_; shared_resource_ = nullptr; } // You can define per-test set-up logic as usual. void SetUp() override { ... } // You can define per-test tear-down logic as usual. void TearDown() override { ... } // Some expensive resource shared by all tests. static T* shared_resource_; }; T* FooTest::shared_resource_ = nullptr; TEST_F(FooTest, Test1) { ... you can refer to shared_resource_ here ... } TEST_F(FooTest, Test2) { ... you can refer to shared_resource_ here ... } ``` -------------------------------- ### mdrun with external MPI Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/user-guide/mdrun-performance.rst Starts mdrun compiled with an external MPI library, launching multiple ranks. The number of OpenMP threads per rank is determined by hardware and MPI setup. This is typically used for multi-node or advanced single-node MPI configurations. ```bash mpirun -np 2 gmx_mpi mdrun ``` -------------------------------- ### Install gmxapi Including Pre-release Versions Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Install the latest version of gmxapi, including any pre-release versions. Use --no-cache-dir to ensure a fresh build. ```bash # Get the latest version, including pre-release versions. pip install --no-cache-dir --pre gmxapi ``` -------------------------------- ### Install Gromacs Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/install-guide/index.rst Installs Gromacs to the directory specified by CMAKE_INSTALL_PREFIX. Super-user privileges may be required if installing to a system directory. ```bash make install ``` -------------------------------- ### Build Docker Image for Sample Restraint Source: https://gitlab.com/gromacs/gromacs/-/blob/main/python_packaging/sample_restraint/README.md Build a Docker image named 'samplerestraint' using the provided Dockerfile. This is an alternative to setting up MPI locally. ```bash docker build -t samplerestraint . Dockerfile ``` -------------------------------- ### Enable Install RPATH Source: https://gitlab.com/gromacs/gromacs/-/blob/main/python_packaging/sample_restraint/src/pythonmodule/CMakeLists.txt Configures the extension to link against an installed GROMACS and use the install RPATH for dynamic linking at runtime. ```cmake set_target_properties(gmxapi_extension PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) ``` ```cmake set_target_properties(gmxapi_extension PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) ``` -------------------------------- ### Install Public Header Directories Source: https://gitlab.com/gromacs/gromacs/-/blob/main/api/gmxapi/CMakeLists.txt Installs the public header directories for the gmxapi. This makes the API headers available to users after installation. ```cmake install(DIRECTORY include/gmxapi DESTINATION include) ``` -------------------------------- ### Install Package Config Files Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/googletest/CMakeLists.txt Installs the generated version and configuration files for the CMake package. These files are placed in the installation directory for CMake to find. ```cmake install(FILES ${version_file} ${config_file} COMPONENT "${PROJECT_NAME}" DESTINATION ${cmake_files_install_dir}) ``` -------------------------------- ### gMock Action Factory Example (Different Counters) Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/gmock_cook_book.md Demonstrates how an action factory creates distinct actions, leading to separate internal states when used repeatedly with different `EXPECT_CALL`s. ```cpp EXPECT_CALL(foo, DoThis()) .WillRepeatedly(IncrementCounter(0)); EXPECT_CALL(foo, DoThat()) .WillRepeatedly(IncrementCounter(0)); foo.DoThis(); // Returns 1. foo.DoThis(); // Returns 2. foo.DoThat(); // Returns 1 - DoThat() uses a different // counter than DoThis()'s. ``` -------------------------------- ### Create Project Directory Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/quickstart-cmake.md Use this command to create a new directory for your project and navigate into it. ```bash $ mkdir my_project && cd my_project ``` -------------------------------- ### Install Configured Resource Assignment Header Source: https://gitlab.com/gromacs/gromacs/-/blob/main/api/gmxapi/CMakeLists.txt Installs the configured resource assignment header file for MPI. This is necessary for the correct functioning of MPI-related features in the installed API. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/mpi/resourceassignment.h DESTINATION include/gmxapi/mpi) ``` -------------------------------- ### Install Configured API Version Header Source: https://gitlab.com/gromacs/gromacs/-/blob/main/api/gmxapi/CMakeLists.txt Installs the configured API version header file from the build tree. This ensures the installed API has the correct version information. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/version.h DESTINATION include/gmxapi) ``` -------------------------------- ### Specify Gromacs Installation Path for gmxapi Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst If gmxapi cannot find the Gromacs installation, you can specify its location using the 'gmxapi_ROOT' environment variable during installation. This is an alternative to sourcing the GMXRC file. ```bash gmxapi_ROOT=/path/to/gromacs pip install . ``` ```bash gmxapi_ROOT=/Users/eric/gromacs pip install --verbose gmxapi ``` -------------------------------- ### Initialize Hermetic Build Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/googlemock/CMakeLists.txt Includes and executes hermetic build setup functions if available. ```cmake # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) if (COMMAND pre_project_set_up_hermetic_build) # Google Test also calls hermetic setup functions from add_subdirectory, # although its changes will not affect things at the current scope. pre_project_set_up_hermetic_build() endif() ``` -------------------------------- ### Example Urea Topology File Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/reference-manual/topologies/topology-file-formats.rst A complete example of a .top file defining a urea molecule, including atoms, bonds, dihedrals, restraints, and system composition. ```text ; ; Example topology file ; ; The force-field files to be included #include "amber99.ff/forcefield.itp" [ moleculetype ] ; name nrexcl Urea 3 [ atoms ] 1 C 1 URE C 1 0.880229 12.01000 ; amber C type 2 O 1 URE O 2 -0.613359 16.00000 ; amber O type 3 N 1 URE N1 3 -0.923545 14.01000 ; amber N type 4 H 1 URE H11 4 0.395055 1.00800 ; amber H type 5 H 1 URE H12 5 0.395055 1.00800 ; amber H type 6 N 1 URE N2 6 -0.923545 14.01000 ; amber N type 7 H 1 URE H21 7 0.395055 1.00800 ; amber H type 8 H 1 URE H22 8 0.395055 1.00800 ; amber H type [ bonds ] 1 2 1 3 1 6 3 4 3 5 6 7 6 8 [ dihedrals ] ; ai aj ak al funct definition 2 1 3 4 9 2 1 3 5 9 2 1 6 7 9 2 1 6 8 9 3 1 6 7 9 3 1 6 8 9 6 1 3 4 9 6 1 3 5 9 [ dihedrals ] 3 6 1 2 4 1 4 3 5 4 1 7 6 8 4 [ position_restraints ] ; you wouldn't normally use this for a molecule like Urea, ; but we include it here for didactic purposes ; ai funct fc 1 1 1000 1000 1000 ; Restrain to a point 2 1 1000 0 1000 ; Restrain to a line (Y-axis) 3 1 1000 0 0 ; Restrain to a plane (Y-Z-plane) [ dihedral_restraints ] ; ai aj ak al type phi dphi fc 3 6 1 2 1 180 0 10 1 4 3 5 1 180 0 10 ; Include TIP3P water topology #include "amber99.ff/tip3p.itp" [ system ] Urea in Water [ molecules ] ;molecule name nr. Urea 1 SOL 1000 ``` -------------------------------- ### Install or Upgrade mpi4py Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Install or upgrade mpi4py, ensuring it is compatible with your MPI installation. Use MPICC to specify the MPI compiler if needed. The --no-cache-dir flag forces a rebuild. ```bash MPICC=`which mpicc` pip install --no-cache-dir --upgrade mpi4py ``` -------------------------------- ### Install Google Test Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/googletest/CMakeLists.txt Installs the gtest and gtest_main targets as part of the project. ```cmake install_project(gtest gtest_main) ``` -------------------------------- ### Initialize Lambda Weights Source: https://gitlab.com/gromacs/gromacs/-/blob/main/share/README_FreeEnergyModifications.txt Example of loading initial weights for lambda states, where the first entry is typically 0.00. ```text init-lambda-weights = 0.00 0.54 1.45 3.45 6.78 ``` -------------------------------- ### Install Latest gmxapi from PyPI Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/gmxapi/userguide/install.rst Fetch and install the latest official release of gmxapi from the Python Packaging Index. Use --no-cache-dir to avoid using potentially incompatible cached wheel packages. ```bash # Get the latest official release. pip install --no-cache-dir gmxapi ``` -------------------------------- ### EXPECT_CALL with Return Actions Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/gmock_for_dummies.md This example demonstrates setting expectations on the turtle's GetX() method, specifying it will be called five times with specific return values for the first two calls and a repeated value for subsequent calls. ```cpp using ::testing::Return; ... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) .WillOnce(Return(150)) .WillRepeatedly(Return(200)); ``` -------------------------------- ### Check Pytest Installation and Version Source: https://gitlab.com/gromacs/gromacs/-/blob/main/python_packaging/sample_restraint/tests/CMakeGROMACS.txt Verifies if pytest is installed and meets the minimum version requirement (>= 3.0). If not found or an older version is detected, it prints a fatal error message with installation instructions. ```cmake if(NOT GMXAPI_PYTEST_FOUND) execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pytest; print(pytest.__version__)" RESULT_VARIABLE pytest_not_found OUTPUT_VARIABLE pytest_version ERROR_QUIET) if(pytest_not_found) message(FATAL_ERROR "Running the tests requires pytest. Please install it manually" " (try: ${PYTHON_EXECUTABLE} -m pip install pytest)") elseif(pytest_version VERSION_LESS 3.0) message(FATAL_ERROR "Running the tests requires pytest >= 3.0. Found: ${pytest_version}" "Please update it (try: ${PYTHON_EXECUTABLE} -m pip install -U pytest)") endif() set(GMXAPI_PYTEST_FOUND TRUE CACHE INTERNAL "Suppress checking for Python pytest module.") endif() ``` -------------------------------- ### Build and Run Tests with CMake Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/docs/quickstart-cmake.md These commands demonstrate how to configure the build using CMake, build the project, and then run the discovered tests using ctest from the build directory. ```bash my_project$ cmake -S . -B build -- Build files have been written to: .../my_project/build my_project$ cmake --build build Scanning dependencies of target gtest ... (build output) [100%] Built target gmock_main my_project$ cd build && ctest Test project .../my_project/build Start 1: HelloTest.BasicAssertions 1/1 Test #1: HelloTest.BasicAssertions ........ Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 0.01 sec ``` -------------------------------- ### Build and Install GROMACS Plugin Source: https://gitlab.com/gromacs/gromacs/-/blob/main/python_packaging/sample_restraint/README.md Build the GROMACS plugin using make, run C++ tests, and optionally install the plugin. The PYTHONPATH environment variable can be set to locate the plugin if not installed. ```bash make # build and run C++ tests make tests make test # optionally, install make install ``` ```bash export PYTHONPATH=`pwd`/src/pythonmodule ``` -------------------------------- ### Import gmxapi and sample_restraint modules Source: https://gitlab.com/gromacs/gromacs/-/blob/main/python_packaging/sample_restraint/examples/example.ipynb Import the necessary gmxapi and sample_restraint modules. Ensure these modules are built and installed. ```python # module built and installed with https://github.com/kassonlab/gmxapi import gmx # module built and installed with https://github.com/kassonlab/sample_restraint import myplugin ``` -------------------------------- ### Build and run tests Source: https://gitlab.com/gromacs/gromacs/-/blob/main/src/external/googletest/CONTRIBUTING.md Standard commands to compile and execute the test suite on *nix systems. ```bash make ``` ```bash make test ``` -------------------------------- ### GROMACS Orientation Restraints Section Example Source: https://gitlab.com/gromacs/gromacs/-/blob/main/docs/reference-manual/functions/restraints.rst Example of how to define orientation restraints in a GROMACS topology file within the [ orientation_restraints ] section. This example shows five N-H residual dipolar coupling restraints. ```ini [ orientation_restraints ] ```