BALL 1.5.0
Loading...
Searching...
No Matches
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
10#endif
11
12#ifndef 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
36namespace 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
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
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),
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
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
347
355 const Molecule* getMolecule() const;
358
359
367 const Fragment* getFragment() const;
370
378 const Residue* getResidue() const;
381
390
396 const Chain* getChain() const;
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
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
464
466 void setTypeName(const String& name);
467
471 void setVelocity(const Vector3& velocity);
472
477
481 const Vector3& getVelocity() const;
482
486 void setForce(const Vector3& force);
488 const Vector3& getForce() const;
491
492
495
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
549
561 Bond* createBond(Bond& bond, Atom& atom);
562
567 Bond* cloneBond(Bond& bond, Atom& atom);
568
580 bool destroyBond(const Atom& atom);
581
594
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
630
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
687 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
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
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
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>
1010template 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
1020#endif
1021
1022
1023#endif // BALL_KERNEL_ATOM_H
#define BALL_ATOM_DEFAULT_FORCE
Definition atom.h:34
#define BALL_ATOM_DEFAULT_FORMAL_CHARGE
Definition atom.h:27
#define BALL_ATOM_DEFAULT_TYPE_NAME
Definition atom.h:29
#define BALL_ATOM_DEFAULT_RADIUS
Definition atom.h:31
#define BALL_ATOM_DEFAULT_POSITION
Definition atom.h:30
#define BALL_ATOM_DEFAULT_VELOCITY
Definition atom.h:33
#define BALL_ATOM_DEFAULT_TYPE
Definition atom.h:32
#define BALL_ATOM_DEFAULT_CHARGE
Definition atom.h:26
#define BALL_CREATE_DEEP(name)
Definition create.h:26
Vector3 & getPosition()
Return the atom coordinates (mutable)
Molecule * getMolecule()
Return the molecule the atom is contained in (mutable)
bool store_interactions_disabled_
Definition atom.h:633
bool isVicinal(const Atom &atom) const
virtual void persistentWrite(PersistenceManager &pm, const char *name=0) const
virtual bool isAtom() const
Definition atom.h:687
unsigned char number_of_bonds_
Definition atom.h:980
bool isBoundTo(const Atom &atom) const
Bond * getBond(const Atom &atom)
void get(Atom &atom, bool deep=true) const
Vector3 force_
Definition atom.h:992
bool isBound() const
Bond * getBond(Position index)
float getRadius() const
Return the atom radius.
void setForce(const Vector3 &force)
float getDistance(const Atom &a) const
const Element * element_
Definition atom.h:974
virtual void persistentRead(PersistenceManager &pm)
const Residue * getResidue() const
float radius_
Definition atom.h:976
virtual void destroy()
Index getFormalCharge() const
Return the atom's formal charge.
void setRadius(float radius)
String getFullName(FullNameType type=ADD_VARIANT_EXTENSIONS) const
BondReverseIterator rbeginBond()
Return a reverse bond iterator pointing to the last bond.
Definition atom.h:922
void set(const Atom &atom, bool deep=true)
const Vector3 & getForce() const
Return the atom's force vector (const)
void enableStoreInteractions()
FullNameType
Definition atom.h:139
@ ADD_VARIANT_EXTENSIONS
Definition atom.h:143
@ ADD_VARIANT_EXTENSIONS_AND_ID
Definition atom.h:147
@ NO_VARIANT_EXTENSIONS
Definition atom.h:141
@ ADD_CHAIN_RESIDUE_ID
Definition atom.h:149
@ ADD_RESIDUE_ID
Definition atom.h:145
bool isGeminal(const Atom &atom) const
BondIterator endBond()
Return a past-the-end bond iterator.
Definition atom.h:896
Residue * getResidue()
Return the residue the atom is contained in (mutable)
void setVelocity(const Vector3 &velocity)
void setElement(const Element &element)
Assign the atom's element.
void setType(Type atom_type)
Assign the numerical atom type.
const Bond * getBond(const Atom &atom) const
Vector3 velocity_
Definition atom.h:990
BondIterator beginBond()
Return a bond iterator pointing to the first bond of the atom.
Definition atom.h:890
void addInteraction(const Atom *atom, String interaction_type, double energy)
Bond * createBond(Atom &atom)
Chain * getChain()
Return the chain the atom is contained in (mutable)
Bond * cloneBond(Bond &bond, Atom &atom)
RandomAccessIterator< Atom, Bond, BondIteratorPosition, BondIteratorTraits > BondIterator
Definition atom.h:887
BondConstIterator endBond() const
Return a constant past-the-end bond iterator.
Definition atom.h:913
std::list< Atom * > AtomPtrList
Definition atom.h:954
const String & getName() const
Return the atom name.
const Bond * getBond(Position index) const
Atom * getPartnerAtom(Position i)
const Fragment * getFragment() const
Type type_
Definition atom.h:978
Atom(Element &element, const String &name, const String &type_name=BALL_ATOM_DEFAULT_TYPE_NAME, Type atom_type=BALL_ATOM_DEFAULT_TYPE, const Vector3 &position=Vector3(BALL_ATOM_DEFAULT_POSITION), const Vector3 &velocity=Vector3(BALL_ATOM_DEFAULT_VELOCITY), const Vector3 &force=Vector3(BALL_ATOM_DEFAULT_FORCE), float charge=BALL_ATOM_DEFAULT_CHARGE, float radius=BALL_ATOM_DEFAULT_RADIUS, Index formal_charge=BALL_ATOM_DEFAULT_FORMAL_CHARGE)
short Type
Definition atom.h:103
static AtomIndexList free_list_
Definition atom.h:967
virtual void clear()
void setName(const String &name)
Set the atom name.
Size countBonds() const
Return the number of bonds.
const Atom * getPartnerAtom(Position i) const
const Molecule * getMolecule() const
BondConstReverseIterator rendBond() const
Return a constant past-the-end bond iterator for reverse traversal.
Definition atom.h:943
SecondaryStructure * getSecondaryStructure()
Return the secondary structure the atom is contained in (mutable)
void setCharge(float charge)
void swap(Atom &atom)
virtual bool isValid() const
const Vector3 & getPosition() const
Return the atom coordinates (const)
Vector3 & getForce()
Return the atom's force vector (mutable)
const SecondaryStructure * getSecondaryStructure() const
Vector3 & getVelocity()
void setFormalCharge(Index formal_charge)
Set the atom's formal charge.
std::reverse_iterator< BondIterator > BondReverseIterator
Reverse random access iterator for bonds.
Definition atom.h:919
virtual void dump(std::ostream &s=std::cout, Size depth=0) const
ConstRandomAccessIterator< Atom, Bond, BondIteratorPosition, BondIteratorTraits > BondConstIterator
Constant random access iterator for bonds.
Definition atom.h:904
Bond * createBond(Bond &bond, Atom &atom)
bool applyBonds(UnaryProcessor< Bond > &processor)
std::reverse_iterator< BondConstIterator > BondConstReverseIterator
Constant reverse random access iterator for bonds.
Definition atom.h:934
void setTypeName(const String &name)
Assign the atom type name.
const Chain * getChain() const
Fragment * getFragment()
Return the fragment the atom is contained in (mutable)
Vector3 position_
Definition atom.h:986
void setPosition(const Vector3 &position)
bool hasBond(const Bond &bond) const
void disableStoreInteractions()
float getCharge() const
BondReverseIterator rendBond()
Return a past-the-end bond iterator for reverse traversal.
Definition atom.h:928
bool destroyBond(const Atom &atom)
Type getType() const
Return the (numerical) atom type.
Index formal_charge_
Definition atom.h:984
BondConstReverseIterator rbeginBond() const
Return a constant reverse bond iterator pointing to the first atom.
Definition atom.h:937
const Vector3 & getVelocity() const
std::list< Position > AtomIndexList
Definition atom.h:957
String getTypeName() const
Return the atom type name.
const Element & getElement() const
Return the atom's element.
Index BondIteratorPosition
Definition atom.h:726
BondConstIterator beginBond() const
Return a constant bond iterator pointing to the first bond.
Definition atom.h:907
void addInteraction(String interaction_type, double energy)
String type_name_
Definition atom.h:972
String name_
Definition atom.h:970
Atom(const Atom &atom, bool deep=true)
float charge_
Definition atom.h:988
void destroyBonds()
MolecularInteractions * interactions
Definition atom.h:623
virtual ~Atom()
void dump(std::ostream &s) const
Definition atom.h:824
Distance getDistance(const BondIteratorTraits &traits) const
Definition atom.h:789
BondIteratorPosition & getPosition()
Definition atom.h:767
BondIteratorTraits(const Atom &atom)
Definition atom.h:742
Bond & getData(Index index)
Definition atom.h:864
const Bond & getData(Index index) const
Definition atom.h:869
void backward(Distance distance)
Definition atom.h:854
const Bond & getData() const
Definition atom.h:815
const Atom * getContainer() const
Definition atom.h:763
void forward(Distance distance)
Definition atom.h:859
BondIteratorTraits(const BondIteratorTraits &traits, bool=true)
Definition atom.h:748
const BondIteratorPosition & getPosition() const
Definition atom.h:769
#define BALL_EXPORT