Mod:Hunt Research Group/CalculateCube.py
CubePy is under CC BY-NC-SA license
CalculateCube.py is a collection of functions that manipulate data from cube files.
Requirements
- Python
- NumPy
ReadCube.py
An easy way to obtain Python with the required modules is by installing Anaconda.
Anaconda comes with Spyder, which is a Python editor that you can use to write and run Python codes (Applications Anaconda Navigator spyder Launch)
Instructions
If you want to use the functions in CalculateCube.py to extract data from cube files in Python, you will need to write a Python script:
import CalculateCube as cc var1 = cc.function_name(arg1=val1, arg2=val2,...) <do something with var1: print it, save it to file, etc.>
The Python script can be written and ran 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
Functions
Derivative
This function returns the Nth derivative of the value matrix from a cube file.
Arguments
fpath(string, default=None) = path for a cube filex_vector(list, default=None) = increment vector in the x directiony_vector(list, default=None) = increment vector in the y directionz_vector(list, default=None) = increment vector in the z directionval(list, default=None) = a matrix of all the valuesorder(integer, default=1) = the order of the derivativeau(boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates andunitsfor valuesdensity(integer, default=1) = an integer number n which indicates that the number of points stored along each axis is reduced by the density value n (therefore the total number of points is reduced by n3)value_type(string, default='esp') = can be ‘esp’/’potential’ or ‘dens’/’density’ (or any uppercase version of the aforementioned); used in conjunction with the keywordsauandunitsin order to convert the values to the appropriate unitsunits(string, default=None) = the units to be used for the value; currently supports ‘V’ for ESP and ‘A’/‘angstrom’, ’nm’, ’pm’, ’m’ for density (or any lowercase/uppercase version of these). In the case of the density, the actual units are the specified units ^(-3). The keywordsvalue_typeandauoverrideunits. Ifauis True, the values will be in atomic units regardless of the value passed forunits. Ifvalue_typeis ‘dens’, the values will be read as density values even if theunitsargument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.
Calls
ExtractData(fromReadCube.py; iffpathis specified)
Returns
a list of two lists: the first one of three arrays corresponding to the derivatives of the value matrix with respect to x, y and z (each array has the same shape as the original matrix) and the second one of the dx, dy and dz values (i.e. the lengths of the x, y and z increment vectors)
Observations
- called with either
fpath, order, au, density, value_type, unitsorx_vector, y_vector, z_vector, val, order - if specified,
fpathtakes priority over the other arguments and [ExtractData] is called (i.e. the script reads and goes through the whole cube file).
Example
import CalculateCube as cc d2 = cc.Derivative(fpath='test_emim_oac_esp.cube',order=2) print(d2[0][0][0][0][0])
This example calculates the second order derivative for the values in test_emim_oac_esp.cube and prints the first one to screen:
-0.0022345003728754002
Laplacian
This function calculates the Laplacian by summing the second order derivative with respect to x, y and z as obtained using Derivative for each data point.
Arguments
fpath(string, default=None) = path for a cube filex_vector(list, default=None) = increment vector in the x directiony_vector(list, default=None) = increment vector in the y directionz_vector(list, default=None) = increment vector in the z directionval(list, default=None) = a matrix of all the valuesau(boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates andunitsfor valuesdensity(integer, default=1) = an integer number n which indicates that the number of points stored along each axis is reduced by the density value n (therefore the total number of points is reduced by n3)value_type(string, default='esp') = can be ‘esp’/’potential’ or ‘dens’/’density’ (or any uppercase version of the aforementioned); used in conjunction with the keywordsauandunitsin order to convert the values to the appropriate unitsunits(string, default=None) = the units to be used for the value; currently supports ‘V’ for ESP and ‘A’/‘angstrom’, ’nm’, ’pm’, ’m’ for density (or any lowercase/uppercase version of these). In the case of the density, the actual units are the specified units ^(-3). The keywordsvalue_typeandauoverrideunits. Ifauis True, the values will be in atomic units regardless of the value passed forunits. Ifvalue_typeis ‘dens’, the values will be read as density values even if theunitsargument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.
Calls
Returns
a matrix of the Laplacian for every data point from a cube file
Observations
- called with either
fpath, order, au, density, value_type, unitsorx_vector, y_vector, z_vector, val, order - if specified,
fpathtakes priority over the other arguments and [ExtractData] is called (i.e. the script reads and goes through the whole cube file).
Example
import CalculateCube as cc l = cc.Laplacian(fpath='test_emim_oac_esp.cube') print(l[0][0][0])
This example calculates the Laplacian for the values in test_emim_oac_esp.cube and prints the first one to screen:
-0.000563911766024
VdWLaplacian
Arguments
fpath(string, default=None) = path for a cube fileaxes_list(list, default=None) = a list of three lists representing the x, y and z coordinates, respectively of all the sampling points (as generated byAxes)gridpts(dictionary, default=None) = an ordered dictionary of each grid point (represented through a tuple of its coordinates) and its corresponding value (the first element in the list generated byValuesAsDictionary)atoms_list(list, default=None) = a list of a number of natoms lists, each list component containing the atomic number, nuclear charge and coordinates of each atom (as generated byAtoms)x_vector(list, default=None) = increment vector in the x directiony_vector(list, default=None) = increment vector in the y directionz_vector(list, default=None) = increment vector in the z directionval(list, default=None) = a matrix of all the valuesfactor(float, default=1) = factor by which to multiply the VdW radiivdw_ind(list, default=None) = a list of lists containing the indices and the values of the points close to the van der Waals surfacevdw_pts(list, default=None) = a list of lists containing the coordinates and the values of the points close to the van der Waals surfaceau(boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates andunitsfor valuesdensity(integer, default=1) = an integer number n which indicates that the number of points stored along each axis is reduced by the density value n (therefore the total number of points is reduced by n3)value_type(string, default='esp') = can be ‘esp’/’potential’ or ‘dens’/’density’ (or any uppercase version of the aforementioned); used in conjunction with the keywordsauandunitsin order to convert the values to the appropriate unitsunits(string, default=None) = the units to be used for the value; currently supports ‘V’ for ESP and ‘A’/‘angstrom’, ’nm’, ’pm’, ’m’ for density (or any lowercase/uppercase version of these). In the case of the density, the actual units are the specified units ^(-3). The keywordsvalue_typeandauoverrideunits. Ifauis True, the values will be in atomic units regardless of the value passed forunits. Ifvalue_typeis ‘dens’, the values will be read as density values even if theunitsargument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.
Calls
ExtractData(fromReadCube.py; iffpathis specified)Axes(fromReadCube.py; if eithervdw_indorvdw_ptsis not specified)ValuesAsDictionary(fromReadCube.py; if eithervdw_indorvdw_ptsis not specified)GetVdWPoints(fromReadCube.py; if eithervdw_indorvdw_ptsis not specified)Laplacian
Returns
two lists: one containing coordinates + Laplacian for each data point on the van der Waals surface and one containing indices + Laplacian for each data point on the van der Waals surface
Observations
- called with
fpath, factor, au, density, value_type, units,fpath, factor, vdw_ind, vdw_pts, au, density, value_type, units,axes_list, gridpts, atoms_list, x_vector, y_vector, z_vector, val, factororaxes_list, gridpts, atoms_list, x_vector, y_vector, z_vector, val, factor, vdw_ind, vdw_pts
- if specified,
fpathtakes priority over the other arguments and [ExtractData] is called (i.e. the script reads and goes through the whole cube file).
Example
import CalculateCube as cc vdwl = cc.VdWLaplacian(fpath='test_emim_oac_esp.cube') print(vdwl[0][0][3])
This example calculates the Laplacian for the van der Waals surface values in test_emim_oac_esp.cube and prints the first one to screen:
2.5970251494598204
Hessian
Arguments
fpath(string, default=None) = path for a cube filex_vector(list, default=None) = increment vector in the x directiony_vector(list, default=None) = increment vector in the y directionz_vector(list, default=None) = increment vector in the z directionval(list, default=None) = a matrix of all the valuesau(boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates andunitsfor valuesdensity(integer, default=1) = an integer number n which indicates that the number of points stored along each axis is reduced by the density value n (therefore the total number of points is reduced by n3)value_type(string, default='esp') = can be ‘esp’/’potential’ or ‘dens’/’density’ (or any uppercase version of the aforementioned); used in conjunction with the keywordsauandunitsin order to convert the values to the appropriate unitsunits(string, default=None) = the units to be used for the value; currently supports ‘V’ for ESP and ‘A’/‘angstrom’, ’nm’, ’pm’, ’m’ for density (or any lowercase/uppercase version of these). In the case of the density, the actual units are the specified units ^(-3). The keywordsvalue_typeandauoverrideunits. Ifauis True, the values will be in atomic units regardless of the value passed forunits. Ifvalue_typeis ‘dens’, the values will be read as density values even if theunitsargument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.
Calls
Returns
a matrix of the Hessian for every data point from a cube file
Observations
- called with either
fpath, order, au, density, value_type, unitsorx_vector, y_vector, z_vector, val, order - if specified,
fpathtakes priority over the other arguments and [ExtractData] is called (i.e. the script reads and goes through the whole cube file).
Example
import CalculateCube as cc
h = cc.Hessian(fpath='test_emim_oac_esp.cube', density=3)
for i in range(3):
print([h[0][0][0][i][j] for j in range(3)])
This example calculates the hessian for the values in test_emim_oac_esp.cube at a reduced density and prints the first one to screen:
[-0.002701294001419571, 0.0068108009963301665, 0.006906352712240404] [0.0068108009963301708, 0.0013040459589339015, 0.01042453556361086] [0.0069063527122403996, 0.010424535563610851, -0.00046992647168781301]
VdWHessian
Arguments
fpath(string, default=None) = path for a cube fileaxes_list(list, default=None) = a list of three lists representing the x, y and z coordinates, respectively of all the sampling points (as generated byAxes)gridpts(dictionary, default=None) = an ordered dictionary of each grid point (represented through a tuple of its coordinates) and its corresponding value (the first element in the list generated byValuesAsDictionary)atoms_list(list, default=None) = a list of a number of natoms lists, each list component containing the atomic number, nuclear charge and coordinates of each atom (as generated byAtoms)x_vector(list, default=None) = increment vector in the x directiony_vector(list, default=None) = increment vector in the y directionz_vector(list, default=None) = increment vector in the z directionval(list, default=None) = a matrix of all the values*factor(float, default=1) = *vdw_ind(list, default=None) = a list of lists containing the indices and the values of the points close to the van der Waals surface*vdw_pts(list, default=None) = a list of lists containing the coordinates and the values of the points close to the van der Waals surfaceau(boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates andunitsfor valuesdensity(integer, default=1) = an integer number n which indicates that the number of points stored along each axis is reduced by the density value n (therefore the total number of points is reduced by n3)value_type(string, default='esp') = can be ‘esp’/’potential’ or ‘dens’/’density’ (or any uppercase version of the aforementioned); used in conjunction with the keywordsauandunitsin order to convert the values to the appropriate unitsunits(string, default=None) = the units to be used for the value; currently supports ‘V’ for ESP and ‘A’/‘angstrom’, ’nm’, ’pm’, ’m’ for density (or any lowercase/uppercase version of these). In the case of the density, the actual units are the specified units ^(-3). The keywordsvalue_typeandauoverrideunits. Ifauis True, the values will be in atomic units regardless of the value passed forunits. Ifvalue_typeis ‘dens’, the values will be read as density values even if theunitsargument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.
Calls
ExtractData(fromReadCube.py; iffpathis specified)*Axes(fromReadCube.py; if eithervdw_indorvdw_ptsis not specified)*ValuesAsDictionary(fromReadCube.py; if eithervdw_indorvdw_ptsis not specified)GetVdWPoints(fromReadCube.py; if eithervdw_indorvdw_ptsis not specified)Hessian
Returns
two lists: one containing coordinates + Hessian matrix for each data point on the van der Waals surface and one containing indices + Hessian matrix for each data point on the van der Waals surface
Observations
- called with
fpath, factor, au, density, value_type, units,fpath, factor, vdw_ind, vdw_pts, au, density, value_type, units,axes_list, gridpts, atoms_list, x_vector, y_vector, z_vector, val, factororaxes_list, gridpts, atoms_list, x_vector, y_vector, z_vector, val, factor, vdw_ind, vdw_pts
- if specified,
fpathtakes priority over the other arguments and [ExtractData] is called (i.e. the script reads and goes through the whole cube file).
Example
import CalculateCube as cc vdwh = cc.VdWHessian(fpath='test_emim_oac_esp.cube') print(vdwh[0][0][3])
This example calculates the hessian for the van der Waals surface values in test_emim_oac_esp.cube and prints the first one to screen:
[[6.2995640717272767, 3.0272898269372841, -0.043632672896223364], [3.0272898269372845, -1.268343295247532, 0.057448511163856956], [-0.043632672896223711, 0.057448511163856707, -2.4341956270199243]]