00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_KERNEL_ATOM_H
00008 #define BALL_KERNEL_ATOM_H
00009
00010 #ifndef BALL_CONCEPT_COMPOSITE_H
00011 # include <BALL/CONCEPT/composite.h>
00012 #endif
00013
00014 #ifndef BALL_CONCEPT_PROPERTY_H
00015 # include <BALL/CONCEPT/property.h>
00016 #endif
00017
00018 #ifndef BALL_CONCEPT_RANDOMACCESSITERATOR_H
00019 # include <BALL/CONCEPT/randomAccessIterator.h>
00020 #endif
00021
00022 #ifndef BALL_MATHS_VECTOR3_H
00023 # include <BALL/MATHS/vector3.h>
00024 #endif
00025
00026
00027 #define BALL_ATOM_DEFAULT_ELEMENT &Element::UNKNOWN
00028 #define BALL_ATOM_DEFAULT_CHARGE 0
00029 #define BALL_ATOM_DEFAULT_FORMAL_CHARGE 0
00030 #define BALL_ATOM_DEFAULT_NAME ""
00031 #define BALL_ATOM_DEFAULT_TYPE_NAME "?"
00032 #define BALL_ATOM_DEFAULT_POSITION 0,0,0
00033 #define BALL_ATOM_DEFAULT_RADIUS 0
00034 #define BALL_ATOM_DEFAULT_TYPE Atom::UNKNOWN_TYPE
00035 #define BALL_ATOM_DEFAULT_VELOCITY 0,0,0
00036 #define BALL_ATOM_DEFAULT_FORCE 0,0,0
00037
00038 namespace BALL
00039 {
00040 class Bond;
00041 class Element;
00042 class Fragment;
00043 class Residue;
00044 class Chain;
00045 class SecondaryStructure;
00046 class Molecule;
00047
00088 class BALL_EXPORT Atom
00089 : public Composite,
00090 public PropertyManager
00091 {
00092 public:
00093
00098 friend class Bond;
00099
00100 BALL_CREATE_DEEP(Atom)
00101
00102
00104 typedef short Type;
00105
00109
00112 enum
00113 {
00117 UNKNOWN_TYPE = -1,
00118
00122 ANY_TYPE = 0,
00123
00125 MAX_NUMBER_OF_BONDS = 12
00126 };
00127
00131 enum Property
00132 {
00133 NUMBER_OF_PROPERTIES = 0
00134 };
00135
00139 enum FullNameType
00140 {
00141
00142 NO_VARIANT_EXTENSIONS,
00143
00144 ADD_VARIANT_EXTENSIONS,
00145
00146 ADD_RESIDUE_ID,
00147
00148 ADD_VARIANT_EXTENSIONS_AND_ID,
00149
00150 ADD_CHAIN_RESIDUE_ID,
00151
00152 ADD_VARIANT_EXTENSIONS_AND_CHAIN_RESIDUE_ID
00153 };
00154
00156
00160
00178 Atom();
00179
00190 Atom(const Atom& atom, bool deep = true);
00191
00208 Atom(Element& element,
00209 const String& name, const String& type_name = BALL_ATOM_DEFAULT_TYPE_NAME,
00210 Type atom_type = BALL_ATOM_DEFAULT_TYPE,
00211 const Vector3& position = Vector3(BALL_ATOM_DEFAULT_POSITION),
00212 const Vector3& velocity = Vector3(BALL_ATOM_DEFAULT_VELOCITY),
00213 const Vector3& force = Vector3(BALL_ATOM_DEFAULT_FORCE),
00214 float charge = BALL_ATOM_DEFAULT_CHARGE,
00215 float radius = BALL_ATOM_DEFAULT_RADIUS,
00216 Index formal_charge = BALL_ATOM_DEFAULT_FORMAL_CHARGE);
00217
00219
00223
00230 virtual ~Atom();
00231
00241 virtual void clear();
00242
00248 virtual void destroy();
00249
00251
00254
00258 virtual void persistentWrite(PersistenceManager& pm, const char* name = 0) const
00259 throw(Exception::GeneralException);
00260
00264 virtual void persistentRead(PersistenceManager& pm)
00265 throw(Exception::GeneralException);
00266
00268
00271
00281 void set(const Atom& atom, bool deep = true);
00282
00288 void get(Atom& atom, bool deep = true) const;
00289
00298 Atom& operator = (const Atom& atom);
00299
00304 void swap(Atom& atom);
00305
00307
00310
00315 bool operator == (const Atom& atom) const;
00316
00320 bool operator != (const Atom& atom) const;
00321
00323
00326
00328 void setElement(const Element& element);
00329
00331 const Element& getElement() const;
00332
00337 void setCharge(float charge);
00338
00343 float getCharge() const;
00344
00346 void setFormalCharge(Index formal_charge);
00347
00349 Index getFormalCharge() const;
00350
00358 const Molecule* getMolecule() const;
00360 Molecule* getMolecule();
00361
00362
00370 const Fragment* getFragment() const;
00372 Fragment* getFragment();
00373
00381 const Residue* getResidue() const;
00383 Residue* getResidue();
00384
00390 const SecondaryStructure* getSecondaryStructure() const;
00392 SecondaryStructure* getSecondaryStructure();
00393
00399 const Chain* getChain() const;
00401 Chain* getChain();
00402
00404 void setName(const String& name);
00405
00407 const String& getName() const;
00408
00438 String getFullName(FullNameType type = ADD_VARIANT_EXTENSIONS) const;
00439
00443 void setPosition(const Vector3& position);
00444
00446 Vector3& getPosition();
00447
00449 const Vector3& getPosition() const;
00450
00454 void setRadius(float radius);
00455
00457 float getRadius() const;
00458
00460 void setType(Type atom_type);
00461
00463 Type getType() const;
00464
00466 String getTypeName() const;
00467
00469 void setTypeName(const String& name);
00470
00474 void setVelocity(const Vector3& velocity);
00475
00479 Vector3& getVelocity();
00480
00484 const Vector3& getVelocity() const;
00485
00489 void setForce(const Vector3& force);
00491 const Vector3& getForce() const;
00493 Vector3& getForce();
00494
00495
00497 Size countBonds() const;
00498
00511 Bond* getBond(Position index)
00512 throw(Exception::IndexOverflow);
00513
00517 const Bond* getBond(Position index) const
00518 throw(Exception::IndexOverflow);
00519
00527 Bond* getBond(const Atom& atom);
00528
00536 const Bond* getBond(const Atom& atom) const;
00538
00539
00543
00551 Bond* createBond(Atom& atom)
00552 throw(Exception::TooManyBonds);
00553
00563 Bond* createBond(Bond& bond, Atom& atom)
00564 throw(Exception::TooManyBonds);
00565
00570 Bond* cloneBond(Bond& bond, Atom& atom);
00571
00583 bool destroyBond(const Atom& atom);
00584
00596 void destroyBonds();
00597
00606 Atom* getPartnerAtom(Position i) throw(Exception::IndexOverflow);
00607
00614 const Atom* getPartnerAtom(Position i) const throw(Exception::IndexOverflow);
00615
00622 float getDistance(const Atom& a) const;
00623
00625
00629
00636 bool hasBond(const Bond& bond) const;
00637
00646 bool isBoundTo(const Atom& atom) const;
00647
00653 bool isBound() const;
00654
00662 bool isGeminal(const Atom& atom) const;
00663
00670 bool isVicinal(const Atom& atom) const;
00672
00676
00681 virtual bool isValid() const;
00682
00690 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00692
00696
00702 bool applyBonds(UnaryProcessor<Bond>& processor);
00703
00705
00708
00709 typedef Index BondIteratorPosition;
00710
00711 class BALL_EXPORT BondIteratorTraits
00712 {
00713 public:
00714
00715 BALL_CREATE_DEEP(BondIteratorTraits)
00716
00717 virtual ~BondIteratorTraits() {}
00718
00719 BondIteratorTraits()
00720 : bound_(0),
00721 position_(0)
00722 {
00723 }
00724
00725 BondIteratorTraits(const Atom& atom)
00726 : bound_((Atom*)&atom),
00727 position_(0)
00728 {
00729 }
00730
00731 BondIteratorTraits(const BondIteratorTraits& traits, bool = true)
00732 : bound_(traits.bound_),
00733 position_(traits.position_)
00734 {
00735 }
00736
00737 BondIteratorTraits& operator = (const BondIteratorTraits& traits)
00738 {
00739 bound_ = traits.bound_;
00740 position_ = traits.position_;
00741 return *this;
00742 }
00743
00744 Atom* getContainer() { return bound_; }
00745
00746 const Atom* getContainer() const { return bound_; }
00747
00748 bool isSingular() const { return (bound_ == 0); }
00749
00750 BondIteratorPosition& getPosition() { return position_; }
00751
00752 const BondIteratorPosition& getPosition() const { return position_; }
00753
00754
00755
00756
00757 bool operator == (const BondIteratorTraits& traits) const
00758 {
00759 return (position_ == traits.position_);
00760 }
00761
00762 bool operator != (const BondIteratorTraits& traits) const
00763 {
00764 return !(position_ == traits.position_);
00765 }
00766
00767 bool operator < (const BondIteratorTraits& traits) const
00768 {
00769 return (position_ < traits.position_);
00770 }
00771
00772 Distance getDistance(const BondIteratorTraits& traits) const
00773 {
00774 return (Distance)(position_ - traits.position_);
00775 }
00776
00777 bool isValid() const
00778 {
00779 return (bound_ != 0 && position_ >= 0 && position_ < bound_->number_of_bonds_);
00780 }
00781
00782 void invalidate()
00783 {
00784 bound_ = 0;
00785 position_ = 0;
00786 }
00787
00788 void toBegin() { position_ = 0; }
00789
00790 bool isBegin() const { return (position_ == 0); }
00791
00792 void toEnd() { position_ = bound_->number_of_bonds_; }
00793
00794 bool isEnd() const { return (position_ >= bound_->number_of_bonds_);}
00795
00796 Bond& getData() { return *(bound_->bond_[position_]); }
00797
00798 const Bond& getData() const { return *(bound_->bond_[position_]); }
00799
00800 void forward() { ++position_; }
00801
00802 friend std::ostream& operator << (std::ostream& s, const BondIteratorTraits& traits)
00803 {
00804 return (s << traits.position_ << ' ');
00805 }
00806
00807 void dump(std::ostream& s) const
00808 {
00809 s << position_ << std::endl;
00810 }
00811
00812 void toRBegin()
00813 {
00814 position_ = bound_->number_of_bonds_ - 1;
00815 }
00816
00817 bool isRBegin() const
00818 {
00819 return (position_ == bound_->number_of_bonds_ - 1);
00820 }
00821
00822 void toREnd()
00823 {
00824 position_ = -1;
00825 }
00826
00827 bool isREnd() const
00828 {
00829 return (position_ <= -1);
00830 }
00831
00832 void backward()
00833 {
00834 --position_;
00835 }
00836
00837 void backward(Distance distance)
00838 {
00839 position_ -= distance;
00840 }
00841
00842 void forward(Distance distance)
00843 {
00844 position_ += distance;
00845 }
00846
00847 Bond& getData(Index index)
00848 {
00849 return *(bound_->bond_[index]);
00850 }
00851
00852 const Bond& getData(Index index) const
00853 {
00854 return *(bound_->bond_[index]);
00855 }
00856
00857 private:
00858
00859 Atom* bound_;
00860 BondIteratorPosition position_;
00861
00862 };
00863
00864 friend class BondIteratorTraits;
00865
00868 typedef RandomAccessIterator
00869 <Atom, Bond, BondIteratorPosition, BondIteratorTraits>
00870 BondIterator;
00871
00873 BondIterator beginBond()
00874 {
00875 return BondIterator::begin(*this);
00876 }
00877
00879 BondIterator endBond()
00880 {
00881 return BondIterator::end(*this);
00882 }
00883
00885 typedef ConstRandomAccessIterator
00886 <Atom, Bond, BondIteratorPosition, BondIteratorTraits>
00887 BondConstIterator;
00888
00890 BondConstIterator beginBond() const
00891 {
00892 return BondConstIterator::begin(*this);
00893 }
00894
00896 BondConstIterator endBond() const
00897 {
00898 return BondConstIterator::end(*this);
00899 }
00900
00902 typedef std::reverse_iterator<BondIterator> BondReverseIterator;
00903
00905 BondReverseIterator rbeginBond()
00906 {
00907 return BondReverseIterator(endBond());
00908 }
00909
00911 BondReverseIterator rendBond()
00912 {
00913 return BondReverseIterator(beginBond());
00914 }
00915
00917 typedef std::reverse_iterator<BondConstIterator> BondConstReverseIterator;
00918
00920 BondConstReverseIterator rbeginBond() const
00921 {
00922 return BondConstReverseIterator(endBond());
00923 }
00924
00926 BondConstReverseIterator rendBond() const
00927 {
00928 return BondConstReverseIterator(beginBond());
00929 }
00930
00932
00935
00937 typedef std::list<Atom*> AtomPtrList;
00938
00940 typedef std::list<Position> AtomIndexList;
00941
00942 protected:
00943
00945
00948
00950 static AtomIndexList free_list_;
00951
00953 String name_;
00955 String type_name_;
00957 const Element* element_;
00959 float radius_;
00961 Type type_;
00963 unsigned char number_of_bonds_;
00965 Bond* bond_[MAX_NUMBER_OF_BONDS];
00967 Index formal_charge_;
00969 Vector3 position_;
00971 float charge_;
00973 Vector3 velocity_;
00975 Vector3 force_;
00977
00978
00979
00980 private:
00981
00983 void clear_();
00984
00986 void swapLastBond_(const Atom* atom);
00987
00988 };
00989
00990
00991 #ifdef BALL_COMPILER_MSVC
00992 #include <vector>
00993 template class BALL_EXPORT std::vector<Atom*>;
00994 #endif
00995
00996 # ifndef BALL_NO_INLINE_FUNCTIONS
00997 # include <BALL/KERNEL/atom.iC>
00998 # endif
00999 }
01000
01001 #ifndef BALL_KERNEL_BONDITERATOR_H
01002 # include <BALL/KERNEL/bondIterator.h>
01003 #endif
01004
01005
01006 #endif // BALL_KERNEL_ATOM_H