Final run
We need to make sure that the following is working:
- [x] Occupation based hamiltonians tutorial on the website
- [x] Spin based hamiltonians tutorial on the website
- [ ] toml utility
@RichRick1 The example Building Integrals from SMILES from Demonstration.ipynb is failing. This is happening because to generate the two body integrals when we do not pass u_onsite PariserParr tries to compute it from connectivity, which is None in this case. What should we do? Should we consider that when the user do not pass connectivity we have only carbons, connected given the adjacency?
I am a little bit confused, because in the example from SMILES we build the Hubbard model, not the PPP model:
# generate a molecule from SMILES
mol = MolFromSmiles('C1=CC=C2C=CC=CC2=C1')
# generate the connectivity matrix
connectivity = rdmolops.GetAdjacencyMatrix(mol)
# generate the Hamiltonian
# generating Huckel model
huckel = HamHub(connectivity, alpha=-0.414, beta=-0.0533)
e0_huck = huckel.generate_zero_body_integral()
h1_huck = huckel.generate_one_body_integral(dense=True, basis='spatial basis')
h2_huck = huckel.generate_two_body_integral(dense=True, basis='spatial basis', sym=4)
# generate Hubbard model
# setting on-site repulsion to 10.84 eV for each atom.
U = 10.84 * np.ones(connectivity.shape[0])
hubbard = HamHub(connectivity, alpha=0, beta=-1,
u_onsite=U)
e0_hub = hubbard.generate_zero_body_integral()
h1_hub = hubbard.generate_one_body_integral(dense=True, basis='spatial basis')
h2_hub = hubbard.generate_two_body_integral(dense=True, basis='spatial basis', sym=4)
And it looks like we are providing U_onsite
I may be missing something
yes, you are right in that part of the code, but here
huckel = HamHub(connectivity, alpha=-0.414, beta=-0.0533), we are not using u_onsite
Here is the error:
{
"name": "TypeError",
"message": "'NoneType' object is not iterable",
"stack": "---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[10], line 13
11 e0_huck = huckel.generate_zero_body_integral()
12 h1_huck = huckel.generate_one_body_integral(dense=True, basis='spatial basis')
---> 13 h2_huck = huckel.generate_two_body_integral(dense=True, basis='spatial basis', sym=4)
15 # generate Hubbard model
16 # setting on-site repulsion to 10.84 eV for each atom.
17 U = 10.84 * np.ones(adjacency.shape[0])
File c:\\Users\\giova\\ModelHamiltonian\\examples\\..\\moha\\hamiltonians.py:250, in HamPPP.generate_two_body_integral(self, basis, dense, sym)
248 v = lil_matrix((Nv * Nv, Nv * Nv))
249 if self.u_onsite is None:
--> 250 self.u_onsite, self.Rxy_matrix = compute_u(
251 self.connectivity, self.atom_dictionary, self.affinity_dct)
253 if self.u_onsite is not None:
254 for p in range(n_sp):
File c:\\Users\\giova\\ModelHamiltonian\\examples\\..\\moha\\rauk\\PariserParr.py:360, in compute_u(connectivity, atom_dictionary, affinity_dictionary)
357 affinity_path = Path(__file__).parent / \"affinity.json\"
358 affinity_dictionary = json.load(open(affinity_path, \"rb\"))
--> 360 unique_atoms = {atom for tpl in connectivity for atom in tpl[:2]}
361 num_sites = len(unique_atoms)
363 u_onsite = []
TypeError: 'NoneType' object is not iterable"
}
That's cool if we are using the values from json files, if U_onsite isn't provided. In the example, where we use Huckel model, we need to explicitly call the Huckel Hamiltonian -- HamHuck, not the HamHub
In this example specifically, we are doing these code:
# generate the Hamiltonian
# generating Huckel model
huckel = HamHub(connectivity, alpha=-0.414, beta=-0.0533)
e0_huck = huckel.generate_zero_body_integral()
h1_huck = huckel.generate_one_body_integral(dense=True, basis='spatial basis')
h2_huck = huckel.generate_two_body_integral(dense=True, basis='spatial basis', sym=4)
We need to change the first line from huckel = HamHub(connectivity, alpha=-0.414, beta=-0.0533) to huckel = HamHuck(connectivity, alpha=-0.414, beta=-0.0533).
This should do the job
I am sorry but I don't think this fixes the problem... I mean anyways the function generate_two_body_integral will be called and connectivity will be set to None