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
|
#include "obtest.h"
#include <iostream>
#include <openbabel/mol.h>
#include <openbabel/stereo/squareplanar.h>
using namespace std;
using namespace OpenBabel;
void testGetType ()
{
OBMol mol;
OBSquarePlanarStereo sp(&mol);
OB_ASSERT( sp.GetType() == OBStereo::SquarePlanar );
}
void testCenter()
{
OBMol mol;
OBSquarePlanarStereo sp(&mol);
OBSquarePlanarStereo::Config cfg;
cfg.center = 42;
cfg.refs = OBStereo::MakeRefs(1, 2, 3, 4);
sp.SetConfig(cfg);
OB_REQUIRE( sp.GetConfig().center == 42 );
}
void testIsValid()
{
OBMol mol;
OBSquarePlanarStereo sp(&mol);
OBSquarePlanarStereo::Config cfg;
OB_REQUIRE( !sp.IsValid() );
// set center atom
cfg.center = 5;
cout << "This error can be ignored" << endl;
sp.SetConfig(cfg);
OB_REQUIRE( !sp.IsValid() );
// set reference atoms
cfg.refs = OBStereo::MakeRefs(1, 2, 3, 4);
sp.SetConfig(cfg);
// the object should now be valid
OB_REQUIRE( sp.IsValid() );
}
// test basic ref setting/getting
void testRefs1()
{
OBMol mol;
OBSquarePlanarStereo sp(&mol);
OBSquarePlanarStereo::Config cfg;
// 1 4 1 4 1 4 1 4
// \ / | | | /| \ /
// C = | C | = | C | = C
// / \ | | |/ | / \
// 2 3 2---3 2 3 2---3
// set refs using default U shape
cfg.center = 0;
cfg.refs = OBStereo::MakeRefs(1, 2, 3, 4);
sp.SetConfig(cfg);
vector<unsigned long> refs;
// get refs using default U shape
refs = sp.GetConfig().refs;
OB_REQUIRE( refs.size() == 4 );
OB_REQUIRE( refs[0] == 1 );
OB_REQUIRE( refs[1] == 2 );
OB_REQUIRE( refs[2] == 3 );
OB_REQUIRE( refs[3] == 4 );
// get refs using Z shape
refs = sp.GetConfig(OBStereo::ShapeZ).refs;
OB_REQUIRE( refs.size() == 4 );
OB_REQUIRE( refs[0] == 1 );
OB_REQUIRE( refs[1] == 2 );
OB_REQUIRE( refs[2] == 4 );
OB_REQUIRE( refs[3] == 3 );
// get refs using 4 shape
refs = sp.GetConfig(OBStereo::Shape4).refs;
OB_REQUIRE( refs.size() == 4 );
OB_REQUIRE( refs[0] == 1 );
OB_REQUIRE( refs[1] == 3 );
OB_REQUIRE( refs[2] == 2 );
OB_REQUIRE( refs[3] == 4 );
}
void testRefs2()
{
OBMol mol;
OBSquarePlanarStereo sp(&mol);
OBSquarePlanarStereo::Config cfg;
// 1 4 1 4 1 4 1 4
// \ / | | | /| \ /
// C = | C | = | C | = C
// / \ | | |/ | / \
// 2 3 2---3 2 3 2---3
// set refs using default U shape
cfg.center = 0;
cfg.refs = OBStereo::MakeRefs(1, 2, 3, 4);
sp.SetConfig(cfg);
vector<unsigned long> refs;
// get refs using default U shape starting from 1
refs = sp.GetConfig((unsigned long)1).refs;
OB_REQUIRE( refs.size() == 4 );
OB_REQUIRE( refs[0] == 1 );
OB_REQUIRE( refs[1] == 2 );
OB_REQUIRE( refs[2] == 3 );
OB_REQUIRE( refs[3] == 4 );
// get refs using Z shape
refs = sp.GetConfig(OBStereo::ShapeZ).refs;
OB_REQUIRE( refs.size() == 4 );
OB_REQUIRE( refs[0] == 1 );
OB_REQUIRE( refs[1] == 2 );
OB_REQUIRE( refs[2] == 4 );
OB_REQUIRE( refs[3] == 3 );
// get refs using 4 shape
refs = sp.GetConfig(OBStereo::Shape4).refs;
OB_REQUIRE( refs.size() == 4 );
OB_REQUIRE( refs[0] == 1 );
OB_REQUIRE( refs[1] == 3 );
OB_REQUIRE( refs[2] == 2 );
OB_REQUIRE( refs[3] == 4 );
}
void testSquarePlanar()
{
OBMol mol;
OBSquarePlanarStereo sp(&mol);
OBSquarePlanarStereo::Config cfg;
cfg.center = 0;
// set refs using default U shape
cfg.refs = OBStereo::MakeRefs(1, 2, 3, 4);
sp.SetConfig(cfg);
//
// Trans
//
// test invalid ids
OB_REQUIRE( !sp.IsTrans(43, 3) );
OB_REQUIRE( !sp.IsTrans(1, 1) );
// test real trans refs in all combinations
OB_REQUIRE( sp.IsTrans(1, 3) );
OB_REQUIRE( sp.IsTrans(3, 1) );
OB_REQUIRE( sp.IsTrans(2, 4) );
OB_REQUIRE( sp.IsTrans(4, 2) );
// test cis atoms, should not be trans...
OB_REQUIRE( !sp.IsTrans(1, 2) );
OB_REQUIRE( !sp.IsTrans(1, 4) );
OB_REQUIRE( !sp.IsTrans(2, 1) );
OB_REQUIRE( !sp.IsTrans(2, 3) );
OB_REQUIRE( !sp.IsTrans(3, 2) );
OB_REQUIRE( !sp.IsTrans(3, 4) );
OB_REQUIRE( !sp.IsTrans(4, 1) );
OB_REQUIRE( !sp.IsTrans(4, 3) );
//
// Cis
//
// test invalid ids
OB_REQUIRE( !sp.IsCis(43, 3) );
OB_REQUIRE( !sp.IsCis(1, 1) );
// test real cis refs in all combinations
OB_REQUIRE( sp.IsCis(1, 2) );
OB_REQUIRE( sp.IsCis(2, 1) );
OB_REQUIRE( sp.IsCis(1, 4) );
OB_REQUIRE( sp.IsCis(4, 1) );
OB_REQUIRE( sp.IsCis(2, 1) );
OB_REQUIRE( sp.IsCis(2, 3) );
OB_REQUIRE( sp.IsCis(3, 2) );
OB_REQUIRE( sp.IsCis(3, 4) );
OB_REQUIRE( sp.IsCis(4, 3) );
OB_REQUIRE( sp.IsCis(4, 1) );
// test trans atoms, should not be cis...
OB_REQUIRE( !sp.IsCis(1, 3) );
OB_REQUIRE( !sp.IsCis(2, 4) );
// test GetTransRef
OB_REQUIRE( sp.GetTransRef(1) == 3);
OB_REQUIRE( sp.GetTransRef(3) == 1);
OB_REQUIRE( sp.GetTransRef(2) == 4);
OB_REQUIRE( sp.GetTransRef(4) == 2);
// test GetCisRef
vector<unsigned long> cis = sp.GetCisRefs(1);
OB_REQUIRE( cis.size() == 2 );
OB_REQUIRE( cis[0] == 2 || cis[1] == 2);
OB_REQUIRE( cis[0] == 4 || cis[1] == 4);
cis = sp.GetCisRefs(4);
OB_REQUIRE( cis.size() == 2 );
OB_REQUIRE( cis[0] == 1 || cis[1] == 1);
OB_REQUIRE( cis[0] == 3 || cis[1] == 3);
cis = sp.GetCisRefs(2);
OB_REQUIRE( cis.size() == 2 );
OB_REQUIRE( cis[0] == 1 || cis[1] == 1);
OB_REQUIRE( cis[0] == 3 || cis[1] == 3);
}
void test_equalsOperator()
{
OBSquarePlanarStereo sq1(0), sq2(0);
OBSquarePlanarStereo::Config cfg;
cfg.center = 0;
cfg.refs = OBStereo::MakeRefs(1, 2, 3, 4);
sq1.SetConfig(cfg);
sq2.SetConfig(cfg);
OB_ASSERT( sq1 == sq2 );
cfg.shape = OBStereo::ShapeZ;
sq2.SetConfig(cfg);
OB_ASSERT( sq1 != sq2 );
OBStereo::Permutate(cfg.refs, 0, 1);
sq2.SetConfig(cfg);
OB_ASSERT( sq1 == sq2 );
}
int main()
{
// Define location of file formats for testing
#ifdef FORMATDIR
char env[BUFF_SIZE];
snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
putenv(env);
#endif
testGetType();
testCenter();
testIsValid();
testRefs1();
testRefs2();
testSquarePlanar();
test_equalsOperator();
cout << "end" << endl;
return 0;
}
|