Skip to content

Instantly share code, notes, and snippets.

@roguephysicist
Created October 29, 2019 00:19
Show Gist options
  • Save roguephysicist/8afdf7142d7cd84b028e980f47f39246 to your computer and use it in GitHub Desktop.
Save roguephysicist/8afdf7142d7cd84b028e980f47f39246 to your computer and use it in GitHub Desktop.
Python NetCDF4: read kpts
'''
A simple script for reading the "kpts.nc" NetCDF file generated by ABINIT, for
determining the generated kpt grid.
'''
import netCDF4
import numpy as np
def kpts_abi(infile):
'''
Reads "infile" using netCDF4 and loads the kpt grid into a numpy array.
'''
rootgrp = netCDF4.Dataset(infile, mode="r")
return np.array((rootgrp.variables["reduced_coordinates_of_kpoints"]))
GRID = kpts_abi("kpts.nc")
np.savetxt('kpts.out', GRID, fmt='% 10.8E % 10.8E % 10.8E')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment