|
14 | 14 |
|
15 | 15 | from __future__ import absolute_import |
16 | 16 |
|
| 17 | +from functools import reduce |
| 18 | + |
17 | 19 | import numpy |
18 | 20 | import pyscf |
19 | | -from functools import reduce |
20 | | -from pyscf import ci, cc, fci, mp |
21 | 21 |
|
22 | | -from openfermion.config import * |
| 22 | +from openfermion import MolecularData |
23 | 23 | from openfermionpyscf import PyscfMolecularData |
24 | 24 |
|
25 | 25 |
|
@@ -204,3 +204,54 @@ def run_pyscf(molecule, |
204 | 204 | pyscf_molecular_data.__dict__.update(molecule.__dict__) |
205 | 205 | pyscf_molecular_data.save() |
206 | 206 | return pyscf_molecular_data |
| 207 | + |
| 208 | + |
| 209 | +def generate_molecular_hamiltonian( |
| 210 | + geometry, |
| 211 | + basis, |
| 212 | + multiplicity, |
| 213 | + charge=0, |
| 214 | + n_active_electrons=None, |
| 215 | + n_active_orbitals=None): |
| 216 | + """Generate a molecular Hamiltonian with the given properties. |
| 217 | +
|
| 218 | + Args: |
| 219 | + geometry: A list of tuples giving the coordinates of each atom. |
| 220 | + An example is [('H', (0, 0, 0)), ('H', (0, 0, 0.7414))]. |
| 221 | + Distances in angstrom. Use atomic symbols to |
| 222 | + specify atoms. |
| 223 | + basis: A string giving the basis set. An example is 'cc-pvtz'. |
| 224 | + Only optional if loading from file. |
| 225 | + multiplicity: An integer giving the spin multiplicity. |
| 226 | + charge: An integer giving the charge. |
| 227 | + n_active_electrons: An optional integer specifying the number of |
| 228 | + electrons desired in the active space. |
| 229 | + n_active_orbitals: An optional integer specifying the number of |
| 230 | + spatial orbitals desired in the active space. |
| 231 | +
|
| 232 | + Returns: |
| 233 | + The Hamiltonian as an InteractionOperator. |
| 234 | + """ |
| 235 | + |
| 236 | + # Run electronic structure calculations |
| 237 | + molecule = run_pyscf( |
| 238 | + MolecularData(geometry, basis, multiplicity, charge) |
| 239 | + ) |
| 240 | + |
| 241 | + # Freeze core orbitals and truncate to active space |
| 242 | + if n_active_electrons is None: |
| 243 | + n_core_orbitals = 0 |
| 244 | + occupied_indices = None |
| 245 | + else: |
| 246 | + n_core_orbitals = (molecule.n_electrons - n_active_electrons) // 2 |
| 247 | + occupied_indices = list(range(n_core_orbitals)) |
| 248 | + |
| 249 | + if n_active_orbitals is None: |
| 250 | + active_indices = None |
| 251 | + else: |
| 252 | + active_indices = list(range(n_core_orbitals, |
| 253 | + n_core_orbitals + n_active_orbitals)) |
| 254 | + |
| 255 | + return molecule.get_molecular_hamiltonian( |
| 256 | + occupied_indices=occupied_indices, |
| 257 | + active_indices=active_indices) |
0 commit comments