Skip to content

Pegamoid crashes when reading a second .h5 file

Hi,

First, thank you for this nice orbital viewer. There seems to be an issue when using the "Load file..." button the second time to load a .h5 file (can even be the same one as the one loaded the first time). Pegamoid crashes with the error message shown below.

Traceback (most recent call last):
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 4659, in file_read
    self.orbitals = self._fileReadThread.orbitals
    ^^^^^^^^^^^^^
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 3750, in orbitals
    self._orbitals_changed(value)
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 3838, in _orbitals_changed
    self.new_box()
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 4908, in new_box
    self.boxSize = self.default_box()[0]
    ^^^^^^^^^^^^
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 4333, in boxSize
    self._boxSize_changed(value, old)
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 4341, in _boxSize_changed
    self.build_grid()
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 4993, in build_grid
    self.update_cache(ngrid)
  File "C:\Users\mfleuti\.conda\envs\pega\Scripts\pegamoid.py", line 5113, in update_cache
    self._cache_file = np.memmap(os.path.join(self._tmpdir, '{0}.cache'.format(__name__.lower())), dtype=dtype, mode='w+', shape=(sum(self.orbitals.N_bas), npoints))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mfleuti\.conda\envs\pega\Lib\site-packages\numpy\core\memmap.py", line 229, in __new__
    f_ctx = open(os_fspath(filename), ('r' if mode == 'c' else mode)+'b')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: 'C:\\Users\\mfleuti\\AppData\\Local\\Temp\\tmpi79u4cc8\\pegamoid.cache '

This behavior seems to be fixed by changing lines

self._cache_file = np.memmap(os.path.join(self._tmpdir, '{0}.cache'.format(__name__.lower())), dtype=dtype, mode='w+', shape=(sum(self.orbitals.N_bas), npoints))

and

self._dens_cache = np.memmap(os.path.join(self._tmpdir, '{0}.cache'.format(__name__.lower()), dtype=dtype, mode='w+', shape=(maxdens, npoints+1))

to use a TemporaryFile instead of the os.path.join(...) thing

Although that might break other things I am not aware of...

I am running Pegamoid inside a conda environment on a windows machine.

Best wishes, Martin

Edited by Jellby