tesliper.writing.gjf_writer
Export of Gaussian input files (.gjf) for setting up new calculation step.
Classes
|
Generates Gaussian input files for each conformer given. |
- class tesliper.writing.gjf_writer.GjfWriter(destination: Union[str, pathlib.Path], mode: str = 'x', link0: Optional[Dict[str, Union[str, bool]]] = None, route: str = '', comment: str = 'No information provided.', post_spec: str = '')[source]
Generates Gaussian input files for each conformer given.
- Parameters
destination (str or pathlib.Path) – Directory, to which generated files should be written.
mode (str, optional) – Specifies how writing to file should be handled. Should be one of characters: “a” (append to existing file); “x” (only write if file doesn’t exist yet); or “w” (overwrite file if it already exists). Defaults to “x”.
link0 (Dict[str, Union[str, bool]], optional) – Link0 commands that should be included in generated files, as a dictionary of {“command”: “value”}. Refer to
link0for more information. If omitted, no link0 commands are added.route (str) – Calculation directives for Gaussan, refer to the Gaussian documentation for information on how to construct the calculations route.
comment (str, optional) – Additional text, describing the calculations, by default “No information provided.”
post_spec (str, optional) – Additional specification written after the molecule specification, written to generated files as provided by the user (you need to take care of line breaks). If omitted, no additional specification is added.
- geometry(geometry: tesliper.glassware.arrays.Geometry, charge: Optional[Union[tesliper.glassware.arrays.IntegerArray, Sequence[int], int]] = None, multiplicity: Optional[Union[tesliper.glassware.arrays.IntegerArray, Sequence[int], int]] = None, name_template: Union[str, string.Template] = '${conf}.${ext}')[source]
Write given conformers’ geometries to multiple Gaussian input files.
- Parameters
geometry (Geometry) –
Geometryobject containing data for each confomer that should be exported as Gaussian input file.charge (Union[IntegerArray, Sequence[int], int, None], optional) – Molecule’s charge for each conformer. May be a sequence of values or one value that will be repeated for each conformer. By default 0 for each.
multiplicity (Union[IntegerArray, Sequence[int], int, None], optional) – Molecule’s multiplicity for each conformer. May be a sequence of values or one value that will be repeated for each conformer. By default 1 for each.
name_template (Union[str, Template], optional) – Template that will be used to generate filenames, by default “${conf}.${ext}”. Refer to
make_name()documentation for details on supported placeholders.
- _get_handle(template: Union[str, string.Template], template_params: dict, open_params: Optional[dict] = None) Iterator[IO]
Helper method for creating files. Given additional kwargs will be passed to
Path.open()method. Implemented as context manager for use withwithstatement.- Parameters
template (str or string.Template) – Template that will be used to generate filenames.
template_params (dict) – Dictionary of {identifier: value} for .make_name method.
open_params (dict, optional) – Arguments for
Path.open()used to open file.
- Yields
IO – file handle, will be closed automatically after
withstatement exitsmeta public:
- _iter_handles(filenames: Iterable[str], template: Union[str, string.Template], template_params: dict, open_params: Optional[dict] = None) Iterator[IO]
Helper method for iteration over generated files. Given additional kwargs will be passed to
Path.open()method.- Parameters
filenames (list of str) – list of source filenames, used as value for ${conf} placeholder in name_template
template_params (dict) – Dictionary of {identifier: value} for .make_name method.
open_params (dict, optional) – arguments for
Path.open()used to open file.
- Yields
TextIO – file handle, will be closed automatically on next iteration
meta public:
- property destination: pathlib.Path
Directory, to which generated files should be written.
- Raises
FileNotFoundError – If given destination doesn’t exist or is not a directory.
- Type
pathlib.Path
- static distribute_data(data: List) Tuple[Dict[str, List], Dict[str, Any]]
Sorts given data by genre category for use by specialized writing methods.
- Returns
distr (dict) – Dictionary with
DataArray-like objects, sorted by their type. Each {key: value} pair is {name of the type in lowercase format: list ofDataArrayobjects of this type}.extras (dict) – Spacial-case genres: extra information used by some writer methods when exporting data. Available {key: value} pairs (if given in data) are:
corrections: dict of {“energy genre”:FloatArray},frequencies:Bands,wavelengths:Bands,excitation:Bands,stoichiometry:InfoArray,charge:IntegerArray,multiplicity:IntegerArray
- energies(energies: tesliper.glassware.arrays.Energies, corrections: Optional[tesliper.glassware.arrays.FloatArray] = None, name_template: Union[str, string.Template] = '')
Interface for writing energies values, and optionally their corrections. Evoked when handling
Energiesobjects.- Parameters
energies – Conformers’ energies. Mandatory in custom implementation.
corrections – Correction of energies values. Mandatory in custom implementation. May be
Nonewhen method evoked by handler.name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- generic(data: List[Union[tesliper.glassware.arrays.DataArray, tesliper.glassware.arrays.IntegerArray, tesliper.glassware.arrays.FloatArray, tesliper.glassware.arrays.BooleanArray, tesliper.glassware.arrays.InfoArray]], name_template: Union[str, string.Template] = '')
Interface for writing generic data: any that provides one value for each conformer. Evoked when handling
DataArray,IntegerArray,FloatArray,BooleanArray, orInfoArray.- Parameters
data – List of objects that provide one value for each conformer.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- make_name(template: Union[str, string.Template], conf: str = '', num: Union[str, int] = '', genre: str = '', cat: str = '', det: str = '', ext: str = '') str
Create filename using given template and given or global values for known identifiers. The identifier should be used in the template as
"${identifier}"where “identifier” is the name of identifier. Available names and their meaning are:${ext}- appropriate file extension${conf}- name of the conformer${num}- number of the file according to internal counter${genre}- genre of exported data${cat}- category of produced output${det}- category-specific detailThe
${ext}identifier is filled with the value of Writersextensionattribute if not explicitly given as parameter to this method’s call. Values for other identifiers should be provided by the caller.- Parameters
template (str or string.Template) – Template that will be used to generate filenames. It should contain only known identifiers, listed above.
conf (str) – value for
${conf}identifier, defaults to empty string.num (str or int) – value for
${str}identifier, defaults to empty string.genre (str) – value for
${genre}identifier, defaults to empty string.cat (str) – value for
${cat}identifier, defaults to empty string.det (str) – value for
${det}identifier, defaults to empty string.ext (str) – value for
${ext}identifier, defaults to empty string.
- Raises
ValueError – If given template or string contains any unexpected identifiers.
Examples
Must be first subclassed and instantiated:
>>> class MyWriter(WriterBase): >>> extension = "foo" >>> wrt = MyWriter("/path/to/some/directory/")
>>> wrt.make_name(template="somefile.${ext}") "somefile.foo" >>> wrt.make_name(template="${conf}.${ext}") ".foo" # conf is empty string by default >>> wrt.make_name(template="${conf}.${ext}", conf="conformer") "conformer.foo" >>> wrt.make_name(template="Unknown_identifier_${bla}.${ext}") Traceback (most recent call last): ValueError: Unexpected identifiers given: bla.
- property mode
Specifies how writing to file should be handled. Should be one of characters: “a”, “x”, or “w”. “a” - append to existing file; “x” - only write if file doesn’t exist yet; “w” - overwrite file if it already exists.
- Raises
ValueError – If given anything other than “a”, “x”, or “w”.
- overview(energies: Sequence[tesliper.glassware.arrays.Energies], frequencies: Optional[tesliper.glassware.arrays.Bands] = None, stoichiometry: Optional[tesliper.glassware.arrays.InfoArray] = None, name_template: Union[str, string.Template] = '')
Intercafe for generating an overview of known conformers: values of energies, number of imaginary frequencies, and stoichiometry for each conformer. Evoked when handling
Energiesobjects.- Parameters
energies – List of objects representing different energies genres for each conformer. Mandatory in custom implementation.
frequencies –
Bandsof “freq” genre, with list of frequencies for each conformer. Mandatory in custom implementation. May beNonewhen method evoked by handler.stoichiometry – Stoichiometry of each conformer. Mandatory in custom implementation. May be
Nonewhen method evoked by handler.name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- single_spectrum(spectrum: tesliper.glassware.spectra.SingleSpectrum, name_template: Union[str, string.Template] = '')
Interface for writing a single spectrum to disk: calculated for one conformer or averaged. Evoked when handling
SingleSpectrumobjects.- Parameters
spectrum – Single calculated spectrum. Mandatory in custom implementation.
name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- spectra(spectra: tesliper.glassware.spectra.Spectra, name_template: Union[str, string.Template] = '')
Interface for writing a set of spectra of one type calculated for many conformers. Evoked when handling
Spectraobjects.- Parameters
spectra – Spectra of one type calculated for multiple conformers. Mandatory in custom implementation.
name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- spectral_activities(band: tesliper.glassware.arrays.Bands, data: List[tesliper.glassware.arrays.SpectralActivities], name_template: Union[str, string.Template] = '')
Interface for writing multiple objects with spectral activities (data that may be converted to signal intensity). Evoked when handling one of the:
VibrationalActivities,ElectronicActivities,ScatteringActivitiesobjects.- Parameters
band – Band at which transitions occur for each conformer. Mandatory in custom implementation.
data – List of objects representing different spectral activities genres. Mandatory in custom implementation.
name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- spectral_data(band: tesliper.glassware.arrays.Bands, data: List[tesliper.glassware.arrays.SpectralData], name_template: Union[str, string.Template] = '')
Interface for writing multiple objects with spectral data that is not a spectral activity (cannot be converted to signal intensity). Evoked when handling one of the:
VibrationalData,ElectronicData,ScatteringDataobjects.- Parameters
band – Band at which transitions occur for each conformer. Mandatory in custom implementation.
data – List of objects representing different spectral data genres (but not spectral activities). Mandatory in custom implementation.
name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- transitions(transitions: tesliper.glassware.arrays.Transitions, wavelengths: tesliper.glassware.arrays.Bands, only_highest: bool = True, name_template: Union[str, string.Template] = '')
Interface for writing single object with electronic transitions data. Evoked when handling
Transitionsobjects.- Parameters
transitions – List of objects representing different spectral data genres (but not spectral_activities). Mandatory in custom implementation.
wavelengths – Wavelengths at which transitions occur for each conformer. Mandatory in custom implementation.
only_highest – Boolean flag indicating if all transitions should be written to disk or only these transition that contributes the most for each wavelength/ May be omitted in custom implementation.
name_template – Template that defines naming scheme for files generated by this method. May be omitted in custom implementation.
- Raises
NotImplementedError – Whenever called, this is an interface that should not be used directly.
- write(data: List) None
Writes
DataArray-like objects to disk, decides how to write them based on the type of each object. If some types of given objects are not supported by this writer, data of this type is ignored and a warning is emitted.- Parameters
data (List) –
DataArray-like objects that should be written to disk.
- property link0: Dict[str, Union[str, bool]]
Link0 commands, in a form of
{"command": "value"}, that will be placed in the beginning of each Gaussian input file created. If anny command is an unknown keword, an exception will be raised. Accepted command keywords are as follows:- Mem
str specifying required memory
- Chk
str with file path
- OldChk
str with file path
- SChk
str with file path
- RWF
str with file path
- OldMatrix
str with file path
- OldRawMatrix
str with file path
- Int
str with spec
- D2E
str with spec
- KJob
str with link number and, optionally, space-separated number
- Save
boolean
- ErrorSave
boolean
- NoSave
boolean, same as ErrorSave
- Subst
str with link number and space-separated file path
Commands that provide a file path as a value may be parametrized for each conformer. You can put a placeholder inside a given string path, that will be parametrized when writing to file. See
make_name()to see available placeholders. You may use any of values listed there, however${conf}and${num}will probably be the most useful.
- property route: str
Also known as # lines, specifies desired calculation type, model chemistry, and other options for Gaussian. If pound sign is missing, it is added in the beginning. For supported keywords and syntax refer to the Gaussian’s documentation.