BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
atom.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_KERNEL_ATOM_H
6 #define BALL_KERNEL_ATOM_H
7 
8 #ifndef BALL_CONCEPT_COMPOSITE_H
9 # include <BALL/CONCEPT/composite.h>
10 #endif
11 
12 #ifndef BALL_CONCEPT_PROPERTY_H
13 # include <BALL/CONCEPT/property.h>
14 #endif
15 
16 #ifndef BALL_CONCEPT_RANDOMACCESSITERATOR_H
18 #endif
19 
20 #ifndef BALL_MATHS_VECTOR3_H
21 # include <BALL/MATHS/vector3.h>
22 #endif
23 
24 // Defines for default values for an atom
25 #define BALL_ATOM_DEFAULT_ELEMENT &Element::UNKNOWN
26 #define BALL_ATOM_DEFAULT_CHARGE 0
27 #define BALL_ATOM_DEFAULT_FORMAL_CHARGE 0
28 #define BALL_ATOM_DEFAULT_NAME ""
29 #define BALL_ATOM_DEFAULT_TYPE_NAME "?"
30 #define BALL_ATOM_DEFAULT_POSITION 0,0,0
31 #define BALL_ATOM_DEFAULT_RADIUS 0
32 #define BALL_ATOM_DEFAULT_TYPE Atom::UNKNOWN_TYPE
33 #define BALL_ATOM_DEFAULT_VELOCITY 0,0,0
34 #define BALL_ATOM_DEFAULT_FORCE 0,0,0
35 
36 namespace BALL
37 {
38  class Bond;
39  class Element;
40  class Fragment;
41  class Residue;
42  class Chain;
43  class SecondaryStructure;
44  class Molecule;
45  class MolecularInteractions;
46 
88  : public Composite,
89  public PropertyManager
90  {
91  public:
92 
97  friend class Bond;
98 
100 
101 
103  typedef short Type;
104 
108 
111  enum
112  {
116  UNKNOWN_TYPE = -1,
117 
121  ANY_TYPE = 0,
122 
124  MAX_NUMBER_OF_BONDS = 12
125  };
126 
130  enum Property
131  {
132  NUMBER_OF_PROPERTIES = 0
133  };
134 
139  {
140  // Do not add extensions
142  // Add the residue extensions
144  // Add the residue ID
146  // Add the residue ID and the residue extension
148  // Add the chain ID and the residue ID
150  // Add the chain ID and the residue ID
151  ADD_VARIANT_EXTENSIONS_AND_CHAIN_RESIDUE_ID
152  };
153 
155 
159 
177  Atom();
178 
189  Atom(const Atom& atom, bool deep = true);
190 
207  Atom(Element& element,
208  const String& name, const String& type_name = BALL_ATOM_DEFAULT_TYPE_NAME,
209  Type atom_type = BALL_ATOM_DEFAULT_TYPE,
210  const Vector3& position = Vector3(BALL_ATOM_DEFAULT_POSITION),
211  const Vector3& velocity = Vector3(BALL_ATOM_DEFAULT_VELOCITY),
212  const Vector3& force = Vector3(BALL_ATOM_DEFAULT_FORCE),
213  float charge = BALL_ATOM_DEFAULT_CHARGE,
214  float radius = BALL_ATOM_DEFAULT_RADIUS,
215  Index formal_charge = BALL_ATOM_DEFAULT_FORMAL_CHARGE);
216 
218 
222 
229  virtual ~Atom();
230 
240  virtual void clear();
241 
247  virtual void destroy();
248 
250 
253 
257  virtual void persistentWrite(PersistenceManager& pm, const char* name = 0) const;
258 
262  virtual void persistentRead(PersistenceManager& pm);
263 
265 
268 
278  void set(const Atom& atom, bool deep = true);
279 
285  void get(Atom& atom, bool deep = true) const;
286 
295  Atom& operator = (const Atom& atom);
296 
301  void swap(Atom& atom);
302 
304 
307 
312  bool operator == (const Atom& atom) const;
313 
317  bool operator != (const Atom& atom) const;
318 
320 
323 
325  void setElement(const Element& element);
326 
328  const Element& getElement() const;
329 
334  void setCharge(float charge);
335 
340  float getCharge() const;
341 
343  void setFormalCharge(Index formal_charge);
344 
346  Index getFormalCharge() const;
347 
355  const Molecule* getMolecule() const;
357  Molecule* getMolecule();
358 
359 
367  const Fragment* getFragment() const;
369  Fragment* getFragment();
370 
378  const Residue* getResidue() const;
380  Residue* getResidue();
381 
387  const SecondaryStructure* getSecondaryStructure() const;
389  SecondaryStructure* getSecondaryStructure();
390 
396  const Chain* getChain() const;
398  Chain* getChain();
399 
401  void setName(const String& name);
402 
404  const String& getName() const;
405 
435  String getFullName(FullNameType type = ADD_VARIANT_EXTENSIONS) const;
436 
440  void setPosition(const Vector3& position);
441 
443  Vector3& getPosition();
444 
446  const Vector3& getPosition() const;
447 
451  void setRadius(float radius);
452 
454  float getRadius() const;
455 
457  void setType(Type atom_type);
458 
460  Type getType() const;
461 
463  String getTypeName() const;
464 
466  void setTypeName(const String& name);
467 
471  void setVelocity(const Vector3& velocity);
472 
476  Vector3& getVelocity();
477 
481  const Vector3& getVelocity() const;
482 
486  void setForce(const Vector3& force);
488  const Vector3& getForce() const;
490  Vector3& getForce();
491 
492 
494  Size countBonds() const;
495 
508  Bond* getBond(Position index);
509 
513  const Bond* getBond(Position index) const;
514 
522  Bond* getBond(const Atom& atom);
523 
531  const Bond* getBond(const Atom& atom) const;
533 
534 
538 
548  Bond* createBond(Atom& atom);
549 
561  Bond* createBond(Bond& bond, Atom& atom);
562 
567  Bond* cloneBond(Bond& bond, Atom& atom);
568 
580  bool destroyBond(const Atom& atom);
581 
593  void destroyBonds();
594 
603  Atom* getPartnerAtom(Position i);
604 
613  const Atom* getPartnerAtom(Position i) const;
614 
621  float getDistance(const Atom& a) const;
622 
624 
625  void addInteraction(const Atom* atom, String interaction_type, double energy);
626 
627  void addInteraction(String interaction_type, double energy);
628 
629  void disableStoreInteractions();
630 
631  void enableStoreInteractions();
632 
634 
636 
640 
647  bool hasBond(const Bond& bond) const;
648 
657  bool isBoundTo(const Atom& atom) const;
658 
664  bool isBound() const;
665 
673  bool isGeminal(const Atom& atom) const;
674 
681  bool isVicinal(const Atom& atom) const;
683 
686  virtual bool isAtom() const { return true; }
689 
693 
698  virtual bool isValid() const;
699 
707  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
709 
713 
719  bool applyBonds(UnaryProcessor<Bond>& processor);
720 
722 
725 
727 
729  {
730  public:
731 
733 
734  virtual ~BondIteratorTraits() {}
735 
737  : bound_(0),
738  position_(0)
739  {
740  }
741 
743  : bound_((Atom*)&atom),
744  position_(0)
745  {
746  }
747 
748  BondIteratorTraits(const BondIteratorTraits& traits, bool /* deep */ = true)
749  : bound_(traits.bound_),
750  position_(traits.position_)
751  {
752  }
753 
754  BondIteratorTraits& operator = (const BondIteratorTraits& traits)
755  {
756  bound_ = traits.bound_;
757  position_ = traits.position_;
758  return *this;
759  }
760 
761  Atom* getContainer() { return bound_; }
762 
763  const Atom* getContainer() const { return bound_; }
764 
765  bool isSingular() const { return (bound_ == 0); }
766 
767  BondIteratorPosition& getPosition() { return position_; }
768 
769  const BondIteratorPosition& getPosition() const { return position_; }
770 
771  // Comparison: We do net check whether these traits are bound to
772  // the same container here for efficiency reasons.
773 
774  bool operator == (const BondIteratorTraits& traits) const
775  {
776  return (position_ == traits.position_);
777  }
778 
779  bool operator != (const BondIteratorTraits& traits) const
780  {
781  return !(position_ == traits.position_);
782  }
783 
784  bool operator < (const BondIteratorTraits& traits) const
785  {
786  return (position_ < traits.position_);
787  }
788 
790  {
791  return (Distance)(position_ - traits.position_);
792  }
793 
794  bool isValid() const
795  {
796  return (bound_ != 0 && position_ >= 0 && position_ < bound_->number_of_bonds_);
797  }
798 
799  void invalidate()
800  {
801  bound_ = 0;
802  position_ = 0;
803  }
804 
805  void toBegin() { position_ = 0; }
806 
807  bool isBegin() const { return (position_ == 0); }
808 
809  void toEnd() { position_ = bound_->number_of_bonds_; }
810 
811  bool isEnd() const { return (position_ >= bound_->number_of_bonds_);}
812 
813  Bond& getData() { return *(bound_->bond_[position_]); }
814 
815  const Bond& getData() const { return *(bound_->bond_[position_]); }
816 
817  void forward() { ++position_; }
818 
819  friend std::ostream& operator << (std::ostream& s, const BondIteratorTraits& traits)
820  {
821  return (s << traits.position_ << ' ');
822  }
823 
824  void dump(std::ostream& s) const
825  {
826  s << position_ << std::endl;
827  }
828 
829  void toRBegin()
830  {
831  position_ = bound_->number_of_bonds_ - 1;
832  }
833 
834  bool isRBegin() const
835  {
836  return (position_ == bound_->number_of_bonds_ - 1);
837  }
838 
839  void toREnd()
840  {
841  position_ = -1;
842  }
843 
844  bool isREnd() const
845  {
846  return (position_ <= -1);
847  }
848 
849  void backward()
850  {
851  --position_;
852  }
853 
854  void backward(Distance distance)
855  {
856  position_ -= distance;
857  }
858 
859  void forward(Distance distance)
860  {
861  position_ += distance;
862  }
863 
865  {
866  return *(bound_->bond_[index]);
867  }
868 
869  const Bond& getData(Index index) const
870  {
871  return *(bound_->bond_[index]);
872  }
873 
874  private:
875 
876  Atom* bound_;
877  BondIteratorPosition position_;
878 
879  };
880 
881  friend class BondIteratorTraits;
882 
885  typedef RandomAccessIterator
888 
891  {
892  return BondIterator::begin(*this);
893  }
894 
897  {
898  return BondIterator::end(*this);
899  }
900 
903  <Atom, Bond, BondIteratorPosition, BondIteratorTraits>
905 
908  {
909  return BondConstIterator::begin(*this);
910  }
911 
914  {
915  return BondConstIterator::end(*this);
916  }
917 
919  typedef std::reverse_iterator<BondIterator> BondReverseIterator;
920 
923  {
924  return BondReverseIterator(endBond());
925  }
926 
929  {
930  return BondReverseIterator(beginBond());
931  }
932 
934  typedef std::reverse_iterator<BondConstIterator> BondConstReverseIterator;
935 
938  {
939  return BondConstReverseIterator(endBond());
940  }
941 
944  {
945  return BondConstReverseIterator(beginBond());
946  }
947 
949 
952 
954  typedef std::list<Atom*> AtomPtrList;
955 
957  typedef std::list<Position> AtomIndexList;
958 
959  protected:
960 
962 
965 
968 
976  float radius_;
980  unsigned char number_of_bonds_;
982  Bond* bond_[MAX_NUMBER_OF_BONDS];
988  float charge_;
994 
995 
996 
997  private:
998 
1000  void clear_();
1001 
1003  void swapLastBond_(const Atom* atom);
1004 
1005  };
1006 
1007 // required for visual studio
1008 #ifdef BALL_COMPILER_MSVC
1009 #include <vector>
1010 template class BALL_EXPORT std::vector<Atom*>;
1011 #endif
1012 
1013 # ifndef BALL_NO_INLINE_FUNCTIONS
1014 # include <BALL/KERNEL/atom.iC>
1015 # endif
1016 } // namespace BALL
1017 
1018 #ifndef BALL_KERNEL_BONDITERATOR_H
1019 # include <BALL/KERNEL/bondIterator.h>
1020 #endif
1021 
1022 
1023 #endif // BALL_KERNEL_ATOM_H
#define BALL_ATOM_DEFAULT_TYPE_NAME
Definition: atom.h:29
#define BALL_ATOM_DEFAULT_FORCE
Definition: atom.h:34
#define BALL_ATOM_DEFAULT_CHARGE
Definition: atom.h:26
short Type
Definition: atom.h:103
std::reverse_iterator< BondIterator > BondReverseIterator
Reverse random access iterator for bonds.
Definition: atom.h:919
bool store_interactions_disabled_
Definition: atom.h:633
float charge_
Definition: atom.h:988
BondIteratorTraits(const Atom &atom)
Definition: atom.h:742
std::list< Atom * > AtomPtrList
Definition: atom.h:954
void forward(Distance distance)
Definition: atom.h:859
Property
Definition: atom.h:130
BondConstReverseIterator rbeginBond() const
Return a constant reverse bond iterator pointing to the first atom.
Definition: atom.h:937
static AtomIndexList free_list_
Definition: atom.h:967
std::list< Position > AtomIndexList
Definition: atom.h:957
ConstRandomAccessIterator< Atom, Bond, BondIteratorPosition, BondIteratorTraits > BondConstIterator
Constant random access iterator for bonds.
Definition: atom.h:904
BondConstIterator endBond() const
Return a constant past-the-end bond iterator.
Definition: atom.h:913
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
Distance getDistance(const BondIteratorTraits &traits) const
Definition: atom.h:789
RandomAccessIterator< Atom, Bond, BondIteratorPosition, BondIteratorTraits > BondIterator
Definition: atom.h:887
bool isREnd() const
Definition: atom.h:844
Bond & getData(Index index)
Definition: atom.h:864
Vector3 velocity_
Definition: atom.h:990
Index BondIteratorPosition
Definition: atom.h:726
BondConstIterator beginBond() const
Return a constant bond iterator pointing to the first bond.
Definition: atom.h:907
FullNameType
Definition: atom.h:138
BondConstReverseIterator rendBond() const
Return a constant past-the-end bond iterator for reverse traversal.
Definition: atom.h:943
const Bond & getData() const
Definition: atom.h:815
Vector3 force_
Definition: atom.h:992
const Element * element_
Definition: atom.h:974
#define BALL_ATOM_DEFAULT_RADIUS
Definition: atom.h:31
BondIteratorTraits(const BondIteratorTraits &traits, bool=true)
Definition: atom.h:748
bool isRBegin() const
Definition: atom.h:834
const Bond & getData(Index index) const
Definition: atom.h:869
BALL_EXPORT bool operator!=(const String &s1, const String &s2)
#define BALL_ATOM_DEFAULT_FORMAL_CHARGE
Definition: atom.h:27
const char * getName()
Definition: rtti.h:97
#define BALL_CREATE_DEEP(name)
Definition: create.h:26
bool isSingular() const
Definition: atom.h:765
TVector3< float > Vector3
Definition: vector3.h:1084
bool isBegin() const
Definition: atom.h:807
BondReverseIterator rbeginBond()
Return a reverse bond iterator pointing to the last bond.
Definition: atom.h:922
void backward(Distance distance)
Definition: atom.h:854
String name_
Definition: atom.h:970
MolecularInteractions * interactions
Definition: atom.h:623
BondIterator beginBond()
Return a bond iterator pointing to the first bond of the atom.
Definition: atom.h:890
#define BALL_ATOM_DEFAULT_VELOCITY
Definition: atom.h:33
Vector3 position_
Definition: atom.h:986
BondReverseIterator rendBond()
Return a past-the-end bond iterator for reverse traversal.
Definition: atom.h:928
String type_name_
Definition: atom.h:972
BALL_EXPORT bool operator==(const String &s1, const String &s2)
std::reverse_iterator< BondConstIterator > BondConstReverseIterator
Constant reverse random access iterator for bonds.
Definition: atom.h:934
BondIterator endBond()
Return a past-the-end bond iterator.
Definition: atom.h:896
bool isValid() const
Definition: atom.h:794
const BondIteratorPosition & getPosition() const
Definition: atom.h:769
BondIteratorPosition & getPosition()
Definition: atom.h:767
Type type_
Definition: atom.h:978
unsigned char number_of_bonds_
Definition: atom.h:980
char Atom[5]
Definition: PDBdefs.h:257
void dump(std::ostream &s) const
Definition: atom.h:824
#define BALL_ATOM_DEFAULT_POSITION
Definition: atom.h:30
Index formal_charge_
Definition: atom.h:984
float radius_
Definition: atom.h:976
#define BALL_EXPORT
Definition: COMMON/global.h:50
const Atom * getContainer() const
Definition: atom.h:763
#define BALL_ATOM_DEFAULT_TYPE
Definition: atom.h:32
BALL_EXPORT bool operator<(const String &s1, const String &s2)