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

MeasureSymmetry.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2008 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: MeasureSymmetry.h,v $
00013  *      $Author: saam $ $Locker:  $             $State: Exp $
00014  *      $Revision: 1.19 $       $Date: 2008/08/21 23:48:47 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  * Thy Symmetry class is the work horse behind the "measure symmetry"
00019  * command which guesses the pointgroup of a selection and returns the
00020  * according symmetry elements (mirror planes rotary axes, rotary reflection
00021  * axes). The algorithm is is fairly forgiving about molecules where atoms
00022  * are perturbed from the ideal position and tries its best to guess the
00023  * correct point group anyway. 
00024  * The 'forgivingness' can be controlled with the sigma parameter which is
00025  * the average allowed deviation from the ideal position.
00026  * Works nice on my 30 non-patholocical test cases. A pathological case
00027  * would for instance be a system with more than only a few atoms (say 15)
00028  * where only one atom distinguishes between two point groups.
00029  * If your selection contains more than a certain number of atoms then only
00030  * that much randomly chosen atoms are used to find planes and axes in order
00031  * to save time.
00032  *
00033  ***************************************************************************/
00034 
00035 #ifndef MEASURESYMMETRY_H
00036 #define MEASURESYMMETRY_H
00037 
00038 #include "ResizeArray.h"
00039 
00040 #define SKIP_IDENTICAL 1
00041 #define NOSKIP_IDENTICAL 0
00042 #define MAXORDERCN 8
00043 
00044 #define PRINCIPAL_AXIS     1
00045 #define PERPENDICULAR_AXIS 2
00046 
00047 
00048 typedef struct plane {
00049   float v[3];
00050   float overlap;
00051   int weight;
00052   int type;
00053 } Plane;
00054 
00055 typedef struct axis {
00056   float v[3];
00057   float overlap;
00058   int order;
00059   int weight;
00060   int type;
00061 } Axis;
00062 
00063 typedef struct elementsummary {
00064   char inv;
00065   char sigma;
00066   char Cinf;
00067   char C[MAXORDERCN+1];  // 0,1 unused; access by order 2, ... MAXORDERCN;
00068   char S[MAXORDERCN*2+1];
00069 } ElementSummary;
00070 
00071 typedef struct bond {
00072   int atom0;
00073   int atom1;
00074   float order;
00075   float length;
00076 } Bond;
00077 
00078 typedef struct bondlist {
00079   int numbonds;
00080   int *bondto;
00081 } Bondlist;
00082 
00083 
00084 class Symmetry {
00085 private:
00086   AtomSel *sel;              
00087   MoleculeList *mlist;
00088 
00089   float *coor;               
00090   float *bondsum;            
00091   float rcom[3];             
00092   float inertiaeigenval[3];  
00093   float inertiaaxes[3][3];   
00094   int uniqueprimary[3];      
00095   int numprimaryCn;
00096   int numverticalplanes;     
00097   int numdihedralplanes;     
00098   int horizontalplane;       
00099   int maxaxisorder;          
00100   int maxrotreflorder;       
00101   int maxnatoms;             
00102   int checkbonds;            
00103   int *atomtype;             
00104   int *atomindex;            
00105   int *uniqueatoms;
00106   char *elementsummarystring;    
00107   char *missingelementstring;    
00108   char *additionalelementstring; 
00109 
00110   Matrix4 orient;            
00111 
00112   // Summarized numbers of elements in table form.
00113   ElementSummary elementsummary;
00114 
00115   int   maxweight;           
00116   float maxoverlap;          
00117   float rmsd;                
00118 
00119   int pointgroup;            
00120 
00121  
00122   int pointgrouporder;       
00123 
00124  
00125   ResizeArray<Plane> planes;         
00126   ResizeArray<Axis>  axes;           
00127   ResizeArray<Axis>  rotreflections; 
00128   ResizeArray<Bond>  bonds;
00129 
00130   Bondlist *bondsperatom;  
00131 
00132   float *idealcoor;
00133 
00134   bool linear;        
00135   bool inversion;     
00136   bool sphericaltop;  
00137   bool symmetrictop;  
00138 
00139 
00141   void find_symmetry_elements();
00142 
00144   void find_elements_from_inertia();
00145 
00147   void find_planes();
00148 
00150   void find_axes_from_plane_intersections();
00151 
00153   void find_C2axes();
00154 
00155 
00157   void check_add_inversion();   
00158 
00161   void check_add_plane(const float *normal, int weight=1);
00162 
00165   void check_add_C2axis(const float *testaxis);
00166 
00169   void check_add_rotary_reflection(const float *testaxis, int maxorder);
00170 
00171 
00173   void classify_planes();
00174 
00176   void classify_axes();
00177 
00179   void purge_planes(float cutoff);
00180 
00182   void purge_axes(float cutoff);
00183 
00185   void purge_rotreflections(float cutoff);
00186 
00188   void prune_planes(int *keep);
00189 
00191   void prune_axes(int *keep);
00192 
00194   void prune_rotreflections(int *keep);
00195 
00197   void assign_axis_orders();
00198 
00200   void assign_C2axis_orders();
00201 
00203   int axis_order(const float *axis, float *overlap);
00204 
00206   void sort_axes();
00207 
00209   void sort_planes();
00210 
00212   void print_statistics();
00213 
00215   void build_element_summary();
00216 
00218   void build_element_summary_string(ElementSummary summary, char *(&sestring));
00219 
00221   void compare_element_summary(const char *pointgroupname);
00222 
00225   void idealize_elements();
00226 
00229   int idealize_angle(const float *refaxis, const float *hub,
00230                     const float *myaxis, float *idealaxis, int reforder);
00231 
00233   void idealize_coordinates();
00234 
00236   int average_coordinates(Matrix4 *trans);
00237 
00239   void identify_transformed_atoms(Matrix4 *trans, int &nmatches, int *(&matchlist));
00240 
00242   float ideal_coordinate_rmsd ();
00243 
00245   void unique_coordinates();
00246 
00248   int* unique_coordinates(Matrix4 *trans);
00249 
00251   void collapse_axis(const float *axis, int order, int refatom, const int *matchlist, int *(&connectedunique));
00252 
00254   void orient_molecule();
00255 
00257   inline int find_collinear_axis(const float *myaxis);
00258 
00260   inline int plane_exists(const float *myplane);
00261 
00263   int is_planar(const float *axis);
00264 
00265   void assign_bonds();
00266 
00268   void wrap_unconnected_unique_atoms(int root, const int *matchlist, int *(&connectedunique));
00269 
00270   // Find all unique atoms that are connnected to root
00271   void find_connected_unique_atoms(int *(&connectedunique), int root);
00272 
00275   void draw_transformed_mol(Matrix4 rot);
00276 
00277 public:
00278   Symmetry(AtomSel *sel, MoleculeList *mlist);
00279   ~Symmetry(void);
00280 
00281   float sigma;     // atomic overlap tolerance
00282   float collintol; // collinearity tolerance in radians
00283   float orthogtol; // coplanarity tolerance in radians
00284 
00285   // Check if center of mass is an inversion center.
00286   float score_inversion();
00287 
00289   float score_axis(const float *testaxis, int order);
00290 
00292   float score_plane(const float *normal);
00293 
00295   float score_rotary_reflection(const float *testaxis, int order);
00296 
00298   int guess(float mysigma);
00299 
00301   void get_pointgroup(char pg[8], int *order);
00302 
00304   float get_rmsd() { return rmsd; }
00305 
00306   float* get_inertia_axes()      { return &(inertiaaxes[0][0]); }
00307   float* get_inertia_eigenvals() { return &(inertiaeigenval[0]); }
00308   int*   get_inertia_unique()    { return &(uniqueprimary[0]); }
00309 
00311   int  get_axisorder(int n);
00312 
00314   int  get_rotreflectorder(int n);
00315 
00317   Matrix4* get_orientation() { return &orient; }
00318 
00320   const char *get_element_summary()     { return elementsummarystring; }
00321 
00323   const char *get_missing_elements()    { return missingelementstring; }
00324 
00326   const char *get_additional_elements() { return additionalelementstring; }
00327 
00329   void set_maxnumatoms(int n) { maxnatoms = n; }
00330 
00332   void set_overlaptol(float tol) { sigma = tol; }
00333 
00335   void set_checkbonds(int flag) { checkbonds = flag; }
00336 
00338   int numplanes()     { return planes.num(); }
00339 
00341   int numaxes()       { return axes.num(); }
00342 
00344   int numprimaryaxes();
00345 
00347   int numrotreflect() { return rotreflections.num(); }
00348 
00350   int numS2n();
00351 
00352   // Return 1 if inversion center is present, zero otherwise
00353   int has_inversion() { return inversion; }
00354 
00355   int is_spherical_top() { return sphericaltop; }
00356   int is_symmetric_top() { return symmetrictop; }
00357 
00358   // Return the center of mass
00359   float* center_of_mass() { return rcom; }
00360 
00362   float* plane(int i)      { return (float *) &(planes[i].v); }
00363 
00365   float* axis(int i)       { return (float *) &(axes[i].v); }
00366 
00368   float* rotreflect(int i) { return (float *) &(rotreflections[i].v); }
00369 
00371   int get_planetype(int i)     { return planes[i].type; }
00372 
00374   int get_axistype(int i)      { return axes[i].type; }
00375 
00377   int get_rotrefltype(int i)   { return rotreflections[i].type; }
00378 
00380   float *idealpos(int i)   { return idealcoor+3*i; }
00381 
00383   int get_unique_atom(int i)   { return uniqueatoms[i]; }
00384 };
00385 
00386 
00387 
00393 int measure_trans_overlap(AtomSel *sel, MoleculeList *mlist, const Matrix4 *trans,
00394                           float sigma, bool skipident, int maxnatoms, float &overlap);
00395 
00396 
00397 int measure_pointset_overlap(const float *posA, int natomsA, int *flagsA,
00398                              const float *posB, int natomsB, int *flagsB,
00399                              float sigma, float pairdist, float &similarity);
00400 
00401 
00402 
00403 
00404 #endif

Generated on Sat Sep 6 01:26:58 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002