qc2.ase.pyscf
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
Module Contents
Classes
An ASE calculator for the PySCF quantum chemistry package. |
Functions
|
Converts ASE atoms to PySCF atom. |
- qc2.ase.pyscf.ase_atoms_to_pyscf(ase_atoms: ase.Atoms) List[List[str | numpy.ndarray]][source]
Converts ASE atoms to PySCF atom.
- Parameters:
ase_atoms (Atoms) – ASE Atoms object.
- Returns:
PySCF atom.
- Return type:
List[List[Union[str, np.ndarray]]]
- class qc2.ase.pyscf.PySCF(restart: bool | None = None, ignore_bad_restart: bool | None = False, label: str | None = 'PySCF', atoms: ase.Atoms | None = None, command: str | None = None, directory: str = '.', **kwargs)[source]
Bases:
ase.calculators.calculator.Calculator,qc2.ase.qc2_ase_base_class.BaseQc2ASECalculatorAn ASE calculator for the PySCF quantum chemistry package.
- Parameters:
Calculator (Calculator) – Base-class for all ASE calculators.
BaseQc2ASECalculator (BaseQc2ASECalculator) – Base class for ase calculartors in qc2.
- Raises:
InputError – If attributes other than ‘method’, ‘xc’, ‘basis’, ‘multiplicity’, ‘charge’, ‘relativistic’, ‘cart’, ‘scf_addons’, ‘verbose’, and ‘output’ are input as Calculator.
CalculatorSetupError – If abinitio methods other than ‘scf.RHF’, ‘scf.UHF’, ‘scf.ROHF’, ‘dft.RKS’, ‘dft.UKS’, and ‘dft.ROKS’ are selected.
- check_pyscf_attributes() None[source]
Checks for any missing and/or mispelling PySCF input attribute.
Notes
it can also be used to eventually set specific environment variables, ios, etc.
- calculate(atoms: ase.Atoms | None = None, properties: List[str] = ['energy'], system_changes: List[str] = all_changes) None[source]
This method is the core responsible for the actual calculation.
Notes
Implementation based on Calculator.calculate() method. see also ase/ase/calculators/calculator.py.
- Parameters:
atoms (Atoms, optional) – Atoms object to which the calculator is attached. Defaults to None.
properties (list[str], optional) – List of what properties need to be calculated. Defaults to [‘energy’].
system_changes (list[str], optional) – 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.
- Raises:
CalculatorSetupError – If a proper geometry is not provided.
CalculatorSetupError – If abinitio methods other than
'scf.RHF', 'scf.UHF', 'scf.ROHF', 'dft.RKS', 'dft.UKS', – and ‘dft.ROKS’ are selected.
- save(datafile: h5py.File | str) None[source]
Dumps qchem data to a datafile using QCSchema or FCIDump formats.
- Parameters:
datafile (Union[h5py.File, str]) – file to save the data to.
- Returns:
None
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')
- load(datafile: h5py.File | str) qiskit_nature.second_q.formats.qcschema.QCSchema | qiskit_nature.second_q.formats.fcidump.FCIDump[source]
Loads electronic structure data from a datafile.
- Parameters:
datafile (Union[h5py.File, str]) – file to read the data from.
- Returns:
Instances of
QCSchemaorFCIDumpdataclasses containing qchem data.
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')
- get_integrals_mo_basis() Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]
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.
- Return type:
A tuple containing np.ndarray types
- get_integrals_ao_basis() Tuple[numpy.ndarray, numpy.ndarray][source]
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.
- Return type:
Tuple[np.ndarray, np.ndarray]
- get_molecular_orbitals_coefficients() Tuple[numpy.ndarray, numpy.ndarray][source]
Retrieves alpha and beta MO coeffs from PySCF routines.
- Returns:
Tuple containing the alpha and beta MO coefficients.
- Return type:
Tuple[np.ndarray, np.ndarray]
- get_molecular_orbitals_energies() Tuple[numpy.ndarray, numpy.ndarray][source]
Retrieves alpha and beta MO energies from PySCF routines.
- Returns:
Tuple containing the alpha and beta MO energies.
- Return type:
Tuple[np.ndarray, np.ndarray]
- get_overlap_matrix() numpy.ndarray[source]
Retrieves overlap matrix from PySCF routines.
- Returns:
The overlap matrix.
- Return type:
np.ndarray
- _expand_mo_object(mo_object: Tuple[numpy.ndarray | None, numpy.ndarray | None] | numpy.ndarray, array_dimension: int = 2) Tuple[numpy.ndarray, numpy.ndarray][source]
Expands the mo object into alpha- and beta-spin components.
- Parameters:
mo_object – the molecular orbital object to expand.
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.
Notes
Adapted from Qiskit-Nature pyscfdriver.py.