From 0b2f9a9fee7f390f30fc01fc78a5104ee4f478d3 Mon Sep 17 00:00:00 2001 From: "M. Eric Irrgang" Date: Wed, 6 Jun 2018 17:54:50 +0300 Subject: [PATCH] gmxapi-30 Tutorial / working Jupyter notebook examples Fix typos and bugs so the testing instructions in Dockerfile are true. Build restraints as static libraries with position independent code to make the myplugin.so object more portable. --- CMakeLists.txt | 2 +- Dockerfile | 2 +- src/cpp/CMakeLists.txt | 6 ++++-- src/cpp/ensemblepotential.cpp | 28 ++++++++++++++++++++++++++++ src/cpp/ensemblepotential.h | 18 +----------------- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4f23e9..633c3d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ endif() # At some point this may be part of a CMake package with several components for which a single CMAKE_INSTALL_PREFIX does # not make sense, so let's manage the install path separately. -set(GMXPLUGIN_INSTALL_PATH ${GMXPLUGIN_DEFAULT_SITE_PACKAGES}/gmx CACHE PATH +set(GMXPLUGIN_INSTALL_PATH ${GMXPLUGIN_DEFAULT_SITE_PACKAGES} CACHE PATH "Path to Python module install location (site-packages). For an automatically determined install location based on \ the Python installation, leave undefined or explicitly undefined with -UGMXPLUGIN_INSTALL_PATH and, optionally, set \ GMXPLUGIN_USER_INSTALL on or off to specify the installation's site-packages directory or the 'user' site-packages \ diff --git a/Dockerfile b/Dockerfile index 6c0ef81..1e564ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ # docker run -ti --name restraint_test sample_restraint # # Test with -# docker run --cpus 2 --rm -ti gmxapi/sample_restraint:devel bash -c "cd /home/jovyan/samplerestraint/tests && mpiexec -n 2 python -m mpi4py -m pytest" +# docker run --cpus 2 --rm -ti gmxapi/sample_restraint:devel bash -c "cd /home/jovyan/sample_restraint/tests && mpiexec -n 2 python -m mpi4py -m pytest" # or replace `gmxapi/sample_restraint:devel` with your local image name diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index d400bd0..6cce157 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -2,9 +2,10 @@ # unit tests and by the Python module target defined in ../pythonmodule/CMakeLists.txt # Create a shared object library for a simple restraint. -add_library(harmonicpotential SHARED +add_library(harmonicpotential STATIC harmonicpotential.h harmonicpotential.cpp) +set_target_properties(harmonicpotential PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(harmonicpotential PUBLIC $ @@ -23,9 +24,10 @@ target_link_libraries(harmonicpotential PRIVATE Gromacs::gmxapi) # Create a shared object library for our restrained ensemble plugin. -add_library(ensemblepotential SHARED +add_library(ensemblepotential STATIC ensemblepotential.h ensemblepotential.cpp) +set_target_properties(ensemblepotential PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(ensemblepotential PUBLIC $ diff --git a/src/cpp/ensemblepotential.cpp b/src/cpp/ensemblepotential.cpp index 33e555a..680344d 100644 --- a/src/cpp/ensemblepotential.cpp +++ b/src/cpp/ensemblepotential.cpp @@ -322,6 +322,34 @@ gmx::PotentialPointData EnsembleHarmonic::calculate(gmx::Vector v, return output; } +std::unique_ptr +makeEnsembleParams(size_t nbins, + double binWidth, + double minDist, + double maxDist, + const std::vector &experimental, + unsigned int nSamples, + double samplePeriod, + unsigned int nWindows, + double k, + double sigma) +{ + using gmx::compat::make_unique; + auto params = make_unique(); + params->nBins = nbins; + params->binWidth = binWidth; + params->minDist = minDist; + params->maxDist = maxDist; + params->experimental = experimental; + params->nSamples = nSamples; + params->samplePeriod = samplePeriod; + params->nWindows = nWindows; + params->k = k; + params->sigma = sigma; + + return params; +}; + EnsembleResourceHandle EnsembleResources::getHandle() const { auto handle = EnsembleResourceHandle(); diff --git a/src/cpp/ensemblepotential.h b/src/cpp/ensemblepotential.h index 86107bb..8f84f22 100644 --- a/src/cpp/ensemblepotential.h +++ b/src/cpp/ensemblepotential.h @@ -281,23 +281,7 @@ makeEnsembleParams(size_t nbins, double samplePeriod, unsigned int nWindows, double k, - double sigma) -{ - using gmx::compat::make_unique; - auto params = make_unique(); - params->nBins = nbins; - params->binWidth = binWidth; - params->minDist = minDist; - params->maxDist = maxDist; - params->experimental = experimental; - params->nSamples = nSamples; - params->samplePeriod = samplePeriod; - params->nWindows = nWindows; - params->k = k; - params->sigma = sigma; - - return params; -}; + double sigma); /*! * \brief a residue-pair bias calculator for use in restrained-ensemble simulations.