00-Nature Tutorial- Electronic structure

[ ]:
# This code is from:
https://qiskit-community.github.io/qiskit-nature/tutorials/01_electronic_structure.html
[1]:
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver

driver = PySCFDriver(
    atom="H 0 0 0; H 0 0 0.735",
    basis="sto3g",
    charge=0,
    spin=0,
    unit=DistanceUnit.ANGSTROM,
)
[2]:
problem = driver.run()
print(problem)
<qiskit_nature.second_q.problems.electronic_structure_problem.ElectronicStructureProblem object at 0x79190596c850>
[3]:
hamiltonian = problem.hamiltonian

coefficients = hamiltonian.electronic_integrals
print(coefficients.alpha)
Polynomial Tensor
 "+-":
array([[-1.25633907e+00,  0.00000000e+00],
       [-4.16333634e-17, -4.71896007e-01]])
 "++--":
array([6.75710155e-01, 1.38777878e-16, 1.80931200e-01, 6.64581730e-01,
       5.55111512e-17, 6.98573723e-01])
[4]:
second_q_op = hamiltonian.second_q_op()
print(second_q_op)

Fermionic Operator
number spin orbitals=4, number terms=36
  0.33785507740175813 * ( +_0 +_0 -_0 -_0 )
+ 0.3322908651276482 * ( +_0 +_1 -_1 -_0 )
+ 0.33785507740175813 * ( +_0 +_2 -_2 -_0 )
+ 0.3322908651276482 * ( +_0 +_3 -_3 -_0 )
+ 0.09046559989211572 * ( +_0 +_0 -_1 -_1 )
+ 0.09046559989211572 * ( +_0 +_1 -_0 -_1 )
+ 0.09046559989211572 * ( +_0 +_2 -_3 -_1 )
+ 0.09046559989211572 * ( +_0 +_3 -_2 -_1 )
+ 0.09046559989211572 * ( +_1 +_0 -_1 -_0 )
+ 0.09046559989211572 * ( +_1 +_1 -_0 -_0 )
+ 0.09046559989211572 * ( +_1 +_2 -_3 -_0 )
+ 0.09046559989211572 * ( +_1 +_3 -_2 -_0 )
+ 0.3322908651276482 * ( +_1 +_0 -_0 -_1 )
+ 0.34928686136600884 * ( +_1 +_1 -_1 -_1 )
+ 0.3322908651276482 * ( +_1 +_2 -_2 -_1 )
+ 0.34928686136600884 * ( +_1 +_3 -_3 -_1 )
+ 0.33785507740175813 * ( +_2 +_0 -_0 -_2 )
+ 0.3322908651276482 * ( +_2 +_1 -_1 -_2 )
+ 0.33785507740175813 * ( +_2 +_2 -_2 -_2 )
+ 0.3322908651276482 * ( +_2 +_3 -_3 -_2 )
+ 0.09046559989211572 * ( +_2 +_0 -_1 -_3 )
+ 0.09046559989211572 * ( +_2 +_1 -_0 -_3 )
+ 0.09046559989211572 * ( +_2 +_2 -_3 -_3 )
+ 0.09046559989211572 * ( +_2 +_3 -_2 -_3 )
+ 0.09046559989211572 * ( +_3 +_0 -_1 -_2 )
+ 0.09046559989211572 * ( +_3 +_1 -_0 -_2 )
+ 0.09046559989211572 * ( +_3 +_2 -_3 -_2 )
+ 0.09046559989211572 * ( +_3 +_3 -_2 -_2 )
+ 0.3322908651276482 * ( +_3 +_0 -_0 -_3 )
+ 0.34928686136600884 * ( +_3 +_1 -_1 -_3 )
+ 0.3322908651276482 * ( +_3 +_2 -_2 -_3 )
+ 0.34928686136600884 * ( +_3 +_3 -_3 -_3 )
+ -1.2563390730032498 * ( +_0 -_0 )
+ -0.4718960072811421 * ( +_1 -_1 )
+ -1.2563390730032498 * ( +_2 -_2 )
+ -0.4718960072811421 * ( +_3 -_3 )
[5]:
hamiltonian.nuclear_repulsion_energy  # NOT included in the second_q_op above
[5]:
0.7199689944489797
[6]:
problem.molecule
[6]:
MoleculeInfo(symbols=['H', 'H'], coords=[(0.0, 0.0, 0.0), (0.0, 0.0, 1.3889487015553204)], multiplicity=1, charge=0, units=<DistanceUnit.BOHR: 'Bohr'>, masses=[1, 1])
[7]:
problem.reference_energy
[7]:
-1.116998996754004
[8]:
problem.num_particles
[8]:
(1, 1)
[9]:
problem.num_spatial_orbitals
[9]:
2
[10]:
problem.basis
[10]:
<ElectronicBasis.MO: 'molecular'>
[11]:
problem.properties
[11]:
<qiskit_nature.second_q.problems.electronic_properties_container.ElectronicPropertiesContainer at 0x791905982f10>
[12]:
problem.properties.particle_number
[12]:
<qiskit_nature.second_q.properties.particle_number.ParticleNumber at 0x791946f3a790>
[13]:
problem.properties.angular_momentum
[13]:
<qiskit_nature.second_q.properties.angular_momentum.AngularMomentum at 0x79194690ac10>
[14]:
problem.properties.magnetization
[14]:
<qiskit_nature.second_q.properties.magnetization.Magnetization at 0x7919059834d0>
[15]:
problem.properties.electronic_dipole_moment
[15]:
<qiskit_nature.second_q.properties.dipole_moment.ElectronicDipoleMoment at 0x79194b9d5710>
[16]:
from qiskit_algorithms import NumPyMinimumEigensolver
from qiskit_nature.second_q.algorithms import GroundStateEigensolver
from qiskit_nature.second_q.mappers import JordanWignerMapper

solver = GroundStateEigensolver(
    JordanWignerMapper(),
    NumPyMinimumEigensolver(),
)
[17]:
result = solver.solve(problem)
print(result)
=== GROUND STATE ENERGY ===

* Electronic ground state energy (Hartree): -1.857275030202
  - computed part:      -1.857275030202
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035753

=== MEASURED OBSERVABLES ===

  0:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000

=== DIPOLE MOMENTS ===

~ Nuclear dipole moment (a.u.): [0.0  0.0  1.3889487]

  0:
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953

[ ]:

[ ]: