def _core_set_variable(key: str, val: Union[core.Matrix, np.ndarray, float]) -> None: """Sets scalar or array QCVariable *key* to *val* in global memory.""" if isinstance(val, core.Matrix): if core.has_scalar_variable(key): raise ValidationError( f"psi4.core.set_variable: Target variable '{key}' already a scalar variable!" ) else: core.set_array_variable(key, val) elif isinstance(val, np.ndarray): if core.has_scalar_variable(key): raise ValidationError( f"psi4.core.set_variable: Target variable '{key}' already a scalar variable!" ) else: core.set_array_variable( key, core.Matrix.from_array(_qcvar_reshape_set(key, val))) else: if core.has_array_variable(key): raise ValidationError( f"psi4.core.set_variable: Target variable '{key}' already an array variable!" ) else: core.set_scalar_variable(key, val)
def _core_set_variable(key, val): if isinstance(val, core.Matrix): if core.has_scalar_variable(key): raise ValidationError("psi4.core.set_variable: Target variable " + key + " already a scalar variable!") else: core.set_array_variable(key, val) elif isinstance(val, np.ndarray): if core.has_scalar_variable(key): raise ValidationError("psi4.core.set_variable: Target variable " + key + " already a scalar variable!") else: core.set_array_variable(key, core.Matrix.from_array(val)) else: if core.has_array_variable(key): raise ValidationError("psi4.core.set_variable: Target variable " + key + " already an array variable!") else: core.set_scalar_variable(key, val)
def _core_variable(key): if core.has_scalar_variable(key): return core.scalar_variable(key) elif core.has_array_variable(key): return core.array_variable(key) else: raise KeyError("psi4.core.variable: Requested variable " + key + " was not set!\n")
def _core_variable(key: str) -> Union[float, core.Matrix, np.ndarray]: """Return copy of scalar or array QCVariable *key* from global memory. Returns ------- float or numpy.ndarray or Matrix Scalar variables are returned as floats. Array variables not naturally 2D (like multipoles) are returned as :class:`numpy.ndarray` of natural dimensionality. Other array variables are returned as :py:class:`~psi4.core.Matrix` and may have an extra dimension with symmetry information. Example ------- >>> psi4.gradient("hf/cc-pvdz") >>> psi4.variable("CURRENT ENERGY") -100.00985995185668 >>> psi4.variable("CURRENT DIPOLE") array([ 0. , 0. , -0.83217802]) >>> psi4.variable("CURRENT GRADIENT") <psi4.core.Matrix object at 0x12d884fc0> >>> psi4.variable("CURRENT GRADIENT").np array([[ 6.16297582e-33, 6.16297582e-33, -9.41037138e-02], [-6.16297582e-33, -6.16297582e-33, 9.41037138e-02]]) """ key = _qcvar_warnings(key) if core.has_scalar_variable(key): return core.scalar_variable(key) elif core.has_array_variable(key): return _qcvar_reshape_get(key, core.array_variable(key)) else: raise KeyError("psi4.core.variable: Requested variable " + key + " was not set!\n")
def _core_del_variable(key: str) -> None: """Removes scalar or array QCVariable *key* from global memory if present.""" if core.has_scalar_variable(key): core.del_scalar_variable(key) elif core.has_array_variable(key): core.del_array_variable(key)
def _core_set_variable(key, val): if isinstance(val, core.Matrix): if core.has_scalar_variable(key): raise ValidationError("psi4.core.set_variable: Target variable " + key + " already a scalar variable!") else: core.set_array_variable(key, val) elif isinstance(val, np.ndarray): if core.has_scalar_variable(key): raise ValidationError("psi4.core.set_variable: Target variable " + key + " already a scalar variable!") else: core.set_array_variable(key, core.Matrix.from_array(_qcvar_reshape_set(key, val))) else: if core.has_array_variable(key): raise ValidationError("psi4.core.set_variable: Target variable " + key + " already an array variable!") else: core.set_scalar_variable(key, val)
def _core_variable(key): _qcvar_warnings(key) if core.has_scalar_variable(key): return core.scalar_variable(key) elif core.has_array_variable(key): return _qcvar_reshape_get(key, core.array_variable(key)) else: raise KeyError("psi4.core.variable: Requested variable " + key + " was not set!\n")
def _core_del_variable(key): if core.has_scalar_variable(key): core.del_scalar_variable(key) elif core.has_array_variable(key): core.del_array_variable(key)
def _core_has_variable(key): return core.has_scalar_variable(key) or core.has_array_variable(key)
def _core_has_variable(key: str) -> bool: """Whether scalar or array QCVariable *key* has been set in global memory.""" return core.has_scalar_variable(key) or core.has_array_variable(key)