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

cmd_mol.C

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 #include <ctype.h>
00010 #include <stdlib.h>
00011 #include <tcl.h>
00012 
00013 #include "config.h"
00014 #include "utilities.h"
00015 #include "VMDApp.h"
00016 #include "TclCommands.h"
00017 #include "VMDDisplayList.h"
00018 #include "MoleculeList.h"
00019 
00020 // the following uses the Cmdtypes MOL_NEW, MOL_DEL, MOL_ACTIVE,
00021 // MOL_FIX, MOL_ON, MOL_TOP, MOL_SELECT, MOL_REP, MOL_COLOR, MOL_ADDREP,
00022 // MOL_MODREP, MOL_DELREP, MOL_MODREPITEM
00023 
00024 
00025 /*
00026  * NOTES:
00027  *
00028  *      1) When referring to a molecule in a command by a number, the
00029  * unique molecule ID is used, NOT the relative index of the molecule into
00030  * the molecule list.  This is because the relative index changes as molecules
00031  * are added/removed, but the unique ID stays the same until the molecule is
00032  * deleted.
00033  *
00034  */
00035 
00036 
00047 class IdList {
00048 private:
00049   int *idList;
00050   int selectedMols;
00051 
00052   void molname_error(Tcl_Interp *interp, const char *fullname, const char *errpart) {
00053     char *errmsg = new char[200 + strlen(fullname) + strlen(errpart)];
00054     sprintf(errmsg, 
00055       "Illegal molecule specification '%s': Could not\nfind molecule '%s'. ",
00056       fullname, errpart);
00057     Tcl_SetResult(interp, errmsg, TCL_VOLATILE);
00058     delete errmsg;
00059   }
00060 
00061 public:
00062   IdList() {
00063     idList = 0;
00064     selectedMols = -1;
00065   }
00066   int find(Tcl_Interp *, VMDApp *app, const char *txt, int *allmolsflag = NULL); // return num()
00067   ~IdList() {
00068     delete [] idList;
00069   }
00070   int num() const { return selectedMols; }
00071   int operator[](int i) const { return idList[i]; }
00072 };
00073 
00074 int IdList::find(Tcl_Interp *interp, VMDApp *app, const char *givenName, int *allmolsflag) {
00075   char name[512];      
00076   int i, numMols;
00077 
00078   if (interp == NULL || app == NULL || givenName == NULL) {
00079     Tcl_SetResult(interp, (char *) "ERROR) IdList::find() bad parameters", TCL_STATIC);
00080     return -1;
00081   }
00082 
00083   numMols = app->num_molecules();
00084   if (!numMols) {
00085     Tcl_SetResult(interp, (char *) "ERROR) No molecules loaded.", TCL_STATIC);
00086     return -1;
00087   }
00088 
00089   idList = new int[numMols];
00090   for (i=0; i<numMols; i++) idList[i] = 0;
00091 
00092   // start to tokenize the string, then
00093   // scan the string and look for molecule specifiers
00094   strcpy(name, givenName);
00095   char *tok = strtok(name, "|/:");
00096   while(tok) {
00097     // look for what kind of name this is
00098     if(isdigit(*tok)) {     // check if it is a molid 
00099       int n = atoi(tok);
00100       if (!app->molecule_valid_id(n)) {
00101         molname_error(interp, givenName, tok);
00102         return -1;
00103       }
00104       for (i=0; i<numMols; i++) {
00105         if (app->molecule_id(i) == n) {
00106           idList[i] = TRUE;
00107         }
00108       }
00109     } else if(!strupncmp(tok, "all", CMDLEN)) {     // check if "all"
00110       // tell caller that _all_ molecules were selected, to allow more
00111       // efficient processing where possible.
00112       if (allmolsflag != NULL) {
00113         *allmolsflag = 1; 
00114       }
00115       for(i=0; i < numMols; i++)
00116         idList[i] = TRUE;
00117     } else if(!strupncmp(tok, "none", CMDLEN)) {    // "none"
00118       for(i=0; i < numMols; i++)
00119         idList[i] = FALSE;
00120     } else if(!strupncmp(tok, "top", CMDLEN)) {     // "top"
00121       int top = app->molecule_top();
00122       for(i=0; i < numMols; i++)
00123         if (app->molecule_id(i) == top)
00124           idList[i] = 1;
00125     } else if(!strupncmp(tok, "active", CMDLEN)) {  // check if "active"
00126       for(i=0; i < numMols; i++)
00127         if (app->molecule_is_active(app->molecule_id(i))) 
00128           idList[i] = 1;
00129     } else if(!strupncmp(tok, "inactive", CMDLEN)) {    // check if "inactive"
00130       for(i=0; i < numMols; i++)
00131         if (!app->molecule_is_active(app->molecule_id(i)))
00132           idList[i] = 1;
00133     } else if(!strupncmp(tok, "displayed", CMDLEN) ||
00134     !strupncmp(tok, "on", CMDLEN)) {        // "displayed" or "on"
00135       for(i=0; i < numMols; i++)
00136         if (app->molecule_is_displayed(app->molecule_id(i)))
00137           idList[i] = 1;
00138     } else if(!strupncmp(tok, "off", CMDLEN)) { // check if "off"
00139       for(i=0; i < numMols; i++)
00140         if (!app->molecule_is_displayed(app->molecule_id(i)))
00141           idList[i] = 1;
00142     } else if(!strupncmp(tok, "fixed", CMDLEN)) {   // check if "fixed"
00143       for(i=0; i < numMols; i++)
00144         if (app->molecule_is_fixed(app->molecule_id(i)))
00145           idList[i] = 1;
00146     } else if(!strupncmp(tok, "free", CMDLEN) ||
00147     !strupncmp(tok, "unfix", CMDLEN)) {         // "free" or "unfix"
00148       for(i=0; i < numMols; i++)
00149         if (!app->molecule_is_fixed(app->molecule_id(i)))
00150           idList[i] = 1;
00151     } else {
00152       // bad molecule name; print error and return
00153       molname_error(interp, givenName, tok);
00154       return -1;
00155     }
00156     tok = strtok(NULL,"|/:");
00157   }
00158 
00159   // found the names; now convert the flag array to a list of id's.  
00160   selectedMols = 0;
00161   for(i=0; i < numMols; i++) {
00162     if(idList[i])
00163       idList[selectedMols++] = app->molecule_id(i);
00164   }
00165   return selectedMols;
00166 }
00167 
00168 static void print_mol_summary(Tcl_Interp *interp, VMDApp *app, int molid) {
00169   if (!app->molecule_valid_id(molid)) return;
00170   // everything except molecule name is bounded in size
00171   char *buf = new char[strlen(app->molecule_name(molid))+50];
00172   sprintf(buf, "%s  Atoms:%d  Frames (C): %d(%d)  Status:%c%c%c%c\n",
00173       app->molecule_name(molid), app->molecule_numatoms(molid),
00174       app->molecule_numframes(molid), app->molecule_frame(molid),
00175       (app->molecule_is_active(molid) ? 'A' : 'a'),
00176       (app->molecule_is_displayed(molid) ? 'D' : 'd'),
00177       (app->molecule_is_fixed(molid) ? 'F' : 'f'),
00178       (molid == app->molecule_top() ? 'T' : 't'));
00179   Tcl_AppendResult(interp, buf, NULL);
00180   delete [] buf;
00181 }
00182 
00183 static void print_arep_summary(Tcl_Interp *interp, VMDApp *app, int molid, 
00184                                int i) {
00185   if (!app->molecule_valid_id(molid)) return;
00186   if (i < 0 || i >= app->num_molreps(molid)) return;
00187   char buf[100];
00188   sprintf(buf, "%d: %s, %d atoms selected.\n", 
00189       i, (app->molecule_is_displayed(molid) ? " on" : "off"), 
00190       app->molrep_numselected(molid, i));
00191   Tcl_AppendResult(interp, buf, NULL);
00192   Tcl_AppendResult(interp, "  Coloring method: ", 
00193       app->molrep_get_color(molid, i), "\n", NULL);
00194   Tcl_AppendResult(interp, "   Representation: ", 
00195       app->molrep_get_style(molid, i), "\n", NULL);
00196   Tcl_AppendResult(interp, "        Selection: ", 
00197       app->molrep_get_selection(molid, i), "\n", NULL);
00198 }
00199 
00200 static void cmd_mol_list(Tcl_Interp *interp, VMDApp *app, const char *moltxt) {
00201   
00202   IdList idList;
00203   if (idList.find(interp, app, moltxt) > 1) {
00204     Tcl_AppendResult(interp, "Molecule Status Overview:\n" , NULL);
00205     Tcl_AppendResult(interp, "-------------------------\n" , NULL);
00206     for (int i=0; i < idList.num(); i++)
00207       print_mol_summary(interp, app, idList[i]);
00208   } else if (idList.num() == 1) {
00209     Tcl_AppendResult(interp, "Status of molecule ", 
00210         app->molecule_name(idList[0]), ":\n", NULL);
00211     print_mol_summary(interp, app, idList[0]);
00212     char buf[50];
00213     sprintf(buf, "Atom representations: %d\n", app->num_molreps(idList[0]));
00214     Tcl_AppendResult(interp, buf, NULL); 
00215     for (int i=0; i < app->num_molreps(idList[0]); i++)
00216       print_arep_summary(interp, app, idList[0], i);
00217   }
00218 }
00219 
00220 static void cmd_mol_usage(Tcl_Interp *interp) {
00221     Tcl_AppendResult(interp, "usage: mol <command> [args...]\n",
00222     "\nMolecules and Data:\n",
00223     "  new [file name] [options...]       -- load file into a new molecule\n",
00224     "  addfile <file name> [options...]   -- load files into existing molecule\n",
00225     "    options: type, first, last, step, waitfor, volsets, filebonds, autobonds, \n",
00226     "             molid (addfile only)\n",
00227     "  load <file type> <file name>       -- load molecule\n" ,
00228     "  urlload <file type> <URL>          -- load molecule from URL\n" ,
00229     "  pdbload <four letter accession id> -- download molecule from the PDB\n",
00230     "  cancel <molid>                     -- cancel load/save of trajectory\n",  
00231     "  delete <molid>                     -- delete given molecule\n" , 
00232     "  rename <molid> <name>              -- Rename the specified molecule\n",     
00233     "  list [all|<molid>]                 -- displays info about molecules\n",
00234     "\nMolecule GUI Properties:\n",
00235     "  top <molid>                        -- make that molecule 'top'\n",
00236     "  on <molid>                         -- make molecule visible\n" ,
00237     "  off <molid>                        -- make molecule invisible\n" ,
00238     "  fix <molid>                        -- don't apply mouse motions\n" ,
00239     "  free <molid>                       -- let mouse move molecules\n" ,
00240     "  active <molid>                     -- make molecule active\n" ,
00241     "  inactive <molid>                   -- make molecule inactive\n" ,
00242     "\nGraphical Representations:\n",
00243     "  addrep <molid>                     -- add a new representation\n" ,
00244     "  delrep <repid> <molid>             -- delete rep\n" ,
00245     "  default [color | style | selection | material] <value>",
00246     "  representation|rep <style>         -- set the drawing style for new reps\n" ,
00247     "  selection <selection>              -- set the selection for new reps\n" ,
00248     "  color <color>                      -- set the color for new reps\n" ,
00249     "  material <material>                -- set the material for new reps\n" ,
00250     "  modstyle <repid> <molid> <style>   -- change the drawing style for a rep\n" ,
00251     "  modselect <repid> <molid> <selection>  -- change the selection for a rep\n" ,
00252     "  modcolor <repid> <molid> <color>   -- change the color for a rep\n" ,
00253     "  modmaterial <repid> <molid> <material> -- change the material for a rep\n" ,
00254     "  repname <molid> <repid>            -- Get the name of a rep\n",
00255     "  repindex <molid> <repname>         -- Get the repid of a rep from its name\n",
00256     "  reanalyze <molid>                  -- Re-analyze structure after changes\n",
00257     "  bondsrecalc <molid>                -- Recalculate bonds, current timestep\n",
00258     "  ssrecalc <molid>                   -- Recalculate secondary structure (Cartoon)\n",
00259     "  selupdate <repid> <molid> [on|off] -- Get/Set auto recalc of rep selection\n",
00260     "  colupdate <repid> <molid> [on|off] -- Get/Set auto recalc of rep color\n",
00261     "  scaleminmax <molid> <repid> [<min> <max>|auto] -- Get/set colorscale minmax\n",
00262     "  drawframes <molid> <repid> [<framespec>|now] -- Get/Set drawn frame range\n", 
00263     "  smoothrep <molid> <repid> [smooth] -- Get or set trajectory smoothing value\n",
00264     "  showperiodic <molid> <repid> [flags] -- Get or set periodic image display\n",
00265     "  numperiodic <molid> <repid> <n>    -- Get or set number of periodic images\n",
00266     "  showrep <molid> <repid> [on|off]   -- Turn selected rep on or off\n",
00267     "\nClipping Planes:\n",
00268     "  clipplane center <clipid> <repid> <molid> [<vector>]\n",
00269     "  clipplane color  <clipid> <repid> <molid> [<vector>]\n",
00270     "  clipplane normal <clipid> <repid> <molid> [<vector>]\n",
00271     "  clipplane status <clipid> <repid> <molid> [<mode>]\n",
00272     "  clipplane num\n",
00273     "\n",
00274     "See also the molinfo command\n",
00275     NULL);
00276 }
00277 
00278 int text_cmd_mol(ClientData cd, Tcl_Interp *interp, int argc,
00279                             const char *argv[]) {
00280 
00281   VMDApp *app = (VMDApp *)cd;
00282 
00283   if (argc == 1) {
00284     cmd_mol_usage(interp);
00285     return TCL_ERROR;
00286   }
00287   if ((argc == 4 || argc == 6) && !strupncmp(argv[1], "load", CMDLEN)) {
00288     // load a new molecule
00289   
00290     // Special-case graphics molecules to load as "blank" molecules
00291     if (argc == 4 && !strupncmp(argv[2], "graphics", CMDLEN)) {
00292       int rc = app->molecule_new(argv[3]);
00293       Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
00294       return TCL_OK;
00295     }
00296     FileSpec spec;
00297     spec.waitfor = -1;
00298     int newmolid = app->molecule_load(-1, argv[3], argv[2], &spec);
00299     if (newmolid < 0) {
00300       Tcl_AppendResult(interp, "Unable to load structure file ",argv[3], NULL);
00301       return TCL_ERROR;
00302     }
00303     if (argc == 6) {
00304       if (app->molecule_load(newmolid, argv[5], argv[4], &spec) < 0) {
00305         Tcl_AppendResult(interp, "Unable to load coordinate file ", argv[5], 
00306                          NULL);
00307         return TCL_ERROR;
00308       }
00309     }
00310     Tcl_SetObjResult(interp, Tcl_NewIntObj(newmolid));
00311 
00312   } else if(argc < 4 && !strupncmp(argv[1], "list", CMDLEN)) {
00313     if(argc == 2)
00314       cmd_mol_list(interp, app, "all");
00315     else
00316       cmd_mol_list(interp, app, argv[2]);
00317   
00318   } else if (argc < 4 && !strupncmp(argv[1], "cancel", CMDLEN)) {
00319     IdList idList;
00320     if (argc == 2) {
00321       idList.find(interp, app, "all");
00322     } else {
00323       idList.find(interp, app, argv[2]);
00324     }
00325     for (int i=0; i<idList.num(); i++) app->molecule_cancel_io(idList[i]);
00326   
00327   } else if(!strupncmp(argv[1],"selection",CMDLEN)) {
00328     char *molstr = combine_arguments(argc, argv, 2);
00329     if (molstr) {
00330       app->molecule_set_selection(molstr);
00331       delete [] molstr;
00332     }
00333   } else if(!strupncmp(argv[1],"representation",CMDLEN) ||
00334         !strupncmp(argv[1],"rep",CMDLEN) ) {
00335     char *molstr = combine_arguments(argc, argv, 2);
00336     if (molstr) {
00337       app->molecule_set_style(molstr);
00338       delete [] molstr;
00339     }
00340 
00341   } else if(!strupncmp(argv[1],"color",CMDLEN)) {
00342     char *molstr = combine_arguments(argc, argv, 2);
00343     if (molstr) {
00344       app->molecule_set_color(molstr);
00345       delete [] molstr;
00346     }
00347 
00348   } else if(!strupncmp(argv[1],"material",CMDLEN)) {
00349     char *molstr = combine_arguments(argc, argv, 2);
00350     if (molstr) {
00351       app->molecule_set_material(molstr);
00352       delete [] molstr;
00353     }
00354 
00355   } else if(argc > 4 && (!strupncmp(argv[1],"modcolor",CMDLEN) ||
00356         !strupncmp(argv[1],"modstyle",CMDLEN) ||
00357         !strupncmp(argv[1],"modselect",CMDLEN) ||  
00358     !strupncmp(argv[1],"modmaterial",CMDLEN)) ) {
00359     IdList idList;
00360     if (idList.find(interp, app, argv[3]) != 1) {
00361       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00362       return TCL_ERROR;
00363     }
00364     int molid = idList[0]; 
00365     char *molstr = combine_arguments(argc, argv, 4);
00366     if(molstr) {
00367       if(!strupncmp(argv[1],"modcolor",CMDLEN))
00368         app->molrep_set_color(molid, atoi(argv[2]), molstr);
00369       else if(!strupncmp(argv[1],"modstyle",CMDLEN))
00370         app->molrep_set_style(molid, atoi(argv[2]), molstr);
00371       else if(!strupncmp(argv[1],"modselect",CMDLEN))
00372         app->molrep_set_selection(molid, atoi(argv[2]), molstr);
00373       else if(!strupncmp(argv[1],"modmaterial",CMDLEN))
00374         app->molrep_set_material(molid, atoi(argv[2]), molstr);
00375       delete [] molstr;
00376     }
00377   
00378   } else if(argc == 3 && !strupncmp(argv[1],"addrep",CMDLEN)) {
00379     IdList idList;
00380     if (idList.find(interp, app, argv[2]) > 1) {
00381       
00382       Tcl_AppendResult(interp, "mol addrep operates on one molecule only.", NULL);
00383       return TCL_ERROR;
00384     }
00385     if (idList.num() < 1) return TCL_ERROR;
00386     if (!app->molecule_addrep(idList[0])) {
00387       Tcl_AppendResult(interp, "addrep: Unable to add rep to molecule ", 
00388         argv[2], NULL);
00389       return TCL_ERROR;
00390     }
00391 
00392   } else if(argc == 4 && !strupncmp(argv[1],"delrep",CMDLEN)) {
00393     IdList idList;
00394     if (idList.find(interp, app, argv[3]) != 1) {
00395       
00396       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00397       return TCL_ERROR;
00398     }
00399     app->molrep_delete(idList[0], atoi(argv[2]));
00400 
00401   } else if(argc == 4 && !strupncmp(argv[1],"modrep",CMDLEN)) {
00402     // XXX This is freakin' lame - deprecate this, please!
00403     IdList idList;
00404     if (idList.find(interp, app, argv[3]) != 1) {
00405       
00406       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00407       return TCL_ERROR;
00408     }
00409     int molid = idList[0];
00410     int repid = atoi(argv[2]);
00411     app->molrep_set_style(molid, repid, app->molecule_get_style());
00412     app->molrep_set_color(molid, repid, app->molecule_get_color());
00413     app->molrep_set_selection(molid, repid, app->molecule_get_selection());
00414     app->molrep_set_material(molid, repid, app->molecule_get_material());
00415 
00416   } else if(argc == 3 && !strupncmp(argv[1],"delete",CMDLEN)) {
00417     IdList idList;
00418     int allmolsflag=0;
00419 #if 1
00420     idList.find(interp, app, argv[2], &allmolsflag);
00421 #else
00422     idList.find(interp, app, argv[2]);
00423 #endif
00424     if (allmolsflag) {
00425       // use most efficient molecule deletion code path
00426       app->molecule_delete_all();
00427     } else {
00428       // delete molecules piecemeal
00429       for (int i=0; i<idList.num(); i++) {
00430         app->molecule_delete(idList[i]);
00431       }
00432     }
00433   } else if(argc == 3 && (!strupncmp(argv[1],"active",CMDLEN) ||
00434                         !strupncmp(argv[1],"inactive",CMDLEN))) {
00435     IdList idList;
00436     idList.find(interp, app, argv[2]);
00437     for (int i=0; i<idList.num(); i++) {
00438       app->molecule_activate(idList[i], !strupncmp(argv[1],"active",CMDLEN));
00439     }
00440 
00441   } else if(argc == 3 && (!strupncmp(argv[1],"on",CMDLEN) ||
00442                         !strupncmp(argv[1],"off",CMDLEN))) {
00443     IdList idList;
00444     idList.find(interp, app, argv[2]);
00445     for (int i=0; i<idList.num(); i++) {
00446       app->molecule_display(idList[i], !strupncmp(argv[1],"on",CMDLEN));
00447     }
00448 
00449   } else if(argc == 3 && (!strupncmp(argv[1],"fix",CMDLEN) ||
00450                         !strupncmp(argv[1],"free",CMDLEN))) {
00451     IdList idList;
00452     idList.find(interp, app, argv[2]);
00453     for (int i=0; i<idList.num(); i++) {
00454       app->molecule_fix(idList[i], !strupncmp(argv[1],"fix",CMDLEN));
00455     }
00456 
00457   } else if(argc == 3 && !strupncmp(argv[1],"top",CMDLEN)) {
00458     IdList idList;
00459     if (idList.find(interp,app, argv[2]) != 1) {
00460       
00461       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00462       return TCL_ERROR;
00463     }
00464     app->molecule_make_top(idList[0]);
00465 
00466   } else if (argc == 4 && !strupncmp(argv[1], "urlload", CMDLEN)) {
00467     // load a file from a URL
00468     //   "mol urlload xyz http://www.umn.edu/test/me/out.xyz
00469     // vmd_mol_urlload url localfile 
00470     char *localfile = vmd_tempfile("urlload");
00471     char *buf = new char[strlen(localfile)+strlen(argv[3])+100];
00472     sprintf(buf, "vmd_mol_urlload %s %s", argv[3], localfile);
00473     int rc = Tcl_Eval(interp, buf);
00474     delete [] buf;
00475     if (rc != TCL_OK) {
00476       Tcl_AppendResult(interp, "vmd_mol_urllload failed.", NULL);
00477       delete [] localfile;
00478       return TCL_ERROR;
00479     }
00480     FileSpec spec;
00481     spec.waitfor = -1;
00482     int molid = app->molecule_load(-1, localfile, argv[2], &spec);
00483     delete [] localfile;
00484     if (molid < 0) {
00485       Tcl_AppendResult(interp, "urlload failed: unable to load downloaded file '", localfile, "' as file type ", argv[2], NULL);
00486       return TCL_ERROR;
00487     }
00488     Tcl_SetObjResult(interp, Tcl_NewIntObj(molid));
00489 
00490   } else if (argc == 3 && !strupncmp(argv[1], "pdbload", CMDLEN)) {
00491     // alias to "mol load webpdb ..."
00492     FileSpec spec;
00493     spec.waitfor = -1;
00494     int rc = app->molecule_load(-1, argv[2], "webpdb", &spec);
00495     if (rc < 0) {
00496       Tcl_AppendResult(interp, "pdbload of '", argv[2], "' failed.", NULL);
00497       return TCL_ERROR;
00498     }
00499     Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
00500 
00501   } else if (argc == 3 && !strupncmp(argv[1], "reanalyze", CMDLEN)) {
00502     IdList idList;
00503     idList.find(interp, app, argv[2]);
00504     for (int i=0; i<idList.num(); i++) {
00505       app->molecule_reanalyze(idList[i]);
00506     }
00507 
00508   } else if (argc == 3 && !strupncmp(argv[1], "bondsrecalc", CMDLEN)) {
00509     IdList idList;
00510     idList.find(interp, app, argv[2]);
00511     for (int i=0; i<idList.num(); i++) {
00512       app->molecule_bondsrecalc(idList[i]);
00513     }
00514 
00515   } else if (argc == 3 && !strupncmp(argv[1], "ssrecalc", CMDLEN)) {
00516     IdList idList;
00517     idList.find(interp, app, argv[2]);
00518     for (int i=0; i<idList.num(); i++) {
00519       app->molecule_ssrecalc(idList[i]);
00520     }
00521 
00522   } else if (argc == 12 && !strupncmp(argv[1], "volume", CMDLEN)) {
00523     
00524     float origin[3], xaxis[3], yaxis[3], zaxis[3];
00525     int xsize, ysize, zsize;
00526     float *data;  // new'ed here; passed to molecule
00527 
00528     IdList idList;
00529     if (idList.find(interp, app, argv[2]) != 1) {
00530       
00531       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00532       return TCL_ERROR;
00533     }
00534     int molid = idList[0];
00535    
00536     if (tcl_get_vector(argv[4], origin, interp) != TCL_OK ||
00537         tcl_get_vector(argv[5], xaxis, interp) != TCL_OK ||
00538         tcl_get_vector(argv[6], yaxis, interp) != TCL_OK ||
00539         tcl_get_vector(argv[7], zaxis, interp) != TCL_OK) {
00540       return TCL_ERROR;
00541     }
00542     if (Tcl_GetInt(interp, argv[8], &xsize) != TCL_OK ||
00543         Tcl_GetInt(interp, argv[9], &ysize) != TCL_OK ||
00544         Tcl_GetInt(interp, argv[10], &zsize) != TCL_OK) {
00545       return TCL_ERROR;
00546     }
00547     int size = xsize*ysize*zsize;
00548     data = new float[size];
00549    
00550     int ndata;
00551     const char **dataAsString;
00552     if (Tcl_SplitList(interp, argv[11], &ndata, &dataAsString) != TCL_OK) {
00553       Tcl_SetResult(interp, (char *) "mol volume: invalid data block", TCL_STATIC);
00554       delete [] data;
00555       return TCL_ERROR;
00556     }
00557     if (ndata != size) {
00558       Tcl_SetResult(interp, (char *) "mol volume: size of data does not match specified sizes", TCL_STATIC);
00559       Tcl_Free((char *)dataAsString);
00560       delete [] data;
00561       return TCL_ERROR;
00562     }
00563     for (int i=0; i<ndata; i++) {
00564       double tmp;
00565       if (Tcl_GetDouble(interp, dataAsString[i], &tmp) != TCL_OK) {
00566         Tcl_SetResult(interp, (char *) "graphics: volume: non-numeric found in data block", TCL_STATIC);
00567         Tcl_Free((char *)dataAsString);
00568         delete [] data;
00569         return TCL_ERROR;
00570       }
00571       data[i] = (float)tmp;
00572     }
00573     app->molecule_add_volumetric(molid, argv[3], origin, xaxis, yaxis, zaxis,
00574       xsize, ysize, zsize, data);
00575     
00576     Tcl_Free((char *)dataAsString);
00577 
00578   } else if ((argc == 4 || argc == 5) && !strupncmp(argv[1], "selupdate", CMDLEN)) {
00579     IdList idList;
00580     if (idList.find(interp, app, argv[3]) != 1) {
00581       
00582       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00583       return TCL_ERROR;
00584     }
00585     int molid = idList[0];
00586     int repid = atoi(argv[2]);
00587     if (argc == 4) {
00588       char tmpstring[64];
00589       sprintf(tmpstring, "%d", app->molrep_get_selupdate(molid, repid));
00590       Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00591     } else {
00592       int onoff;
00593       if (Tcl_GetBoolean(interp, argv[4], &onoff) != TCL_OK)
00594         return TCL_ERROR; // GetBoolean sets error message.
00595       if (!app->molrep_set_selupdate(molid, repid, onoff)) {
00596         Tcl_AppendResult(interp, "Could not set auto update", NULL);
00597         return TCL_ERROR;
00598       }
00599     }
00600   } else if ((argc == 4 || argc == 5) && !strupncmp(argv[1], "colupdate", CMDLEN)) {
00601     IdList idList;
00602     if (idList.find(interp, app, argv[3]) != 1) {
00603       
00604       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00605       return TCL_ERROR;
00606     }
00607     int molid = idList[0];
00608     int repid = atoi(argv[2]);
00609     if (argc == 4) {
00610       char tmpstring[64];
00611       sprintf(tmpstring, "%d", app->molrep_get_colorupdate(molid, repid));
00612       Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00613     } else {
00614       int onoff;
00615       if (Tcl_GetBoolean(interp, argv[4], &onoff) != TCL_OK)
00616         return TCL_ERROR; // GetBoolean sets error message.
00617       if (!app->molrep_set_colorupdate(molid, repid, onoff)) {
00618         Tcl_AppendResult(interp, "Could not set auto color update", NULL);
00619         return TCL_ERROR;
00620       }
00621     }
00622 
00623   // Clipping plane functions:
00624   // mol clipplane center <clipid> <repid> <molid> [<vector>]
00625   //   set/get the clipplane center
00626   // mol clipplane color <clipid> <repid> <molid> [<vector>]
00627   //   set/get the clipplane color 
00628   // mol clipplane normal <clipid> <repid> <molid> [<vector>]
00629   //   set/get the clipplane normal 
00630   // mol clipplane status <clipid> <repid> <molid> [<mode>]
00631   // mol clipplane num
00632   } else if (argc >= 2 && !strupncmp(argv[1], "clipplane", CMDLEN)) {
00633     if (argc == 3 && !strupncmp(argv[1], "clipplane", CMDLEN) &&
00634         !strupncmp(argv[2], "num", CMDLEN)) {
00635       Tcl_SetObjResult(interp, Tcl_NewIntObj(app->num_clipplanes()));
00636       return TCL_OK;
00637     } else if (argc >= 6 && !strupncmp(argv[1], "clipplane", CMDLEN)) {
00638       int clipid = atoi(argv[3]);
00639       int repid = atoi(argv[4]);
00640       int molid = atoi(argv[5]);  // XXX should use IDList
00641       if (clipid < 0 || clipid >= app->num_clipplanes()) {
00642         Tcl_AppendResult(interp, "Invalid clip plane id specified: ", 
00643            argv[3], NULL);
00644         return TCL_ERROR;
00645       }
00646       if (!app->molecule_valid_id(molid)) {
00647         Tcl_AppendResult(interp, "Invalid molid specified:", argv[5], NULL);
00648         return TCL_ERROR;
00649       }
00650       if (repid < 0 || repid >= app->num_molreps(molid)) {
00651         Tcl_AppendResult(interp, "Invalid repid specified:", argv[4], NULL);
00652         return TCL_ERROR;
00653       }
00654 
00655       float center[3], normal[3], color[3];
00656       int status;
00657       if (argc == 6) {
00658         if (!app->molrep_get_clipplane(molid, repid, clipid, center, normal, color, &status)) {
00659           Tcl_AppendResult(interp, "Unable to get clip plane information", NULL);
00660           return TCL_ERROR;
00661         }
00662         if (!strupncmp(argv[2], "center", CMDLEN)) {
00663           // return center
00664           Tcl_Obj *result = Tcl_NewListObj(0, NULL);
00665           for (int i=0; i<3; i++) {
00666             Tcl_ListObjAppendElement(interp, result, 
00667               Tcl_NewDoubleObj(center[i]));
00668           }
00669           Tcl_SetObjResult(interp, result);
00670           return TCL_OK;
00671         } else if (!strupncmp(argv[2], "normal", CMDLEN)) { 
00672           // return normal
00673           Tcl_Obj *result = Tcl_NewListObj(0, NULL);
00674           for (int i=0; i<3; i++) {
00675             Tcl_ListObjAppendElement(interp, result, 
00676               Tcl_NewDoubleObj(normal[i]));
00677           }
00678           Tcl_SetObjResult(interp, result);
00679           return TCL_OK;
00680         } else if (!strupncmp(argv[2], "color", CMDLEN)) { 
00681           // return color 
00682           Tcl_Obj *result = Tcl_NewListObj(0, NULL);
00683           for (int i=0; i<3; i++) {
00684             Tcl_ListObjAppendElement(interp, result, 
00685               Tcl_NewDoubleObj(color[i]));
00686           }
00687           Tcl_SetObjResult(interp, result);
00688           return TCL_OK;
00689         } else if (!strupncmp(argv[2], "status", CMDLEN)) { 
00690           // return status 
00691           Tcl_SetObjResult(interp, Tcl_NewIntObj(status));
00692           return TCL_OK; 
00693         }
00694       } else if (argc == 7) {
00695         if (!strupncmp(argv[2], "center", CMDLEN)) {
00696           // set center
00697           if (tcl_get_vector(argv[6], center, interp) != TCL_OK) {
00698             return TCL_ERROR;
00699           }
00700           if (!app->molrep_set_clipcenter(molid, repid, clipid, center)) {
00701             Tcl_AppendResult(interp, "Unable to set clip center\n");
00702             return TCL_ERROR;
00703           }
00704         } else if (!strupncmp(argv[2], "normal", CMDLEN)) { 
00705           // set normal
00706           if (tcl_get_vector(argv[6], normal, interp) != TCL_OK) {
00707             return TCL_ERROR;
00708           }
00709           if (!app->molrep_set_clipnormal(molid, repid, clipid, normal)) {
00710             Tcl_AppendResult(interp, "Unable to set clip normal\n");
00711             return TCL_ERROR;
00712           }
00713         } else if (!strupncmp(argv[2], "color", CMDLEN)) { 
00714           // set color
00715           if (tcl_get_vector(argv[6], color, interp) != TCL_OK) {
00716             return TCL_ERROR;
00717           }
00718           if (!app->molrep_set_clipcolor(molid, repid, clipid, color)) {
00719             Tcl_AppendResult(interp, "Unable to set clip color\n");
00720             return TCL_ERROR;
00721           }
00722         } else if (!strupncmp(argv[2], "status", CMDLEN)) { 
00723           // set status 
00724           if (Tcl_GetInt(interp, argv[6], &status) != TCL_OK) {
00725             return TCL_ERROR;
00726           }
00727           if (!app->molrep_set_clipstatus(molid, repid, clipid, status)) {
00728             Tcl_AppendResult(interp, "Unable to set clip status\n");
00729             return TCL_ERROR;
00730           }
00731         }
00732         return TCL_OK;
00733       }
00734     } 
00735     Tcl_AppendResult(interp, "Usage: \n",
00736       "mol clipplane center <clipid> <repid> <molid> [<vector>]\n",
00737       "mol clipplane normal <clipid> <repid> <molid> [<vector>]\n",
00738       "mol clipplane color  <clipid> <repid> <molid> [<vector>]\n",
00739       "mol clipplane status <clipid> <repid> <molid> [<mode>]\n",
00740       "mol clipplane num\n",
00741       NULL);
00742     return TCL_ERROR;
00743   } else if (argc == 4 && !strupncmp(argv[1], "rename", CMDLEN)) {
00744     IdList idList;
00745     if (idList.find(interp, app, argv[2]) != 1) {
00746       
00747       Tcl_AppendResult(interp, argv[0], " operates on one molecule only.", NULL);
00748       return TCL_ERROR;
00749     }
00750     int molid = idList[0];
00751     if (!app->molecule_rename(molid, argv[3])) {
00752       Tcl_AppendResult(interp, "Unable to rename molecule.", NULL);
00753       return TCL_ERROR;
00754     }
00755   } else if (argc==4 && !strupncmp(argv[1], "repname", CMDLEN)) {
00756     IdList idList;
00757     if (idList.find(interp, app, argv[2]) != 1) {
00758       Tcl_AppendResult(interp, argv[0], argv[1], 
00759         " operates on one molecule only", NULL);
00760       return TCL_ERROR;
00761     }
00762     int repid = atoi(argv[3]);
00763     const char *name = app->molrep_get_name(idList[0], repid);
00764     if (!name) {
00765       Tcl_AppendResult(interp, "mol repname: invalid repid ", argv[3], NULL);
00766       return TCL_ERROR;
00767     }
00768     Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
00769   } else if (argc == 4 && !strupncmp(argv[1], "repindex", CMDLEN)) {
00770     IdList idList;
00771     if (idList.find(interp, app, argv[2]) > 1) {
00772       Tcl_AppendResult(interp, argv[0], " ", argv[1], 
00773         " operates on one molecule only", NULL);
00774       return TCL_ERROR;
00775     }
00776     int repid = -1;
00777     if (idList.num() == 1)
00778       repid = app->molrep_get_by_name(idList[0], argv[3]);
00779     Tcl_SetObjResult(interp, Tcl_NewIntObj(repid));
00780 // mol new [filename] [options...]
00781 // mol addfile <filename> [options...]
00782 // options: 
00783 //   type <filetype> 
00784 //   filebonds <onoff> 
00785 //   autobonds <onoff> 
00786 //   first <firstframe> 
00787 //   last <lastframe>
00788 //   step <frame stride>
00789 //   waitfor <all | number>
00790 //   volsets <list of set ids>
00791 //   molid   (for addfile only; must be the last item)
00792   } else if ((argc >= 2 && !strupncmp(argv[1], "new", CMDLEN)) ||
00793              (argc >= 3 && !strupncmp(argv[1], "addfile", CMDLEN))) {
00794 
00795     int molid = -1;
00796     const char *type = NULL;
00797     if (argc == 2) {
00798       molid = app->molecule_new("molecule");
00799       if (molid < 0) {
00800         Tcl_AppendResult(interp, "Unable to create new molecule.", NULL);
00801         return TCL_ERROR;
00802       }
00803       char buf[30];
00804       sprintf(buf, "molecule%d", molid);
00805       app->molecule_rename(molid, buf);
00806     } else if (argc >= 3) {
00807       if (!strupncmp(argv[1], "addfile", CMDLEN)) {
00808         molid = app->molecule_top();
00809       } // otherwise just -1
00810       // Check for optional parameters
00811       FileSpec spec;
00812       int a;
00813       for (a=3; a<argc; a+=2) {
00814         if (!strupncmp(argv[a], "type", CMDLEN)) {
00815           if ((a+1) < argc) {
00816             type = argv[a+1];
00817           } else {
00818             Tcl_AppendResult(interp, "Error, missing type parameter", NULL);
00819             return TCL_ERROR;
00820           }
00821         } else if (!strupncmp(argv[a], "autobonds", CMDLEN)) {
00822           if (Tcl_GetBoolean(interp, argv[a+1], &spec.autobonds) != TCL_OK)
00823             return TCL_ERROR;
00824         } else if (!strupncmp(argv[a], "filebonds", CMDLEN)) {
00825           if (Tcl_GetBoolean(interp, argv[a+1], &spec.filebonds) != TCL_OK)
00826             return TCL_ERROR;
00827         } else if (!strupncmp(argv[a], "first", CMDLEN)) {
00828           if (Tcl_GetInt(interp, argv[a+1], &spec.first) != TCL_OK)
00829             return TCL_ERROR;
00830         } else if (!strupncmp(argv[a], "last", CMDLEN)) {
00831           if (Tcl_GetInt(interp, argv[a+1], &spec.last) != TCL_OK)
00832             return TCL_ERROR;
00833         } else if (!strupncmp(argv[a], "step", CMDLEN)) {
00834           if (Tcl_GetInt(interp, argv[a+1], &spec.stride) != TCL_OK)
00835             return TCL_ERROR;
00836         } else if (!strupncmp(argv[a], "waitfor", CMDLEN)) {
00837           if ((a+1) < argc) {
00838             if (!strupncmp(argv[a+1], "all", CMDLEN)) {
00839               spec.waitfor = -1;
00840             } else {
00841               if (Tcl_GetInt(interp, argv[a+1], &spec.waitfor) != TCL_OK)
00842                 return TCL_ERROR;
00843             }
00844           } else {
00845             Tcl_AppendResult(interp, "Error, missing waitfor parameter", NULL);
00846             return TCL_ERROR;
00847           }
00848         } else if (!strupncmp(argv[a], "volsets", CMDLEN)) {
00849           int nsets;
00850           const char **sets;
00851           if (Tcl_SplitList(interp, argv[a+1], &nsets, &sets) != TCL_OK) {
00852             Tcl_AppendResult(interp, "Cannot parse list of volsets.", NULL);
00853             return TCL_ERROR;
00854           }
00855           if (nsets > 0) {
00856             spec.nvolsets = nsets;
00857             spec.setids = new int[nsets];
00858             for (int i=0; i<nsets; i++) {
00859               if (Tcl_GetInt(interp, sets[i], spec.setids+i) != TCL_OK) {
00860                 return TCL_ERROR;
00861               }
00862             }
00863           }
00864           Tcl_Free((char *)sets);
00865         }
00866       }
00867       if (!type) {
00868         type = app->guess_filetype(argv[2]);
00869         if (!type) {
00870           Tcl_AppendResult(interp, "Could not determine file type for file '",
00871               argv[2], "' from its extension.", NULL);
00872           return TCL_ERROR;
00873         }
00874       }
00875       if (a == argc+1) {
00876         IdList idList;
00877         if (idList.find(interp, app, argv[argc-1]) != 1) {
00878           Tcl_AppendResult(interp, argv[0], " ", argv[1], 
00879             " operates on one molecule only", NULL);
00880           return TCL_ERROR;
00881         }
00882         molid = idList[0];
00883       }
00884       molid = app->molecule_load(molid, argv[2], type, &spec);
00885       if (molid < 0) {
00886         Tcl_AppendResult(interp, "Unable to load file '", argv[2], "' using file type '", type, "'.", NULL);
00887         return TCL_ERROR;
00888       }
00889     }
00890     Tcl_SetObjResult(interp, Tcl_NewIntObj(molid));
00891     return TCL_OK;
00892 
00893   } else if ( (argc == 4 || argc == 5) && !strupncmp(argv[1], "smoothrep", CMDLEN)) {
00894     // smoothrep <molid> <repid> [<smoothness]
00895     IdList idList;
00896     if (idList.find(interp, app, argv[2]) != 1) {
00897       Tcl_AppendResult(interp, argv[0], " ", argv[1],
00898           " operates on one molecule only", NULL);
00899       return TCL_ERROR;
00900     }
00901     int repid;
00902     if (Tcl_GetInt(interp, argv[3], &repid) != TCL_OK) return TCL_ERROR;
00903     if (argc == 4) {
00904       int smooth = app->molrep_get_smoothing(idList[0], repid);
00905       if (smooth < 0) {
00906         Tcl_AppendResult(interp, "mol smoothrep: invalid rep", NULL);
00907         return TCL_ERROR;
00908       }
00909       Tcl_SetObjResult(interp, Tcl_NewIntObj(smooth));
00910     } else {
00911       int smooth;
00912       if (Tcl_GetInt(interp, argv[4], &smooth) != TCL_OK) return TCL_ERROR;
00913       if (smooth < 0) {
00914         Tcl_AppendResult(interp, "mol smoothrep: smoothness must be nonnegative", NULL);
00915         return TCL_ERROR;
00916       }
00917       if (!app->molrep_set_smoothing(idList[0], repid, smooth)) {
00918         Tcl_AppendResult(interp, "mol smoothrep: Unable to set smoothing for this rep", NULL);
00919         return TCL_ERROR;
00920       }
00921     }
00922     return TCL_OK;
00923     // mol showperiodic <molid> <repid> <string>
00924     // where string is x, y, z, xy, xz, yz, or xyz
00925   } else if ((argc == 4 || argc == 5) && !strupncmp(argv[1], "showperiodic", CMDLEN)) {
00926     IdList idList;
00927     if (idList.find(interp, app, argv[2]) != 1) {
00928       Tcl_AppendResult(interp, argv[0], " ", argv[1],
00929           (char *)" operates on one molecule only", NULL);
00930       return TCL_ERROR;
00931     }
00932     int repid;
00933     if (Tcl_GetInt(interp, argv[3], &repid) != TCL_OK) return TCL_ERROR;
00934     if (argc == 5) {
00935       int pbc = PBC_NONE;  // defaults to PBC_NONE if no 5th argument is given
00936       if (strchr(argv[4], 'x')) pbc |= PBC_X;
00937       if (strchr(argv[4], 'y')) pbc |= PBC_Y;
00938       if (strchr(argv[4], 'z')) pbc |= PBC_Z;
00939       if (strchr(argv[4], 'X')) pbc |= PBC_OPX;
00940       if (strchr(argv[4], 'Y')) pbc |= PBC_OPY;
00941       if (strchr(argv[4], 'Z')) pbc |= PBC_OPZ;
00942       if (strchr(argv[4], 'n')) pbc |= PBC_NOSELF;
00943       if (!app->molrep_set_pbc(idList[0], repid, pbc)) {
00944         Tcl_AppendResult(interp, "mol setpbc: Unable to set periodic images for this rep",
00945             NULL);
00946         return TCL_ERROR;
00947       }
00948     } else {
00949       int pbc = app->molrep_get_pbc(idList[0], repid);
00950       if (pbc < 0) {
00951         Tcl_AppendResult(interp, "mol showperiodic: Unable to get periodic info for this rep", NULL);
00952         return TCL_ERROR;
00953       }
00954       char buf[10];
00955       buf[0] = '\0';
00956       if (pbc & PBC_X) strcat(buf, "x");
00957       if (pbc & PBC_Y) strcat(buf, "y");
00958       if (pbc & PBC_Z) strcat(buf, "z");
00959       if (pbc & PBC_OPX) strcat(buf, "X");
00960       if (pbc & PBC_OPY) strcat(buf, "Y");
00961       if (pbc & PBC_OPZ) strcat(buf, "Z");
00962       if (pbc & PBC_NOSELF) strcat(buf, "n");
00963       Tcl_SetResult(interp, buf, TCL_VOLATILE);
00964     }
00965   } else if ((argc == 4 || argc == 5) && !strupncmp(argv[1], "numperiodic", CMDLEN)) {
00966     IdList idList;
00967     if (idList.find(interp, app, argv[2]) != 1) {
00968       Tcl_AppendResult(interp, argv[0], " ", argv[1],
00969           (char *)" operates on one molecule only", NULL);
00970       return TCL_ERROR;
00971     }
00972     int repid;
00973     if (Tcl_GetInt(interp, argv[3], &repid) != TCL_OK) return TCL_ERROR;
00974     if (argc == 5) {
00975       int npbc;
00976       if (Tcl_GetInt(interp, argv[4], &npbc) != TCL_OK) return TCL_ERROR;
00977       if (!app->molrep_set_pbc_images(idList[0], repid, npbc)) {
00978         Tcl_AppendResult(interp, "mol numperiodic: Unable to set number of replicas for this rep", NULL);
00979         return TCL_ERROR;
00980       }
00981     } else {
00982       int npbc = app->molrep_get_pbc_images(idList[0], repid);
00983       if (npbc < 0) {
00984         Tcl_AppendResult(interp, "mol numperiodic: Unable to get number of replicas for this rep", NULL);
00985         return TCL_ERROR;
00986       }
00987       Tcl_SetObjResult(interp, Tcl_NewIntObj(npbc));
00988     }
00989   } else if ((argc >= 4 && argc <= 6) && !strupncmp(argv[1], "scaleminmax", CMDLEN)) {
00990     IdList idList;
00991     if (idList.find(interp, app, argv[2]) != 1) {
00992       Tcl_AppendResult(interp, argv[0], " ", argv[1],
00993           (char *)" operates on one molecule only", NULL);
00994       return TCL_ERROR;
00995     }
00996     int repid;
00997     if (Tcl_GetInt(interp, argv[3], &repid) != TCL_OK) return TCL_ERROR;
00998     if (argc == 4) {
00999       float min, max;
01000       if (!app->molrep_get_scaleminmax(idList[0], repid, &min, &max)) {
01001         Tcl_AppendResult(interp, "mol scaleminmax: Unable to get color range for this rep", NULL);
01002         return TCL_ERROR;
01003       }
01004 
01005       char tmpstring[128];
01006       sprintf(tmpstring, "%f %f", min, max);
01007       Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
01008     } else if (argc == 5 && !strupncmp(argv[4], "auto", CMDLEN)) {
01009       if (!app->molrep_reset_scaleminmax(idList[0], repid)) {
01010         Tcl_AppendResult(interp, "mol scaleminmax: Unable to reset color range for this rep", NULL);
01011         return TCL_ERROR;
01012       }
01013     } else {
01014       double min, max;
01015       if (Tcl_GetDouble(interp, argv[4], &min) != TCL_OK ||
01016           Tcl_GetDouble(interp, argv[5], &max) != TCL_OK)
01017         return TCL_ERROR;
01018       if (!app->molrep_set_scaleminmax(idList[0],repid,(float)min,(float)max)) {
01019         Tcl_AppendResult(interp, "mol scaleminmax: Unable to set color range for this rep", NULL);
01020         return TCL_ERROR;
01021       }
01022     }
01023     // mol showrep <molid> <repid> [<onoff>]
01024   } else if ((argc == 4 || argc == 5) && !strupncmp(argv[1], "showrep", CMDLEN)) {
01025     IdList idList;
01026     if (idList.find(interp, app, argv[2]) != 1) {
01027       Tcl_AppendResult(interp, argv[0], " ", argv[1],
01028           (char *)" operates on one molecule only", NULL);
01029       return TCL_ERROR;
01030     }
01031     int repid;
01032     if (Tcl_GetInt(interp, argv[3], &repid) != TCL_OK) return TCL_ERROR;
01033     if (argc == 4) {
01034       Tcl_SetObjResult(interp, Tcl_NewIntObj(app->molrep_is_shown(idList[0], repid)));
01035     } else {
01036       int onoff;
01037       if (Tcl_GetBoolean(interp, argv[4], &onoff) != TCL_OK) return TCL_ERROR;
01038       if (!app->molrep_show(idList[0], repid, onoff)) {
01039         Tcl_AppendResult(interp, "Unable to show/hide this rep", NULL);
01040         return TCL_ERROR;
01041       }
01042     }
01043   } else if ((argc == 4 || argc == 5) && !strupncmp(argv[1], "drawframes", CMDLEN)) {
01044     IdList idList;
01045     if (idList.find(interp, app, argv[2]) != 1) {
01046       Tcl_AppendResult(interp, argv[0], " ", argv[1],
01047           (char *)" operates on one molecule only", NULL);
01048       return TCL_ERROR;
01049     }
01050     int repid;
01051     if (Tcl_GetInt(interp, argv[3], &repid) != TCL_OK) return TCL_ERROR;
01052 
01053     if (argc == 4) {
01054       Tcl_SetObjResult(interp, Tcl_NewStringObj(app->molrep_get_drawframes(idList[0], repid), -1));
01055     } else {
01056       if (!app->molrep_set_drawframes(idList[0], repid, argv[4])) {
01057         Tcl_AppendResult(interp, "Set drawframes failed.", NULL);
01058         return TCL_ERROR;
01059       }
01060     }
01061   } else if ((argc == 3 || argc == 4) && !strupncmp(argv[1], "default", CMDLEN)) {
01062     if (argc == 3) {
01063       if (!strupncmp(argv[2], "color", CMDLEN)) {
01064         Tcl_SetResult(interp, (char *)app->moleculeList->default_color(), TCL_VOLATILE);
01065       } else if (!strupncmp(argv[2], "style", CMDLEN) || !strupncmp(argv[2], "representation", CMDLEN)) {
01066 
01067         Tcl_SetResult(interp, (char *)app->moleculeList->default_representation(), TCL_VOLATILE);
01068       } else if (!strupncmp(argv[2], "selection", CMDLEN)) {
01069         Tcl_SetResult(interp, (char *)app->moleculeList->default_selection(), TCL_VOLATILE);
01070       } else if (!strupncmp(argv[2], "material", CMDLEN)) {
01071         Tcl_SetResult(interp, (char *)app->moleculeList->default_material(), TCL_VOLATILE);
01072       } else {
01073         Tcl_SetResult(interp, "Usage: mol default [color | style | selection | material]", TCL_STATIC);
01074         return TCL_ERROR;
01075       }
01076       return TCL_OK;
01077     } else {
01078       if (!strupncmp(argv[2], "color", CMDLEN)) {
01079         if (!app->moleculeList->set_default_color(argv[3])) {
01080           Tcl_AppendResult(interp, "Could not set default color to ", argv[3], NULL);
01081           return TCL_ERROR;
01082         }
01083       } else if (!strupncmp(argv[2], "style", CMDLEN) || !strupncmp(argv[2], "representation", CMDLEN)) {
01084         if (!app->moleculeList->set_default_representation(argv[3])) {
01085           Tcl_AppendResult(interp, "Could not set default style to ", argv[3], NULL);
01086           return TCL_ERROR;
01087         }
01088       } else if (!strupncmp(argv[2], "selection", CMDLEN)) {
01089         if (!app->moleculeList->set_default_selection(argv[3])) {
01090           Tcl_AppendResult(interp, "Could not set default selection to ", argv[3], NULL);
01091           return TCL_ERROR;
01092         }
01093       } else if (!strupncmp(argv[2], "material", CMDLEN)) {
01094         if (!app->moleculeList->set_default_material(argv[3])) {
01095           Tcl_AppendResult(interp, "Could not set default material to ", argv[3], NULL);
01096           return TCL_ERROR;
01097         }
01098       } else {
01099         Tcl_SetResult(interp, "Usage: mol default [color | style | selection | material] <value>", TCL_STATIC);
01100         return TCL_ERROR;
01101       }
01102       return TCL_OK;
01103     }
01104   } else {
01105     cmd_mol_usage(interp);
01106     return TCL_ERROR;
01107   }
01108   return TCL_OK;
01109 }
01110 
01111 

Generated on Sun Jul 6 01:27:21 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002