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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
//------------------------------------------------------------------------------
// 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
//------------------------------------------------------------------------------
/*
* Authors: Marco Biasini, Juergen Haas
*/
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <ost/mol/mol.hh>
#include <ost/log.hh>
#include <ost/message.hh>
#include <ost/geom/geom.hh>
using ost::Logger;
using namespace ost;
using namespace ost::mol;
struct Structure {
Structure()
{
e=CreateEntity();
ICSEditor editor=e.EditICS();
c=editor.InsertChain("A");
r=editor.AppendResidue(c, "ANGELIN");
a1=editor.InsertAtom(r, "CC", geom::Vec3(-1.0, 0.0, 0.0));
a2=editor.InsertAtom(r, "X1", geom::Vec3( 0.0, 0.0, 0.0));
a3=editor.InsertAtom(r, "X2", geom::Vec3( 1.0, 0.0, 0.0));
a4=editor.InsertAtom(r, "X3", geom::Vec3( 0.0, 0.0, -1.0));
a5=editor.InsertAtom(r, "X4", geom::Vec3( 0.0, 0.0, 1.0));
editor.Connect(a1, a2);
editor.Connect(a2, a3);
editor.Connect(a2, a4);
editor.Connect(a2, a5);
}
EntityHandle e;
ChainHandle c;
ResidueHandle r;
AtomHandle a1;
AtomHandle a2;
AtomHandle a3;
AtomHandle a4;
AtomHandle a5;
};
struct TorsionStructure {
TorsionStructure()
{
e=CreateEntity();
ICSEditor editor=e.EditICS();
c=editor.InsertChain("A");
r=editor.AppendResidue(c, "TORSTIN");
a1=editor.InsertAtom(r, "X1", geom::Vec3( 0.0, -1.0, 0.0));
a2=editor.InsertAtom(r, "X2", geom::Vec3( 1.0, 0.0, 0.0));
a3=editor.InsertAtom(r, "X3", geom::Vec3( 2.0, 0.0, 0.0));
a4=editor.InsertAtom(r, "X4", geom::Vec3( 3.0, 1.0, 0.0));
a5=editor.InsertAtom(r, "X5", geom::Vec3( 3.0, -1.0, 0.0));
editor.Connect(a1, a2);
editor.Connect(a2, a3);
editor.Connect(a3, a4);
editor.Connect(a3, a5);
t1 = editor.AddTorsion("T1", a1, a2, a3, a4);
t2 = editor.AddTorsion("T2", a1, a2, a3, a5);
}
EntityHandle e;
ChainHandle c;
ResidueHandle r;
AtomHandle a1;
AtomHandle a2;
AtomHandle a3;
AtomHandle a4;
AtomHandle a5;
TorsionHandle t1;
TorsionHandle t2;
};
const static Real EPSILON=0.000001;
Real angle_xcs(AtomHandle a1, AtomHandle a2, AtomHandle a3) {
return acos(Dot(geom::Normalize(a1.GetPos()-a2.GetPos()),
geom::Normalize(a3.GetPos()-a2.GetPos())));
}
bool test_angle(Real a, Real e) {
return std::abs(fmod(float(a-e), float(M_PI/2)))<EPSILON;
}
BOOST_AUTO_TEST_SUITE( mol_base );
BOOST_AUTO_TEST_CASE(ics_update_icsbondlength)
{
TorsionStructure s;
mol::BondHandle bond = s.a2.FindBondToAtom(s.a3);
BOOST_CHECK_CLOSE(bond.GetLength(), Real(1.0), Real(EPSILON));
}
BOOST_AUTO_TEST_CASE(ics_settorsion_unbuffered)
{
Real eps = 0.0001;
TorsionStructure s;
ICSEditor e = s.e.EditICS(mol::UNBUFFERED_EDIT);
BOOST_CHECK_CLOSE(std::abs(s.t1.GetAngle()), Real(M_PI), Real(eps));
BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
e.SetTorsionAngle(s.t1,0);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_CLOSE(std::abs(s.t2.GetAngle()), Real(M_PI), Real(eps));
e.SetTorsionAngle(s.t2,M_PI/4);
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(-M_PI+M_PI/4), Real(eps));
e.SetTorsionAngle(s.t1,-M_PI/4);
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(-M_PI/4), Real(eps));
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(3/4.*M_PI), Real(eps));
e.RotateTorsionAngle(s.t1, M_PI/4);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_CLOSE(std::abs(s.t2.GetAngle()), Real(M_PI), Real(eps));
}
BOOST_AUTO_TEST_CASE(ics_settorsion_buffered)
{
Real eps = 0.0001;
TorsionStructure s;
ICSEditor e = s.e.EditICS(mol::BUFFERED_EDIT);
BOOST_CHECK_CLOSE(std::abs(s.t1.GetAngle()), Real(M_PI), Real(eps));
BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
e.SetTorsionAngle(s.t1,0);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_CLOSE(std::abs(s.t2.GetAngle()), Real(M_PI), Real(eps));
e.SetTorsionAngle(s.t2,M_PI/4);
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(-M_PI+M_PI/4), Real(eps));
e.SetTorsionAngle(s.t1,-M_PI/4);
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(-M_PI/4), Real(eps));
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(3/4.*M_PI), Real(eps));
e.RotateTorsionAngle(s.t1, M_PI/4);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_CLOSE(std::abs(s.t2.GetAngle()), Real(M_PI), Real(eps));
}
BOOST_AUTO_TEST_CASE(ics_settorsion_unbuffered_update_others)
{
Real eps = 0.0001;
TorsionStructure s;
ICSEditor e = s.e.EditICS(mol::UNBUFFERED_EDIT);
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(M_PI), Real(eps));
BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
e.SetTorsionAngle(s.t1,0,false);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
e.SetTorsionAngle(s.t2,M_PI/4,false);
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
e.SetTorsionAngle(s.t1,-M_PI/4,false);
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(-M_PI/4), Real(eps));
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
e.RotateTorsionAngle(s.t1, M_PI/4,false);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
}
BOOST_AUTO_TEST_CASE(ics_settorsion_buffered_update_others)
{
Real eps = 0.0001;
TorsionStructure s;
ICSEditor e = s.e.EditICS(mol::BUFFERED_EDIT);
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(M_PI), Real(eps));
BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
e.SetTorsionAngle(s.t1,0,false);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
e.SetTorsionAngle(s.t2,M_PI/4,false);
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
e.SetTorsionAngle(s.t1,-M_PI/4,false);
BOOST_CHECK_CLOSE(s.t1.GetAngle(), Real(-M_PI/4), Real(eps));
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
e.RotateTorsionAngle(s.t1, M_PI/4,false);
BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
}
// This unit test has been observed to fail (EXTREMELY RARELY)
// It tests the edge case of 3 atoms that are all on a line.
// From an external coordinate system perspective, the dihedral
// is not defined in this case.
// From an internal coordinate perspective this should not matter.
// The last line is the failing line. The expected behaviour is
// that a rotation of x around t1 (The "linear" dihedral) should
// propagate and affect t2 accordingly. Observed failure:
// difference{4} between s.t2.GetAngle(){-2.3561945} and Real(3.14159265358979323846/4){0.785398185} exceeds 0.0001%
// In the meantime we propose to use internal coordinates with caution and
// open a task in JIRA for someone brave enough to deep dive into the code.
//BOOST_AUTO_TEST_CASE(ics_settorsion_linear_unbuffered)
//{
// Real eps = 0.0001;
// TorsionStructure s;
// ICSEditor e = s.e.EditICS(mol::UNBUFFERED_EDIT);
// e.SetAngle(s.a2,s.a3,s.a4,M_PI);
// BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
// BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
// e.SetTorsionAngle(s.t1,0);
// BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
// BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
// e.SetTorsionAngle(s.t2,M_PI/4);
// BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
// BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
// e.SetTorsionAngle(s.t1,-M_PI/4);
// BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
// BOOST_CHECK_SMALL(s.t2.GetAngle(), eps);
// e.RotateTorsionAngle(s.t1, M_PI/4);
// BOOST_CHECK_SMALL(s.t1.GetAngle(), eps);
// BOOST_CHECK_CLOSE(s.t2.GetAngle(), Real(M_PI/4), Real(eps));
//}
BOOST_AUTO_TEST_CASE(ics_angle_trivia)
{
Structure s;
ICSEditor e=s.e.EditICS();
BOOST_CHECK(!e.SetAngle(s.a1, s.a3, s.a2, 0));
BOOST_CHECK(!e.SetAngle(s.a2, s.a3, s.a1, 0));
BOOST_CHECK(e.SetAngle(s.a1, s.a2, s.a3, 0));
BOOST_CHECK(!e.SetAngle(s.a1, s.a3, s.a2, 0));
BOOST_CHECK(!e.SetAngle(s.a2, s.a3, s.a1, 0));
BOOST_CHECK(e.SetAngle(s.a1, s.a2, s.a3, 0));
BOOST_CHECK_THROW(s.e.GetAngle(s.a1, s.a3, s.a2), Error);
BOOST_CHECK_THROW(s.e.GetAngle(s.a2, s.a3, s.a1), Error);
BOOST_CHECK_NO_THROW(s.e.GetAngle(s.a1, s.a2, s.a3));
}
BOOST_AUTO_TEST_CASE(ics_set_angle_sec)
{
Structure s;
// test for set angle of two secondary connectors
ICSEditor e=s.e.EditICS();
geom::Plane p(s.a3.GetPos(), s.a2.GetPos(), s.a4.GetPos());
e.SetAngle(s.a3, s.a2, s.a4, M_PI/4);
e.UpdateXCS();
BOOST_CHECK_MESSAGE(test_angle(M_PI/4, angle_xcs(s.a3, s.a2, s.a4)),
"expected " << M_PI/4 << " but " <<
angle_xcs(s.a3, s.a2, s.a4));
BOOST_CHECK(geom::IsInPlane(p, s.a3.GetPos(), EPSILON));
BOOST_CHECK(geom::IsInPlane(p, s.a2.GetPos(), EPSILON));
BOOST_CHECK(geom::IsInPlane(p, s.a4.GetPos(), EPSILON));
}
BOOST_AUTO_TEST_CASE(ics_set_angle_prim)
{
Structure s;
// test for set angle of two secondary connectors
ICSEditor e=s.e.EditICS();
e.SetAngle(s.a1, s.a2, s.a4, M_PI/4);
e.UpdateXCS();
geom::Plane p(s.a1.GetPos(), s.a2.GetPos(), s.a4.GetPos());
BOOST_CHECK_MESSAGE(test_angle(M_PI/4, angle_xcs(s.a1, s.a2, s.a4)),
"expected " << M_PI/4 << " but " <<
angle_xcs(s.a1, s.a2, s.a4));
BOOST_CHECK(geom::IsInPlane(p, s.a1.GetPos(), EPSILON));
BOOST_CHECK(geom::IsInPlane(p, s.a2.GetPos(), EPSILON));
BOOST_CHECK(geom::IsInPlane(p, s.a4.GetPos(), EPSILON));
}
BOOST_AUTO_TEST_CASE(ics_get_angle)
{
Structure s;
// test for get angle with secondary connectors only
Real a=s.e.GetAngle(s.a3, s.a2, s.a4);
Real e=angle_xcs(s.a3, s.a2, s.a4);
BOOST_CHECK_MESSAGE(test_angle(a, e),
"expected " << e << " but " << a
<< " found");
a=s.e.GetAngle(s.a5, s.a2, s.a4);
e=angle_xcs(s.a5, s.a2, s.a4);
BOOST_CHECK_MESSAGE(test_angle(a, e),
"expected " << e << " but " << a
<< " found");
a=s.e.GetAngle(s.a5, s.a2, s.a5);
e=angle_xcs(s.a5, s.a2, s.a5);
BOOST_CHECK_MESSAGE(test_angle(a, e),
"expected " << e << " but " << a
<< " found");
}
BOOST_AUTO_TEST_SUITE_END();
|