File: test_entity.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 (496 lines) | stat: -rw-r--r-- 18,137 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
//------------------------------------------------------------------------------
// 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/geom/vec_mat_predicates.hh>
#include <ost/mol/chem_class.hh>
#include <ost/mol/mol.hh>
#include <ost/mol/property_id.hh>
#include <cmath>

#define CHECK_TRANSFORMED_ATOM_POSITION(ATOM,TARGET) \
   BOOST_CHECK(vec3_is_close(ATOM.GetPos(), TARGET,Real(0.1)))

#define CHECK_ORIGINAL_ATOM_POSITION(ATOM,TARGET) \
   BOOST_CHECK(vec3_is_close(ATOM.GetOriginalPos(), TARGET,Real(0.1)))

#define CHECK_ALTERNATE_ATOM_POSITION(ATOM,TARGET,GROUP) \
   BOOST_CHECK(vec3_is_close(ATOM.GetAltPos(GROUP), TARGET,Real(0.1)))

using namespace ost;
using namespace ost::mol;


EntityHandle make_test_entity()
{
  EntityHandle eh = CreateEntity();
  XCSEditor e=eh.EditXCS();
  ChainHandle chain = e.InsertChain("A");
  ResidueHandle res1 = e.AppendResidue(chain, "MET");

  eh.SetName("TestEntity");

  e.InsertAtom(res1, "N",geom::Vec3(21.609,35.384,56.705));
  e.InsertAtom(res1, "CA",geom::Vec3(20.601,35.494,57.793));
  e.InsertAtom(res1, "C",geom::Vec3(19.654,34.300,57.789));
  e.InsertAtom(res1, "O",geom::Vec3(18.447,34.456,57.595));
  e.Connect(res1.FindAtom("N"), res1.FindAtom("CA"));
  e.Connect(res1.FindAtom("CA"), res1.FindAtom("C"));
  e.Connect(res1.FindAtom("C"), res1.FindAtom("O"));    
  ResidueHandle res2 = e.AppendResidue(chain, "ARG");
  e.InsertAtom(res2, "N",geom::Vec3(20.202,33.112,58.011));
  e.InsertAtom(res2, "CA",geom::Vec3(19.396,31.903,58.033));
  e.InsertAtom(res2, "C",geom::Vec3(18.608,31.739,59.328));
  e.InsertAtom(res2, "O",geom::Vec3(17.651,30.965,59.381));
  e.Connect(res1.FindAtom("C"), res2.FindAtom("N"));
  e.Connect(res2.FindAtom("N"), res2.FindAtom("CA"));
  e.Connect(res2.FindAtom("CA"), res2.FindAtom("C"));
  e.Connect(res2.FindAtom("C"), res2.FindAtom("O"));
  res1.SetChemClass(ChemClass(ChemClass::L_PEPTIDE_LINKING));
  res2.SetChemClass(ChemClass(ChemClass::L_PEPTIDE_LINKING));  
  e.AddTorsion("PHI", res1.FindAtom("C"), res2.FindAtom("N"), 
               res2.FindAtom("CA"), res2.FindAtom("C"));
  return eh;
}

BOOST_AUTO_TEST_SUITE( mol_base );


BOOST_AUTO_TEST_CASE(throw_invalid_ent_handle)
{
  EntityHandle ent;
  BOOST_CHECK_THROW(CheckHandleValidity(ent), InvalidHandle);  
  ent=CreateEntity();
  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent));
}

BOOST_AUTO_TEST_CASE(throw_invalid_ent_view)
{
  EntityView ent_view;
  BOOST_CHECK_THROW(CheckHandleValidity(ent_view), InvalidHandle);  
  EntityHandle ent=CreateEntity();
  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent.CreateFullView()));
  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent.CreateEmptyView()));
}

BOOST_AUTO_TEST_CASE(bzdng250)
{
  EntityHandle eh=make_test_entity();
  eh.EditXCS().ApplyTransform(geom::Mat4(-1, 0, 0, 0,
                                          0, 1, 0, 0,
                                          0, 0,-1, 0,
                                          0, 0, 0, 1));
  BOOST_CHECK_NO_THROW(eh.FindResidue("A", 1).FindTorsion("PHI").GetAngle());
}

BOOST_AUTO_TEST_CASE(entity_creator) 
{
  EntityHandle eh = CreateEntity();
  eh.SetName("TestEntity");
  BOOST_CHECK(eh.GetName()=="TestEntity");

  XCSEditor e=eh.EditXCS();
  ChainHandle chain = e.InsertChain("C");
  BOOST_CHECK(chain.GetName()=="C");

  ResidueHandle res = e.AppendResidue(chain, "FOO", ResNum(13));
  BOOST_CHECK(chain.GetName()==res.GetChain().GetName());
  BOOST_CHECK(res.GetNumber()==ResNum(13));
  BOOST_CHECK(res.GetKey()=="FOO");

  AtomHandle atom1 = e.InsertAtom(res, "X1",geom::Vec3());
  BOOST_CHECK(res==atom1.GetResidue());
  BOOST_CHECK(atom1.GetName()=="X1");
  BOOST_CHECK(atom1.GetIndex()==0);

  AtomHandle atom2 = e.InsertAtom(res, "X2",geom::Vec3());
  BOOST_CHECK(res==atom2.GetResidue());
  BOOST_CHECK(atom2.GetName()=="X2");
  BOOST_CHECK(atom2.GetIndex()==1);

  BondHandle bond = e.Connect(atom1, atom2);

  BOOST_CHECK(eh.GetChainCount()==1);
  BOOST_CHECK(eh.GetResidueCount()==1);
  BOOST_CHECK(eh.GetAtomCount()==2);
  
  BOOST_CHECK(eh.GetAtomCount()==chain.GetAtomCount());
  BOOST_CHECK(eh.GetResidueCount()==chain.GetResidueCount());

  chain.SetIntProp("amazing",42);
  EntityHandle eh2 = CreateEntity();
  XCSEditor e2 = eh2.EditXCS();
  ChainHandle inserted_chain=e2.InsertChain("Q",chain);
  BOOST_CHECK(eh2.GetChainCount()==1);
  BOOST_CHECK(eh2.GetResidueCount()==0);
  BOOST_CHECK(eh2.GetAtomCount()==0);
  BOOST_CHECK(inserted_chain.HasProp("amazing"));
  BOOST_CHECK(eh2.FindChain("Q").IsValid());

  EntityHandle eh3 = CreateEntity();
  XCSEditor e3 = eh3.EditXCS();
  e3.InsertChain("Q",chain,true);
  BOOST_CHECK(eh3.GetResidueCount()==1);
  BOOST_CHECK(eh3.GetAtomCount()==2);

  EntityVisitor v;
  eh.Apply(v);
}

BOOST_AUTO_TEST_CASE(spatial_organizer) 
{
  EntityHandle eh=CreateEntity();
  XCSEditor e=eh.EditXCS();  
  ChainHandle chain = e.InsertChain("A");
  ResidueHandle res = e.AppendResidue(chain, "X");

  AtomHandle a1=e.InsertAtom(res, "X1",geom::Vec3(0.0,0.0,0.0));
  AtomHandle a2=e.InsertAtom(res, "X2",geom::Vec3(1.0,0.0,0.0));
  AtomHandle a3=e.InsertAtom(res, "X3",geom::Vec3(0.0,-1.0,0.0));
  AtomHandle a4=e.InsertAtom(res, "X4",geom::Vec3(17.0,3.0,-33.0));
  AtomHandle a5=e.InsertAtom(res, "X5",geom::Vec3(-2.0,3.0,1.0));

  AtomHandleList ahv = eh.FindWithin(geom::Vec3(0.0,0.0,0.0),5.0);
  BOOST_CHECK_EQUAL(ahv.size(), size_t(4));
  BOOST_CHECK_EQUAL(std::count(ahv.begin(), ahv.end(), a1), 1);
  BOOST_CHECK_EQUAL(std::count(ahv.begin(), ahv.end(), a2), 1);
  BOOST_CHECK_EQUAL(std::count(ahv.begin(), ahv.end(), a3), 1);
  BOOST_CHECK_EQUAL(std::count(ahv.begin(), ahv.end(), a5), 1);
}

BOOST_AUTO_TEST_CASE(transformation) 
{
  EntityHandle eh = CreateEntity();
  XCSEditor e=eh.EditXCS();
  ChainHandle chain = e.InsertChain("A");
  ResidueHandle res = e.AppendResidue(chain, "X");

  AtomHandle atom1 = e.InsertAtom(res, "X1",geom::Vec3(1.0,0.0,0.0));
  AtomHandle atom2 = e.InsertAtom(res, "X2",geom::Vec3(0.0,2.0,0.0));
  AtomHandle atom3 = e.InsertAtom(res, "X3",geom::Vec3(0.0,0.0,-3.0));

  AtomHandleList within_list1 = eh.FindWithin(atom1.GetPos(),2.5);
  BOOST_CHECK(within_list1.size()==2);
  BOOST_CHECK(within_list1[0]==atom1);
  BOOST_CHECK(within_list1[1]==atom2);

  BOOST_CHECK(eh.HasTransform()==false);

  geom::Transform trans;
  trans.ApplyZAxisRotation(90.0);
  e.ApplyTransform(trans);
  BOOST_CHECK(eh.HasTransform()==true);

  geom::Vec3 orig_atom1=geom::Vec3(1.0,0.0,0.0);
  geom::Vec3 orig_atom2=geom::Vec3(0.0,2.0,0.0);
  geom::Vec3 orig_atom3=geom::Vec3(0.0,0.0,-3.0);

  geom::Vec3 tr_atom1=geom::Vec3(0.0,-1.0,0.0);
  geom::Vec3 tr_atom2=geom::Vec3(2.0,0.0,0.0);
  geom::Vec3 tr_atom3=geom::Vec3(0.0,0.0,-3.0);

  CHECK_TRANSFORMED_ATOM_POSITION(atom1,tr_atom1);
  CHECK_ORIGINAL_ATOM_POSITION(atom1,orig_atom1);
  CHECK_TRANSFORMED_ATOM_POSITION(atom2,tr_atom2);
  CHECK_ORIGINAL_ATOM_POSITION(atom2,orig_atom2);
  CHECK_TRANSFORMED_ATOM_POSITION(atom3,tr_atom3);
  CHECK_ORIGINAL_ATOM_POSITION(atom3,orig_atom3);

  geom::Transform trans2;
  trans2.ApplyXAxisTranslation(3.5);
  e.ApplyTransform(trans2);

  BOOST_CHECK(eh.HasTransform()==true);

  tr_atom1=geom::Vec3(3.5,-1.0,0.0);
  tr_atom2=geom::Vec3(5.5,0.0,0.0);
  tr_atom3=geom::Vec3(3.5,0.0,-3.0);

  CHECK_TRANSFORMED_ATOM_POSITION(atom1,tr_atom1);
  CHECK_ORIGINAL_ATOM_POSITION(atom1,orig_atom1);
  CHECK_TRANSFORMED_ATOM_POSITION(atom2,tr_atom2);
  CHECK_ORIGINAL_ATOM_POSITION(atom2,orig_atom2);
  CHECK_TRANSFORMED_ATOM_POSITION(atom3,tr_atom3);
  CHECK_ORIGINAL_ATOM_POSITION(atom3,orig_atom3);

  AtomHandleList within_list2 = eh.FindWithin(atom1.GetPos(),2.5);
  BOOST_CHECK_EQUAL(within_list2.size(), size_t(2));
  BOOST_CHECK_EQUAL(std::count(within_list2.begin(), within_list2.end(), atom1), 1);
  BOOST_CHECK_EQUAL(std::count(within_list2.begin(), within_list2.end(), atom2), 1);  
  e.SetAtomPos(atom3,geom::Vec3(3.5,0.0,0.0));
  e.SetAtomPos(atom1,geom::Vec3(3.5,-0.9,0.0));
  tr_atom3=geom::Vec3(3.5,0.0,0.0);
  orig_atom3=geom::Vec3(0.0,0.0,0.0);
  tr_atom1=geom::Vec3(3.5,-0.9,0.0);
  orig_atom1=geom::Vec3(0.9,0.0,0.0);
  CHECK_TRANSFORMED_ATOM_POSITION(atom3,tr_atom3);
  CHECK_ORIGINAL_ATOM_POSITION(atom3,orig_atom3);
  CHECK_TRANSFORMED_ATOM_POSITION(atom1,tr_atom1);
  CHECK_ORIGINAL_ATOM_POSITION(atom1,orig_atom1);

  AtomHandleList within_list3 = eh.FindWithin(atom1.GetPos(),2.5);
  BOOST_CHECK(within_list3.size()==3);
  BOOST_CHECK_EQUAL(std::count(within_list3.begin(), within_list3.end(), atom1), 1);
  BOOST_CHECK_EQUAL(std::count(within_list3.begin(), within_list3.end(), atom2), 1);
  BOOST_CHECK_EQUAL(std::count(within_list3.begin(), within_list3.end(), atom3), 1);    

  geom::Vec3 new_orig1 = geom::Vec3(0.0,0.0,0.0);
  geom::Vec3 new_orig2 = geom::Vec3(1.5,0.0,0.0);
  geom::Vec3 new_orig3 = geom::Vec3(0.0,0.0,-2.0);

  e.SetAtomOriginalPos(atom1,new_orig1);
  e.SetAtomOriginalPos(atom2,new_orig2);
  e.SetAtomOriginalPos(atom3,new_orig3);

  geom::Mat4 identity;
  e.SetTransform(identity);
  //BOOST_CHECK(eh.HasTransform()==false);

  BondHandle bond1 = e.Connect(atom1,atom2);
  BondHandle bond2 = e.Connect(atom1,atom3);

  BOOST_CHECK(bond1.GetLength()==1.5);
  BOOST_CHECK(bond2.GetLength()==2.0);

  e.SetTransform(trans);
  
  //BOOST_CHECK(eh.HasTransform()==true);

  BOOST_CHECK(bond1.GetLength()==1.5);
  BOOST_CHECK(bond2.GetLength()==2.0);
  ICSEditor i = eh.EditICS();
  i.SetBondLength(bond1,1.0);
  i.SetBondLength(bond2,3.0);

  BOOST_CHECK(bond1.GetLength()==1.0);
  BOOST_CHECK(bond2.GetLength()==3.0);

  geom::Vec3 atom1_af = geom::Vec3(0.0,0.0,0.0);
  geom::Vec3 atom2_af = geom::Vec3(1.0,0.0,0.0);
  geom::Vec3 atom3_af = geom::Vec3(0.0,0.0,-3.0);

  CHECK_ORIGINAL_ATOM_POSITION(atom1,atom1_af);
  CHECK_ORIGINAL_ATOM_POSITION(atom2,atom2_af);
  CHECK_ORIGINAL_ATOM_POSITION(atom3,atom3_af);

  geom::Vec3 atom1_tr = geom::Vec3(0.0,0.0,0.0);
  geom::Vec3 atom2_tr = geom::Vec3(0.0,-1.0,0.0);
  geom::Vec3 atom3_tr = geom::Vec3(0.0,0.0,-3.0);

  CHECK_TRANSFORMED_ATOM_POSITION(atom1,atom1_tr);
  CHECK_TRANSFORMED_ATOM_POSITION(atom2,atom2_tr);
  CHECK_TRANSFORMED_ATOM_POSITION(atom3,atom3_tr);
  i.SetAngle(atom2,atom1,atom3,M_PI);

  atom1_af = geom::Vec3(0.0,0.0,0.0);
  atom2_af = geom::Vec3(1.0,0.0,0.0);
  atom3_af = geom::Vec3(-3.0,0.0,0.0);

  CHECK_ORIGINAL_ATOM_POSITION(atom1,atom1_af);
  CHECK_ORIGINAL_ATOM_POSITION(atom2,atom2_af);
  CHECK_ORIGINAL_ATOM_POSITION(atom3,atom3_af);

  atom1_tr = geom::Vec3(0.0,0.0,0.0);
  atom2_tr = geom::Vec3(0.0,-1.0,0.0);
  atom3_tr = geom::Vec3(0.0,3.0,0.0);

  CHECK_TRANSFORMED_ATOM_POSITION(atom1,atom1_tr);
  CHECK_TRANSFORMED_ATOM_POSITION(atom2,atom2_tr);
  CHECK_TRANSFORMED_ATOM_POSITION(atom3,atom3_tr);

  geom::Vec3 orig_atom4 = geom::Vec3(0.0,0.0,2.0);
  geom::Vec3 tr_atom4 = geom::Vec3(0.0,0.0,2.0);
  geom::Vec3 alt_atom4 = geom::Vec3(1.0,0.0,2.0);
  geom::Vec3 tr_alt_atom4 = geom::Vec3(0.0,-1.0,2.0);


  AtomHandle atom4 = e.InsertAltAtom(res, "X4","Set1",geom::Vec3(0.0,0.0,2.0));
  e.AddAltAtomPos("Set2",atom4, alt_atom4);

  CHECK_ORIGINAL_ATOM_POSITION(atom4,orig_atom4);
  CHECK_TRANSFORMED_ATOM_POSITION(atom4,tr_atom4);
  CHECK_ALTERNATE_ATOM_POSITION(atom4,alt_atom4,"Set2");

  res.SwitchAtomPos("Set2");

  CHECK_ORIGINAL_ATOM_POSITION(atom4,alt_atom4);
  CHECK_TRANSFORMED_ATOM_POSITION(atom4,tr_alt_atom4);
  CHECK_ALTERNATE_ATOM_POSITION(atom4,orig_atom4,"Set1");
}

BOOST_AUTO_TEST_CASE(copy) 
{
  EntityHandle eh=make_test_entity();
  EntityHandle cp=eh.Copy();
  BOOST_CHECK_EQUAL(cp.GetName(),eh.GetName());

  ResidueHandle x2=eh.FindResidue("A", mol::ResNum(2));
  BOOST_CHECK_EQUAL(cp.GetAtomCount(),eh.GetAtomCount());
  BOOST_CHECK_EQUAL(cp.GetResidueCount(),eh.GetResidueCount());
  BOOST_CHECK_EQUAL(cp.GetChainCount(),eh.GetChainCount());
  BOOST_CHECK_EQUAL(cp.GetBondCount(),eh.GetBondCount());
  ResidueHandle r1=cp.FindResidue("A", mol::ResNum(1));
  ResidueHandle r2=cp.FindResidue("A", mol::ResNum(2));  
  BOOST_CHECK(mol::BondExists(r1.FindAtom("N"), r1.FindAtom("CA")));
  BOOST_CHECK(mol::BondExists(r1.FindAtom("CA"), r1.FindAtom("C")));
  BOOST_CHECK(mol::BondExists(r1.FindAtom("C"), r1.FindAtom("O")));
  
  BOOST_CHECK(mol::BondExists(r1.FindAtom("C"), r2.FindAtom("N")));   
  
  BOOST_CHECK(mol::BondExists(r2.FindAtom("N"), r2.FindAtom("CA")));
  BOOST_CHECK(mol::BondExists(r2.FindAtom("CA"), r2.FindAtom("C")));
  BOOST_CHECK(mol::BondExists(r2.FindAtom("C"), r2.FindAtom("O")));
  BOOST_CHECK(r2.GetPhiTorsion());
}

BOOST_AUTO_TEST_CASE(copy_residue_props)
{
  EntityHandle ent=mol::CreateEntity();
  XCSEditor edi=ent.EditXCS();
  ChainHandle ch=edi.InsertChain("A");
  ResidueHandle res=edi.AppendResidue(ch, "DUMMY", mol::ResNum(666, '6'));
  res.SetOneLetterCode('X');
  res.SetIsProtein(true);
  res.SetIsLigand(true);
  ChemClass cl(ChemClass::L_PEPTIDE_LINKING);  
  res.SetSecStructure(SecStructure(SecStructure::ALPHA_HELIX));
  res.SetChemClass(cl);
  EntityHandle copy=ent.Copy();
  ResidueHandle res2=copy.GetResidueList()[0];
  BOOST_CHECK_EQUAL(res2.GetName(), String("DUMMY"));
  BOOST_CHECK_EQUAL(res2.GetOneLetterCode(), 'X');

  BOOST_CHECK_EQUAL(res2.GetChemClass(), cl);
  BOOST_CHECK_EQUAL(res.GetSecStructure(), SecStructure::ALPHA_HELIX);
  BOOST_CHECK(res2.IsProtein()==true);
  BOOST_CHECK(res2.IsLigand()==true);  
  BOOST_CHECK_EQUAL(res2.GetNumber(), ResNum(666, '6'));
}

BOOST_AUTO_TEST_CASE(copy_atom_props)
{
  EntityHandle ent=mol::CreateEntity();
  XCSEditor edi=ent.EditXCS();
  ChainHandle ch=edi.InsertChain("A");
  ResidueHandle res=edi.AppendResidue(ch, "DUMMY");
  AtomHandle   atom=edi.InsertAtom(res, "X", geom::Vec3(1,2,3), "C");
  atom.SetMass(100.0);
  atom.SetBFactor(200.0);
  atom.SetOccupancy(300.0);
  atom.SetHetAtom(true);
  atom.SetRadius(500);
  atom.SetCharge(800);
  atom.SetAnisou(geom::Mat3(100,200,300));
  EntityHandle copy=ent.Copy();
  AtomHandle atom2=copy.GetAtomList()[0];
  BOOST_CHECK_EQUAL(atom2.GetPos(), geom::Vec3(1,2,3));
  BOOST_CHECK_EQUAL(atom2.GetName(), String("X"));
  BOOST_CHECK_EQUAL(atom2.GetElement(), String("C"));
  BOOST_CHECK_EQUAL(atom2.GetMass(), Real(100.0));
  BOOST_CHECK_EQUAL(atom2.GetCharge(), Real(800.0));  
  BOOST_CHECK_EQUAL(atom2.GetBFactor(), Real(200.0)); 
  BOOST_CHECK_EQUAL(atom2.IsHetAtom(), true);
  BOOST_CHECK_EQUAL(atom2.GetAnisou(), geom::Mat3(100,200,300));
  BOOST_CHECK_EQUAL(atom2.GetRadius(), Real(500.0));
}

BOOST_AUTO_TEST_CASE(rename_atom)
{
   EntityHandle ent=CreateEntity();
   XCSEditor edi=ent.EditXCS();
   ChainHandle ch1=edi.InsertChain("A");
   ResidueHandle res = edi.AppendResidue(ch1, "A");
   AtomHandle   atom=edi.InsertAtom(res, "A", geom::Vec3(1,2,3), "C");
   edi.RenameAtom(atom, "B");
   BOOST_CHECK_EQUAL(atom.GetName(), "B");
}

BOOST_AUTO_TEST_CASE(minmax)
{
  EntityHandle eh=make_test_entity();
  EntityView ev = eh.CreateFullView();
  mol::AtomViewList avl = ev.GetAtomList();
  mol::AtomViewList::iterator i;
  int n=0.0;
  for (i=avl.begin(); i!=avl.end(); ++i, ++n) {
    i->SetFloatProp("test", n);
  }
  std::pair<float,float> minmax = ev.GetMinMax("test", Prop::ATOM);
  BOOST_CHECK_EQUAL(minmax.first, 0.0);
  BOOST_CHECK_EQUAL(minmax.second, 7.0);
}

BOOST_AUTO_TEST_CASE(prune) {
  EntityHandle ent=mol::CreateEntity();
  XCSEditor edi = ent.EditXCS();

  ChainHandle ch1 = edi.InsertChain("A");
  ChainHandle ch2 = edi.InsertChain("B");

  ResidueHandle res1_1 = edi.AppendResidue(ch1, "DUMMY");
  ResidueHandle res1_2 = edi.AppendResidue(ch1, "DUMMY");
  AtomHandle   atom1_1_1 = edi.InsertAtom(res1_1, "X", geom::Vec3(1,2,3), "C");
  AtomHandle   atom1_2_1 = edi.InsertAtom(res1_2, "X", geom::Vec3(1,2,3), "C");

  ResidueHandle res2_1 = edi.AppendResidue(ch2, "DUMMY");
  ResidueHandle res2_2 = edi.AppendResidue(ch2, "DUMMY");
  AtomHandle   atom2_1_1 = edi.InsertAtom(res2_1, "X", geom::Vec3(1,2,3), "C");
  AtomHandle   atom2_2_1 = edi.InsertAtom(res2_2, "X", geom::Vec3(1,2,3), "C");

  BOOST_CHECK_EQUAL(ent.GetChainCount(), 2);
  BOOST_CHECK_EQUAL(ent.GetResidueCount(), 4);
  BOOST_CHECK_EQUAL(ent.GetAtomCount(), 4);

  // shouldn't do anything
  edi.Prune();
  BOOST_CHECK_EQUAL(ent.GetChainCount(), 2);
  BOOST_CHECK_EQUAL(ent.GetResidueCount(), 4);
  BOOST_CHECK_EQUAL(ent.GetAtomCount(), 4);

  // remove one atom, the subsequent prune call should then remove the
  // according residue but the number of chains should remain the same
  edi.DeleteAtom(atom1_1_1);
  edi.Prune();
  BOOST_CHECK_EQUAL(ent.GetChainCount(), 2);
  BOOST_CHECK_EQUAL(ent.GetResidueCount(), 3);
  BOOST_CHECK_EQUAL(ent.GetAtomCount(), 3);

  // remove the second atom from the first chain, the whole chain should then
  // be removed by Prune
  edi.DeleteAtom(atom1_2_1);
  edi.Prune();
  BOOST_CHECK_EQUAL(ent.GetChainCount(), 1);
  BOOST_CHECK_EQUAL(ent.GetResidueCount(), 2);
  BOOST_CHECK_EQUAL(ent.GetAtomCount(), 2);

  // remove both residues from the second chain. The entity should be empty
  // afterwards
  edi.DeleteResidue(res2_1);
  edi.DeleteResidue(res2_2);
  edi.Prune();
  BOOST_CHECK_EQUAL(ent.GetChainCount(), 0);
  BOOST_CHECK_EQUAL(ent.GetResidueCount(), 0);
  BOOST_CHECK_EQUAL(ent.GetAtomCount(), 0);
}

BOOST_AUTO_TEST_SUITE_END();