Mod:Hunt Research Group/Python scripts for cube files
Contents
Processing Cube Files
Python Codes
The latest version of CubePy, along with a test cube file can be found here.
CubePy is under CC BY-NC-SA license
CubePy encompasses six modules that can be used to read, save, manipulate and visualise data from cube files:
- ReadCube.py - used to extract data from cube files and return it in convenient python formats
- SaveCube.py - used to save data from cube files in convenient formats
- CalculateCube.py - used to manipulate data from cube files
- PlotCube.py - used to plot data from cube files (using Matplotlib)
- PlotCube_mayavi.py - used to plot data from cube files (using Mayavi)
- AdditionalFunctions.py - used to manipulate data not from cube files, but from files produced by the scripts above
Getting started
- you will need to have installed
- matplotlib
- numpy
- scipy
- mayavi
- pandas
to run the modules a python script is needed
The Python script can be written and run in different ways:
- as a new .py file using Spyder (Spyder -> File -> New file... -> [write the file] -> Save As... [make sure you save the file in the same directory as
CalculateCube.py-> Run -> Run [the file will be run in the iPython console] - in the IPython console in Spyder: write the Python commands directly in the console, but make sure that the current working directory is the one containing
CalculateCube.py - in the terminal window: type
ipython, then write the Python commands directly in the terminal, but make sure that the current working directory is the one containingCalculateCube.py
If you want to save data from cube files
- for saving the values from the cube files, use the functions from SaveCube.py
- for saving histogram data, use the function
PlotHistogramfrom PlotCube.py withsave=True - for saving a short summary file of the minimum, maximum and lowest curvature points on the van der Waals surface, use
save=Truewhen runningPlotSurfacefrom PlotCube_mayavi.py
If you want to plot surfaces, isosurfaces, slices
- use the functions from PlotCube_mayavi.py. They are faster and better at 3D plotting than the equivalent functions from PlotCube.py
If you want to generate static figures you can also consider using the 3D plotting functions from PlotCube.py. These are especially recommended when wanting to display atoms as they look better than their PlotCube_mayavi.py equivalents. However, keep in mind that Matplotlib sometimes fails at 3D rendering, which generates "incorrect" plots (i.e. elements that should be behind the rest of the plot appear at the front). Therefore, plots created using function from PlotCube.py should be double-checked (by comparing them with plots from PlotCube_mayavi.py, by example).
If you want to plot histograms and KDEs
- use
PlotHistogramfrom PlotCube.py to plot a histogram and/or KDE directly from cube files - use
OverlapKDEsandPlotHistogramfrom AdditionalFunctions.py to plot histograms and KDEs from files written byPlotHistogramfrom PlotCube.py whensave=True
