Jump to content

Mod:Hunt Research Group/CalculateCube.py

From ChemWiki

CubePy is under CC BY-NC-SA license

CalculateCube.py is a collection of functions that manipulate data from cube files.

Requirements


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 containing CalculateCube.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 file
  • x_vector (list, default=None) = increment vector in the x direction
  • y_vector (list, default=None) = increment vector in the y direction
  • z_vector (list, default=None) = increment vector in the z direction
  • val (list, default=None) = a matrix of all the values
  • order (integer, default=1) = the order of the derivative
  • au (boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates and units for values
  • density (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 keywords au and units in order to convert the values to the appropriate units
  • units (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 keywords value_type and au override units. If au is True, the values will be in atomic units regardless of the value passed for units. If value_type is ‘dens’, the values will be read as density values even if the units argument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.

Calls

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, units or x_vector, y_vector, z_vector, val, order
  • if specified, fpath takes 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 file
  • x_vector (list, default=None) = increment vector in the x direction
  • y_vector (list, default=None) = increment vector in the y direction
  • z_vector (list, default=None) = increment vector in the z direction
  • val (list, default=None) = a matrix of all the values
  • au (boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates and units for values
  • density (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 keywords au and units in order to convert the values to the appropriate units
  • units (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 keywords value_type and au override units. If au is True, the values will be in atomic units regardless of the value passed for units. If value_type is ‘dens’, the values will be read as density values even if the units argument 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, units or x_vector, y_vector, z_vector, val, order
  • if specified, fpath takes 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 file
  • axes_list (list, default=None) = a list of three lists representing the x, y and z coordinates, respectively of all the sampling points (as generated by Axes)
  • 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 by ValuesAsDictionary)
  • 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 by Atoms)
  • x_vector (list, default=None) = increment vector in the x direction
  • y_vector (list, default=None) = increment vector in the y direction
  • z_vector (list, default=None) = increment vector in the z direction
  • val (list, default=None) = a matrix of all the values
  • factor (float, default=1) = factor by which to multiply the VdW radii
  • 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 surface
  • au (boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates and units for values
  • density (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 keywords au and units in order to convert the values to the appropriate units
  • units (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 keywords value_type and au override units. If au is True, the values will be in atomic units regardless of the value passed for units. If value_type is ‘dens’, the values will be read as density values even if the units argument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.

Calls

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, factor or axes_list, gridpts, atoms_list, x_vector, y_vector, z_vector, val, factor, vdw_ind, vdw_pts
  • if specified, fpath takes 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 file
  • x_vector (list, default=None) = increment vector in the x direction
  • y_vector (list, default=None) = increment vector in the y direction
  • z_vector (list, default=None) = increment vector in the z direction
  • val (list, default=None) = a matrix of all the values
  • au (boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates and units for values
  • density (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 keywords au and units in order to convert the values to the appropriate units
  • units (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 keywords value_type and au override units. If au is True, the values will be in atomic units regardless of the value passed for units. If value_type is ‘dens’, the values will be read as density values even if the units argument 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, units or x_vector, y_vector, z_vector, val, order
  • if specified, fpath takes 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 file
  • axes_list (list, default=None) = a list of three lists representing the x, y and z coordinates, respectively of all the sampling points (as generated by Axes)
  • 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 by ValuesAsDictionary)
  • 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 by Atoms)
  • x_vector (list, default=None) = increment vector in the x direction
  • y_vector (list, default=None) = increment vector in the y direction
  • z_vector (list, default=None) = increment vector in the z direction
  • val (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 surface
  • au (boolean, default=False) = if True, use atomic units (i.e. bohr for coordinates); if False, use Angstroms for coordinates and units for values
  • density (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 keywords au and units in order to convert the values to the appropriate units
  • units (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 keywords value_type and au override units. If au is True, the values will be in atomic units regardless of the value passed for units. If value_type is ‘dens’, the values will be read as density values even if the units argument has a valid ESP value (such as ‘V’). The default unit for ESP is V and for density 1/Å3.

Calls

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, factor or axes_list, gridpts, atoms_list, x_vector, y_vector, z_vector, val, factor, vdw_ind, vdw_pts
  • if specified, fpath takes 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]]