Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
Add unit test case (#40)
Browse files Browse the repository at this point in the history
* Add Catch2 unit test

* Fix unit test

* Add git support in Dockerfile

* Add git in CI basic packages

* Fix file path in parse_pdqt_test.cpp

* Update CMakeLists.txt to link unit_tests with lib and cuda
  • Loading branch information
ysyecust authored Feb 29, 2024
1 parent 1bec259 commit 862b802
Show file tree
Hide file tree
Showing 8 changed files with 1,654 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_test_unidock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: install basic packages
run: |
apt-get update
apt-get install -y build-essential cmake libboost-all-dev ninja-build
apt-get install -y build-essential cmake libboost-all-dev ninja-build git
- if: ${{ env.ACT }}
name: Hack container for local development
Expand Down
19 changes: 18 additions & 1 deletion unidock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ add_compile_definitions(VERSION="v${PROJECT_VERSION}")
find_package(OpenMP REQUIRED) # OpenMP only required in main.cpp
find_package(Boost 1.72 REQUIRED
COMPONENTS system thread serialization filesystem program_options timer)
Include(FetchContent)

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0 # or a later release
)

FetchContent_MakeAvailable(Catch2)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(src/lib src/cuda)
add_executable(${VINA_BIN_NAME} src/main/main.cpp)
Expand All @@ -55,11 +64,19 @@ add_library(lib OBJECT
src/lib/ad4cache.cpp src/lib/cache.cpp src/lib/non_cache.cpp src/lib/conf_independent.cpp src/lib/coords.cpp src/lib/grid.cpp src/lib/szv_grid.cpp src/lib/model.cpp src/lib/mutate.cpp src/lib/parallel_mc.cpp src/lib/parse_pdbqt.cpp src/lib/quasi_newton.cpp src/lib/quaternion.cpp src/lib/random.cpp src/lib/utils.cpp src/lib/vina.cpp src/lib/precalculate.h)
# src/lib/monte_carlo
# set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cuda)
include_directories(${CMAKE_SOURCE_DIR}/unittest)
file(GLOB_RECURSE TEST_SOURCES ${CMAKE_SOURCE_DIR}/unittest/*.cpp ${CMAKE_SOURCE_DIR}/unittest/*.hpp)
add_executable(unit_tests ${TEST_SOURCES})


add_library(cuda OBJECT src/lib/monte_carlo.h src/cuda/monte_carlo.cu src/cuda/precalculate.cu)
target_link_libraries(${VINA_BIN_NAME} cuda lib)
target_include_directories(${VINA_BIN_NAME} PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) # For detecting CUDA memory size
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${VINA_BIN_NAME} TYPE BIN)

target_link_libraries(unit_tests Boost::system Boost::thread Boost::serialization Boost::filesystem Boost::program_options Boost::timer)
target_link_libraries(unit_tests OpenMP::OpenMP_CXX)
target_link_libraries(unit_tests lib cuda)
target_link_libraries(unit_tests Catch2::Catch2WithMain)
file(GLOB_RECURSE sources CONFIGURE_DEPENDS src/*.cpp src/*.h src/*.cu)
set(CLANG_FORMAT clang-format)

Expand Down
2 changes: 1 addition & 1 deletion unidock/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG CUDA_VERSION=12.0.0
FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04

RUN apt-get update && apt install -y cmake \
libboost-system-dev libboost-thread-dev libboost-serialization-dev libboost-filesystem-dev libboost-program-options-dev libboost-timer-dev
libboost-system-dev libboost-thread-dev libboost-serialization-dev libboost-filesystem-dev libboost-program-options-dev libboost-timer-dev git

COPY . /opt/unidock

Expand Down
4 changes: 1 addition & 3 deletions unidock/src/lib/parse_pdbqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ struct movable_atom : public atom {
}
};

struct rigid {
atomv atoms;
};


typedef std::vector<movable_atom> mav;

Expand Down
6 changes: 5 additions & 1 deletion unidock/src/lib/parse_pdbqt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include <string>
#include "model.h"
#include <set>

struct rigid {
atomv atoms;
};
model parse_receptor_pdbqt(const std::string &rigid = std::string(),
const std::string &flex = std::string(),
atom_type::t atype = atom_type::XS); // can throw struct_parse_error
Expand All @@ -47,4 +49,6 @@ model parse_ligand_pdbqt_from_string(const std::string &string_name,
atom_type::t atype); // can exit with code EXIT_FAILURE
model parse_ligand_pdbqt_from_string_no_failure(
const std::string &string_name, atom_type::t atype); // can return empty model as failure
void parse_pdbqt_rigid(const path& name, rigid& r);

#endif
2 changes: 1 addition & 1 deletion unidock/src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int predict_peak_memory(int batch_size, int exhaustiveness, int all_atom2_number
// states
gpu_memory
+= (int64_t)(1) * batch_size * exhaustiveness * 64; // sizeof(curandStatePhilox4_32_10_t)

return gpu_memory / (1024 * 1024);
}

Expand Down
1,614 changes: 1,614 additions & 0 deletions unidock/unittest/ParseTests/def.pdbqt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions unidock/unittest/ParseTests/parse_pdqt_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <catch2/catch_test_macros.hpp>
#include "parse_pdbqt.h"
#include "atom.h"


TEST_CASE("parse pdbqt rigid", "[parse_pdbqt_rigid]") {
// Test pdbqt atom number
std::string valid_pdbqt_receptor_path = "../unittest/ParseTests/def.pdbqt";
rigid r;
REQUIRE_NOTHROW(parse_pdbqt_rigid(valid_pdbqt_receptor_path, r));
REQUIRE(r.atoms.size() == 1613);

}

0 comments on commit 862b802

Please sign in to comment.