qc2.ase.pyscf ============= .. py:module:: qc2.ase.pyscf .. autoapi-nested-parse:: This module defines an ASE interface to PySCF. https://pyscf.org/ => Official documentation https://github.com/pyscf/pyscf => GitHub page Note: Adapted from https://github.com/pyscf/pyscf/blob/master/pyscf/pbc/tools/pyscf_ase.py & https://github.com/pyscf/pyscf/issues/624 Classes ------- .. autoapisummary:: qc2.ase.pyscf.PySCF Functions --------- .. autoapisummary:: qc2.ase.pyscf.ase_atoms_to_pyscf Module Contents --------------- .. py:function:: ase_atoms_to_pyscf(ase_atoms: ase.Atoms) -> List[List[Union[str, numpy.ndarray]]] Converts ASE atoms to PySCF atom. :param ase_atoms: ASE Atoms object. :type ase_atoms: Atoms :returns: PySCF atom. :rtype: List[List[Union[str, np.ndarray]]] .. py:class:: PySCF(restart: Optional[bool] = None, ignore_bad_restart: Optional[bool] = False, label: Optional[str] = 'PySCF', atoms: Optional[ase.Atoms] = None, command: Optional[str] = None, directory: str = '.', **kwargs) Bases: :py:obj:`ase.calculators.calculator.Calculator`, :py:obj:`qc2.ase.qc2_ase_base_class.BaseQc2ASECalculator` An ASE calculator for the PySCF quantum chemistry package. :param Calculator: Base-class for all ASE calculators. :type Calculator: Calculator :param BaseQc2ASECalculator: Base class for ase calculartors in qc2. :type BaseQc2ASECalculator: BaseQc2ASECalculator :raises InputError: If attributes other than 'method', 'xc', 'basis', 'multiplicity', 'charge', 'relativistic', 'cart', 'scf_addons', 'verbose', and 'output' are input as Calculator. :raises CalculatorSetupError: If abinitio methods other than 'scf.RHF', 'scf.UHF', 'scf.ROHF', 'dft.RKS', 'dft.UKS', and 'dft.ROKS' are selected. .. py:attribute:: implemented_properties :type: List[str] :value: ['energy', 'forces'] .. py:attribute:: default_parameters :type: Dict[str, Any] .. py:attribute:: mol :value: None .. py:attribute:: mf :value: None .. py:method:: check_pyscf_attributes() -> None Checks for any missing and/or mispelling PySCF input attribute. .. rubric:: Notes it can also be used to eventually set specific environment variables, ios, etc. .. py:method:: calculate(atoms: Optional[ase.Atoms] = None, properties: List[str] = ['energy'], system_changes: List[str] = all_changes) -> None This method is the core responsible for the actual calculation. .. rubric:: Notes Implementation based on Calculator.calculate() method. see also ase/ase/calculators/calculator.py. :param atoms: Atoms object to which the calculator is attached. Defaults to None. :type atoms: Atoms, optional :param properties: List of what properties need to be calculated. Defaults to ['energy']. :type properties: list[str], optional :param system_changes: List of what has changed since last calculation. Can be any combination of these six: 'positions', 'numbers', 'cell', 'pbc', 'initial_charges' and 'initial_magmoms'. Defaults to all_changes. :type system_changes: list[str], optional :raises CalculatorSetupError: If a proper geometry is not provided. :raises CalculatorSetupError: If abinitio methods other than :raises 'scf.RHF', 'scf.UHF', 'scf.ROHF', 'dft.RKS', 'dft.UKS',: and 'dft.ROKS' are selected. .. py:method:: save(datafile: Union[h5py.File, str]) -> None Dumps qchem data to a datafile using QCSchema or FCIDump formats. :param datafile: file to save the data to. :type datafile: Union[h5py.File, str] :returns: None .. rubric:: Notes files are written following the QCSchema or FCIDump formats. **Example** >>> from ase.build import molecule >>> from qc2.ase import PySCF >>> >>> molecule = molecule('H2') >>> molecule.calc = PySCF() # => RHF/STO-3G >>> molecule.calc.schema_format = "qcschema" >>> molecule.calc.get_potential_energy() >>> molecule.calc.save('h2.hdf5') >>> >>> molecule = molecule('H2') >>> molecule.calc = PySCF() # => RHF/STO-3G >>> molecule.calc.schema_format = "fcidump" >>> molecule.calc.get_potential_energy() >>> molecule.calc.save('h2.fcidump') .. py:method:: load(datafile: Union[h5py.File, str]) -> Union[qiskit_nature.second_q.formats.qcschema.QCSchema, qiskit_nature.second_q.formats.fcidump.FCIDump] Loads electronic structure data from a datafile. :param datafile: file to read the data from. :type datafile: Union[h5py.File, str] :returns: Instances of :class:`QCSchema` or :class:`FCIDump` dataclasses containing qchem data. .. rubric:: Notes files are read following the qcschema or fcidump formats. **Example** >>> from ase.build import molecule >>> from qc2.ase import PySCF >>> >>> molecule = molecule('H2') >>> molecule.calc = PySCF() # => RHF/STO-3G >>> molecule.calc.schema_format = "qcschema" >>> qcschema = molecule.calc.load('h2.h5') >>> >>> molecule = molecule('H2') >>> molecule.calc = PySCF() # => RHF/STO-3G >>> molecule.calc.schema_format = "fcidump" >>> fcidump = molecule.calc.load('h2.fcidump') .. py:method:: get_integrals_mo_basis() -> Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] Retrieves 1- & 2-body integrals in MO basis from PySCF routines. :returns: - one_body_int_a & one_body_int_b: Numpy arrays containing alpha and beta components of the one-body integrals. - two_body_int_aa, two_body_int_bb, two_body_int_ab & two_body_int_ba: Numpy arrays containing alpha-alpha, beta-beta, alpha-beta & beta-alpha components of the two-body integrals. :rtype: A tuple containing `np.ndarray` types .. py:method:: get_integrals_ao_basis() -> Tuple[numpy.ndarray, numpy.ndarray] Retrieves 1- & 2-e integrals in AO basis from PySCF routines. :returns: Tuple containing the 1-electron integrals and the 2-electron integrals in the AO basis. :rtype: Tuple[np.ndarray, np.ndarray] .. py:method:: get_molecular_orbitals_coefficients() -> Tuple[numpy.ndarray, numpy.ndarray] Retrieves alpha and beta MO coeffs from PySCF routines. :returns: Tuple containing the alpha and beta MO coefficients. :rtype: Tuple[np.ndarray, np.ndarray] .. py:method:: get_molecular_orbitals_energies() -> Tuple[numpy.ndarray, numpy.ndarray] Retrieves alpha and beta MO energies from PySCF routines. :returns: Tuple containing the alpha and beta MO energies. :rtype: Tuple[np.ndarray, np.ndarray] .. py:method:: get_overlap_matrix() -> numpy.ndarray Retrieves overlap matrix from PySCF routines. :returns: The overlap matrix. :rtype: np.ndarray .. py:method:: _expand_mo_object(mo_object: Union[Tuple[Optional[numpy.ndarray], Optional[numpy.ndarray]], numpy.ndarray], array_dimension: int = 2) -> Tuple[numpy.ndarray, numpy.ndarray] Expands the mo object into alpha- and beta-spin components. :param mo_object: the molecular orbital object to expand. :param array_dimension: This argument specifies the dimension of the numpy array (if a tuple is not encountered). Making this configurable permits this function to be used to expand both, MO coefficients (3D array) and MO energies (2D array). :returns: The (alpha, beta) tuple of MO data. .. rubric:: Notes Adapted from Qiskit-Nature pyscfdriver.py.