00001
00010 #ifndef HAMOLECULE_H
00011 #define HAMOLECULE_H
00012
00013 #include "hastring.h"
00014 #include "hastl.h"
00015 #include "halinalg.h"
00016 #include "gaufile.h"
00017 #include "haatom.h"
00018 #include "habond.h"
00019 #include "haatgroup.h"
00020 #include "object3d.h"
00021 #include "command.h"
00022
00023 class HaAtom;
00024 class HaBond;
00025 class HaQCMod;
00026 class HaMolView;
00027
00028 typedef list<HaAtom> AtomsType;
00029 typedef set<HaBond, less<HaBond> > BondsType;
00030
00031 #define SourceNone 0
00032 #define SourcePDB 1
00033 #define SourceCalc 2
00034
00036 enum ADD_ATOM_TYPE
00037 {
00038 ADD_ALL_ATOMS = 0x0,
00039 ADD_HYDROGENS = 0x1,
00040 ADD_POLAR_HYDROGENS = 0x2,
00041 ADD_HEAVY_ATOMS = 0x4
00042 };
00043
00044 #define FeatHelix 1
00045 #define FeatSheet 2
00046 #define FeatTurn 3
00047
00048
00049 class FeatEntry
00050 {
00051 public:
00052 FeatEntry();
00053 virtual ~FeatEntry();
00054
00055 int init, term;
00056 char chain;
00057 char type;
00058
00059 bool operator == (const FeatEntry& rhs);
00060 bool operator < (const FeatEntry& rhs);
00061
00062 protected:
00063 };
00064
00065 class AtomNode
00067 {
00068 public:
00069 AtomNode() {}
00070 AtomNode(const AtomNode& ref_node);
00071 virtual ~AtomNode() {}
00072
00073
00074 HaAtom* at;
00075 HaAtom* ar;
00076
00077
00078 int ntype;
00079 int nresolv_neib;
00080 vector<int> bonded_nodes;
00081
00082 };
00083
00084 class AtomIteratorMolecule;
00085 class BondIteratorMolecule;
00086 class ResidueIteratorMolecule;
00087
00089 class HaMolecule: public Object3D, public AtomCollection
00090 {
00091 public:
00092 HaMolecule(HaMolSet* new_phost_mset, HaString new_name="HARLEMMOL");
00093 HaMolecule(const HaMolecule& Mol_ref);
00094 virtual ~HaMolecule();
00095
00096
00097 typedef BondIteratorMolecule BondIterator;
00098 typedef ResidueIteratorMolecule ResidueIterator;
00099
00100 HaMolSet* GetHostMolSet() { return phost_mset; }
00101 const HaMolSet* GetHostMolSet() const { return phost_mset; }
00102
00103 bool AddMolCopy(const HaMolecule& Mol_ref, bool create_new_chain = true,
00104 map<HaAtom*, HaAtom*, less<HaAtom*> > *ptr_atom_map = NULL);
00105
00106 static int AttachFragment( HaAtom* catom_host, HaAtom* catom_frag );
00107 int CombineMolecules(HaMolecule* frag_mol, HaAtom* catom_host, HaAtom* catom_frag );
00108
00109
00110 protected:
00111 HaMolSet* phost_mset;
00112
00113 public:
00114
00115 HaString GetRef() const;
00116 bool FillRef(char* buf,int mode = 0) const;
00117
00119
00120 virtual bool SetObjName(const char* new_name);
00121
00122 virtual int RotateObj( const HaMat_double& rot_mat, const Vec3D& cnt );
00123
00124 virtual int Translate( const Vec3D& tr_vec );
00125
00126 int GetStdPosition(HaMat_double& rot_std, Vec3D& trans_std);
00127 int SetPosition(const HaMat_double& rot_new, const Vec3D& trans_new);
00128 int SetPosEulerTrans(double phi, double cos_theta, double psi, const Vec3D& trans);
00129 void GetPosEulerTrans( double& phi, double& cos_theta, double& psi, Vec3D& trans);
00130
00131 int SetIntCoordFromStr(const char* int_crd_str);
00132
00133
00134
00135 int SetAtomScreenCoord(HaMolView* pview);
00136
00137 bool SetUniqueAtomNames();
00138
00140
00141 bool InitAtomsGRWF();
00142 bool InitAtoms(GauFile& gfile);
00143
00144 static bool SetCoordSubstH(const HaAtom* aptr1, const HaAtom* aptr2, HaAtom* haptr);
00146
00147
00148 HaAtom* AddAtomFromTempl( HaAtom* aptr2, HaAtom* aptr3, HaAtom* aptr4,
00149 const HaAtom* aptr_templ, const HaAtom* aptr_templ_2, const HaAtom* aptr_templ_3,
00150 const HaAtom* aptr_templ_4);
00151
00152 int GetSeqNumOfAtom(const HaAtom* aptr) const;
00153 HaAtom* GetAtomBySeqNum(const int index);
00154 const HaAtom* GetAtomBySeqNum(const int index) const;
00155
00156 HaAtom* GetAtomByRef(const char* at_ref);
00157
00158
00159
00160 virtual int GetNAtoms() const;
00161 virtual int IsMember(const HaAtom* aptr) const;
00162 virtual AtomIterator* GetAtomIterator();
00163
00164
00165
00166 public:
00167 int GetNBonds() const;
00168 int GetNHBonds() const;
00169 int GetNSSBonds() const;
00170
00171 int AreHBonded(HaAtom* src, HaAtom* dst) const;
00172
00173 void CalcHydrogenBonds();
00174
00175 bool AreHBondsFound() const { return HBonds_found; }
00176 bool AreSSBondsFound() const { return SSBonds_found; }
00177
00178 void CreateMoleculeBonds();
00179
00180 HaBond* AddBond(HaAtom* src, HaAtom* dst,int flag );
00181 HaHBond* AddHBond(HaAtom* src, HaAtom* dst);
00182 HaHBond* AddSSBond(HaAtom* src, HaAtom* dst);
00183 bool DeleteBond(HaAtom* src, HaAtom* dst);
00184
00185 int AddAllMissingAtoms(ADD_ATOM_TYPE atom_type);
00186 int AddMissingAtoms(HaResidue* pres,ADD_ATOM_TYPE atom_type);
00187 int AddWaterHydrogens(HaResidue* pres);
00188
00189 protected:
00190 int AddMissingAtoms_2(HaResidue* pres, HaResidue* prtempl, ADD_ATOM_TYPE atom_type);
00191
00192
00193 vector<AtomNode> nodes;
00194 public:
00195 void BondIfClose(HaAtom* sptr, HaAtom* dptr);
00196
00197 void CreateHydrogenBond(HaAtom* src, HaAtom* dst,
00198 int energy, int offset );
00199
00200 void CalcNucleicHBonds(HaChain* chn1 );
00201 void CalcProteinHBonds(HaChain* chn1 );
00202 int CalculateBondEnergy(HaResidue* group );
00203 void TestDisulphideBridge(HaResidue* group1,HaResidue* group2, HaAtom* cys1 );
00204
00205 int SetTermResNames();
00206 int SetCysBridgeNames();
00207
00208 public:
00209
00210 bool Print_info(ostream &sout, const int level) const;
00211
00212
00213
00214 HaResidue* CreateMolResidue();
00215 int GetNRes() const;
00216
00217 HaResidue* GetResByRef(const HaString& res_str);
00218
00219
00220 int GetNChains() { return Chains.size(); }
00221 HaChain* AddChain(char ident);
00222
00223 HaChain* GetFirstChain();
00224 HaChain* GetNextChain();
00225
00226 HaChain* GetChain(const char chain_id );
00227
00228
00229
00230 virtual PointIterator* GetPointIterator();
00231 virtual int GetPtNum() { return GetNAtoms(); }
00232
00233 bool FixChainsIdent();
00234
00235
00236 public:
00237 void DescribeMolecule();
00238 void DetermineStructure(int flag);
00239 void FindDisulphideBridges();
00240
00241 void Renumber(int start );
00242 void DescribeSequence();
00243
00244 static int SeqFormat;
00245
00246 FeatEntry* AddFeature();
00247 int GetNumFeatures(const int itype) const;
00248 void UpdateFeature(FeatEntry* ptr, int mask);
00249 void ProcessFeatures();
00250
00251 bool IsSecStructFound() { return sec_struct_found; }
00252 bool sec_struct_found;
00253
00254 int structsource;
00255
00256 list<FeatEntry> Features;
00257
00258 protected:
00259 void FindAlphaHelix( int pitch, int flag );
00260 void FindTurnStructure();
00261 void FindBetaTurns();
00262 void FindBetaSheets();
00263 void TestLadder(list<HaChain>::iterator chain_ref,HaResidue* prevri,HaResidue* curri, HaResidue* nexti);
00264
00265 public:
00266
00268 bool GetMinMaxCrd(double& MinX_v, double& MinY_v, double& MinZ_v,
00269 double& MaxX_v, double& MaxY_v, double& MaxZ_v);
00270
00272 bool GetAverageCoord(double& avx, double& avy, double& avz);
00273
00275 bool GetStdRotMat(HaMat_double& rot_mat);
00276
00277
00278
00279
00280 public:
00281 list<HaChain> Chains;
00282 set<HaHBond, less<HaHBond> > HBonds;
00283 set<HaHBond, less<HaHBond> > SSBonds;
00284 set<HaBond, less<HaBond> > Bonds;
00285
00286 list<HaAtom> Atoms;
00287
00288 bool SSBonds_found;
00289
00290
00291
00292 public:
00293 bool HBonds_found;
00294
00295
00296 public:
00297
00298 HaString classification;
00299 HaString identcode;
00300
00301
00302 protected:
00303
00304
00305
00306 public:
00307 HaResidue* CurResidue;
00308 HaChain* CurChain;
00309 protected:
00310
00311 list<HaChain>::iterator CurChainItr;
00312
00313
00314 protected:
00315
00316 };
00317
00318
00319 class AtomIteratorMolecule: public AtomIterator
00321 {
00322 public:
00323
00324 AtomIteratorMolecule(HaMolecule* new_pMol);
00325 virtual ~AtomIteratorMolecule();
00326
00327 virtual HaAtom* GetFirstAtom();
00328 virtual HaAtom* GetNextAtom();
00329
00330
00331
00332 virtual Vec3D* GetFirstPt() { return GetFirstAtom(); }
00333 virtual Vec3D* GetNextPt() { return GetNextAtom(); }
00334
00335 protected:
00336 list<HaAtom>::iterator aitrm;
00337
00338 HaMolecule* pMol;
00339 };
00340
00341 class BondIteratorMolecule
00343 {
00344 public:
00345 BondIteratorMolecule(HaMolecule* new_pMol);
00346 virtual ~BondIteratorMolecule();
00347
00348 HaBond* GetFirstBond();
00349 HaBond* GetNextBond();
00350
00351 protected:
00352 set<HaBond>::iterator bitrm;
00353
00354 HaMolecule* pMol;
00355 };
00356
00357 class ResidueIteratorMolecule
00359 {
00360 public:
00361 ResidueIteratorMolecule(HaMolecule* new_pmol);
00362 virtual ~ResidueIteratorMolecule();
00363
00364 HaResidue* GetFirstRes();
00365 HaResidue* GetNextRes();
00366
00367 protected:
00368 Residues_type::iterator res_itr;
00369 list<HaChain>::iterator ch_itr;
00370
00371 HaMolecule* pmol;
00372 };
00373
00374
00375 const int START_TERM_ATOM_ID=50000;
00376
00377
00378
00379
00380
00381
00382 const int SelectFlag = 0x01;
00383 const int DrawBondFlag = 0x0e;
00384 const int AllAtomFlag = 0x1c;
00385 const int HelixFlag = 0x03;
00386 const int DrawKnotFlag = 0x7e;
00387 const int WideKnotFlag = 0x0e;
00388
00389
00390
00391 const int WireFlag = 0x02;
00392 const int DashFlag = 0x04;
00393 const int CylinderFlag = 0x08;
00394
00395 const int HydrBondFlag = 0x00;
00396 const int NormBondFlag = 0x10;
00397 const int DoubBondFlag = 0x20;
00398 const int TripBondFlag = 0x40;
00399 const int AromBondFlag = 0x80;
00400
00401
00402
00403 const int CystineFlag = 0x01;
00404 const int StrandFlag = 0x02;
00405 const int DashStrandFlag = 0x04;
00406 const int RibbonFlag = 0x08;
00407 const int TraceFlag = 0x10;
00408 const int CartoonFlag = 0x20;
00409 const int DotsFlag = 0x40;
00410
00411
00412 const int Helix3Flag = 0x01;
00413 const int Helix4Flag = 0x02;
00414 const int Helix5Flag = 0x03;
00415 const int SheetFlag = 0x04;
00416 const int TurnFlag = 0x08;
00417
00418
00419
00420
00421
00422 #define SerNoFlag 0x01
00423 #define ResNoFlag 0x02
00424
00425
00426
00427
00428 #define ForEachChain_HAMOL for(chain=GetFirstChain();chain;chain=GetNextChain())
00429 #define ForEachResidue_HAMOL for(chain=GetFirstChain();chain;chain=GetNextChain()) \
00430 for( group=chain->GetFirstRes(); group; group=chain->GetNextRes() )
00431 #define ForEachBack_HAMOL for(chain=GetFirstChain();chain;chain=GetNextChain()) \
00432 for(bptr=chain->GetFirstBackB();bptr;bptr=chain->GetNextBackB())
00433
00434
00435 #endif
00436
00437
00438