Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_h2_dimer(bond_length):
# Set molecule parameters.
basis = "sto-3g"
multiplicity = 1
charge = 0
geometry = [("H", [0.0, 0.0, 0.0]), ("H", [0.0, 0.0, bond_length])]
molecule = MolecularData(geometry, basis, multiplicity, charge)
molecule.filename = "./" + molecule.filename.split("/")[-1]
# Run Psi4.
molecule = run_psi4(
molecule, run_scf=True, run_mp2=False, run_cisd=False, run_ccsd=True, run_fci=True
)
return molecule
spacings += [0.1 * r for r in range(1, 31)]
# Set run options
run_scf = 1
run_mp2 = 1
run_cisd = 1
run_ccsd = 1
run_fci = 1
verbose = 1
# Run Diatomic Curve
for spacing in spacings:
description = "{}".format(spacing)
geometry = [[element_names[0], [0, 0, 0]],
[element_names[1], [0, 0, spacing]]]
molecule = MolecularData(geometry,
basis,
multiplicity,
charge,
description)
molecule = run_pyscf(molecule,
run_scf=run_scf,
run_mp2=run_mp2,
run_cisd=run_cisd,
run_ccsd=run_ccsd,
run_fci=run_fci,
verbose=verbose)
molecule.save()
# Run Li H single point
description = "1.45"
reduce_spin(bool): True if one wishes to perform spin reduction on
integrals that are given in interaction operator. Assumes
spatial (x) spin structure generically.
Returns:
molecule(MolecularData):
Instance that captures the
interaction_operator converted into the format that would come
from an electronic structure package adorned with some meta-data
that may be useful.
"""
n_spin_orbitals = interaction_operator.n_qubits
# Introduce bare molecular operator to fill
molecule = MolecularData(geometry=geometry,
basis=basis,
multiplicity=multiplicity,
data_directory=data_directory)
molecule.nuclear_repulsion = interaction_operator.constant
# Remove spin from integrals and put into molecular operator
if reduce_spin:
reduction_indices = list(range(0, n_spin_orbitals, 2))
else:
reduction_indices = list(range(n_spin_orbitals))
molecule.n_orbitals = len(reduction_indices)
molecule.one_body_integrals = interaction_operator.one_body_tensor[
numpy.ix_(reduction_indices, reduction_indices)]
qc_package_error_message = (
"Integration with quantum chemistry package '{}' is not available. \n Please set"
" 'qc_package' to 'psi4' or 'pyscf'.".format(qc_package)
)
raise TypeError(qc_package_error_message)
qcp_dir = os.path.join(outpath.strip(), qc_package)
path_to_hf_data = os.path.join(qcp_dir, basis.strip())
if not os.path.isdir(qcp_dir):
os.mkdir(qcp_dir)
os.mkdir(path_to_hf_data)
elif not os.path.isdir(path_to_hf_data):
os.mkdir(path_to_hf_data)
molecule = MolecularData(
geometry,
basis,
multiplicity,
charge,
filename=os.path.join(path_to_hf_data, mol_name.strip()),
)
if qc_package == "psi4":
run_psi4(molecule, run_scf=1, verbose=0, tolerate_error=1)
if qc_package == "pyscf":
run_pyscf(molecule, run_scf=1, verbose=0)
return path_to_hf_data
([0], [1, 2])
Args:
mol_name (str): name of the molecule
hf_data (str): path to the directory containing the file with the Hartree-Fock electronic
structure
n_active_electrons (int): Optional argument to specify the number of active electrons.
If not specified, all electrons are treated as active
n_active_orbitals (int): Optional argument to specify the number of active orbitals.
If not specified, all orbitals considered active
Returns:
tuple: lists of indices for doubly-occupied and active orbitals
"""
# pylint: disable=too-many-branches
molecule = MolecularData(filename=os.path.join(hf_data.strip(), mol_name.strip()))
if n_active_electrons is None:
n_docc_orbitals = 0
docc_indices = []
else:
if n_active_electrons <= 0:
raise ValueError(
"The number of active electrons ({}) "
"has to be greater than 0.".format(n_active_electrons)
)
if n_active_electrons > molecule.n_electrons:
raise ValueError(
"The number of active electrons ({}) "
"can not be greater than the total "
"number of electrons ({}).".format(n_active_electrons, molecule.n_electrons)
mol_name (str): name of the molecule
hf_data (str): path to the directory containing the file with the Hartree-Fock electronic structure
mapping (str): optional argument to specify the fermion-to-qubit mapping
Input values can be ``'jordan_wigner'`` or ``'bravyi_kitaev'``
docc_mo_indices (list): indices of doubly-occupied molecular orbitals, i.e.,
the orbitals that are not correlated in the many-body wave function
active_mo_indices (list): indices of active molecular orbitals, i.e., the orbitals used to
build the correlated many-body wave function
Returns:
transformed_operator: instance of the QubitOperator class representing the electronic
Hamiltonian
"""
# loading HF data from a hdf5 file
molecule = MolecularData(filename=os.path.join(hf_data.strip(), mol_name.strip()))
# getting the terms entering the second-quantized Hamiltonian
terms_molecular_hamiltonian = molecule.get_molecular_hamiltonian(
occupied_indices=docc_mo_indices, active_indices=active_mo_indices
)
# generating the fermionic Hamiltonian
fermionic_hamiltonian = get_fermion_operator(terms_molecular_hamiltonian)
mapping = mapping.strip().lower()
if mapping not in ("jordan_wigner", "bravyi_kitaev"):
raise TypeError(
"The '{}' transformation is not available. \n "
"Please set 'mapping' to 'jordan_wigner' or 'bravyi_kitaev'.".format(mapping)
)
description)
molecule = run_pyscf(molecule,
run_scf=run_scf,
run_mp2=run_mp2,
run_cisd=run_cisd,
run_ccsd=run_ccsd,
run_fci=run_fci,
verbose=verbose)
molecule.save()
# Run Li H single point
description = "1.45"
geometry = [['Li', [0, 0, 0]],
['H', [0, 0, 1.45]]]
molecule = MolecularData(geometry,
basis,
multiplicity,
charge,
description)
molecule = run_pyscf(molecule,
run_scf=run_scf,
run_mp2=run_mp2,
run_cisd=run_cisd,
run_ccsd=run_ccsd,
run_fci=run_fci,
verbose=verbose)
molecule.save()
def __init__(self, geometry=None, basis=None, multiplicity=None,
charge=0, description="", filename="", data_directory=None):
MolecularData.__init__(self, geometry, basis, multiplicity,
charge, description, filename, data_directory)
self._pyscf_data = {}