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

MoleculeList.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 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: MoleculeList.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.72 $       $Date: 2020/10/28 17:26:39 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * The MoleculeList class, which is a list of the molecules being displayed.
00020  * This is a Displayable object, where each molecule is a child Displayable.
00021  *
00022  ***************************************************************************/
00023 #ifndef MOLECULELIST_H
00024 #define MOLECULELIST_H
00025 
00026 #include "Molecule.h"
00027 #include "AtomColor.h"
00028 #include "AtomRep.h"
00029 #include "ResizeArray.h"
00030 #include "JString.h"
00031 #include "utilities.h"
00032 #include "inthash.h"
00033 
00034 // use hash table to accelerate lookups
00035 #define MLIST_USE_HASH 1
00036 
00037 class VMDApp;
00038 
00039 // number of color categories, and where they're found in the table
00040 enum { MLCAT_NAMES, MLCAT_TYPES, MLCAT_ELEMENTS, 
00041        MLCAT_RESNAMES, MLCAT_RESTYPES,
00042        MLCAT_CHAINS, MLCAT_SEGNAMES, MLCAT_CONFORMATIONS, MLCAT_MOLECULES,
00043        MLCAT_SPECIAL, MLCAT_SSTRUCT, MLCAT_SURFACES, NUM_MLCAT};
00044 
00045 
00047 class MoleculeList {
00048 private:
00050   VMDApp *app;
00051 
00053   Scene *scene;
00054 
00057   Molecule *topMol;
00058 
00060   ResizeArray<Molecule *> molList;
00061 #if defined(MLIST_USE_HASH)
00062   inthash_t indexIDhash;           
00063 #endif
00064 
00067   AtomColor *currAtomColor;
00068   AtomRep *currAtomRep;
00069   char *currAtomSel;
00070   int currMaterial;
00071   float lastCenter[4];
00072 
00073 
00075   JString defaultAtomColor;
00076   JString defaultAtomRepresentation;
00077   JString defaultAtomSelection;
00078   JString defaultAtomMaterial;
00079 
00081   void set_top_molecule(Molecule *);
00082 
00083 protected:
00085   void init_colors();
00086 
00087 public:
00089   NameList<const char *> resTypes;
00090 
00092   int colorCatIndex[NUM_MLCAT];
00093 
00095   void add_color_names(int);
00096 
00097 public:
00098   MoleculeList(VMDApp *, Scene *);
00099   virtual ~MoleculeList(void);
00100 
00102   int num(void) { return int(molList.num()); }
00103 
00105   Molecule *molecule(int n) {
00106     Molecule *retval = NULL;
00107     if(n >= 0 && n < num())
00108       retval = molList[n];
00109     return retval;
00110   }
00111 
00113   int mol_index_from_id(int id) {
00114 #if defined(MLIST_USE_HASH)
00115     // HASH_FAIL == -1, so if we don't find the requested key 
00116     // the return code is still correct (-1 means no such molecule to VMD).
00117     return inthash_lookup(&indexIDhash, id);
00118 #else
00119     // XXX slow linear search implementation, causes N^2 molecule load behavior
00120     for (int i=num() - 1; i >= 0; i--) {
00121       if (id == (molList[i])->id()) {
00122         return i;
00123       }
00124     }
00125     return -1;
00126 #endif
00127   }
00128 
00130   Molecule *mol_from_id(int id) {
00131     return molecule(mol_index_from_id(id));
00132   }
00133   
00135   void add_molecule(Molecule *);
00136 
00138   int del_molecule(int);
00139 
00141   int del_all_molecules(void);
00142 
00143 
00144   //
00145   // routines to get/set characteristics for new graphics representations
00146   //
00147   
00149   int set_color(char *);
00150   char *color(void) { return currAtomColor->cmdStr; }
00151   
00153   int set_representation(char *);
00154   char *representation(void) { return currAtomRep->cmdStr; }
00155   
00157   int set_selection(const char *);
00158   const char *selection() const { return currAtomSel; }
00159   
00161   int set_material(char *);
00162   const char *material(void);
00163 
00165   int set_default_color(const char *);
00166   int set_default_representation(const char *);
00167   int set_default_selection(const char *);
00168   int set_default_material(const char *);
00169   const char *default_color() const {
00170     return defaultAtomColor; 
00171   }
00172   const char *default_representation() const {
00173     return defaultAtomRepresentation;
00174   }
00175   const char *default_selection() const {
00176     return defaultAtomSelection;
00177   }
00178   const char *default_material() const {
00179     return defaultAtomMaterial;
00180   }
00181 
00184   int add_rep(int n);
00185   
00188   int change_rep(int m, int n);
00189 
00191   int change_repcolor(int m, int n, char *);
00192   
00194   int change_repmethod(int m, int n, char *);
00195   
00198   int change_repsel(int m, int n, const char *);
00199  
00201   int change_repmat(int m, int n, const char *);
00202 
00205   int del_rep(int m, int n);
00206 
00207   //
00208   //
00209   // routines to get/set top, active, displayed, fixed molecules
00210   //
00211   
00213   Molecule *top(void) { return topMol; }
00214   int is_top(int n) { return (molecule(n) == topMol); }
00215   int is_top(Molecule *m) { return topMol == m; }
00216   void make_top(int n) { make_top(molecule(n)); }
00217   void make_top(Molecule *m);
00218 
00220   int active(int n) { return molecule(n)->active; }
00221   int active(Molecule *m) { return (m && m->active); }
00222   void activate(int n) { molecule(n)->active = TRUE; }
00223   void inactivate(int n) { molecule(n)->active = FALSE; }
00224   
00226   int displayed(int n) { return molecule(n)->displayed(); }
00227   int displayed(Molecule *m) { return (m && m->displayed()); }
00228   void show(int n) { molecule(n)->on(); }
00229   void hide(int n) { molecule(n)->off(); }
00230   
00232   int fixed(int n) { return molecule(n)->fixed(); }
00233   int fixed(Molecule *m) { return (m && m->fixed()); }
00234   void fix(int n) { molecule(n)->fix(); }
00235   void unfix(int n) { molecule(n)->unfix(); }
00236 
00238   void center_from_top_molecule_reps(void);
00239   void center_top_molecule(void);
00240   void center_all_molecules(void);
00241 
00243   Molecule *check_pickable(Pickable *pobj);
00244 };
00245 
00246 #endif
00247 

Generated on Wed Oct 9 02:42:52 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002