saving TSHS file as NetCDF4 format

Asked by Zhenfei Liu on 2017-01-11

I have a naive question: I saw in Src/m_ts_io.F90, there is "ts_read_TSHS_nc" that can read a TSHS file in NetCDF4 format - but I am just wondering, is there a way to save/write TSHS file as NetCDF4 format? In that same file, it seems to me that the "ts_write_TSHS" only writes the files in the regular format. Can we even convert a regular TSHS file to .nc format? Or is there a plan to add that functionality to save / convert TSHS file to NetCDF4 format in the future?

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
Siesta Edit question
Assignee:
Nick Papior Edit question
Solved by:
Nick Papior
Solved:
2017-01-11
Last query:
2017-01-11
Last reply:
2017-01-11
Best Nick Papior (nickpapior) said : #1

The NetCDF-4 format of siesta/transiesta can be achieved by using the fdf flag:

CDF.Save T

which will create a file called SIESTA.nc.
This file contains ALL required information regarded Hamiltonian, density matrix, real-space grids etc.
Due to it being a NetCDF-4 file this file enables intrinsic compression by adding this flag:

CDF.Compress <integer>

the integer must be between 0 (no compression) to 9 (highest compression). A reasonable value is 3.

If you have the TSHS file you can convert it to a SIESTA.nc file using the sisl tool-package (developed by me).

https://github.com/zerothi/sisl

This Python package can do many more things than just converting a TSHS file to NetCDF-4. For instance it can be used to generate tight-binding models for tbtrans (easily construction of tight-binding models on more than 500,000 atoms!). For details see the package site and the recent transiesta paper:

http://www.sciencedirect.com/science/article/pii/S001046551630306X

In order to convert from TSHS to nc you may use this small script:

>>> script begin <<<
#!/usr/bin/env python
import sys
import sisl
# Read the electronic structure from the file
H = get_sile(sys.argv[1]).read_es()
H.write('output.nc')
>>> script end <<<

and then call it by:

python convert.py siesta.TSHS

Note that you can change the Hamiltonian elements and do band-structures etc. using the Python sisl tool package. See the API documentation for details.

Zhenfei Liu (zfliu) said : #2

Thanks Nick Papior, that solved my question.

Nick Papior (nickpapior) said : #3

Note that the script should have read:

>>> script begin <<<
#!/usr/bin/env python
import sys
import sisl
# Read the electronic structure from the file
H = sisl.get_sile(sys.argv[1]).read_hamiltonian()
H.write('output.nc')
>>> script end <<<

and secondly, this only works for TSHS files generated from siesta versions 4.1 and later.