BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 00005 #ifndef BALL_KERNEL_ATOM_H 00006 #define BALL_KERNEL_ATOM_H 00007 00008 #ifndef BALL_CONCEPT_COMPOSITE_H 00009 # include <BALL/CONCEPT/composite.h> 00010 #endif 00011 00012 #ifndef BALL_CONCEPT_PROPERTY_H 00013 # include <BALL/CONCEPT/property.h> 00014 #endif 00015 00016 #ifndef BALL_CONCEPT_RANDOMACCESSITERATOR_H 00017 # include <BALL/CONCEPT/randomAccessIterator.h> 00018 #endif 00019 00020 #ifndef BALL_MATHS_VECTOR3_H 00021 # include <BALL/MATHS/vector3.h> 00022 #endif 00023 00024 // Defines for default values for an atom 00025 #define BALL_ATOM_DEFAULT_ELEMENT &Element::UNKNOWN 00026 #define BALL_ATOM_DEFAULT_CHARGE 0 00027 #define BALL_ATOM_DEFAULT_FORMAL_CHARGE 0 00028 #define BALL_ATOM_DEFAULT_NAME "" 00029 #define BALL_ATOM_DEFAULT_TYPE_NAME "?" 00030 #define BALL_ATOM_DEFAULT_POSITION 0,0,0 00031 #define BALL_ATOM_DEFAULT_RADIUS 0 00032 #define BALL_ATOM_DEFAULT_TYPE Atom::UNKNOWN_TYPE 00033 #define BALL_ATOM_DEFAULT_VELOCITY 0,0,0 00034 #define BALL_ATOM_DEFAULT_FORCE 0,0,0 00035 00036 namespace BALL 00037 { 00038 class Bond; 00039 class Element; 00040 class Fragment; 00041 class Residue; 00042 class Chain; 00043 class SecondaryStructure; 00044 class Molecule; 00045 00086 class BALL_EXPORT Atom 00087 : public Composite, 00088 public PropertyManager 00089 { 00090 public: 00091 00096 friend class Bond; 00097 00098 BALL_CREATE_DEEP(Atom) 00099 00100 00102 typedef short Type; 00103 00107 00110 enum 00111 { 00115 UNKNOWN_TYPE = -1, 00116 00120 ANY_TYPE = 0, 00121 00123 MAX_NUMBER_OF_BONDS = 12 00124 }; 00125 00129 enum Property 00130 { 00131 NUMBER_OF_PROPERTIES = 0 00132 }; 00133 00137 enum FullNameType 00138 { 00139 // Do not add extensions 00140 NO_VARIANT_EXTENSIONS, 00141 // Add the residue extensions 00142 ADD_VARIANT_EXTENSIONS, 00143 // Add the residue ID 00144 ADD_RESIDUE_ID, 00145 // Add the residue ID and the residue extension 00146 ADD_VARIANT_EXTENSIONS_AND_ID, 00147 // Add the chain ID and the residue ID 00148 ADD_CHAIN_RESIDUE_ID, 00149 // Add the chain ID and the residue ID 00150 ADD_VARIANT_EXTENSIONS_AND_CHAIN_RESIDUE_ID 00151 }; 00152 00154 00158 00176 Atom(); 00177 00188 Atom(const Atom& atom, bool deep = true); 00189 00206 Atom(Element& element, 00207 const String& name, const String& type_name = BALL_ATOM_DEFAULT_TYPE_NAME, 00208 Type atom_type = BALL_ATOM_DEFAULT_TYPE, 00209 const Vector3& position = Vector3(BALL_ATOM_DEFAULT_POSITION), 00210 const Vector3& velocity = Vector3(BALL_ATOM_DEFAULT_VELOCITY), 00211 const Vector3& force = Vector3(BALL_ATOM_DEFAULT_FORCE), 00212 float charge = BALL_ATOM_DEFAULT_CHARGE, 00213 float radius = BALL_ATOM_DEFAULT_RADIUS, 00214 Index formal_charge = BALL_ATOM_DEFAULT_FORMAL_CHARGE); 00215 00217 00221 00228 virtual ~Atom(); 00229 00239 virtual void clear(); 00240 00246 virtual void destroy(); 00247 00249 00252 00256 virtual void persistentWrite(PersistenceManager& pm, const char* name = 0) const; 00257 00261 virtual void persistentRead(PersistenceManager& pm); 00262 00264 00267 00277 void set(const Atom& atom, bool deep = true); 00278 00284 void get(Atom& atom, bool deep = true) const; 00285 00294 Atom& operator = (const Atom& atom); 00295 00300 void swap(Atom& atom); 00301 00303 00306 00311 bool operator == (const Atom& atom) const; 00312 00316 bool operator != (const Atom& atom) const; 00317 00319 00322 00324 void setElement(const Element& element); 00325 00327 const Element& getElement() const; 00328 00333 void setCharge(float charge); 00334 00339 float getCharge() const; 00340 00342 void setFormalCharge(Index formal_charge); 00343 00345 Index getFormalCharge() const; 00346 00354 const Molecule* getMolecule() const; 00356 Molecule* getMolecule(); 00357 00358 00366 const Fragment* getFragment() const; 00368 Fragment* getFragment(); 00369 00377 const Residue* getResidue() const; 00379 Residue* getResidue(); 00380 00386 const SecondaryStructure* getSecondaryStructure() const; 00388 SecondaryStructure* getSecondaryStructure(); 00389 00395 const Chain* getChain() const; 00397 Chain* getChain(); 00398 00400 void setName(const String& name); 00401 00403 const String& getName() const; 00404 00434 String getFullName(FullNameType type = ADD_VARIANT_EXTENSIONS) const; 00435 00439 void setPosition(const Vector3& position); 00440 00442 Vector3& getPosition(); 00443 00445 const Vector3& getPosition() const; 00446 00450 void setRadius(float radius); 00451 00453 float getRadius() const; 00454 00456 void setType(Type atom_type); 00457 00459 Type getType() const; 00460 00462 String getTypeName() const; 00463 00465 void setTypeName(const String& name); 00466 00470 void setVelocity(const Vector3& velocity); 00471 00475 Vector3& getVelocity(); 00476 00480 const Vector3& getVelocity() const; 00481 00485 void setForce(const Vector3& force); 00487 const Vector3& getForce() const; 00489 Vector3& getForce(); 00490 00491 00493 Size countBonds() const; 00494 00507 Bond* getBond(Position index); 00508 00512 const Bond* getBond(Position index) const; 00513 00521 Bond* getBond(const Atom& atom); 00522 00530 const Bond* getBond(const Atom& atom) const; 00532 00533 00537 00547 Bond* createBond(Atom& atom); 00548 00560 Bond* createBond(Bond& bond, Atom& atom); 00561 00566 Bond* cloneBond(Bond& bond, Atom& atom); 00567 00579 bool destroyBond(const Atom& atom); 00580 00592 void destroyBonds(); 00593 00602 Atom* getPartnerAtom(Position i); 00603 00612 const Atom* getPartnerAtom(Position i) const; 00613 00620 float getDistance(const Atom& a) const; 00621 00623 00627 00634 bool hasBond(const Bond& bond) const; 00635 00644 bool isBoundTo(const Atom& atom) const; 00645 00651 bool isBound() const; 00652 00660 bool isGeminal(const Atom& atom) const; 00661 00668 bool isVicinal(const Atom& atom) const; 00670 00674 00679 virtual bool isValid() const; 00680 00688 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const; 00690 00694 00700 bool applyBonds(UnaryProcessor<Bond>& processor); 00701 00703 00706 00707 typedef Index BondIteratorPosition; 00708 00709 class BALL_EXPORT BondIteratorTraits 00710 { 00711 public: 00712 00713 BALL_CREATE_DEEP(BondIteratorTraits) 00714 00715 virtual ~BondIteratorTraits() {} 00716 00717 BondIteratorTraits() 00718 : bound_(0), 00719 position_(0) 00720 { 00721 } 00722 00723 BondIteratorTraits(const Atom& atom) 00724 : bound_((Atom*)&atom), 00725 position_(0) 00726 { 00727 } 00728 00729 BondIteratorTraits(const BondIteratorTraits& traits, bool /* deep */ = true) 00730 : bound_(traits.bound_), 00731 position_(traits.position_) 00732 { 00733 } 00734 00735 BondIteratorTraits& operator = (const BondIteratorTraits& traits) 00736 { 00737 bound_ = traits.bound_; 00738 position_ = traits.position_; 00739 return *this; 00740 } 00741 00742 Atom* getContainer() { return bound_; } 00743 00744 const Atom* getContainer() const { return bound_; } 00745 00746 bool isSingular() const { return (bound_ == 0); } 00747 00748 BondIteratorPosition& getPosition() { return position_; } 00749 00750 const BondIteratorPosition& getPosition() const { return position_; } 00751 00752 // Comparison: We do net check whether these traits are bound to 00753 // the same container here for efficiency reasons. 00754 00755 bool operator == (const BondIteratorTraits& traits) const 00756 { 00757 return (position_ == traits.position_); 00758 } 00759 00760 bool operator != (const BondIteratorTraits& traits) const 00761 { 00762 return !(position_ == traits.position_); 00763 } 00764 00765 bool operator < (const BondIteratorTraits& traits) const 00766 { 00767 return (position_ < traits.position_); 00768 } 00769 00770 Distance getDistance(const BondIteratorTraits& traits) const 00771 { 00772 return (Distance)(position_ - traits.position_); 00773 } 00774 00775 bool isValid() const 00776 { 00777 return (bound_ != 0 && position_ >= 0 && position_ < bound_->number_of_bonds_); 00778 } 00779 00780 void invalidate() 00781 { 00782 bound_ = 0; 00783 position_ = 0; 00784 } 00785 00786 void toBegin() { position_ = 0; } 00787 00788 bool isBegin() const { return (position_ == 0); } 00789 00790 void toEnd() { position_ = bound_->number_of_bonds_; } 00791 00792 bool isEnd() const { return (position_ >= bound_->number_of_bonds_);} 00793 00794 Bond& getData() { return *(bound_->bond_[position_]); } 00795 00796 const Bond& getData() const { return *(bound_->bond_[position_]); } 00797 00798 void forward() { ++position_; } 00799 00800 friend std::ostream& operator << (std::ostream& s, const BondIteratorTraits& traits) 00801 { 00802 return (s << traits.position_ << ' '); 00803 } 00804 00805 void dump(std::ostream& s) const 00806 { 00807 s << position_ << std::endl; 00808 } 00809 00810 void toRBegin() 00811 { 00812 position_ = bound_->number_of_bonds_ - 1; 00813 } 00814 00815 bool isRBegin() const 00816 { 00817 return (position_ == bound_->number_of_bonds_ - 1); 00818 } 00819 00820 void toREnd() 00821 { 00822 position_ = -1; 00823 } 00824 00825 bool isREnd() const 00826 { 00827 return (position_ <= -1); 00828 } 00829 00830 void backward() 00831 { 00832 --position_; 00833 } 00834 00835 void backward(Distance distance) 00836 { 00837 position_ -= distance; 00838 } 00839 00840 void forward(Distance distance) 00841 { 00842 position_ += distance; 00843 } 00844 00845 Bond& getData(Index index) 00846 { 00847 return *(bound_->bond_[index]); 00848 } 00849 00850 const Bond& getData(Index index) const 00851 { 00852 return *(bound_->bond_[index]); 00853 } 00854 00855 private: 00856 00857 Atom* bound_; 00858 BondIteratorPosition position_; 00859 00860 }; 00861 00862 friend class BondIteratorTraits; 00863 00866 typedef RandomAccessIterator 00867 <Atom, Bond, BondIteratorPosition, BondIteratorTraits> 00868 BondIterator; 00869 00871 BondIterator beginBond() 00872 { 00873 return BondIterator::begin(*this); 00874 } 00875 00877 BondIterator endBond() 00878 { 00879 return BondIterator::end(*this); 00880 } 00881 00883 typedef ConstRandomAccessIterator 00884 <Atom, Bond, BondIteratorPosition, BondIteratorTraits> 00885 BondConstIterator; 00886 00888 BondConstIterator beginBond() const 00889 { 00890 return BondConstIterator::begin(*this); 00891 } 00892 00894 BondConstIterator endBond() const 00895 { 00896 return BondConstIterator::end(*this); 00897 } 00898 00900 typedef std::reverse_iterator<BondIterator> BondReverseIterator; 00901 00903 BondReverseIterator rbeginBond() 00904 { 00905 return BondReverseIterator(endBond()); 00906 } 00907 00909 BondReverseIterator rendBond() 00910 { 00911 return BondReverseIterator(beginBond()); 00912 } 00913 00915 typedef std::reverse_iterator<BondConstIterator> BondConstReverseIterator; 00916 00918 BondConstReverseIterator rbeginBond() const 00919 { 00920 return BondConstReverseIterator(endBond()); 00921 } 00922 00924 BondConstReverseIterator rendBond() const 00925 { 00926 return BondConstReverseIterator(beginBond()); 00927 } 00928 00930 00933 00935 typedef std::list<Atom*> AtomPtrList; 00936 00938 typedef std::list<Position> AtomIndexList; 00939 00940 protected: 00941 00943 00946 00948 static AtomIndexList free_list_; 00949 00951 String name_; 00953 String type_name_; 00955 const Element* element_; 00957 float radius_; 00959 Type type_; 00961 unsigned char number_of_bonds_; 00963 Bond* bond_[MAX_NUMBER_OF_BONDS]; 00965 Index formal_charge_; 00967 Vector3 position_; 00969 float charge_; 00971 Vector3 velocity_; 00973 Vector3 force_; 00975 00976 00977 00978 private: 00979 00981 void clear_(); 00982 00984 void swapLastBond_(const Atom* atom); 00985 00986 }; 00987 00988 // required for visual studio 00989 #ifdef BALL_COMPILER_MSVC 00990 #include <vector> 00991 template class BALL_EXPORT std::vector<Atom*>; 00992 #endif 00993 00994 # ifndef BALL_NO_INLINE_FUNCTIONS 00995 # include <BALL/KERNEL/atom.iC> 00996 # endif 00997 } // namespace BALL 00998 00999 #ifndef BALL_KERNEL_BONDITERATOR_H 01000 # include <BALL/KERNEL/bondIterator.h> 01001 #endif 01002 01003 01004 #endif // BALL_KERNEL_ATOM_H