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
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: moleculeObjectCreator.C,v 1.1.4.1 2007/03/25 22:00:06 oliver Exp $
#include <BALL/CONCEPT/moleculeObjectCreator.h>
#include <BALL/KERNEL/atom.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/KERNEL/forEach.h>
#include <BALL/KERNEL/molecule.h>
#include <BALL/KERNEL/protein.h>
#include <BALL/KERNEL/system.h>
using namespace std;
namespace BALL
{
MoleculeObjectCreator::MoleculeObjectCreator()
: ObjectCreator()
{
}
MoleculeObjectCreator::~MoleculeObjectCreator()
{
#ifdef BALL_DEBUG
cout << "Destructing object " << (void *)this
<< " of class " << RTTI::getName<MoleculeObjectCreator>() << endl;
#endif
}
void MoleculeObjectCreator::clear()
{
ObjectCreator::clear();
}
void MoleculeObjectCreator::initPersistenceManager(TextPersistenceManager &pm)
{
using namespace RTTI;
#define REGISTER(A)\
pm.registerClass(getStreamName<A>(), getNew<A>);
REGISTER(Atom)
REGISTER(Bond)
REGISTER(AtomContainer)
REGISTER(Vector3)
REGISTER(PDBAtom)
REGISTER(Residue)
REGISTER(Chain)
REGISTER(SecondaryStructure)
REGISTER(Protein)
REGISTER(Molecule)
REGISTER(System)
REGISTER(Composite)
REGISTER(Fragment)
REGISTER(Nucleotide)
REGISTER(NucleicAcid)
#undef REGISTER
}
Composite* MoleculeObjectCreator::convertObject(PersistentObject &po)
{
cout << "read object @ " << (void*)&po << endl;
if (RTTI::isKindOf<Atom>(&po))
{
Atom* atom = RTTI::castTo<Atom>(po);
cout << " read atom " << atom->getName() << endl;
return (Composite *)atom;
}
else if (RTTI::isKindOf<Protein>(&po))
{
Protein* p = RTTI::castTo<Protein>(po);
cout << " read protein with "
<< p->count(KernelPredicate<Atom>()) << " atoms." << endl;
AtomIterator atom_it;
Atom::BondIterator bond_it;
Size count = 0;
BALL_FOREACH_BOND(*p, atom_it, bond_it)
{
count++;
}
cout << "read " << count << " bonds" << endl;
System *s = new System;
s->insert(*p);
return (Composite *)s;
}
else if (RTTI::isKindOf<System>(&po))
{
System *s = RTTI::castTo<System>(po);
cout << " read system with "
<< s->count(KernelPredicate<Atom>()) << " atoms." << endl;
AtomIterator atom_it;
Atom::BondIterator bond_it;
Size count = 0;
BALL_FOREACH_BOND(*s, atom_it, bond_it)
{
count++;
}
cout << "read " << count << " bonds" << endl;
return (Composite *)s;
}
else
{
cout << "read something strange!" << endl;
}
return 0;
}
} // namespace BALL
|