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 const Vector3& getVelocity() const;
00480
00484 void setForce(const Vector3& force);
00486 const Vector3& getForce() const;
00488 Vector3& getForce();
00489
00490
00492 Size countBonds() const;
00493
00506 Bond* getBond(Position index)
00507 throw(Exception::IndexOverflow);
00508
00512 const Bond* getBond(Position index) const
00513 throw(Exception::IndexOverflow);
00514
00522 Bond* getBond(const Atom& atom);
00523
00531 const Bond* getBond(const Atom& atom) const;
00533
00534
00538
00546 Bond* createBond(Atom& atom)
00547 throw(Exception::TooManyBonds);
00548
00558 Bond* createBond(Bond& bond, Atom& atom)
00559 throw(Exception::TooManyBonds);
00560
00565 Bond* cloneBond(Bond& bond, Atom& atom);
00566
00578 bool destroyBond(const Atom& atom);
00579
00591 void destroyBonds();
00592
00601 Atom* getPartnerAtom(Position i) throw(Exception::IndexOverflow);
00602
00609 const Atom* getPartnerAtom(Position i) const throw(Exception::IndexOverflow);
00610
00617 float getDistance(const Atom& a) const;
00618
00620
00624
00631 bool hasBond(const Bond& bond) const;
00632
00641 bool isBoundTo(const Atom& atom) const;
00642
00648 bool isBound() const;
00649
00657 bool isGeminal(const Atom& atom) const;
00658
00665 bool isVicinal(const Atom& atom) const;
00667
00671
00676 virtual bool isValid() const;
00677
00685 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00687
00691
00697 bool applyBonds(UnaryProcessor<Bond>& processor);
00698
00700
00703
00704 typedef Index BondIteratorPosition;
00705
00706 class BALL_EXPORT BondIteratorTraits
00707 {
00708 public:
00709
00710 BALL_CREATE_DEEP(BondIteratorTraits)
00711
00712 virtual ~BondIteratorTraits() {}
00713
00714 BondIteratorTraits()
00715 : bound_(0),
00716 position_(0)
00717 {
00718 }
00719
00720 BondIteratorTraits(const Atom& atom)
00721 : bound_((Atom*)&atom),
00722 position_(0)
00723 {
00724 }
00725
00726 BondIteratorTraits(const BondIteratorTraits& traits, bool = true)
00727 : bound_(traits.bound_),
00728 position_(traits.position_)
00729 {
00730 }
00731
00732 BondIteratorTraits& operator = (const BondIteratorTraits& traits)
00733 {
00734 bound_ = traits.bound_;
00735 position_ = traits.position_;
00736 return *this;
00737 }
00738
00739 Atom* getContainer() { return bound_; }
00740
00741 const Atom* getContainer() const { return bound_; }
00742
00743 bool isSingular() const { return (bound_ == 0); }
00744
00745 BondIteratorPosition& getPosition() { return position_; }
00746
00747 const BondIteratorPosition& getPosition() const { return position_; }
00748
00749
00750
00751
00752 bool operator == (const BondIteratorTraits& traits) const
00753 {
00754 return (position_ == traits.position_);
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 Distance getDistance(const BondIteratorTraits& traits) const
00768 {
00769 return (Distance)(position_ - traits.position_);
00770 }
00771
00772 bool isValid() const
00773 {
00774 return (bound_ != 0 && position_ >= 0 && position_ < bound_->number_of_bonds_);
00775 }
00776
00777 void invalidate()
00778 {
00779 bound_ = 0;
00780 position_ = 0;
00781 }
00782
00783 void toBegin() { position_ = 0; }
00784
00785 bool isBegin() const { return (position_ == 0); }
00786
00787 void toEnd() { position_ = bound_->number_of_bonds_; }
00788
00789 bool isEnd() const { return (position_ >= bound_->number_of_bonds_);}
00790
00791 Bond& getData() { return *(bound_->bond_[position_]); }
00792
00793 const Bond& getData() const { return *(bound_->bond_[position_]); }
00794
00795 void forward() { ++position_; }
00796
00797 friend std::ostream& operator << (std::ostream& s, const BondIteratorTraits& traits)
00798 {
00799 return (s << traits.position_ << ' ');
00800 }
00801
00802 void dump(std::ostream& s) const
00803 {
00804 s << position_ << std::endl;
00805 }
00806
00807 void toRBegin()
00808 {
00809 position_ = bound_->number_of_bonds_ - 1;
00810 }
00811
00812 bool isRBegin() const
00813 {
00814 return (position_ == bound_->number_of_bonds_ - 1);
00815 }
00816
00817 void toREnd()
00818 {
00819 position_ = -1;
00820 }
00821
00822 bool isREnd() const
00823 {
00824 return (position_ <= -1);
00825 }
00826
00827 void backward()
00828 {
00829 --position_;
00830 }
00831
00832 void backward(Distance distance)
00833 {
00834 position_ -= distance;
00835 }
00836
00837 void forward(Distance distance)
00838 {
00839 position_ += distance;
00840 }
00841
00842 Bond& getData(Index index)
00843 {
00844 return *(bound_->bond_[index]);
00845 }
00846
00847 const Bond& getData(Index index) const
00848 {
00849 return *(bound_->bond_[index]);
00850 }
00851
00852 private:
00853
00854 Atom* bound_;
00855 BondIteratorPosition position_;
00856
00857 };
00858
00859 friend class BondIteratorTraits;
00860
00863 typedef RandomAccessIterator
00864 <Atom, Bond, BondIteratorPosition, BondIteratorTraits>
00865 BondIterator;
00866
00868 BondIterator beginBond()
00869 {
00870 return BondIterator::begin(*this);
00871 }
00872
00874 BondIterator endBond()
00875 {
00876 return BondIterator::end(*this);
00877 }
00878
00880 typedef ConstRandomAccessIterator
00881 <Atom, Bond, BondIteratorPosition, BondIteratorTraits>
00882 BondConstIterator;
00883
00885 BondConstIterator beginBond() const
00886 {
00887 return BondConstIterator::begin(*this);
00888 }
00889
00891 BondConstIterator endBond() const
00892 {
00893 return BondConstIterator::end(*this);
00894 }
00895
00897 typedef std::reverse_iterator<BondIterator> BondReverseIterator;
00898
00900 BondReverseIterator rbeginBond()
00901 {
00902 return BondReverseIterator(endBond());
00903 }
00904
00906 BondReverseIterator rendBond()
00907 {
00908 return BondReverseIterator(beginBond());
00909 }
00910
00912 typedef std::reverse_iterator<BondConstIterator> BondConstReverseIterator;
00913
00915 BondConstReverseIterator rbeginBond() const
00916 {
00917 return BondConstReverseIterator(endBond());
00918 }
00919
00921 BondConstReverseIterator rendBond() const
00922 {
00923 return BondConstReverseIterator(beginBond());
00924 }
00925
00927
00930
00932 class BALL_EXPORT StaticAtomAttributes
00933 {
00934 public:
00936 Index formal_charge;
00938 float charge;
00940 Vector3 position;
00942 Type type;
00944 Vector3 velocity;
00946 Vector3 force;
00948 Atom* ptr;
00949
00951 void clear();
00952
00958 void swap(StaticAtomAttributes& attr);
00959
00962 void set(StaticAtomAttributes& attr);
00963
00966 StaticAtomAttributes& operator = (const StaticAtomAttributes& attr);
00967 };
00968
00970 class BALL_EXPORT AttributeVector
00971 : public std::vector<StaticAtomAttributes>
00972 {
00973 public:
00974 ~AttributeVector();
00975 };
00976
00978 typedef std::list<Atom*> AtomPtrList;
00979
00981 typedef std::list<Position> AtomIndexList;
00982
00988 static Position compact(const AtomIndexList& indices)
00989 throw(Exception::OutOfRange);
00990
00993 static AttributeVector& getAttributes();
00994
00997 Position getIndex() const;
00998
00999 StaticAtomAttributes* getAttributePtr();
01000 const StaticAtomAttributes* getAttributePtr() const;
01001
01007 static const PreciseTime& getAttributesModificationTime()
01008 { return attributes_changed_time_;}
01009
01010 protected:
01011
01013
01016
01018 static AttributeVector static_attributes_;
01019
01021 static AtomIndexList free_list_;
01022
01024 static PreciseTime attributes_changed_time_;
01025
01027 Position index_;
01029 const Element* element_;
01031 String name_;
01033 String type_name_;
01035 float radius_;
01037 unsigned char number_of_bonds_;
01039 Bond* bond_[MAX_NUMBER_OF_BONDS];
01041
01042 private:
01043
01045 static Position nextIndex_();
01046
01048 static void freeIndex_(Position index);
01049
01051 void clear_();
01052
01054 void swapLastBond_(const Atom* atom);
01055
01056 };
01057
01058
01059 #ifdef BALL_COMPILER_MSVC
01060 #include <vector>
01061 template class BALL_EXPORT std::vector<Atom*>;
01062 #endif
01063
01064 # ifndef BALL_NO_INLINE_FUNCTIONS
01065 # include <BALL/KERNEL/atom.iC>
01066 # endif
01067 }
01068
01069 #ifndef BALL_KERNEL_BONDITERATOR_H
01070 # include <BALL/KERNEL/bondIterator.h>
01071 #endif
01072
01073
01074 #endif // BALL_KERNEL_ATOM_H