epsman.elecStructure.ESclass_bk100621 module

Basic methods for dealing with Gamess & Molden file IO for ePolyScat.

10/06/21 Added some basic error checks during testing. SHOULD SET AS A DECORATOR.

03/02/21 v2 Revisiting and finishing off…
  • Fixed formatting options.

  • Added wrappers for cclib moldenwriter.MOLDEN as new class.

  • Use EShandler class for general IO.

  • Tested with N2O demo file + ePS test job OK for Molden2006 format.

Files from writeMoldenFile2006() are working with ePS (tested for N2O test file). Files from reformatMoldenFile() are NOT working due to line-endings issues. See notes/epsman_EShandler_class_demo_050221.ipynb for demo & testing.

26/08/20 v1 Quick hack from existing functions - needs some more sophistication for file handling. Should have utils for this…

Dev work currently in [Bemo] http://localhost:8888/notebooks/ePS/N2O/N2O_electronic_structure_proc_tests_250820.ipynb

class epsman.elecStructure.ESclass_bk100621.EShandler(fileName=None, fileBase=None, outFile=None)[source]

Bases: object

Basic class for handling Gamess & Molden file IO.

Uses CCLIB to read Gamess log files & convert to Molden format.

For ePS compatibilty, this is slightly modified to match the “Molden2006” specifications defined therein (see source in MoldenCnv2006.f90).

Parameters:
  • fileName (str or Path obj, optional, default = None) – Gamess or Molden file.

  • fileBase (str or Path obj, optional, default = None) – Path to file location, defaults to current working dir.

  • outFile (str or Path obj, optional, default = None) – Name for output Molden file, defaults to fileName.molden if not set.

  • passed (If no args are) –

  • set (fileName = None will be) –

  • dir. (and filePath = working) –

Examples

>>> fileBase = Path(modPath, 'epsman', 'elecStructure','fileTest')  # Set for test file, where modPath = path to epsman root
>>> fileName = r'N2O_aug-cc-pVDZ_geomOpt.log'
>>> esData = EShandler(fileName, fileBase)  # Create class instance
>>> esData.readGamessLog()  # Read Gamess file
>>> esData.writeMoldenFile2006()  # Write Molden2006 file
>>> esData.writeMoldenFile()  # Write Molden file as per CCLIB defaults.
>>> esData = EShandler(fileName = 'test.molden') # Pass a Molden file to set & use the reformatter
>>> esData.reformatMoldenFile()

Notes

Thanks to the CCLIB authors for making this possible!

To do

  • Implement directory scan (or wrapper class/decorator for this).

  • Better file handling, should implement Pathlib tests for file(s).

  • Fix reformatMoldenFile() method, this currently outputs OS specific line endings.

19/02/21: For full eps job class inheritance, use ESjob class instead.

readGamessLog()[source]

Read Gamess log file using CCLIB.io.ccread(self.fullPath)

reformatMoldenFile(inplace=True, backup='', verbose=False)[source]

Reformat atom details & coords in an exisiting Molden file to match ePS IO “Molden2006” formatting.

Uses data in existing file, as set in self.moldenFile.

Notes

Default settings use inplace writing to replace existing file, pass backup=’.bk’ to set backup file extension for original file contents.

See https://docs.python.org/3/library/fileinput.html#fileinput.FileInput for details.

setFiles(fileName=None, fileBase=None, outFile=None)[source]

Set fileName, fileBase and outFile

Parameters:
  • fileName (str or Path obj, optional, default = None) – Gamess or Molden file.

  • fileBase (str or Path obj, optional, default = None) – Path to file location, defaults to current working dir.

  • outFile (str or Path obj, optional, default = None) – Name for output Molden file, defaults to fileName.molden if not set.

  • passed (If no args are) –

  • set (fileName = None will be) –

  • dir. (and filePath = working) –

setMoldenFile(fileName, fileBase=None)[source]

Set self.moldenFile with new fileName and existing path, or new path.

Parameters:
  • fileName (str or Path obj, optional, default = None) – Molden filename.

  • fileBase (str or Path obj, optional, default = None) – Path to file location, defaults to currently set path.

writeMoldenFile()[source]

Write data to Molden format file using CCLIB.io.ccwrite(self.data)

writeMoldenFile2006()[source]

Write data to Molden format file using reformatted CCLIB code, for ePS compatible ‘Molden2006’ formatting.

See moldenCCLIBReformatted for details.

epsman.elecStructure.ESclass_bk100621.fileParse(fileName, startPhrase=None, endPhrase=None, comment=None, verbose=False)[source]

Parse a file, return segment(s) from startPhrase:endPhase, excluding comments.

Parameters:
  • fileName (str) – File to read (file in working dir, or full path)

  • startPhrase (str, optional) – Phrase denoting start of section to read. Default = None

  • endPhase (str, optional) – Phrase denoting end of section to read. Default = None

  • comment (str, optional) – Phrase denoting comment lines, which are skipped. Default = None

Returns:

  • list – [lineStart, lineStop], ints for line #s found from start and end phrases.

  • list – segments, list of lines read from file.

  • All lists can contain multiple entries, if more than one segment matches the search criteria.

class epsman.elecStructure.ESclass_bk100621.moldenCCLIBReformatted(*args: Any, **kwargs: Any)[source]

Bases: MOLDEN

Patch for cclib’s modenwriter to conform to ePS ‘Molden2006’ format spec.

This class inherits from cclib.io.moldenwriter.MOLDEN (github source), and:

  • Redefines _coords_from_ccdata() and _gto_from_ccdata().

  • _coords_from_ccdata() uses super() to run the original function, than applies a slightly different coordinates format spec. to the output.

  • _gto_from_ccdata() is basically a modified version of the original cclib code, again with just a modified format spec.

Thanks to the CCLIB authors for making this possible!