1 /*
2 * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 #define BOOST_TEST_MAIN
19
20 #define BOOST_TEST_MODULE nblist_3body_test
21
22 // Standard includes
23 #include <string>
24 #include <vector>
25
26 // Third party includes
27 #include <boost/test/unit_test.hpp>
28
29 // Local VOTCA includes
30 #include "votca/csg/bead.h"
31 #include "votca/csg/beadlist.h"
32 #include "votca/csg/nblistgrid_3body.h"
33 #include "votca/csg/topology.h"
34
35 using namespace std;
36 using namespace votca::csg;
37
38 BOOST_AUTO_TEST_SUITE(nblist_3body_test)
39
BOOST_AUTO_TEST_CASE(test_nblist_3body_constructor)40 BOOST_AUTO_TEST_CASE(test_nblist_3body_constructor) { NBList_3Body nb; }
41
BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list)42 BOOST_AUTO_TEST_CASE(test_nblist_3body_generate_list) {
43 NBList_3Body nb;
44
45 nb.setCutoff(2.0);
46
47 Topology top;
48
49 Eigen::Matrix3d m = 5 * Eigen::Matrix3d::Identity();
50
51 top.setBox(m);
52
53 Eigen::Vector3d pos;
54
55 Molecule *mol;
56 mol = top.CreateMolecule("UNKNOWN");
57
58 string bead_type_name = "CG";
59 top.RegisterBeadType(bead_type_name);
60 string name = "dummy1";
61 votca::Index resnr = 0;
62 double mass = 1.0;
63 double charge = -1.0;
64 Bead *b;
65 b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
66 charge);
67 pos[0] = 0.0;
68 pos[1] = 0.0;
69 pos[2] = 0.0;
70 b->setPos(pos);
71 mol->AddBead(b, bead_type_name);
72
73 name = "dummy2";
74 resnr = 0;
75 mass = 2.0;
76 charge = -2.0;
77 b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
78 charge);
79 mol->AddBead(b, bead_type_name);
80 pos[0] = 1.0;
81 pos[1] = 0.0;
82 pos[2] = 0.0;
83 b->setPos(pos);
84
85 name = "dummy3";
86 resnr = 0;
87 mass = 3.0;
88 charge = -3.0;
89 b = top.CreateBead(Bead::spherical, name, bead_type_name, resnr, mass,
90 charge);
91 mol->AddBead(b, bead_type_name);
92 pos[0] = 1.0;
93 pos[1] = 1.0;
94 pos[2] = 0.0;
95 b->setPos(pos);
96
97 BeadList beads;
98 beads.Generate(top, "CG");
99
100 nb.Generate(beads, true);
101
102 BOOST_CHECK_EQUAL(nb.size(), 3);
103
104 NBList_3Body::iterator triple_iter;
105 triple_iter = nb.begin();
106 BOOST_CHECK_EQUAL((*triple_iter)->bead1()->getId(), 0);
107 BOOST_CHECK_EQUAL((*triple_iter)->bead2()->getId(), 1);
108 BOOST_CHECK_EQUAL((*triple_iter)->bead3()->getId(), 2);
109 BOOST_CHECK_CLOSE((*triple_iter)->dist12(), 1.0, 1e-4);
110 BOOST_CHECK_CLOSE((*triple_iter)->dist13(), 1.414214, 1e-4);
111 BOOST_CHECK_CLOSE((*triple_iter)->dist23(), 1.0, 1e-4);
112
113 ++triple_iter;
114
115 BOOST_CHECK_EQUAL((*triple_iter)->bead1()->getId(), 1);
116 BOOST_CHECK_EQUAL((*triple_iter)->bead2()->getId(), 0);
117 BOOST_CHECK_EQUAL((*triple_iter)->bead3()->getId(), 2);
118 BOOST_CHECK_CLOSE((*triple_iter)->dist12(), 1.0, 1e-4);
119 BOOST_CHECK_CLOSE((*triple_iter)->dist13(), 1.0, 1e-4);
120 BOOST_CHECK_CLOSE((*triple_iter)->dist23(), 1.414214, 1e-4);
121
122 ++triple_iter;
123
124 BOOST_CHECK_EQUAL((*triple_iter)->bead1()->getId(), 2);
125 BOOST_CHECK_EQUAL((*triple_iter)->bead2()->getId(), 0);
126 BOOST_CHECK_EQUAL((*triple_iter)->bead3()->getId(), 1);
127 BOOST_CHECK_CLOSE((*triple_iter)->dist12(), 1.414214, 1e-4);
128 BOOST_CHECK_CLOSE((*triple_iter)->dist13(), 1.0, 1e-4);
129 BOOST_CHECK_CLOSE((*triple_iter)->dist23(), 1.0, 1e-4);
130 }
131
132 BOOST_AUTO_TEST_SUITE_END()
133