Parsing CASTEP Formatted Density Header Grid

When parsing a CASTEP formatted grid with python, you may be tempted to use numpy.loadtxt – in particular, as it allows for fast access to the numerical data afterwards. However, you need to know the number of grid points in each dimension in order to work out the proper arguments for numpy.reshape. I my office, ridiculous ideas how to get this information from the comments of the file header emerged quite quickly. Here’s the associated timing along with the disappointing result that the simplest solution actually is the fastest. (Tests on Late-2013 Mac with a 2.4 GHz i5 and SSD)

Results (time per run in seconds):

Leave a comment

Your e-mail address will not be published.