Jump to content

Mod:Hunt Research Group/SaveCube.py

From ChemWiki

CubePy is under CC BY-NC-SA license

SaveCube.py is a collection of functions that save the data from cube files in convenient formats.


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

The saving functions can be run from the terminal window by typing:

python SaveCube.py function_name cube_file_path arg1=val1 arg2=val2...


Functions

SaveAll

This function writes the x, y, z coordinates and the values from a cube file to a new file (4 columns).

Required arguments

  • fpath (string) = path for a cube file

Optional arguments

  • outfile (string, default=None) = path for the output file (if None, the script used the input filename with the extension ".csv"
  • 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

Observations

  • very slow if run for all the points in a cube file
  • the script predicts the size of the file (which is also an indication of the running time) and it allows the user to:
  1. Proceed
  2. Reduce the number of points then proceed
  3. Abort
  • if the user selects option number 2, they will be asked to input an integer number n so that only every nth value is saved to the file. Afterwards, the scripts prints the new predicted size and allows the user to once again select between options 1, 2 and 3.

Example

python SaveCube.py SaveAll test_emim_oac_esp.cube outfile='emim_oac_all.csv'

This example will raise the follow message:

Your file size will be 34MB. Options: 1. Proceed 2. Reduce the number of points then proceed 3. Abort. Pick an option [1/2/3]:

If the user chooses to reduce the number of points (by typing in 2 then enter), a new message will be printed:

Please input an integer number n so that only every n value is saved to the file:

If the user inputs the number 100 (by typing 100 then enter), the new message will be:

Your file size will be 340KB. Options: 1. Proceed 2. Reduce the number of points then proceed 3. Abort. Pick an option [1/2/3]:

If the user chooses to proceed (by typing in 1 then enter), the new emim_oac_all.csv file should be:


       X coord/A       Y coord/A       Z coord/A            Value/V
       -6.342285       -6.155011       -3.804660        1.98280E-01
       -6.342285       -6.016080        2.169381        2.57662E-01
       -6.342285       -5.738218        0.224345        3.08147E-01
       -6.342285       -5.460355       -1.720692        2.99211E-01
       -6.342285       -5.182493       -3.665729        2.39004E-01
       ...

SaveVdW

This function writes the x, y, z coordinates and the values of all the points that lie on a surface defined by the van der Waals radii of the atoms to a new file (4 columns).

Required arguments

  • fpath (string) = path for a cube file

Optional arguments

  • outfile (string, default=None) = path for the output file (if None, the script used the input filename with the extension ".csv"
  • factor (float, default=1) = factor by which to multiply the VdW radii
  • 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

Observations

  • the script predicts the size of the file (which is also an indication of the running time) and it allows the user to:
  1. Proceed
  2. Reduce the number of points then proceed
  3. Abort
  • if the user selects option number 2, they will be asked to input an integer number n so that only every nth value is saved to the file. Afterwards, the scripts prints the new predicted size and allows the user to once again select between options 1, 2 and 3.

Example

python SaveCube.py SaveVdW test_emim_oac_esp.cube outfile='emim_oac_vdw_dens2.csv' density=2

This example will raise the follow message:

Your file size will be 18KB. Options: 1. Proceed 2. Reduce the number of points then proceed 3. Abort. Pick an option [1/2/3]:

If the user chooses to proceed (by typing in 1 then enter), the new emim_oac_vdw_dens2.csv file should be:

       X coord/A       Y coord/A       Z coord/A            Value/V
       -4.952973       -0.875626        0.085413        1.88899E+00
       -4.952973       -0.875626        0.363276        1.98856E+00
       -4.952973       -0.875626        0.641138        1.90018E+00
       -4.952973       -0.597764       -0.192449        1.72317E+00
       -4.952973       -0.597764        0.085413        2.00726E+00
       ...