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

Generated on Sat May 26 01:47:46 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002