Running stand-alone qc2-ASE calculations

Note

If you do not plan to use qc2-ASE calculators alone, you do not need to worry about all the details provided in this section. When using qc2, most of the qc2-ASE features mentioned below are naturally abstracted within qc2Data; see qc2Data class.

Running basic calculations

The first step to run qc2-ASE calculations is to import the necessary ase and qc2.ase packages:

1from ase import Atoms
2from qc2.ase import Psi4

where we import the implemented Psi4 qc2-ASE calculator as an example. To carry out a basic single-point energy calculation with it, use:

 1from ase import Atoms
 2from ase.units import Ha
 3from qc2.ase import Psi4
 4
 5# set target molecule using ASE `Atoms` class
 6mol = Atoms(
 7    'H2',
 8    positions=[
 9        [0, 0, 0],
10        [0, 0, 0.737166]]
11)
12
13# attach a qchem calculator to `Atoms` object
14mol.calc = Psi4(method='hf', basis='sto-3g')
15
16# run qchem calculation and print energy in a.u.
17energy = mol.get_potential_energy()/Ha
18print(f"* Single-point energy (Hartree): {energy}")

As you can see, qc2-ASE calculators are executed in the same manner as traditional ASE calculators.

Saving qchem data into formatted data files

As mentioned in About qc2, the key distinction between qc2-ASE and traditional ASE calculators is that the former are specifically designed to accommodate extra methods for easy integration with quantum computing libraries. One of such methods is save() which is particularly useful for retrieving and dumping qchem data into formatted data files.

Here is an example of how you can save quantum chemistry data to a formatted hdf5 file according to QCSchema:

 1from ase.build import molecule
 2from ase.units import Ha
 3from qc2.ase import PySCF
 4
 5# set target molecule using G2 molecule dataset
 6mol = molecule('H2O')
 7
 8# attach a qchem calculator
 9mol.calc = PySCF(method='scf.HF', basis='sto-3g')
10# define format in which to save the qchem data
11mol.calc.schema_format = 'qcschema'
12
13# perform qchem calculation
14energy = mol.get_potential_energy()/Ha
15print(f"* Single-point energy (Hartree): {energy}")
16
17# save qchem data to a file
18mol.calc.save('h2o.hdf5')

where the schema_format attribute of the qc2-ASE calculator is used to set the format in which to save the data via the save() method.

If you wish to save data using FCIDump [KH89] format, use:

 1from ase.build import molecule
 2from ase.units import Ha
 3from qc2.ase import PySCF
 4
 5# set target molecule using G2 molecule dataset
 6mol = molecule('H2O')
 7
 8# attach a qchem calculator
 9mol.calc = PySCF(method='scf.HF', basis='sto-3g')
10# define format in which to save the qchem data
11mol.calc.schema_format = 'fcidump'
12
13# perform qchem calculation
14energy = mol.get_potential_energy()/Ha
15print(f"* Single-point energy (Hartree): {energy}")
16
17# save qchem data to a file
18mol.calc.save('h2o.fcidump')

Loading qchem data from formatted data files

In addition to the save() method, qc2-ASE calculators are also equipped with a load() method. Its primary function is to read data from qcschema- or fcidump-formatted data files and store them in FCIdump and QCSchema dataclasses; see Qiskit Nature documentation.

So, if you have done a quantum chemistry calculation in the past and have already a formatted data file, e.g., h2o.fcidump, containing qchem info you can read data from this file and save it into an instance of FCIdump dataclass:

 1from ase.build import molecule
 2from qc2.ase.qc2_ase_base_class import BaseQc2ASECalculator
 3
 4# set target molecule
 5mol = molecule('H2O')
 6
 7# attach a generic qchem calculator
 8mol.calc = BaseQc2ASECalculator()
 9# set the reading format
10mol.calc.schema_format = "fcidump"
11
12# load qchem data into a instance of `FCIDump` dataclass
13fcidump = mol.calc.load('h2o.fcidump')

Note that a dummy (generic) calculator has been attached to the ASE Atoms object (mol). The importance of BaseQc2ASECalculator will be emphasized in Building your own qc2-ASE calculator.

Note

Instances of FCIdump and QCSchema dataclasses generated by the load() method have no direct use within qc2-ASE calculators alone. However, they play a crucial role in communication with qc2Data and, subsequently, with quantum computing libraries.