1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2020 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include <boost/test/unit_test.hpp>
#include <ost/mol/mm/settings.hh>
#include <ost/mol/mm/forcefield.hh>
#include <ost/mol/mm/interaction.hh>
#include <ost/mol/mm/buildingblock.hh>
#include <ost/mol/mm/gromacs_block_modifiers.hh>
#include <ost/message.hh>
#include <ost/mol/builder.hh>
#include <ost/mol/xcs_editor.hh>
using namespace ost::mol::mm;
BOOST_AUTO_TEST_SUITE( mol_mm );
BOOST_AUTO_TEST_CASE(test_forcefield_basics){
Forcefield ff;
//if a building block doesn't exist, it should throw an error
//this is not the case for hydrogen constructors and block modifiers
BOOST_CHECK_THROW(ff.GetBuildingBlock("IDoNotExist"),ost::Error);
//add some atom types
ff.AddMass("one",1.0);
ff.AddMass("two",2.0);
ff.AddMass("three",3.0);
ff.AddMass("four",4.0);
ff.AddMass("five",5.0);
BOOST_CHECK_THROW(ff.GetBond("one","two"),ost::Error);
BOOST_CHECK_THROW(ff.GetAngle("one","two","three"),ost::Error);
BOOST_CHECK_THROW(ff.GetDihedrals("one","two","three","four"),ost::Error);
BOOST_CHECK_THROW(ff.GetImpropers("one","two","three","four"),ost::Error);
BOOST_CHECK_THROW(ff.GetCMap("one","two","three","four","five"),ost::Error);
BOOST_CHECK_THROW(ff.GetImplicitGenborn("one"),ost::Error);
BOOST_CHECK_THROW(ff.GetLJ("one"),ost::Error);
BOOST_CHECK_THROW(ff.GetLJ("one","two"),ost::Error);
BOOST_CHECK_THROW(ff.GetConstraint("one","two"),ost::Error);
BOOST_CHECK_THROW(ff.GetMass("i_do_not_exist"),ost::Error);
//let's add some interactions
std::vector<String> one_string, two_string, three_string, four_string, five_string;
std::vector<Real> one_real, two_real, three_real, four_real, five_real;
one_string.push_back("one");
two_string.push_back("one");
three_string.push_back("one");
four_string.push_back("one");
five_string.push_back("one");
two_string.push_back("two");
three_string.push_back("two");
four_string.push_back("two");
five_string.push_back("two");
three_string.push_back("three");
four_string.push_back("three");
five_string.push_back("three");
four_string.push_back("four");
five_string.push_back("four");
five_string.push_back("five");
one_real.push_back(1.0);
two_real.push_back(1.0);
three_real.push_back(1.0);
four_real.push_back(1.0);
five_real.push_back(1.0);
two_real.push_back(2.0);
three_real.push_back(2.0);
four_real.push_back(2.0);
five_real.push_back(2.0);
three_real.push_back(3.0);
four_real.push_back(3.0);
five_real.push_back(3.0);
four_real.push_back(4.0);
five_real.push_back(4.0);
five_real.push_back(5.0);
InteractionPtr harmonic_bond(new Interaction(HarmonicBond));
InteractionPtr urey_bradley_angle(new Interaction(UreyBradleyAngle));
InteractionPtr harmonic_angle(new Interaction(HarmonicAngle));
InteractionPtr periodic_dihedral(new Interaction(PeriodicDihedral));
InteractionPtr periodic_improper(new Interaction(PeriodicImproper));
InteractionPtr harmonic_improper(new Interaction(HarmonicImproper));
InteractionPtr cmap(new Interaction(CMap));
InteractionPtr lj(new Interaction(LJ));
InteractionPtr lj_pair(new Interaction(LJPair));
InteractionPtr gbsa(new Interaction(GBSA));
InteractionPtr distance_constraint(new Interaction(DistanceConstraint));
//check whether errors get thrown when incorrectly parametrized interactions are added
BOOST_CHECK_THROW(ff.AddBond(harmonic_bond),ost::Error);
harmonic_bond->SetTypes(two_string);
BOOST_CHECK_THROW(ff.AddBond(harmonic_bond),ost::Error);
harmonic_angle->SetParam(two_real);
BOOST_CHECK_THROW(ff.AddAngle(harmonic_angle),ost::Error);
harmonic_bond->SetParam(two_real);
BOOST_CHECK_NO_THROW(ff.AddBond(harmonic_bond));
harmonic_angle->SetTypes(three_string);
//parametrize the rest
urey_bradley_angle->SetTypes(three_string);
urey_bradley_angle->SetParam(four_real);
periodic_dihedral->SetTypes(four_string);
periodic_dihedral->SetParam(three_real);
periodic_improper->SetTypes(four_string);
periodic_improper->SetParam(three_real);
harmonic_improper->SetTypes(four_string);
harmonic_improper->SetParam(two_real);
std::vector<Real> cmap_param = five_real;
cmap_param[0] = 2.0;
cmap->SetTypes(five_string);
cmap->SetParam(cmap_param);
lj->SetTypes(one_string);
lj->SetParam(two_real);
lj_pair->SetTypes(two_string);
lj_pair->SetParam(two_real);
gbsa->SetTypes(one_string);
gbsa->SetParam(two_real);
distance_constraint->SetTypes(two_string);
distance_constraint->SetParam(one_real);
//check whether errors get thrown when wrong interactions get added
BOOST_CHECK_THROW(ff.AddBond(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddAngle(harmonic_bond),ost::Error);
BOOST_CHECK_THROW(ff.AddDihedral(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddImproper(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddCMap(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddImplicitGenborn(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddLJ(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddLJPair(harmonic_angle),ost::Error);
BOOST_CHECK_THROW(ff.AddConstraint(harmonic_angle),ost::Error);
BOOST_CHECK_NO_THROW(ff.AddBond(harmonic_bond));
BOOST_CHECK_NO_THROW(ff.AddAngle(harmonic_angle));
BOOST_CHECK_NO_THROW(ff.AddDihedral(periodic_dihedral));
BOOST_CHECK_NO_THROW(ff.AddImproper(periodic_improper));
BOOST_CHECK_NO_THROW(ff.AddImproper(harmonic_improper));
BOOST_CHECK_NO_THROW(ff.AddCMap(cmap));
BOOST_CHECK_NO_THROW(ff.AddImplicitGenborn(gbsa));
BOOST_CHECK_NO_THROW(ff.AddLJ(lj));
BOOST_CHECK_NO_THROW(ff.AddLJPair(lj_pair));
BOOST_CHECK_NO_THROW(ff.AddConstraint(distance_constraint));
//add a building block
BuildingBlockPtr block(new BuildingBlock);
block->AddAtom("a","one",0.5);
block->AddAtom("b","two",1.0);
ff.AddBuildingBlock("im_so_sexy",block);
//add block modifier
BlockModifierPtr modifier(new GromacsBlockModifier);
ff.AddBlockModifier("el_modificator",modifier);
//add hydrogen constructor
HydrogenConstructorPtr hydrogen_constructor(new GromacsHydrogenConstructor);
ff.AddHydrogenConstructor("death_metal",hydrogen_constructor);
//add some renaming rules
ff.AddResidueRenamingRule("im_so_sexy","even_sexier","sexy_n","sexy_c","sexy_two");
ff.AddAtomRenamingRule("even_sexier","a","z");
ff.AddAtomRenamingRule("sexy_two","a","z");
//save and load it again, before we check parameters
ff.Save("test.ff");
ForcefieldPtr loaded_ff = Forcefield::Load("test.ff");
//check the parameters
BOOST_CHECK(loaded_ff->GetBond("one","two")->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetBond("two","one")->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetAngle("one","two","three")->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetAngle("three","two","one")->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetDihedrals("one","two","three","four")[0]->GetParam() == three_real);
BOOST_CHECK(loaded_ff->GetDihedrals("four","three","two","one")[0]->GetParam() == three_real);
BOOST_CHECK(loaded_ff->GetImpropers("one","two","three","four")[0]->GetParam() == three_real);
BOOST_CHECK(loaded_ff->GetImpropers("four","three","two","one")[0]->GetParam() == three_real);
BOOST_CHECK(loaded_ff->GetDihedrals("one","two","three","four")[0]->GetParam() == three_real);
BOOST_CHECK(loaded_ff->GetDihedrals("four","three","two","one")[0]->GetParam() == three_real);
BOOST_CHECK(loaded_ff->GetCMap("one","two","three","four","five")->GetParam() == cmap_param);
//cmaps are directional...
BOOST_CHECK_THROW(loaded_ff->GetCMap("five","four","three","two","one"),ost::Error);
BOOST_CHECK(loaded_ff->GetImplicitGenborn("one")->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetLJ("one","two",true)->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetLJ("two","one",true)->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetLJ("one")->GetParam() == two_real);
BOOST_CHECK(loaded_ff->GetConstraint("one","two")->GetParam() == one_real);
BOOST_CHECK(loaded_ff->GetConstraint("two","one")->GetParam() == one_real);
BOOST_CHECK(loaded_ff->GetMass("two") == 2.0);
BOOST_CHECK(loaded_ff->GetAtomType("im_so_sexy","a") == "one");
//check whether the modifiers are still there
BOOST_CHECK(loaded_ff->GetHydrogenConstructor("death_metal"));
BOOST_CHECK(loaded_ff->GetBlockModifier("el_modificator"));
//check the renaming stuff
ost::mol::EntityHandle new_ent = ost::mol::Builder()
.Chain("A")
.Residue("im_so_sexy")
.Atom("a",geom::Vec3(0,0,0))
.Atom("b",geom::Vec3(1,1,1))
.Residue("im_so_sexy")
.Atom("a",geom::Vec3(2,2,2))
.Atom("b",geom::Vec3(3,3,3))
.Residue("im_so_sexy")
.Atom("a",geom::Vec3(4,4,4))
.Atom("b",geom::Vec3(5,5,5));
ost::mol::XCSEditor ed = new_ent.EditXCS();
loaded_ff->AssignFFSpecificNames(new_ent);
ost::mol::ResidueHandleList res_list = new_ent.GetResidueList();
ost::mol::AtomHandleList atom_list = new_ent.GetAtomList();
BOOST_CHECK(res_list[0].GetName() == "sexy_n");
BOOST_CHECK(res_list[1].GetName() == "even_sexier");
BOOST_CHECK(res_list[2].GetName() == "sexy_c");
BOOST_CHECK(atom_list[2].GetName() == "z");
loaded_ff->AssignFFSpecificNames(new_ent,true);
BOOST_CHECK(res_list[0].GetName() == "im_so_sexy");
BOOST_CHECK(res_list[1].GetName() == "im_so_sexy");
BOOST_CHECK(res_list[2].GetName() == "im_so_sexy");
BOOST_CHECK(atom_list[2].GetName() == "a");
ost::mol::EntityHandle new_ent_two = ost::mol::Builder()
.Chain("A")
.Residue("im_so_sexy")
.Atom("a",geom::Vec3(0,0,0))
.Atom("b",geom::Vec3(1,1,1));
loaded_ff->AssignFFSpecificNames(new_ent_two);
res_list = new_ent_two.GetResidueList();
atom_list = new_ent_two.GetAtomList();
BOOST_CHECK(res_list[0].GetName() == "sexy_two");
BOOST_CHECK(atom_list[0].GetName() == "z");
loaded_ff->AssignFFSpecificNames(new_ent_two,true);
BOOST_CHECK(res_list[0].GetName() == "im_so_sexy");
BOOST_CHECK(atom_list[0].GetName() == "a");
}
BOOST_AUTO_TEST_SUITE_END();
|