From: Andrew Dalke (dalke_at_mag.com)
Date: Thu Nov 06 1997 - 04:24:54 CST

Hello,

  I'm glad you could track it down to a simultaneous open file
descriptor problem as I was worried that there was yet another
Babel peculiarity I would have to figure out.

> I imagine the fix should be trivial.

  I tracked the problem down to CoorFileData.C . The best solution is to
take Ivo's suggestion and do everything within a Tcl loop.

The real solution requires some explaining of VMD internals:

  If a file format needs Babel, VMD calls Babel to do the translation to PDB
  Since animation formats use multiple PDB files, for those cases VMD puts
     a sequence of "read PDB file XXXXX" commands on the command queue.
  The command queue opens the file and places it on the input file queue
     (technically, ResizeArray<CoorFileData *> coorIOFiles)
  During each step through the main event loop (in the 'prepare' phase) the
     next frame from the top file in the input queue is read (if there are
     no frames remaining, it is closed and popped off the stack)

The problem is CoorFileData calls "open" during the constructor, but that
file isn't used until possibly much later. This is where VMD can run out
of file descriptors.

The solution is to move the open call (the text in CoorFileData.C in
the else block that starts:
    // open the requested file and initialize it, to make sure it's valid
) down to CoorFileData::next.

You'll also have to change Molecule.C so it doesn't use
  if(cfdata->opened) {
in MoleculeFile::read_coor_file to determine if the file is available.
(Either ignore the value, or do a stat, or open then close the file.)

Similarly, you'll have to change MoleculeFile::write_coor_file to
take advantage of the changes.

So it isn't trivial, but not too hard. Thanks for the bug report.

                                                Andrew