Mod:Hunt Research Group/Python scripts for cube files

From wiki
Jump to navigation Jump to search
Ia2514 small gif.gif

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:


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 containing CalculateCube.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 PlotHistogram from PlotCube.py with save=True
  • for saving a short summary file of the minimum, maximum and lowest curvature points on the van der Waals surface, use save=True when running PlotSurface from PlotCube_mayavi.py


If you want to plot surfaces, isosurfaces, slices

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 PlotHistogram from PlotCube.py to plot a histogram and/or KDE directly from cube files
  • use OverlapKDEs and PlotHistogram from AdditionalFunctions.py to plot histograms and KDEs from files written by PlotHistogram from PlotCube.py when save=True