File: test_interaction.cc

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (291 lines) | stat: -rw-r--r-- 12,786 bytes parent folder | download | duplicates (4)
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
//------------------------------------------------------------------------------
// 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/interaction.hh>
#include <ost/mol/mol.hh>
#include <ost/mol/builder.hh>

#include <ost/message.hh>

using namespace ost::mol::mm;



BOOST_AUTO_TEST_SUITE( mol_mm );

BOOST_AUTO_TEST_CASE(test_set_stuff) 
{
  Interaction harmonic_bond = Interaction(HarmonicBond);
  Interaction harmonic_angle = Interaction(HarmonicAngle);
  Interaction urey_bradley = Interaction(UreyBradleyAngle);
  Interaction periodic_dihedral = Interaction(PeriodicDihedral);
  Interaction periodic_improper = Interaction(PeriodicImproper);
  Interaction harmonic_improper = Interaction(HarmonicImproper);
  Interaction cmap = Interaction(CMap);
  Interaction lj = Interaction(LJ);
  Interaction lj_pair = Interaction(LJPair);
  Interaction gbsa = Interaction(GBSA);
  Interaction distance_constraint = Interaction(DistanceConstraint);
  Interaction exclusion = Interaction(Exclusion);
  Interaction harmonic_distance_restraint = Interaction(HarmonicDistanceRestraint);
  Interaction harmonic_position_restraint = Interaction(HarmonicPositionRestraint);

  //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, zero_real;

  std::vector<Real> one_real(1);
  std::vector<Real> two_real(2);
  std::vector<Real> three_real(3);
  std::vector<Real> four_real(4);
  std::vector<Real> five_real(5);
  std::vector<Real> seven_real(7);
  std::vector<Real> zero_real(0);

  std::vector<String> one_string(1);
  std::vector<String> two_string(2);
  std::vector<String> three_string(3);
  std::vector<String> four_string(4);
  std::vector<String> five_string(5);


  BOOST_CHECK(!harmonic_bond.IsParametrized());

  BOOST_CHECK_THROW(harmonic_bond.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_angle.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(urey_bradley.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(periodic_dihedral.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(periodic_improper.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_improper.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(cmap.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(lj.SetNames(two_string),ost::Error);
  BOOST_CHECK_THROW(lj_pair.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(gbsa.SetNames(two_string),ost::Error);
  BOOST_CHECK_THROW(distance_constraint.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(exclusion.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_distance_restraint.SetNames(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_position_restraint.SetNames(two_string),ost::Error);


  BOOST_CHECK_THROW(harmonic_bond.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_angle.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(urey_bradley.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(periodic_dihedral.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(periodic_improper.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_improper.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(cmap.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(lj.SetTypes(two_string),ost::Error);
  BOOST_CHECK_THROW(lj_pair.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(gbsa.SetTypes(two_string),ost::Error);
  BOOST_CHECK_THROW(distance_constraint.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(exclusion.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_distance_restraint.SetTypes(one_string),ost::Error);
  BOOST_CHECK_THROW(harmonic_position_restraint.SetTypes(two_string),ost::Error);

  BOOST_CHECK_THROW(harmonic_bond.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(harmonic_angle.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(urey_bradley.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(periodic_dihedral.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(periodic_improper.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(harmonic_improper.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(cmap.SetParam(two_real),ost::Error);
  BOOST_CHECK_THROW(lj.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(lj_pair.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(gbsa.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(distance_constraint.SetParam(two_real),ost::Error);
  BOOST_CHECK_THROW(exclusion.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(harmonic_distance_restraint.SetParam(one_real),ost::Error);
  BOOST_CHECK_THROW(harmonic_position_restraint.SetParam(one_real),ost::Error);



  BOOST_CHECK_NO_THROW(harmonic_bond.SetNames(two_string));
  BOOST_CHECK_NO_THROW(harmonic_angle.SetNames(three_string));
  BOOST_CHECK_NO_THROW(urey_bradley.SetNames(three_string));
  BOOST_CHECK_NO_THROW(periodic_dihedral.SetNames(four_string));
  BOOST_CHECK_NO_THROW(periodic_improper.SetNames(four_string));
  BOOST_CHECK_NO_THROW(harmonic_improper.SetNames(four_string));
  BOOST_CHECK_NO_THROW(cmap.SetNames(five_string));
  BOOST_CHECK_NO_THROW(lj.SetNames(one_string));
  BOOST_CHECK_NO_THROW(lj_pair.SetNames(two_string));
  BOOST_CHECK_NO_THROW(gbsa.SetNames(one_string));
  BOOST_CHECK_NO_THROW(distance_constraint.SetNames(two_string));
  BOOST_CHECK_NO_THROW(exclusion.SetNames(two_string));
  BOOST_CHECK_NO_THROW(harmonic_distance_restraint.SetNames(two_string));
  BOOST_CHECK_NO_THROW(harmonic_position_restraint.SetNames(one_string));
  

  BOOST_CHECK_NO_THROW(harmonic_bond.SetTypes(two_string));
  BOOST_CHECK_NO_THROW(harmonic_angle.SetTypes(three_string));
  BOOST_CHECK_NO_THROW(urey_bradley.SetTypes(three_string));
  BOOST_CHECK_NO_THROW(periodic_dihedral.SetTypes(four_string));
  BOOST_CHECK_NO_THROW(periodic_improper.SetTypes(four_string));
  BOOST_CHECK_NO_THROW(harmonic_improper.SetTypes(four_string));
  BOOST_CHECK_NO_THROW(cmap.SetTypes(five_string));
  BOOST_CHECK_NO_THROW(lj.SetTypes(one_string));
  BOOST_CHECK_NO_THROW(lj_pair.SetTypes(two_string));
  BOOST_CHECK_NO_THROW(gbsa.SetTypes(one_string));
  BOOST_CHECK_NO_THROW(distance_constraint.SetTypes(two_string));
  BOOST_CHECK_NO_THROW(exclusion.SetTypes(two_string));
  BOOST_CHECK_NO_THROW(harmonic_distance_restraint.SetTypes(two_string));
  BOOST_CHECK_NO_THROW(harmonic_position_restraint.SetTypes(one_string));

  BOOST_CHECK_NO_THROW(harmonic_bond.SetParam(two_real));
  BOOST_CHECK_NO_THROW(harmonic_angle.SetParam(two_real));
  BOOST_CHECK_NO_THROW(urey_bradley.SetParam(four_real));
  BOOST_CHECK_NO_THROW(periodic_dihedral.SetParam(three_real));
  BOOST_CHECK_NO_THROW(periodic_improper.SetParam(three_real));
  BOOST_CHECK_NO_THROW(harmonic_improper.SetParam(two_real));
  BOOST_CHECK_NO_THROW(lj.SetParam(two_real));
  BOOST_CHECK_NO_THROW(lj_pair.SetParam(two_real));
  BOOST_CHECK_NO_THROW(gbsa.SetParam(two_real));
  BOOST_CHECK_NO_THROW(distance_constraint.SetParam(one_real));
  BOOST_CHECK_NO_THROW(exclusion.SetParam(zero_real));
  BOOST_CHECK_NO_THROW(harmonic_distance_restraint.SetParam(two_real));
  BOOST_CHECK_NO_THROW(harmonic_position_restraint.SetParam(seven_real));

  std::vector<Real> valid_cmap_parameters;
  valid_cmap_parameters.push_back(2.0);
  valid_cmap_parameters.push_back(0.0);
  valid_cmap_parameters.push_back(0.0);
  valid_cmap_parameters.push_back(0.0);
  valid_cmap_parameters.push_back(0.0);

  BOOST_CHECK_NO_THROW(cmap.SetParam(valid_cmap_parameters));
  BOOST_CHECK(harmonic_bond.IsParametrized());

  Interaction new_bond = Interaction(HarmonicBond);
  std::vector<String> with_wildcard, without_wildcard;
  with_wildcard.push_back("A");
  without_wildcard.push_back("A");
  with_wildcard.push_back("X");
  without_wildcard.push_back("A");

  //should be initialized with false
  BOOST_CHECK(!new_bond.HasNameWildcard());
  BOOST_CHECK(!new_bond.HasTypeWildcard());

  new_bond.SetNames(without_wildcard);
  new_bond.SetTypes(without_wildcard);
  BOOST_CHECK(!new_bond.HasNameWildcard());
  BOOST_CHECK(!new_bond.HasTypeWildcard());

  new_bond.SetNames(with_wildcard);
  new_bond.SetTypes(with_wildcard);
  BOOST_CHECK(new_bond.HasNameWildcard());
  BOOST_CHECK(new_bond.HasTypeWildcard());

  //Check hasname/hastype
  BOOST_CHECK(new_bond.HasType("A"));
  BOOST_CHECK(!new_bond.HasType("B"));
  BOOST_CHECK(new_bond.HasName("A"));
  BOOST_CHECK(!new_bond.HasType("B"));

}

BOOST_AUTO_TEST_CASE(test_match_stuff) 
{
  Interaction dihedral = Interaction(PeriodicDihedral);

  std::vector<String> with_wildcard, without_wildcard;
  with_wildcard.push_back("X");
  with_wildcard.push_back("A");
  with_wildcard.push_back("A");
  with_wildcard.push_back("A");
  without_wildcard.push_back("A");
  without_wildcard.push_back("A");
  without_wildcard.push_back("A");
  without_wildcard.push_back("A");

  dihedral.SetTypes(with_wildcard);
  BOOST_CHECK(dihedral.MatchTypes(with_wildcard));
  BOOST_CHECK(dihedral.MatchTypes(without_wildcard));
  dihedral.SetTypes(without_wildcard);
  BOOST_CHECK(dihedral.MatchTypes(without_wildcard));
  BOOST_CHECK(!dihedral.MatchTypes(with_wildcard));

  dihedral.SetNames(with_wildcard);
  BOOST_CHECK(dihedral.MatchNames(with_wildcard));
  BOOST_CHECK(dihedral.MatchNames(without_wildcard));
  dihedral.SetNames(without_wildcard);
  BOOST_CHECK(dihedral.MatchNames(without_wildcard));
  BOOST_CHECK(!dihedral.MatchNames(with_wildcard));

}

BOOST_AUTO_TEST_CASE(test_replace_atom){
  Interaction bond = Interaction(HarmonicBond);
  std::vector<String> strings;
  strings.push_back("A");
  strings.push_back("B");
  bond.SetNames(strings);
  bond.ReplaceAtom("A","X","X");
  std::vector<String> new_names = bond.GetNames();
  BOOST_CHECK(new_names != strings);
  bond.SetTypes(strings);
  bond.ReplaceAtom("X","A","X");
  std::vector<String> new_types = bond.GetTypes();
  BOOST_CHECK(new_types == new_names);

}

BOOST_AUTO_TEST_CASE(test_getatoms){
  ost::mol::EntityHandle e = ost::mol::Builder()
                             .Chain("A")
                                .Residue("ONE")
                                  .Atom("A",geom::Vec3(-5,-5,-5))
                                  .Atom("B",geom::Vec3(-5, 5,-5))
                                .Residue("TWO")
                                  .Atom("A",geom::Vec3(1,1,1))
                                  .Atom("B",geom::Vec3(2,2,2))
                                .Residue("THREE")
                                  .Atom("A",geom::Vec3(3,3,3))
                                  .Atom("B",geom::Vec3(4,4,4));

  ost::mol::ResidueHandleList res_list = e.GetResidueList();
  ost::mol::AtomHandleList atom_list_one  = res_list[0].GetAtomList();
  ost::mol::AtomHandleList atom_list_two  = res_list[1].GetAtomList();
  ost::mol::AtomHandleList atom_list_three  = res_list[2].GetAtomList();

  Interaction bond = Interaction(HarmonicBond);
  std::vector<String> strings;
  strings.push_back("A");
  strings.push_back("B");
  bond.SetNames(strings);
  ost::mol::AtomHandleList bond_atom_list = bond.GetAtoms(res_list[0]);
  BOOST_CHECK(atom_list_one[0] == bond_atom_list[0]);
  BOOST_CHECK(atom_list_one[1] == bond_atom_list[1]);
  strings[1] = "X";
  bond.SetNames(strings);
  BOOST_CHECK_THROW(bond.GetAtoms(res_list[0]),ost::Error);
  strings[0] = "-A";
  strings[1] = "B";
  bond.SetNames(strings);
  BOOST_CHECK_THROW(bond.GetAtoms(res_list[0]),ost::Error);
  bond_atom_list = bond.GetAtoms(res_list[1]);  
  BOOST_CHECK(bond_atom_list[0] == atom_list_one[0]);
  BOOST_CHECK(bond_atom_list[1] == atom_list_two[1]);
  strings[1]="+B";
  bond.SetNames(strings);
  BOOST_CHECK_THROW(bond.GetAtoms(res_list[2]),ost::Error);
  bond_atom_list = bond.GetAtoms(res_list[1]);
  BOOST_CHECK(bond_atom_list[0] == atom_list_one[0]);
  BOOST_CHECK(bond_atom_list[1] == atom_list_three[1]); 
}
BOOST_AUTO_TEST_SUITE_END();