sisl icon indicating copy to clipboard operation
sisl copied to clipboard

Siesta read wfs and wfsx files

Open zerothi opened this issue 4 years ago • 11 comments

Describe the feature Title says it all.

Probably this should only be in fdf since then we can read the Hamiltonian and associate it simultaneously with the gauge.

zerothi avatar Oct 21 '19 10:10 zerothi

Given this some thought and files should implement this read_state method

zerothi avatar Feb 15 '20 20:02 zerothi

This would be very nice to have :)

pfebrer avatar Jun 03 '20 17:06 pfebrer

I'll reopen since it is not stable for real use. It is slow and only provides one way of dealing with it.

zerothi avatar Jun 03 '20 21:06 zerothi

I would like to improve the reading of WFSX files so that it is usable in practice for visualization purposes. I have two different use cases:

  • Get the eigenstate for a given k point (e.g. to plot wavefunctions): In this case, a quick solution could be to read the whole file once to get all k points, pick the best match (if any) and then use _siesta.read_wfsx_index_* to read the eigenstate. This would be simple and scale linearly because the worst case is that you need to read the full file twice. Not optimal I guess but better than the current implementation.
  • Iterate over all eigenstates (e.g. for fatbands): I'm sorry if this is stupid because I don't know how the interaction between python and fortran works. Can you keep the file handle open in fortran so that when you call _siesta.read_wfsx_index_* it doesn't read the file from the beginning again? Otherwise could a temporary solution be to just read everything in one go? It could make the computer run out of memory, but at least it would be usable for not that big WFSX files and again much faster than the current implementation.

Also, I've done a quick search to know if direct accessing is a possibility (i.e. going directly to the part of the file where the WF that we want is). It seems like there are portability issues between fortran runtimes. Is that right? Do you know if it could be possible to use for WFSX files?

pfebrer avatar Oct 19 '21 15:10 pfebrer

Good idea, could you have a look in the gf fortran sources, they can do this and is quite sufficient in performance!

zerothi avatar Oct 19 '21 15:10 zerothi

What do I have to do to test changes in fortran sources? Reinstall sisl again?

pfebrer avatar Oct 19 '21 15:10 pfebrer

What do I have to do to test changes in fortran sources? Reinstall sisl again?

Yes, it is fastest locally, and fortran codes are quite fast to compile, so I don't think it should be a problem? A little tedious, but ok...

zerothi avatar Oct 19 '21 15:10 zerothi

So say I add a new function in sisl/io/siesta/wfsx_read.f90. Just doing pip uninstall sisl and pip install sisl should make the function available under sisl.io.siesta._siesta?

pfebrer avatar Oct 19 '21 15:10 pfebrer

Yes, if all you do is change the wfsx_read.f90 source file, then all you need is to re-install the code to ensure it gets compiled. This should also be trivially seen when installing, it lists gfortran commands if it compiles the sources, and setuptools detects changes from a build directory. So you don't need anything special in this regard.

Only if you want to add a file (which I don't think you need, except if you need wfsx_write.f90?).

I would encourage you to do the same as in sisl/io/siesta/_src/gf_read.f90 for consistency, there exists a function read_gf_find which jumps the file-handle forward to the correct position (just before the actual data). Then a subsequent read returns the data.

As a last remark, note that WFSX files contain the k-points in 1/bohr units (as far as I recall).

zerothi avatar Oct 19 '21 16:10 zerothi

Oh, and check the _gfSile which contains the file handle. The wfsx_read.f90 should be changed quite a bit to store file unit from fortran. In that way you can have the file open and need not read through the entire file on every call (this is what can be very problematic...)

zerothi avatar Oct 19 '21 16:10 zerothi

Also, I've done a quick search to know if direct accessing is a possibility (i.e. going directly to the part of the file where the WF that we want is). It seems like there are portability issues between fortran runtimes. Is that right? Do you know if it could be possible to use for WFSX files?

This won't work due to the incompatibilities as you mention. Storing the file handle in the python object is the way forward :)

zerothi avatar Oct 19 '21 20:10 zerothi

I believe @pfebrer has done everything here :) I'll close this.

zerothi avatar Jan 08 '23 14:01 zerothi