Skip to content

Commit

Permalink
Add mmcif tests to api
Browse files Browse the repository at this point in the history
Currently just one stub of a test - but the point of this commit
was to make something that can be build as a stand-alone executable
and as a chapi function.
  • Loading branch information
pemsley committed Sep 26, 2024
1 parent 95398f8 commit cbcbe2f
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ add_library(cootapi SHARED
${coot_src}/api/molecules-container-superpose.cc
${coot_src}/api/molecules-container-modelling.cc
${coot_src}/api/molecules-container-ligand-fitting.cc
${coot_src}/api/mmcif-tests.cc
${coot_src}/api/phi-psi-prob.cc
${coot_src}/api/moorhen-h-bonds.cc
${coot_src}/api/add-terminal-residue.cc
Expand Down Expand Up @@ -482,6 +483,8 @@ add_executable(res-tracer-libcootapi ${coot_src}/ligand/res-tracer.cc)

add_executable(test-molecules-container ${coot_src}/api/test-molecules-container.cc ${coot_src}/api/filo-tests.cc ${coot_src}/api/lucrezia-tests.cc)

add_executable(mmcif-tests ${coot_src}/api/mmcif-tests-main.cc)

target_compile_features(coot-mini-rsr PRIVATE cxx_std_17)

target_compile_features(res-tracer-libcootapi PRIVATE cxx_std_17)
Expand All @@ -508,6 +511,10 @@ target_include_directories(test-molecules-container PRIVATE ${coot_src} ${coot_s

target_link_libraries(test-molecules-container PUBLIC cootapi ${SSM_LIBRARY} ${CLIPPER-MINIMOL_LIBRARY} ${CLIPPER-MMDB_LIBRARY} ${CLIPPER-CIF_LIBRARY} ${CLIPPER-CORE_LIBRARY} ${CLIPPER-CCP4_LIBRARY} ${CLIPPER-CONTRIB_LIBRARY} ${FFTW2_LIBRARY} ${RFFTW2_LIBRARY} ${MMDB2_LIBRARY} ${CCP4C_LIBRARY} ${ZLIB_LIBRARIES} ${GSL_LIBRARIES} ${RDKit_libs_for_libcootapi} ${PNG_LIBRARY} gemmi::gemmi_cpp ${libdwarf} ${libelf} Threads::Threads)

target_include_directories(mmcif-tests PRIVATE ${MMDB2_INCLUDE_DIR}/include)

target_link_libraries(mmcif-tests PUBLIC cootapi ${MMDB2_LIBRARY})

set_target_properties(cootapi PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

set_target_properties(cootapi PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
Expand Down
14 changes: 14 additions & 0 deletions api/mmcif-tests-main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <string>
#include <iostream>

namespace mmcif_tests {
int run_tests(bool last_test_only);
}

int main(int argc, char **argv) {

std::cout << "------------- main() --- start ---" << std::endl;
int status = 0;
std::cout << "------------- main() --- end ---" << std::endl;
return status;
}
91 changes: 91 additions & 0 deletions api/mmcif-tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

#include "mmdb2/mmdb_defs.h"
#include "mmdb2/mmdb_model.h"
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>

#include <mmdb2/mmdb_manager.h>

int n_tests = 0;
static std::vector<std::pair<std::string, int> > test_results;

namespace mmcif_tests {

void write_test_name(const std::string &test_name);
int run_test(int (*test_func) (), const std::string &test_name);
int run_tests(bool last_test_only);
int read_pdb();
enum status_t { BAD, GOOD };
}

void
mmcif_tests::write_test_name(const std::string &test_name) {

std::ofstream f(".current-test");
f << "\"" << test_name << "\"" << "\n";
f.close();
}

int
mmcif_tests::run_test(int (*test_func) (), const std::string &test_name) {

n_tests++;
write_test_name(test_name);
int status = test_func();
std::string status_string = "FAIL: ";
std::string uncol = "";
std::string col = "";
if (status == 1) {
status_string = "PASS: ";
col = "";
}
std::cout << status_string << std::setw(40) << std::left << test_name << col << "" << uncol << std::endl;
test_results.push_back(std::make_pair(test_name, status));

return status;
}

int mmcif_tests::read_pdb() {

int status = 0;
mmdb::Manager *mol = new mmdb::Manager;
// 6DGD for DNA bases
// https://files.rcsb.org/download/6GDG.cif
mmdb::ERROR_CODE read_status = mol->ReadCoorFile("6gdg.cif");
std::cout << "TEST read_pdb() with read_status " << read_status << std::endl;
if (read_status == mmdb::Error_NoError) {
for (int imod = 1; imod <= mol->GetNumberOfModels(); imod++) {
mmdb::Model *model_p = mol->GetModel(imod);
if (model_p) {
int n_links = model_p->GetNumberOfLinks();
std::cout << "n_links: " << n_links << std::endl;
for (int i_link = 0; i_link < n_links; i_link++) {
mmdb::Link *link_p = model_p->GetLink(i_link);
std::cout << "Link " << i_link << " " << link_p << std::endl;
}
}
}
}
return status;
};

// return "all pass" status (1 for true)
int
mmcif_tests::run_tests(bool last_test_only) {

std::cout << "--------------- run_tests() --- start --- " << std::endl;
if (! last_test_only) {
run_test(read_pdb, "read_pdb");
}
int status = 1;
for (const auto &t : test_results) {
if (t.second != 1)
status = 0;
}
std::cout << "--------------- run_tests() --- end --- " << std::endl;
return status;
}

1 change: 1 addition & 0 deletions api/molecules-container-nanobind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ NB_MODULE(chapi, m) {
.def("make_power_scaled_map", &molecules_container_t::make_power_scaled_map)
.def("merge_molecules", nb::overload_cast<int,const std::string &>(&molecules_container_t::merge_molecules))
.def("minimize_energy",&molecules_container_t::minimize_energy)
.def("mmcif_tests",&molecules_container_t::mmcif_tests)
.def("mmrrcc",&molecules_container_t::mmrrcc)
.def("move_molecule_to_new_centre",&molecules_container_t::move_molecule_to_new_centre)
.def("multiply_residue_temperature_factors",&molecules_container_t::multiply_residue_temperature_factors)
Expand Down
14 changes: 14 additions & 0 deletions api/molecules-container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5367,6 +5367,20 @@ molecules_container_t::test_thread_pool_threads(unsigned int n_threads) {

}

namespace mmcif_tests {
int run_tests(bool last_test_only);
}

//! a test for mmdb/gemmi/mmcif functionality
int
molecules_container_t::mmcif_tests(bool last_test_only) {

int status = mmcif_tests::run_tests(last_test_only);
return status;

}



//! @return a vector of string pairs that were part of a gphl_chem_comp_info.
//! return an empty vector on failure to find any such info.
Expand Down
9 changes: 9 additions & 0 deletions api/molecules-container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,15 @@ public:
//! @return time in microsections
double test_thread_pool_threads(unsigned int n_threads);

//! a test for mmdb/gemmi/mmcif functionality
//
//! @param last_test_only is `true` to mean that only that last test should be run.
//! The default is `false`.
//! This is useful to set to `true` while a test is being developed.
//!
//! @return the success status: 1 means that all the tests passed.
int mmcif_tests(bool last_test_only);

// get acces to protein geometry
coot::protein_geometry & get_geometry() {
return geom;
Expand Down

0 comments on commit cbcbe2f

Please sign in to comment.