Skip to content

Commit

Permalink
Merge pull request #83 from BOINC/vko_simplify_config
Browse files Browse the repository at this point in the history
[boinc-autodock-vina] Simplify configuration by removing ambiguous vinardo configuration fields
  • Loading branch information
AenBleidd authored Jun 3, 2023
2 parents 06559c4 + da6bce8 commit 445589e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 73 deletions.
10 changes: 5 additions & 5 deletions boinc-autodock-vina/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions boinc-autodock-vina/src/boinc-autodock-vina/calculate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
84 changes: 44 additions & 40 deletions boinc-autodock-vina/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,36 +254,65 @@ bool config::load(const jsoncons::basic_json<char>& json, const std::filesystem:
if (json.contains("weight_gauss1")) {
weight_gauss1 = json["weight_gauss1"].as<double>();
}
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<double>();
}
if (json.contains("weight_repulsion")) {
weight_repulsion = json["weight_repulsion"].as<double>();
}
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<double>();
}
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<double>();
}
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<double>();
}
if (json.contains("weight_vinardo_gauss1")) {
weight_vinardo_gauss1 = json["weight_vinardo_gauss1"].as<double>();
}
if (json.contains("weight_vinardo_repulsion")) {
weight_vinardo_repulsion = json["weight_vinardo_repulsion"].as<double>();
}
if (json.contains("weight_vinardo_hydrophobic")) {
weight_vinardo_hydrophobic = json["weight_vinardo_hydrophobic"].as<double>();
}
if (json.contains("weight_vinardo_hydrogen")) {
weight_vinardo_hydrogen = json["weight_vinardo_hydrogen"].as<double>();
}
if (json.contains("weight_vinardo_rot")) {
weight_vinardo_rot = json["weight_vinardo_rot"].as<double>();
}
if (json.contains("weight_ad4_vdw")) {
weight_ad4_vdw = json["weight_ad4_vdw"].as<double>();
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions boinc-autodock-vina/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
82 changes: 62 additions & 20 deletions boinc-autodock-vina/src/unit-tests/config-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 445589e

Please sign in to comment.