Пример #1
0
def test_magnetizability_rhf():
    mol = molecules.molecule_glycine_sto3g()
    mol.build()

    mf = pyscf.scf.RHF(mol)
    mf.scf()

    C = utils.fix_mocoeffs_shape(mf.mo_coeff)
    E = utils.fix_moenergies_shape(mf.mo_energy)
    occupations = utils.occupations_from_pyscf_mol(mol, C)

    calculator_common = magnetic.Magnetizability(Program.PySCF, mol, C, E, occupations)
    calculator_common.form_operators()
    calculator_common.run(hamiltonian="rpa", spin="singlet")
    calculator_common.form_results()
    ref_eigvals, ref_iso, _ = utils.tensor_printer(ref_magnetizability_rhf)
    res_eigvals, res_iso, _ = utils.tensor_printer(calculator_common.magnetizability)
    thresh_eigval = 1.0e-3
    for i in range(3):
        assert abs(ref_eigvals[i] - res_eigvals[i]) < thresh_eigval

    # TODO it isn't so simple; there are actually many more terms
    # present when using London orbitals.
    # calculator_giao = magnetic.Magnetizability(mol, C, E, occupations, hamiltonian='rpa', spin='singlet', use_giao=True)
    # calculator_giao.form_operators()
    # calculator_giao.run()
    # calculator_giao.form_results()

    return
Пример #2
0
def test_magnetizability_uhf() -> None:
    mol = molecules.molecule_glycine_sto3g()
    mol.charge = 1
    mol.spin = 1
    mol.build()

    mf = pyscf.scf.uhf.UHF(mol)
    mf.scf()

    C = utils.fix_mocoeffs_shape(mf.mo_coeff)
    E = utils.fix_moenergies_shape(mf.mo_energy)
    occupations = occupations_from_pyscf_mol(mol, C)

    calculator_common = magnetic.Magnetizability(
        Program.PySCF,
        mol,
        cphf.CPHF(solvers.ExactInv(C, E, occupations)),
        C,
        E,
        occupations,
    )
    calculator_common.form_operators()
    calculator_common.run(hamiltonian=Hamiltonian.RPA, spin=Spin.singlet)
    calculator_common.form_results()
    ref_eigvals, ref_iso, _ = utils.tensor_printer(ref_magnetizability_rohf)
    res_eigvals, res_iso, _ = utils.tensor_printer(
        calculator_common.magnetizability)
    thresh_eigval = 1.0e-1
    for i in range(3):
        assert abs(ref_eigvals[i] - res_eigvals[i]) < thresh_eigval
Пример #3
0
def test_iterators():
    """Test that each kind of iterator gives identical results."""

    mol = molecules_pyscf.molecule_glycine_sto3g()
    mol.charge = 1
    mol.spin = 1
    mol.build()

    mf = pyscf.scf.uhf.UHF(mol)
    mf.scf()

    assert isinstance(mf.mo_coeff, np.ndarray)
    assert len(mf.mo_coeff) == 2
    C = utils.fix_mocoeffs_shape(mf.mo_coeff)
    E = utils.fix_moenergies_shape(mf.mo_energy)
    occupations = utils.occupations_from_pyscf_mol(mol, C)

    solver_ref = iterators.ExactInv(C, E, occupations)
    calculator_ref = magnetic.Magnetizability(Program.PySCF,
                                              mol,
                                              C,
                                              E,
                                              occupations,
                                              solver=solver_ref)
    calculator_ref.form_operators()
    calculator_ref.run(hamiltonian="rpa", spin="singlet")
    calculator_ref.form_results()

    ref = calculator_ref.magnetizability
    inv_funcs = (sp.linalg.inv, sp.linalg.pinv, sp.linalg.pinv2)

    thresh = 6.0e-14

    for inv_func in inv_funcs:
        solver_res = iterators.ExactInv(C, E, occupations, inv_func=inv_func)
        calculator_res = magnetic.Magnetizability(Program.PySCF,
                                                  mol,
                                                  C,
                                                  E,
                                                  occupations,
                                                  solver=solver_res)
        calculator_res.form_operators()
        calculator_res.run(hamiltonian="rpa", spin="singlet")
        calculator_res.form_results()

        np.testing.assert_equal(
            np.sign(calculator_ref.magnetizability),
            np.sign(calculator_res.magnetizability),
        )
        diff = calculator_ref.magnetizability - calculator_res.magnetizability
        abs_diff = np.abs(diff)
        print(abs_diff)
        assert np.all(abs_diff < thresh)

    return