repESP.cube_format module¶
Parsing and writing Gaussian “cube” format describing molecular fields
-
class
Cube(info: repESP.cube_format.Cube.Info, molecule: repESP.types.Molecule[repESP.charges.AtomWithCoordsAndCharge][repESP.charges.AtomWithCoordsAndCharge], field: repESP.fields.Field[~FieldValue][FieldValue])[source]¶ Bases:
typing.GenericDataclass representing information in a Gaussian “cube” file
This class is generic in the type of the values of the field described by the cube file. This type can be any type, as can fields.FieldValue.
Parameters: - info (Info) – Additional, less structured information about the cube file.
- molecule (Molecule[AtomWithCoordsAndCharge]) – The molecule which field is described by the cube file. Atoms have coordinates and partial charges specified.
- field (Field[FieldValue]) – The field described by the cube file.
-
info¶ See initialization parameter
-
molecule¶ See initialization parameter
-
field¶ See initialization parameter
-
parse_cube(f: TextIO, make_value: Callable[[repESP.cube_format.Cube.Info, str], FieldValue]) → repESP.cube_format.Cube[~FieldValue][FieldValue][source]¶ Parse a file in the Gaussian “cube” file format
You probably mean to use parse_ed_cube or parse_esp_cube unless your cube file is of neither of those types.
Note that the values are expected to be space separated. If your cube file comes from elsewhere than Gaussian, you should ensure that the coordinates are given in bohr.
Parameters: - f (TextIO) – File object opened in read mode containing the cube file to be parsed.
- make_value (Callable[[Cube.Info, str], FieldValue]) –
A function taking two parameters: the cube information and a string representing the field value. The function should parse the field value into the desired internal representation, for example an Esp object. The cube information is provided in case verification of the cube file type is required.
Example
In the simplest case this could be:
lambda _, str_: float(str_)
which ignores the cube information (thus performing no verification) and simply parses the string value as a float.
Raises: InputFormatError– Raised when the file does not follow the expected format.Returns: Data from the parsed cube file.
Return type: Cube[FieldValue]
-
parse_esp_cube(f: TextIO, verify_title: bool = True) → repESP.cube_format.Cube[repESP.fields.Esp][repESP.fields.Esp][source]¶ Parse a Gaussian “cube” file describing an ESP field
If your cube file comes from elsewhere than Gaussian, you should ensure that the coordinates are given in bohr and ESP values in atomic units.
Parameters: - f (TextIO) – File object opened in read mode containing the cube file to be parsed.
- verify_title (bool, optional) – If this flag is set to True (default), an InputFormatError will
be raised if the cube title does not start with the string
" Electrostatic potential".
Returns: Data from the parsed cube file.
Return type:
-
parse_ed_cube(f: TextIO, verify_title: bool = True) → repESP.cube_format.Cube[repESP.fields.Ed][repESP.fields.Ed][source]¶ Parse a Gaussian “cube” file describing electron density field
If your cube file comes from elsewhere than Gaussian, you should ensure that the coordinates are given in bohr and electron density values in atomic units.
Parameters: - f (TextIO) – File object opened in read mode containing the cube file to be parsed.
- verify_title (bool, optional) – If this flag is set to True (default), an InputFormatError will
be raised if the cube title does not start with the string
" Electron density".
Returns: Data from the parsed cube file.
Return type:
-
write_cube(f: TextIO, cube: repESP.cube_format.Cube[~NumericValue][NumericValue]) → None[source]¶ Write a Gaussian “cube” file described by the given input data
Parameters: - f (TextIO) – File object to which the supplied data is to be saved. Must be opened in write mode.
- cube (Cube[Field.NumericValue]) – The dataclass containing the information needed to create a cube file. Note that only cube files describing fields with values matching Field.NumericValue are supported.