cube_parser
Cube parser, taken from cubetools (see below).
Module: cubetools
Description: Module to work with Gaussian cube format files (see http://paulbourke.net/dataformats/cube/)
What does it do:
Read/write cube files to/from numpy arrays (dtype=float*)
Read/write pairse of cube files to/from numpy arrays (dtype=complex*)
Provides a CubeFile object, to be used when cubefiles with constant and static data is required. It simulates the readline method of a file object with a cube file opened, without creating a file
Dependency: numpy
Author: P. R. Vaidyanathan (aditya95sriram <at> gmail <dot> com) Date: 25th June 2017
MIT License
Copyright (c) 2019 P. R. Vaidyanathan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- class CubeFile(srcname, const=1)[source]
Bases:
object
Object which mimics a cube file opened as a file object.
Done by returning output in the correct format, matching the metadata of the source cube file and replacing volumetric data with static data provided as arg to the constructor. Doesn’t copy atoms metadata, retains number of atoms, but returns dummy atoms Mimics file object’s readline method.
- Parameters:
srcname (string) – source file to copy metadata from
const (int) – numeric value to return instead of volumetric data
- read_cube(fname)[source]
Read cube file into numpy array.
- Parameters:
fname (string) – filename of cube file.
- Returns:
data (numpy.array) – Data from cube file.
meta (dict) – Metadata from cube file.
- read_imcube(rfname, ifname='')[source]
Read in two cube files at once.
One contains the real part and the other contains the imag part. If only one filename given, other filename is inferred.
params:
returns: np.array (real part + j*imag part)
- Parameters:
rfname (string) – filename of cube file of real part
ifname (string) – optional, filename of cube file of imag part
- Returns:
data (numpy.array) – Data from cube file.
meta (dict) – Meta data from cube file.
- write_cube(data, meta, fname)[source]
Write volumetric data to cube file.
- Parameters:
data (numpy.array) – volumetric data consisting real values
meta (dict) –
dict containing metadata with following keys:
atoms: list of atoms in the form (mass, [position])
org: origin
xvec,yvec,zvec: lattice vector basis
fname (string) – filename of cubefile (existing files overwritten)
- write_imcube(data, meta, rfname, ifname='')[source]
Write two cube files from compley valued volumetric data.
One for the real part and one for the imaginary part. Data about atoms, origin and lattice vectors are kept same for both. If only one filename given, other filename is inferred.
- Parameters:
data (numpy.array) – volumetric data consisting complex values
meta (dict) –
dict containing metadata with following keys:
atoms: list of atoms in the form (mass, [position])
org: origin
xvec,yvec,zvec: lattice vector basis
rfname (string) – filename of cube file containing real part
ifname (string) – optional, filename of cube file containing imag part