epsproc.vol.wfPlot module

ePSproc wfPlot

Functions for calculating and plotting wavefunctions from ePolyScat.

Makes use of pyvista/itkwidgets on the backend (see notes below).

15/07/20 v1, adapting from test notebook, pyVista_tests_070320_basics_working_150320.ipynb
See also epsproc.vol.orbPlot.molOrbPlotter() for class development, use as template.
class epsproc.vol.wfPlot.wfPlotter(fileIn=None, fileBase=None, prefix=None, mol=None, fType='_Orb.dat', dataTypes=['Re', 'Im', 'Abs'], optionsFile=None, tempdir=None)[source]

Bases: object

Class to define & plot wavefunctions from ePS data.

fileIn : str, list of strs, optional.
File(s) to read (file in working dir, or full path). Defaults to current working dir if only a file name is supplied. For consistent results, pass raw strings, e.g. fileIn = r”C:sharecodeePSprocpython_dev

o2_demo_ePS.out”

fileBase : str, optional.
Dir to scan for files. Currently only accepts a single dir. Defaults to current working dir if no other parameters are passed.
prefix : str, optional, default = None
In case of dir/file parsing issue, a manually set file prefix can be passed. This may be neceassy if filename components are not split by ‘_’, or only a single file is present. (See example notebook somewhere…?)
mol : str, optional, default = None
Will be (hopefully) found from filenames, but can be set here.
fType : str, optional, default = ‘_Orb.dat’
File ending for ePS output files containing wavefunction data.
dataTypes : list, optional, default = [‘Re’, ‘Im’, ‘Abs’]
Datatypes present in data file (will be looped over on read in).
optionsFile : str or path object, optional, default = None
Specify path to plot options file (.json) used by setPlotOptions() method. Default file should be [modulePath]epsproc/vol/plotOptions.json, this will be set if nothing is passed.
tempdir : str or path object, optional, default = None
Temporary directory for image file outputs. Default is system tempdir, as provided by the tempfile module (tempfile.gettempdir()).

wfPlotter class object, with wavefunction data + plotting methods.

On the backend, this uses: - epsproc.readOrb3D() for file IO - pyvista/ITK for plotting. - Should improve filehandling with Path() here…? See orbPlot.py.

May want to change method ordering and structure here - this currently imports data, then assigns (duplicates) to pyVista object. Not very efficient.

TODO: add molecular structure… should be able to plot with orbPlot object…?

getOrbFiles(verbose=True)[source]

Call functionality from IO.getFiles to allow for more control (vs. readOrb3D, which will always get all files).

Also sort outputs by (Sym, E) groups.

head()[source]

Return first item in self.fDictSel[key]

plotWf(pType=None, opacity=None, verbose=True)[source]

Plot wavefunction(s) with pyVista/ITK.

ALREADY BECOMING SPAGHETTI… must do better here.

07/08/20 v3, use this as main wrapper & to set logic, then call sub-methods for various plotting cases.
Options to a dict, this should fix issues with some methods only available for some plot types.

TODO - kwargs pass to setLocalOptions and/or pyvista? - Logic/hierarchy for plot type and options. Setting plotter-based options may help? - Orbit animations, combined with subplots?

plotWfV2(wfN=None, pType='Abs', isoLevels=6, isoValsAbs=None, isoValsPC=None, interactive=True, opacity=0.5, animate=False)[source]

Plot wavefunction(s) with pyVista/ITK

# CURRENTLY NOT FUNCTIONAL with dictionary version. # SUBSELECT files first instead. # wfN : str or list of strs, optional, default = None # Wavefn(s) to plot, by key (item number) from self.fDiictSel[key].vol PV object. # By default these are set to wavefunction numbers, corresponding to files read in. # If not supplied, plot all available surfaces, i.e. items in self.vol.array_names

isoLevels : int, optional, default = 6
Number of isosurfs to compute & render.
isoValsAbs : list or array, default = None
Isovals to use (absolute values). If both isoValsAbs and isoValsPC are passed, only PC values will be used.
isoValsPC : list or array, default = None
Isovals to use, percentage values. Plot values are set by +/-isoValsPC * np.abs(self.vol[item]).mean(). If both isoValsAbs and isoValsPC are passed, only PC values will be used.
interactive : bool, optional, default = True
Plot inteactively using itkwidgets if true. Otherwise use pyVista.Plotter(), which produces static output.
opacity : float, optional, default = 0.5
Set isosurface opacity.
animate : bool, optional, default = False
Generate animation from dataset, as per https://docs.pyvista.org/examples/02-plot/gif.html Note this overrides the “interactive” setting above, and will only return the final frame to the self.pl object. UPDATE 06/08/20: plotter.update() for pv.Plotter() object doesn’t seem to work for isosurfs, employing alternative method from https://docs.pyvista.org/plotting/plotting.html#plot-time-series-data This means that animation runs will use BackgroundPlotter() plotter, and open in a separate window.

Notes

07/08/20 v3, unthreading looped plotting in favour of two-method soloution - currently set as new method. 03/08/20 v2, testing animation plus additional plotting options. 18/07/20 v1, adapted from molOrbPlotter.plotOrb function.

readOrbFiles(fList=None, EList=None, SymList=None, verbose=False)[source]

Read wavefunction files.

Parameters:
  • flist (list of strs, Paths or ints, optional, default = None) – Pass fList as list of files or ints as indexes into self.fList index. Note this is the ungrouped file list (the original fList), and items are resorted, so may not match self.fDictE or self.fDictSym
  • EList (list of ints, floats, optional, default = None) – Pass list of energies to select files to read in. If floats, these are assumed to be EKE values. If ints, these are used as indexes into the master EKE list.
  • SymList (list of strs or ints, optional, default = None) – Pass list of symmetries to select for file IO. Either strings of symmetry names, or by index.
  • are parsed in order above, i.e. fList is set, then filtered by E and/or Sym. (Lists) –
  • nothing is set, read all files from self.fList. (If) –
selectOrbFiles(fDictE=None, EList=None, SymList=None, verbose=True)[source]

Subselect data files by Sym and E from sorted dict.

Parameters:
  • fDictE (dict, optional, default = None) – Pass dictionary for subselection. If not set, use self.fDictE.
  • EList (list of ints, floats, optional, default = None) – Pass list of energies to select files to read in. If floats, these are assumed to be EKE values to match. If ints, these are used as indexes into the master EKE list.
  • SymList (list of strs or ints, optional, default = None) – Pass list of symmetries to select for file IO. Either strings of symmetry names, or by index.
  • verbose (bool, optional, default = True) – Print info on subselections if True.
Returns:

Return type:

self.fDictSel dictionary will be set to subselected items.

Note

Lists are parsed in order above, i.e. fDictE is set, then filtered by E and/or Sym. Unmatched inputs are ignored.

TODO

  • Add a range option.
  • Nearest value matching.
setData()[source]

Sort self.dataSet items to pyVista object.

TODO: useful naming for data + structure by E and Sym. EDIT: this is now in self.fDictSym, self.fDictE, self.fDictSel, and should be propagated here.

NOTE - PyVista items are indexed sequentially, so may not match input dict keys. This may change in future.

setGrid(methodType=2)[source]

Set wavefunction grids from files.

Basic wrapper for epsproc.conversion.orb3DCoordConv().

setIsoVals()[source]

Set isosurf properties per item, or use global values.

setPlotOptions(optionsFile=None, verbose=False, **kwargs)[source]

List of default plot options. Set here, change later if required.

Default file should be [modulePath]epsproc/vol/plotOptions.json, this will be set if nothing is passed.

TODO: testing to see if this is robust. Otherwise may want to include defaults directly in source here. Setting options in nested dicts from **kwargs needs some work. See: http://127.0.0.1:8888/notebooks/python/python_basics/Dictionary_methods_Benedict_120820.ipynb

showGif()[source]

Show GIF in Jupyter notebook usng IPython.display

HTML export safe version, from https://github.com/ipython/ipython/issues/10045#issuecomment-642640541 Thanks to @maedoc Marmaduke Woodman, https://github.com/maedoc

sortOrbFiles(fList=None, masterFlag=False, groupByPrefix=True)[source]

Sort input list of wavefunction files to dictionary by symmetry & energy.

Parameters:
  • fList (list, optional, default = None) – List of files to sort. If fList = None, use self.fList.
  • masterFlag (bool, optional, default = True) – If masterFlag = True, set to class variables, otherwise return values to calling function.
  • groupByPrefix (bool, optional, default = True) – Group sorted files by prefix? Will use self.prefix if set, otherwise determined from file names by epsproc.util.misc.fileListSort(). In latter case, self.prefix will be set if masterFlag = True
tail()[source]

Return last item in self.fDictSel[key]

writeOptions()[source]

Wrapper for file writer