opan.grad¶
Module implementing imports of gradient data from external computations.
The abstract superclass SuperOpanGrad
defines a common initializer
and common method(s) that for use by subclasses importing
gradient data from external computational packages.
Implemented Subclasses
OrcaEngrad
– Imports ‘.engrad’ files from ORCA
Requirements
The import for each external software package SHOULD have its own subclass.
Each subclass MUST implement a
_load(self, **kwargs)
instance method as the entry point for import of gradient data.The gradient data MUST be stored:
- In the instance member
self.gradient
- As a one-dimensional
np.array
- With dtype descended from
np.float
- In units of Hartrees per Bohr \(\left(\frac{\mathrm{E_h}}{\mathrm B}\right)\)
- With elements ordered as:
\[\begin{split}\left[ \begin{array}{cccccccc} \frac{\partial E}{\partial x_1} & \frac{\partial E}{\partial y_1} & \frac{\partial E}{\partial z_1} & \frac{\partial E}{\partial x_2} & \frac{\partial E}{\partial y_2} & \dots & \frac{\partial E}{\partial y_N} & \frac{\partial E}{\partial z_N} \\ \end{array} \right]\end{split}\]The geometry data MUST be stored:
- In the instance member
self.geom
- As a one-dimensional
np.array
- With dtype descended from
np.float
- In units of Bohrs \(\left(\mathrm B\right)\)
- With elements ordered as:
\[\begin{split}\left[ \begin{array}{cccccccc} x_1 & y_1 & z_1 & x_2 & y_2 & \dots & y_N & z_N \\ \end{array} \right]\end{split}\]The atoms list MUST be stored:
- In the instance member
self.atom_syms
- As a
list
ofstr
, with each atom specified by an all-caps atomic symbol (opan.const.atom_sym
may be helpful)Subclasses MAY define an unlimited number of methods, class variables, and/or instance variables of unrestricted type, in addition to those defined above.
Superclass
-
class
opan.grad.
SuperOpanGrad
(**kwargs)¶ Abstract superclass of gradient import classes.
Performs the following actions:
- Ensures that the abstract superclass is not being instantiated, but instead a subclass.
- Calls the
_load()
method on the subclass, passing all kwargs through unmodified. - Typechecks the
self.gradient
,self.geom
, andself.atom_syms
required members for existence, proper data type, and properly matched lengths.
The checks performed in step 3 are primarily for design-time member- and type-enforcement during development of subclasses for newly implemented external software packages, rather than run-time data checking. It is RECOMMENDED to include robust data validity checking inside each subclass, rather than relying on these tests.
Methods
-
check_geom
(coords, atoms[, tol])¶ Check for consistency of gradient geometry with input coords/atoms.
The cartesian coordinates associated with a gradient object are considered consistent with the input coords if each component matches to within tol. If coords or atoms vectors are passed that are of different length than those stored in the instance, a
False
value is returned, rather than an exception raised.Parameters: - coords – length-3N
np.float_
– Vector of stacked ‘lab-frame’ Cartesian coordinates - atoms – length-N
str
orint
– Vector of atom symbols or atomic numbers - tol –
float
, optional Tolerance for acceptable deviation of each passed geometry coordinate from that in the instance to still be considered matching. Default value isDEF.GRAD_COORD_MATCH_TOL
See
opan.utils.check_geom
for details on return values and exceptions raised.- coords – length-3N
Subclasses
-
class
opan.grad.
OrcaEngrad
(path='...')¶ Container for gradient data generated by ORCA.
Initialize by passing the path to the file to be loaded as the path keyword argument.
Key information contained includes the gradient, the energy, the number of atoms, the geometry, and the atom IDs. For ORCA, the precision of the geometry is inferior to that in an XYZ file.
Methods
-
_load
(**kwargs)¶ Initialize
OrcaEngrad
object from .engrad fileSearches indicated file for energy, geometry, gradient, and number of atoms and stores in the corresponding instance variables.
Parameters: path –
str
– Complete path to the .engrad file to be read.Raises:
Class Variables
-
class
Pat
¶ re.compile()
patterns for data parsing.-
atblock
¶ Captures the entire block of atom ID & geometry data.
-
atline
¶ Extracts single lines from the atom ID / geometry block.
-
energy
¶ Captures the electronic energy.
-
gradblock
¶ Captures the gradient data block.
-
numats
¶ Retrieves the stand-along ‘number of atoms’ field.
-
Instance Variables
-
gradient
¶ length-3N
np.float_
– Vector of the Cartesian gradient in \(\frac{\mathrm{E_h}}{\mathrm B}\).
-
in_str
¶ str
– Complete text of the ENGRAD file read in to generate theOrcaEngrad
instance.
-