From da6bce8d41ad7b8adcbac653bb7dca92ad46f1d4 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Sat, 3 Jun 2023 03:05:16 +0200 Subject: [PATCH] [boinc-autodock-vina] Simplify onfiguration by removing ambiguous vinardo configuration fields Signed-off-by: Vitalii Koshura --- boinc-autodock-vina/README.md | 10 +-- .../src/boinc-autodock-vina/calculate.cpp | 6 +- boinc-autodock-vina/src/common/config.cpp | 84 ++++++++++--------- boinc-autodock-vina/src/common/config.h | 5 -- .../src/unit-tests/config-tests.cpp | 82 +++++++++++++----- 5 files changed, 114 insertions(+), 73 deletions(-) diff --git a/boinc-autodock-vina/README.md b/boinc-autodock-vina/README.md index 914ee9a..d4cc298 100644 --- a/boinc-autodock-vina/README.md +++ b/boinc-autodock-vina/README.md @@ -43,11 +43,11 @@ This file supports next parameters: `vinardo` scoring function specific parameters. -- `weight_vinardo_gauss1` - gauss_1 weight. This is an **optional** `double` parameter. Default value is `-0.045`. -- `weight_vinardo_repulsion` - repulsion weight. This is an **optional** `double` parameter. Default value is `0.8`. -- `weight_vinardo_hydrophobic` - hydrophobic weight. This is an **optional** `double` parameter. Default value is `-0.035`. -- `weight_vinardo_hydrogen` - Hydrogen bond weight. This is an **optional** `double` parameter. Default value is `0.600`. -- `weight_vinardo_rot` - N_rot weight. This is an **optional** `double` parameter. Default value is `0.05846`. +- `weight_gauss1` - gauss_1 weight. This is an **optional** `double` parameter. Default value is `-0.045`. +- `weight_repulsion` - repulsion weight. This is an **optional** `double` parameter. Default value is `0.8`. +- `weight_hydrophobic` - hydrophobic weight. This is an **optional** `double` parameter. Default value is `-0.035`. +- `weight_hydrogen` - Hydrogen bond weight. This is an **optional** `double` parameter. Default value is `0.600`. +- `weight_rot` - N_rot weight. This is an **optional** `double` parameter. Default value is `0.05846`. `ad4` scoring function specific parameters. diff --git a/boinc-autodock-vina/src/boinc-autodock-vina/calculate.cpp b/boinc-autodock-vina/src/boinc-autodock-vina/calculate.cpp index 8842db3..f6d6233 100644 --- a/boinc-autodock-vina/src/boinc-autodock-vina/calculate.cpp +++ b/boinc-autodock-vina/src/boinc-autodock-vina/calculate.cpp @@ -37,9 +37,9 @@ bool calculator::calculate(const config& config, const int& ncpus, const std::fu config.weight_glue, config.weight_rot); } else if (config.scoring == scoring::vinardo) { - vina.set_vinardo_weights(config.weight_vinardo_gauss1, config.weight_vinardo_repulsion, - config.weight_vinardo_hydrophobic, config.weight_vinardo_hydrogen, - config.weight_glue, config.weight_vinardo_rot); + vina.set_vinardo_weights(config.weight_gauss1, config.weight_repulsion, + config.weight_hydrophobic, config.weight_hydrogen, + config.weight_glue, config.weight_rot); } else if (config.scoring == scoring::ad4) { vina.set_ad4_weights(config.weight_ad4_vdw, config.weight_ad4_hb, diff --git a/boinc-autodock-vina/src/common/config.cpp b/boinc-autodock-vina/src/common/config.cpp index 9ab818c..a8be415 100644 --- a/boinc-autodock-vina/src/common/config.cpp +++ b/boinc-autodock-vina/src/common/config.cpp @@ -254,36 +254,65 @@ bool config::load(const jsoncons::basic_json& json, const std::filesystem: if (json.contains("weight_gauss1")) { weight_gauss1 = json["weight_gauss1"].as(); } + else + { + if (scoring == scoring::vina) + { + weight_gauss1 = -0.035579; + } + else if (scoring == scoring::vinardo) + { + weight_gauss1 = -0.045; + } + } if (json.contains("weight_gauss2")) { weight_gauss2 = json["weight_gauss2"].as(); } if (json.contains("weight_repulsion")) { weight_repulsion = json["weight_repulsion"].as(); } + else + { + if (scoring == scoring::vina) + { + weight_repulsion = 0.840245; + } + else if (scoring == scoring::vinardo) + { + weight_repulsion = 0.8; + } + } if (json.contains("weight_hydrophobic")) { weight_hydrophobic = json["weight_hydrophobic"].as(); } + else + { + if (scoring == scoring::vina) + { + weight_hydrophobic = -0.035069; + } + else if (scoring == scoring::vinardo) + { + weight_hydrophobic = -0.035; + } + } if (json.contains("weight_hydrogen")) { weight_hydrogen = json["weight_hydrogen"].as(); } + else + { + if (scoring == scoring::vina) + { + weight_hydrogen = -0.587439; + } + else if (scoring == scoring::vinardo) + { + weight_hydrogen = 0.600; + } + } if (json.contains("weight_rot")) { weight_rot = json["weight_rot"].as(); } - if (json.contains("weight_vinardo_gauss1")) { - weight_vinardo_gauss1 = json["weight_vinardo_gauss1"].as(); - } - if (json.contains("weight_vinardo_repulsion")) { - weight_vinardo_repulsion = json["weight_vinardo_repulsion"].as(); - } - if (json.contains("weight_vinardo_hydrophobic")) { - weight_vinardo_hydrophobic = json["weight_vinardo_hydrophobic"].as(); - } - if (json.contains("weight_vinardo_hydrogen")) { - weight_vinardo_hydrogen = json["weight_vinardo_hydrogen"].as(); - } - if (json.contains("weight_vinardo_rot")) { - weight_vinardo_rot = json["weight_vinardo_rot"].as(); - } if (json.contains("weight_ad4_vdw")) { weight_ad4_vdw = json["weight_ad4_vdw"].as(); } @@ -512,31 +541,6 @@ bool config::save(const std::filesystem::path& config_file_path) const { return false; } - if (!json.value("weight_vinardo_gauss1", weight_vinardo_gauss1)) { - error_message("weight_vinardo_gauss1"); - return false; - } - - if (!json.value("weight_vinardo_repulsion", weight_vinardo_repulsion)) { - error_message("weight_vinardo_repulsion"); - return false; - } - - if (!json.value("weight_vinardo_hydrophobic", weight_vinardo_hydrophobic)) { - error_message("weight_vinardo_hydrophobic"); - return false; - } - - if (!json.value("weight_vinardo_hydrogen", weight_vinardo_hydrogen)) { - error_message("weight_vinardo_hydrogen"); - return false; - } - - if (!json.value("weight_vinardo_rot", weight_vinardo_rot)) { - error_message("weight_vinardo_rot"); - return false; - } - if (!json.value("weight_ad4_vdw", weight_ad4_vdw)) { error_message("weight_ad4_vdw"); return false; diff --git a/boinc-autodock-vina/src/common/config.h b/boinc-autodock-vina/src/common/config.h index 3ff61ab..445047a 100644 --- a/boinc-autodock-vina/src/common/config.h +++ b/boinc-autodock-vina/src/common/config.h @@ -57,11 +57,6 @@ class config { double weight_hydrophobic = -0.035069; double weight_hydrogen = -0.587439; double weight_rot = 0.05846; - double weight_vinardo_gauss1 = -0.045; - double weight_vinardo_repulsion = 0.8; - double weight_vinardo_hydrophobic = -0.035; - double weight_vinardo_hydrogen = 0.600; - double weight_vinardo_rot = 0.05846; double weight_ad4_vdw = 0.1662; double weight_ad4_hb = 0.1209; double weight_ad4_elec = 0.1406; diff --git a/boinc-autodock-vina/src/unit-tests/config-tests.cpp b/boinc-autodock-vina/src/unit-tests/config-tests.cpp index 56b7a87..7896c66 100644 --- a/boinc-autodock-vina/src/unit-tests/config-tests.cpp +++ b/boinc-autodock-vina/src/unit-tests/config-tests.cpp @@ -308,6 +308,68 @@ TEST_F(Config_UnitTests, FailOnAbsolutePathInConfig_WriteMaps) { EXPECT_FALSE(config.load(dummy_json_file_path)); } +TEST_F(Config_UnitTests, CheckForDefaultValues_Vina) +{ + const auto& dummy_json_file_path = std::filesystem::current_path() / "dummy.json"; + config config; + + dummy_ofstream json; + json.open(dummy_json_file_path); + + jsoncons::json_stream_encoder jsoncons_encoder(json()); + const json_encoder_helper json_encoder(jsoncons_encoder); + + json_encoder.begin_object(); + json_encoder.value("receptor", "receptor_sample"); + json_encoder.begin_array("ligands"); + json_encoder.value("ligand_sample2"); + json_encoder.end_array(); + json_encoder.end_object(); + + jsoncons_encoder.flush(); + json.close(); + ASSERT_TRUE(config.load(dummy_json_file_path)); + + EXPECT_EQ(scoring::vina, config.scoring); + EXPECT_DOUBLE_EQ(-0.035579, config.weight_gauss1); + EXPECT_DOUBLE_EQ(-0.005156, config.weight_gauss2); + EXPECT_DOUBLE_EQ(0.840245, config.weight_repulsion); + EXPECT_DOUBLE_EQ(-0.035069, config.weight_hydrophobic); + EXPECT_DOUBLE_EQ(-0.587439, config.weight_hydrogen); + EXPECT_DOUBLE_EQ(0.05846, config.weight_rot); +} + +TEST_F(Config_UnitTests, CheckForDefaultValues_Vinardo) +{ + const auto& dummy_json_file_path = std::filesystem::current_path() / "dummy.json"; + config config; + + dummy_ofstream json; + json.open(dummy_json_file_path); + + jsoncons::json_stream_encoder jsoncons_encoder(json()); + const json_encoder_helper json_encoder(jsoncons_encoder); + + json_encoder.begin_object(); + json_encoder.value("scoring", std::string(magic_enum::enum_name(scoring::vinardo))); + json_encoder.value("receptor", "receptor_sample"); + json_encoder.begin_array("ligands"); + json_encoder.value("ligand_sample2"); + json_encoder.end_array(); + json_encoder.end_object(); + + jsoncons_encoder.flush(); + json.close(); + ASSERT_TRUE(config.load(dummy_json_file_path)); + + EXPECT_EQ(scoring::vinardo, config.scoring); + EXPECT_DOUBLE_EQ(-0.045, config.weight_gauss1); + EXPECT_DOUBLE_EQ(0.8, config.weight_repulsion); + EXPECT_DOUBLE_EQ(-0.035, config.weight_hydrophobic); + EXPECT_DOUBLE_EQ(0.600, config.weight_hydrogen); + EXPECT_DOUBLE_EQ(0.05846, config.weight_rot); +} + TEST_F(Config_UnitTests, CheckForDeaultValueInConfig_Out) { const auto& dummy_json_file_path = std::filesystem::current_path() / "dummy.json"; config config; @@ -372,11 +434,6 @@ TEST_F(Config_UnitTests, LoadValidator) { json_encoder.value("weight_hydrophobic", -0.654321); json_encoder.value("weight_hydrogen", 0.135246); json_encoder.value("weight_rot", -0.135246); - json_encoder.value("weight_vinardo_gauss1", -0.642531); - json_encoder.value("weight_vinardo_repulsion", 0.642531); - json_encoder.value("weight_vinardo_hydrophobic", -0.010011); - json_encoder.value("weight_vinardo_hydrogen", 0.010011); - json_encoder.value("weight_vinardo_rot", -1.023456); json_encoder.value("weight_ad4_vdw", 1.023456); json_encoder.value("weight_ad4_hb", -1.654320); json_encoder.value("weight_ad4_elec", 1.065432); @@ -437,11 +494,6 @@ TEST_F(Config_UnitTests, LoadValidator) { EXPECT_DOUBLE_EQ(-0.654321, config.weight_hydrophobic); EXPECT_DOUBLE_EQ(0.135246, config.weight_hydrogen); EXPECT_DOUBLE_EQ(-0.135246, config.weight_rot); - EXPECT_DOUBLE_EQ(-0.642531, config.weight_vinardo_gauss1); - EXPECT_DOUBLE_EQ(0.642531, config.weight_vinardo_repulsion); - EXPECT_DOUBLE_EQ(-0.010011, config.weight_vinardo_hydrophobic); - EXPECT_DOUBLE_EQ(0.010011, config.weight_vinardo_hydrogen); - EXPECT_DOUBLE_EQ(-1.023456, config.weight_vinardo_rot); EXPECT_DOUBLE_EQ(1.023456, config.weight_ad4_vdw); EXPECT_DOUBLE_EQ(-1.654320, config.weight_ad4_hb); EXPECT_DOUBLE_EQ(1.065432, config.weight_ad4_elec); @@ -753,11 +805,6 @@ TEST_F(Config_UnitTests, TestConfigsEqualAfterReadWrite) { json_encoder.value("weight_hydrophobic", -0.654321); json_encoder.value("weight_hydrogen", 0.135246); json_encoder.value("weight_rot", -0.135246); - json_encoder.value("weight_vinardo_gauss1", -0.642531); - json_encoder.value("weight_vinardo_repulsion", 0.642531); - json_encoder.value("weight_vinardo_hydrophobic", -0.010011); - json_encoder.value("weight_vinardo_hydrogen", 0.010011); - json_encoder.value("weight_vinardo_rot", -1.023456); json_encoder.value("weight_ad4_vdw", 1.023456); json_encoder.value("weight_ad4_hb", -1.654320); json_encoder.value("weight_ad4_elec", 1.065432); @@ -813,11 +860,6 @@ TEST_F(Config_UnitTests, TestConfigsEqualAfterReadWrite) { EXPECT_DOUBLE_EQ(config.weight_hydrophobic, config_copy.weight_hydrophobic); EXPECT_DOUBLE_EQ(config.weight_hydrogen, config_copy.weight_hydrogen); EXPECT_DOUBLE_EQ(config.weight_rot, config_copy.weight_rot); - EXPECT_DOUBLE_EQ(config.weight_vinardo_gauss1, config_copy.weight_vinardo_gauss1); - EXPECT_DOUBLE_EQ(config.weight_vinardo_repulsion, config_copy.weight_vinardo_repulsion); - EXPECT_DOUBLE_EQ(config.weight_vinardo_hydrophobic, config_copy.weight_vinardo_hydrophobic); - EXPECT_DOUBLE_EQ(config.weight_vinardo_hydrogen, config_copy.weight_vinardo_hydrogen); - EXPECT_DOUBLE_EQ(config.weight_vinardo_rot, config_copy.weight_vinardo_rot); EXPECT_DOUBLE_EQ(config.weight_ad4_vdw, config_copy.weight_ad4_vdw); EXPECT_DOUBLE_EQ(config.weight_ad4_hb, config_copy.weight_ad4_hb); EXPECT_DOUBLE_EQ(config.weight_ad4_elec, config_copy.weight_ad4_elec);