Skip to content

Instantly share code, notes, and snippets.

@aditya95sriram
Last active October 3, 2018 21:21
Show Gist options
  • Save aditya95sriram/ecffa33089713e1ef9f74e292bae4afb to your computer and use it in GitHub Desktop.
Save aditya95sriram/ecffa33089713e1ef9f74e292bae4afb to your computer and use it in GitHub Desktop.
Sample usage of cubetools.py
import cubetools
# https://gist.github.com/aditya95sriram/8d1fccbb91dae93c4edf31cd6a22510f
# read_cube function reads in cube file as (numpy array, metadata) tuple
data, meta = cubetools.read_cube('demo.cube')
# volumetric data
print data.shape
# (8L, 8L, 8L)
# metadata
print meta['org'] # origin
# [0.0, 0.0, 0.0]
print meta['xvec'], meta['yvec'], meta['zvec']
# [0.151178, 0.0, 0.0] [0.0, 0.151178, 0.0] [0.0, 0.0, 0.151178]
print meta['atoms']
# [(6, [6.0, 15.117809, 15.117809, 15.117809])]
# write_cube function writes numpy array and metadata to file
# size information is inferred from numpy array and
# metadata doesn't contain size information
cubetools.write_cube(data[:5,:5,:5], meta, 'new.cube')
# read_imcube function reads in two cube files one containing real component
# of volumetric data and the other containing imaginary component
# as a (numpy complex128 array, metadata) tuple
# retains metadata from file containing real component
data, meta = cubetools.read_imcube('demo.cube', 'demo.cube')
print data.dtype
# complex128
print data.shape
# (8L, 8L, 8L)
# write_imcube function writes numpy complex128 array and metadata to file
cubetools.write_imcube(data[:5,:5,:5], meta, 'new.real.cube', 'new.imag.cube')
Cubefile created by cubetools.py
source: none
1 0.000000 0.000000 0.000000
8 0.151178 0.000000 0.000000
8 0.000000 0.151178 0.000000
8 0.000000 0.000000 0.151178
6 6.000000 15.117809 15.117809 15.117809
-2.41160E+00 -1.82970E+00 -1.15690E+00 -1.74140E+00 -3.56050E+00 -5.66240E+00
-6.87530E+00 -6.41720E+00
-1.82970E+00 -1.45910E+00 -1.15950E+00 -1.97120E+00 -3.82710E+00 -5.84170E+00
-6.90200E+00 -6.33450E+00
-1.15690E+00 -1.15950E+00 -1.53610E+00 -2.74600E+00 -4.58800E+00 -6.29960E+00
-6.90680E+00 -6.07500E+00
-1.74140E+00 -1.97120E+00 -2.74600E+00 -4.08810E+00 -5.66240E+00 -6.78160E+00
-6.70550E+00 -5.64260E+00
-3.56050E+00 -3.82710E+00 -4.58800E+00 -5.66240E+00 -6.63160E+00 -6.88550E+00
-6.16260E+00 -5.12310E+00
-5.66240E+00 -5.84170E+00 -6.29960E+00 -6.78160E+00 -6.88550E+00 -6.33450E+00
-5.40370E+00 -4.64800E+00
-6.87530E+00 -6.90200E+00 -6.90680E+00 -6.70550E+00 -6.16260E+00 -5.40370E+00
-4.73750E+00 -4.24790E+00
-6.41720E+00 -6.33450E+00 -6.07500E+00 -5.64260E+00 -5.12310E+00 -4.64800E+00
-4.24790E+00 -3.85840E+00
-1.82970E+00 -1.45910E+00 -1.15950E+00 -1.97120E+00 -3.82710E+00 -5.84170E+00
-6.90200E+00 -6.33450E+00
-1.45910E+00 -1.24750E+00 -1.23370E+00 -2.21890E+00 -4.08810E+00 -6.00790E+00
-6.91580E+00 -6.24940E+00
-1.15950E+00 -1.23370E+00 -1.74140E+00 -3.01770E+00 -4.82450E+00 -6.42450E+00
-6.88550E+00 -5.98700E+00
-1.97120E+00 -2.21890E+00 -3.01770E+00 -4.34230E+00 -5.84170E+00 -6.83530E+00
-6.64140E+00 -5.56060E+00
-3.82710E+00 -4.08810E+00 -4.82450E+00 -5.84170E+00 -6.71350E+00 -6.85380E+00
-6.07510E+00 -5.06010E+00
-5.84170E+00 -6.00790E+00 -6.42450E+00 -6.83530E+00 -6.85380E+00 -6.24940E+00
-5.32940E+00 -4.60590E+00
-6.90200E+00 -6.91580E+00 -6.88550E+00 -6.64140E+00 -6.07510E+00 -5.32940E+00
-4.69180E+00 -4.21580E+00
-6.33450E+00 -6.24940E+00 -5.98700E+00 -5.56060E+00 -5.06010E+00 -4.60590E+00
-4.21580E+00 -3.83050E+00
-1.15690E+00 -1.15950E+00 -1.53610E+00 -2.74600E+00 -4.58800E+00 -6.29960E+00
-6.90680E+00 -6.07500E+00
-1.15950E+00 -1.23370E+00 -1.74140E+00 -3.01770E+00 -4.82450E+00 -6.42450E+00
-6.88550E+00 -5.98700E+00
-1.53610E+00 -1.74140E+00 -2.47840E+00 -3.82710E+00 -5.47050E+00 -6.71360E+00
-6.76310E+00 -5.72660E+00
-2.74600E+00 -3.01770E+00 -3.82710E+00 -5.05100E+00 -6.29960E+00 -6.91580E+00
-6.41700E+00 -5.32930E+00
-4.58800E+00 -4.82450E+00 -5.47050E+00 -6.29960E+00 -6.87530E+00 -6.70560E+00
-5.81230E+00 -4.88760E+00
-6.29960E+00 -6.42450E+00 -6.71360E+00 -6.91580E+00 -6.70560E+00 -5.98700E+00
-5.12300E+00 -4.48830E+00
-6.90680E+00 -6.88550E+00 -6.76310E+00 -6.41700E+00 -5.81230E+00 -5.12300E+00
-4.56530E+00 -4.12230E+00
-6.07500E+00 -5.98700E+00 -5.72660E+00 -5.32930E+00 -4.88760E+00 -4.48830E+00
-4.12230E+00 -3.74960E+00
-1.74140E+00 -1.97120E+00 -2.74600E+00 -4.08810E+00 -5.66240E+00 -6.78160E+00
-6.70550E+00 -5.64260E+00
-1.97120E+00 -2.21890E+00 -3.01770E+00 -4.34230E+00 -5.84170E+00 -6.83530E+00
-6.64140E+00 -5.56060E+00
-2.74600E+00 -3.01770E+00 -3.82710E+00 -5.05100E+00 -6.29960E+00 -6.91580E+00
-6.41700E+00 -5.32930E+00
-4.08810E+00 -4.34230E+00 -5.05100E+00 -6.00770E+00 -6.78150E+00 -6.81270E+00
-5.98690E+00 -4.99990E+00
-5.66240E+00 -5.84170E+00 -6.29960E+00 -6.78150E+00 -6.88540E+00 -6.33440E+00
-5.40370E+00 -4.64810E+00
-6.78160E+00 -6.83530E+00 -6.91580E+00 -6.81270E+00 -6.33440E+00 -5.56060E+00
-4.83520E+00 -4.31310E+00
-6.70550E+00 -6.64140E+00 -6.41700E+00 -5.98690E+00 -5.40370E+00 -4.83520E+00
-4.38080E+00 -3.97250E+00
-5.64260E+00 -5.56060E+00 -5.32930E+00 -4.99990E+00 -4.64810E+00 -4.31310E+00
-3.97250E+00 -3.62310E+00
-3.56050E+00 -3.82710E+00 -4.58800E+00 -5.66240E+00 -6.63160E+00 -6.88550E+00
-6.16260E+00 -5.12310E+00
-3.82710E+00 -4.08810E+00 -4.82450E+00 -5.84170E+00 -6.71350E+00 -6.85380E+00
-6.07510E+00 -5.06010E+00
-4.58800E+00 -4.82450E+00 -5.47050E+00 -6.29960E+00 -6.87530E+00 -6.70560E+00
-5.81230E+00 -4.88760E+00
-5.66240E+00 -5.84170E+00 -6.29960E+00 -6.78150E+00 -6.88540E+00 -6.33440E+00
-5.40370E+00 -4.64810E+00
-6.63160E+00 -6.71350E+00 -6.87530E+00 -6.88540E+00 -6.49600E+00 -5.72650E+00
-4.94240E+00 -4.38080E+00
-6.88550E+00 -6.85380E+00 -6.70560E+00 -6.33440E+00 -5.72650E+00 -5.06010E+00
-4.52620E+00 -4.09160E+00
-6.16260E+00 -6.07510E+00 -5.81230E+00 -5.40370E+00 -4.94240E+00 -4.52620E+00
-4.15310E+00 -3.77630E+00
-5.12310E+00 -5.06010E+00 -4.88760E+00 -4.64810E+00 -4.38080E+00 -4.09160E+00
-3.77630E+00 -3.46350E+00
-5.66240E+00 -5.84170E+00 -6.29960E+00 -6.78160E+00 -6.88550E+00 -6.33450E+00
-5.40370E+00 -4.64800E+00
-5.84170E+00 -6.00790E+00 -6.42450E+00 -6.83530E+00 -6.85380E+00 -6.24940E+00
-5.32940E+00 -4.60590E+00
-6.29960E+00 -6.42450E+00 -6.71360E+00 -6.91580E+00 -6.70560E+00 -5.98700E+00
-5.12300E+00 -4.48830E+00
-6.78160E+00 -6.83530E+00 -6.91580E+00 -6.81270E+00 -6.33440E+00 -5.56060E+00
-4.83520E+00 -4.31310E+00
-6.88550E+00 -6.85380E+00 -6.70560E+00 -6.33440E+00 -5.72650E+00 -5.06010E+00
-4.52620E+00 -4.09160E+00
-6.33450E+00 -6.24940E+00 -5.98700E+00 -5.56060E+00 -5.06010E+00 -4.60580E+00
-4.21570E+00 -3.83050E+00
-5.40370E+00 -5.32940E+00 -5.12300E+00 -4.83520E+00 -4.52620E+00 -4.21570E+00
-3.88620E+00 -3.55230E+00
-4.64800E+00 -4.60590E+00 -4.48830E+00 -4.31310E+00 -4.09160E+00 -3.83050E+00
-3.55230E+00 -3.28300E+00
-6.87530E+00 -6.90200E+00 -6.90680E+00 -6.70550E+00 -6.16260E+00 -5.40370E+00
-4.73750E+00 -4.24790E+00
-6.90200E+00 -6.91580E+00 -6.88550E+00 -6.64140E+00 -6.07510E+00 -5.32940E+00
-4.69180E+00 -4.21580E+00
-6.90680E+00 -6.88550E+00 -6.76310E+00 -6.41700E+00 -5.81230E+00 -5.12300E+00
-4.56530E+00 -4.12230E+00
-6.70550E+00 -6.64140E+00 -6.41700E+00 -5.98690E+00 -5.40370E+00 -4.83520E+00
-4.38080E+00 -3.97250E+00
-6.16260E+00 -6.07510E+00 -5.81230E+00 -5.40370E+00 -4.94240E+00 -4.52620E+00
-4.15310E+00 -3.77630E+00
-5.40370E+00 -5.32940E+00 -5.12300E+00 -4.83520E+00 -4.52620E+00 -4.21570E+00
-3.88620E+00 -3.55230E+00
-4.73750E+00 -4.69180E+00 -4.56530E+00 -4.38080E+00 -4.15310E+00 -3.88620E+00
-3.59910E+00 -3.32130E+00
-4.24790E+00 -4.21580E+00 -4.12230E+00 -3.97250E+00 -3.77630E+00 -3.55230E+00
-3.32130E+00 -3.08730E+00
-6.41720E+00 -6.33450E+00 -6.07500E+00 -5.64260E+00 -5.12310E+00 -4.64800E+00
-4.24790E+00 -3.85840E+00
-6.33450E+00 -6.24940E+00 -5.98700E+00 -5.56060E+00 -5.06010E+00 -4.60590E+00
-4.21580E+00 -3.83050E+00
-6.07500E+00 -5.98700E+00 -5.72660E+00 -5.32930E+00 -4.88760E+00 -4.48830E+00
-4.12230E+00 -3.74960E+00
-5.64260E+00 -5.56060E+00 -5.32930E+00 -4.99990E+00 -4.64810E+00 -4.31310E+00
-3.97250E+00 -3.62310E+00
-5.12310E+00 -5.06010E+00 -4.88760E+00 -4.64810E+00 -4.38080E+00 -4.09160E+00
-3.77630E+00 -3.46350E+00
-4.64800E+00 -4.60590E+00 -4.48830E+00 -4.31310E+00 -4.09160E+00 -3.83050E+00
-3.55230E+00 -3.28300E+00
-4.24790E+00 -4.21580E+00 -4.12230E+00 -3.97250E+00 -3.77630E+00 -3.55230E+00
-3.32130E+00 -3.08730E+00
-3.85840E+00 -3.83050E+00 -3.74960E+00 -3.62310E+00 -3.46350E+00 -3.28300E+00
-3.08730E+00 -2.87920E+00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment