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.
wfPlotter(fileIn=None, fileBase=None, prefix=None, mol=None, fType='_Orb.dat', dataTypes=['Re', 'Im', 'Abs'], optionsFile=None, tempdir=None)¶
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
- 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…?
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.
Return first item in self.fDictSel[key]
plotWf(pType=None, opacity=None, verbose=True)¶
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)¶
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.
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.
- Plot type (re/im/abs) to add. Set to abs for testing.
- Fix naming & colourmapping for multiple objects in ITK plotter.
- Consolidate atoms > molecular geometry pyVista object.
- orbN as list of ints or np.array? Integrate with calcOrb()?
- Opacity mapping for isosurfs? For pv.Plotter() can do this via transfer fns, e.g. ‘linear’, https://docs.pyvista.org/examples/02-plot/opacity.html#sphx-glr-examples-02-plot-opacity-py
readOrbFiles(fList=None, EList=None, SymList=None, verbose=False)¶
Read wavefunction files.
- 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)¶
Subselect data files by Sym and E from sorted dict.
- 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.
- verbose (bool, optional, default = True) – Print info on subselections if True.
Returns: Return type:
self.fDictSel dictionary will be set to subselected items.
Lists are parsed in order above, i.e. fDictE is set, then filtered by E and/or Sym. Unmatched inputs are ignored.
- Add a range option.
- Nearest value matching.
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.
Set wavefunction grids from files.
Basic wrapper for
Set isosurf properties per item, or use global values.
setPlotOptions(optionsFile=None, verbose=False, **kwargs)¶
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
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)¶
Sort input list of wavefunction files to dictionary by symmetry & energy.
- 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
Return last item in self.fDictSel[key]
Wrapper for file writer