Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

BaseMolecule.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2011 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: BaseMolecule.h,v $
00013  *      $Author: akohlmey $     $Locker:  $             $State: Exp $
00014  *      $Revision: 1.134 $      $Date: 2011/12/06 05:04:38 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * Base class for all molecules, without display-specific information.  This
00020  * portion of a molecule contains the structural data, and all routines to
00021  * find the structure (backbone, residues, etc).  It contains the
00022  * animation list as well.
00023  *
00024  ***************************************************************************/
00025 #ifndef BASEMOLECULE_H
00026 #define BASEMOLECULE_H
00027 
00028 #ifndef NAMELIST_TEMPLATE_H
00029 #include "NameList.h"
00030 #endif
00031 #ifndef RESIZEARRAY_TEMPLATE_H
00032 #include "ResizeArray.h"
00033 #endif
00034 #include "Atom.h"
00035 #include "Residue.h"
00036 #include "Timestep.h"
00037 #include "Fragment.h"
00038 #include "intstack.h"
00039 
00040 #ifdef VMDWITHCARBS
00041 #include "SmallRing.h"
00042 #include "SmallRingLinkages.h"
00043 #include "inthash.h"
00044 #endif
00045 
00046 #if 0
00047 #define VMDFASTRIBBONS
00048 #endif
00049 
00050 class VolumetricData;
00051 class QMData;
00052 
00057 class BaseMolecule {
00058 public:
00059   //
00060   // public molecular structure data (for ease of access):
00061   //
00062   int nAtoms;                         
00063   int nResidues;                      
00064   int nWaters;                        
00065   int nSegments;                      
00066   int nFragments;                     
00067   int nProteinFragments;              
00068   int nNucleicFragments;              
00069 
00070   NameList<int> atomNames;            
00071   NameList<int> atomTypes;            
00072   NameList<int> resNames;             
00073   NameList<int> chainNames;           
00074   NameList<int> segNames;             
00075   NameList<int> altlocNames;          
00076 
00077   ResizeArray<Residue *> residueList; 
00078   ResizeArray<Fragment *> fragList;   
00079 
00080   ResizeArray<Fragment *> pfragList;  
00081 
00082   ResizeArray<int> pfragCyclic;       
00083 #if defined(VMDFASTRIBBONS)
00084   ResizeArray<int *> pfragCPList;     
00085 
00086 #endif
00087 
00088 
00089   ResizeArray<Fragment *> nfragList;  
00090   ResizeArray<int> nfragCyclic;       
00091 #if defined(VMDFASTRIBBONS)
00092   ResizeArray<int *> nfragCPList;     
00093 
00094 #endif
00095 
00096 #ifdef VMDWITHCARBS
00097   ResizeArray<SmallRing *> smallringList; 
00098 
00099   SmallRingLinkages smallringLinkages; 
00100   int currentMaxRingSize;             
00101   int currentMaxPathLength;           
00102 #endif
00103 
00104   // Extra molecular dynamics structure info not normally needed for
00105   // anything but structure building tasks
00106   ResizeArray<int> angles;            
00107   ResizeArray<int> dihedrals;         
00108   ResizeArray<int> impropers;         
00109   ResizeArray<int> cterms;            
00110 
00111   // Extra (optional) data for this molecule.
00112   // If the name is unassigned then the values can be taken to be zero.
00113   NameList<float *> extraflt;         
00114   NameList<int *> extraint;           
00115 
00116   // more structure topology handling info. assign names to FF types.
00117   ResizeArray<int> angleTypes;        
00118   ResizeArray<int> dihedralTypes;     
00119   ResizeArray<int> improperTypes;     
00120   NameList<int> bondTypeNames;        
00121   NameList<int> angleTypeNames;       
00122   NameList<int> dihedralTypeNames;    
00123   NameList<int> improperTypeNames;    
00124 
00125   // Data related to quantum mechanics simulations.
00126   QMData *qm_data;
00127 
00128   // Interface to standard extra data.  These will exist and be initialized
00129   // to zero when init_atoms is called.
00130 
00132   enum dataset_flag {       
00133                NODATA=0x0000,
00134             INSERTION=0x0001, 
00135             OCCUPANCY=0x0002, 
00136               BFACTOR=0x0004, 
00137                  MASS=0x0008, 
00138                CHARGE=0x0010, 
00139                RADIUS=0x0020, 
00140                ALTLOC=0x0040, 
00141          ATOMICNUMBER=0x0080, 
00142                 BONDS=0x0100, 
00143            BONDORDERS=0x0200,
00144                ANGLES=0x0400,
00145                CTERMS=0x0800, 
00146             BONDTYPES=0x1000,
00147            ANGLETYPES=0x2000 };
00148   
00149   int datasetflags;
00150   void set_dataset_flag(int flag) { 
00151     datasetflags |= flag;
00152   }
00153   void unset_dataset_flag(int flag) {
00154     datasetflags &= (~flag);
00155   }
00156   int test_dataset_flag(int flag) {
00157     return (datasetflags & flag) != 0;
00158   }
00159 
00161   float *radius() { return extraflt.data("radius"); }
00162   float *mass() { return extraflt.data("mass");   }
00163   float *charge() { return extraflt.data("charge"); }
00164   float *beta() { return extraflt.data("beta");   }
00165   float *occupancy() { return extraflt.data("occupancy"); }
00166 
00169   int radii_minmax_need_update;
00170   float radii_min;
00171   float radii_max;
00172   void set_radii_changed() { radii_minmax_need_update = 1; }
00173 
00174   void get_radii_minmax(float &min, float &max) {
00175     const float *r = NULL;
00176     if (radii_minmax_need_update && nAtoms > 0 &&
00177         (r = extraflt.data("radius")) != NULL) {
00178       radii_min = r[0];
00179       radii_max = r[0];
00180       for (int i=0; i<nAtoms; i++) {
00181         if (r[i] < radii_min) radii_min = r[i];
00182         if (r[i] > radii_max) radii_max = r[i];
00183       }
00184       radii_minmax_need_update = 0;
00185     }
00186 
00187     min = radii_min;  
00188     max = radii_max;  
00189   }
00190 
00192   float *bondorders() { return extraflt.data("bondorders"); }
00193   void setbondorder(int atom, int bond, float order);
00194   float getbondorder(int atom, int bond);
00195 
00197   int *bondtypes() { return extraint.data("bondtypes"); }
00198 
00200   void setbondtype(int atom, int bond, int type);
00201 
00203   int  getbondtype(int atom, int bond);
00204 
00206   int has_structure() const { return cur_atom > 0; }
00207 
00209   void clear_bonds(void);
00210 
00212   int count_bonds(void);
00213 
00214 #ifdef VMDWITHCARBS
00215 
00216   void find_small_rings_and_links(int maxpathlength, int maxringsize);
00217 #endif
00218 
00219 private:
00220   const int ID;          
00221 
00222   //
00223   // molecular structure data:
00224   //
00225   int cur_atom;          
00226   MolAtom *atomList;     
00227   int lastbonderratomid; 
00228   int bonderrorcount;    
00229  
00230   //
00231   // routines to determine components of molecular structure
00232   //
00233  
00241   int find_backbone(void);
00242 
00243   // find the residues in the molecule; return number found.
00244   // I look for atoms with the same resid connected to 
00245   // backbone atoms with the same resid (find enough backbone
00246   // atoms, then find atoms connected to them)
00247   int find_connected_backbone(IntStackHandle, int, int, int, int, int *);
00248   void clean_up_connection(IntStackHandle, int, int, int *);
00249   void find_connected_atoms_in_resid(IntStackHandle, int, int, 
00250      int, int, int *);
00251   void find_and_mark(int, int, int,
00252      int *, int *);
00253   int make_uniq_resids(int *flgs); 
00254 
00261   int find_residues(void);
00262   
00264   // This should take place after find_residues to keep
00265   // from mistaking a protein resname as a water resname, maybe
00266   void find_connected_waters(int i, char *tmp);
00267   int find_connected_waters2(void);
00268 
00273   int find_waters(void);
00274 
00280   void find_connected_residues(int num_residues);
00281   
00283   int find_segments(void) { return segNames.num(); }
00284   
00286   int find_connected_fragments();
00287 
00294   int find_fragments(void);
00295 
00296   void find_subfragments_cyclic(ResizeArray<Fragment *> *subfragList, int restype);  
00297   void find_cyclic_subfragments(ResizeArray<Fragment *> *subfragList, ResizeArray<int> *subfragCyclic);
00298  
00300   void find_connected_subfragment(int resnum, int fragnum, char *flgs, 
00301          int endatom, int altendatom, int alt2endatom, int alt3endatom,
00302          int restype, 
00303          ResizeArray<Fragment *> *subfragList);
00304 
00305   void find_subfragments(int startatom, int altstartatom, int alt2startatom,
00306     int endatom, int altendatom, int alt2endatom, int alt3endatom,
00307     int restype, ResizeArray<Fragment *> *subfragList);
00308 
00309   void find_subfragments_topologically(int restype, ResizeArray<Fragment *> *subfragList, int endatom, int altendatom, int alt2endatom, int alt3endatom);
00310 
00311 #if defined(VMDFASTRIBBONS)
00314   void calculate_ribbon_controlpoints();
00315 #endif
00316 
00317 #ifdef VMDWITHCARBS
00318 
00319    int find_small_rings(int maxringsize);
00320    int find_back_edges(ResizeArray<int> &back_edge_src, ResizeArray<int> &back_edge_dest);
00321    int find_connected_subgraph_back_edges(int atomid, ResizeArray<int> &back_edge_src, ResizeArray<int> &back_edge_dest,
00322                                           int *intree_parents);
00323    int find_small_rings_from_back_edges(int maxringsize, ResizeArray<int> &back_edge_src, ResizeArray<int> &back_edge_dest);
00324    int find_small_rings_from_partial(SmallRing *ring, int maxringsize, inthash_t *used_edges, inthash_t *used_atoms);
00325    int get_edge_key(int edge_src, int edge_dest);
00326    
00327    // orientate small rings
00328    void orientate_small_rings(int maxringsize);
00329    void orientate_small_ring(SmallRing &ring,int maxringsize);
00330    
00331    // find links between small rings
00332    int find_orientated_small_ring_linkages(int maxpathlength,int maxringsize);
00333    int find_linkages_for_ring_from_partial(LinkagePath &lp, int maxpathlength, inthash_t *atom_to_ring, inthash_t *multi_ring_atoms, inthash_t *used_atoms);
00334 #endif
00335 
00336 
00337 protected:
00338   char *moleculename;  
00339   int need_find_bonds; 
00340 
00341 public:
00342   // constructor; just sets most things to null.  Derived classes must put
00343   // in structure in 'create' routine.  Typical sequence of creating a
00344   // molecule should be:
00345   //    mol = new Molecule(....)
00346   //    ( specify parameters for creation )
00347   //    mol->create();  ... return success
00348   //    mol->analyze(); ... find information about the structure
00349   BaseMolecule(int);      
00350   virtual ~BaseMolecule(void); 
00351 
00352   //
00353   // routines to develop molecular structure
00354   //
00355   
00358   int init_atoms(int n); 
00359 
00361   void find_bonds_from_timestep() { need_find_bonds = 1; }
00362   void find_unique_bonds_from_timestep() { need_find_bonds = 2; }
00363 
00365   int add_atom(char *name, char *type, int atomicnumber, 
00366                char *resname, int resid,
00367                const char *chainid,const char *segname,
00368                char *insertion = (char *) " ", const char *altloc = "");
00369 
00371   int add_bond(int, int, float, int, int = ATOMNORMAL);
00372 
00374   int add_bond_dupcheck(int, int, float, int);
00375 
00377   void clear_angles(void) { angles.clear(); angleTypes.clear(); }
00378 
00380   int num_angles() { return angles.num() / 3; }
00381 
00384   int add_angle(int a, int b, int c, int type=-1);
00385 
00387   int set_angletype(int a, int type);
00388 
00390   int get_angletype(int a);
00391 
00393   void clear_dihedrals(void) { dihedrals.clear(); dihedralTypes.clear(); }
00394 
00396   int num_dihedrals() { return dihedrals.num() / 4; }
00397 
00400   int add_dihedral(int a, int b, int c, int d, int type=-1);
00401     
00403   int set_dihedraltype(int d, int type);
00404 
00406   int get_dihedraltype(int d);
00407 
00409   void clear_impropers(void) { impropers.clear(); improperTypes.clear(); }
00410 
00412   int num_impropers() { return impropers.num() / 4; }
00413 
00416   int add_improper(int a, int b, int c, int d, int type=-1);
00417   
00419   int set_impropertype(int i, int type);
00421   int get_impropertype(int i);
00422 
00424   void clear_cterms() {cterms.clear();}
00425 
00427   int num_cterms() { return cterms.num() / 8; }
00428 
00430   void add_cterm(int a, int b, int c, int d, 
00431                  int e, int f, int g, int h)  {
00432     cterms.append(a); cterms.append(b); cterms.append(c); cterms.append(d); 
00433     cterms.append(e); cterms.append(f); cterms.append(g); cterms.append(h); 
00434   }
00435   
00437   // (By this time, the molecule is on the MoleculeList!)
00438   void analyze(void);
00439 
00440   //
00441   // query info about the molecule
00442   //
00443   int id(void) const { return ID; } 
00444   const char *molname() const {return moleculename; } 
00445 
00446   // Return the Nth atom, residue, and fragment.  All assume correct index 
00447   // and that the structure has been initialized (for speed).
00448   MolAtom *atom(int n) { return atomList+n; } 
00449   Residue *residue(int);                      
00450   Fragment *fragment(int);                    
00451 
00452   // return the residue or fragment in which the given atom is located.
00453   Residue *atom_residue(int);       
00454   Fragment *atom_fragment(int);     
00455 
00457 
00458   int find_atom_in_residue(int atomnameindex, int residue) {
00459     const ResizeArray<int> &atoms = residueList[residue]->atoms;
00460     int num = atoms.num();
00461     for (int i=0; i<num; i++) {
00462       if (atom(atoms[i])->nameindex == atomnameindex) return atoms[i];
00463     }
00464     return -3;
00465   }
00466 
00467   int find_atom_in_residue(const char *atomname, int residue);
00469 
00471 
00472   float default_charge(char *);
00473   float default_mass(char *);
00474   float default_radius(char *);
00475   float default_occup(void) { return 1.0; }
00476   float default_beta(void) { return 0.0; }
00478 
00480   void add_volume_data(const char *name, const float *o, 
00481     const float *xa, const float *ya, const float *za, int x, int y, int z,
00482     float *voldata); 
00483 
00484   int num_volume_data(); 
00485   const VolumetricData *get_volume_data(int); 
00486   void compute_volume_gradient(VolumetricData *);  
00487 
00488 protected:
00489   ResizeArray<VolumetricData *>volumeList;    
00490 };
00491 
00492 // Hydrogen atom name detection macro
00493 #define IS_HYDROGEN(s) (s[0] == 'H' || (isdigit(s[0]) && s[1] == 'H' ))
00494 
00495 #endif
00496 

Generated on Wed May 16 01:49:02 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002