예제 #1
0
    def test_imul(self):
        ref = cache.refstate["h2o_sto3g"]
        a = OneParticleOperator(ref.mospaces, is_symmetric=False)
        a["o1o1"].set_random()
        a["v1o1"].set_random()
        a["o1v1"].set_random()
        a["v1v1"].set_random()

        ref = 12 * a.to_ndarray()
        a *= 12
        assert_array_almost_equal_nulp(a.to_ndarray(), ref)
예제 #2
0
    def test_isub(self):
        ref = cache.refstate["h2o_sto3g"]
        a = OneParticleOperator(ref.mospaces, is_symmetric=True)
        a["o1o1"].set_random()
        a["o1v1"].set_random()

        b = OneParticleOperator(ref.mospaces, is_symmetric=True)
        b["o1v1"].set_random()
        b["v1v1"].set_random()

        ref = a.to_ndarray() - b.to_ndarray()
        a -= b
        assert_array_almost_equal_nulp(a.to_ndarray(), ref)
예제 #3
0
    def test_add(self):
        ref = cache.refstate["h2o_sto3g"]
        a = OneParticleOperator(ref.mospaces, is_symmetric=False)
        a["o1o1"].set_random()
        a["v1o1"].set_random()
        a["v1v1"].set_random()

        b = OneParticleOperator(ref.mospaces, is_symmetric=True)
        b["o1o1"].set_random()
        b["v1v1"].set_random()

        assert_array_almost_equal_nulp((a + b).to_ndarray(),
                                       a.to_ndarray() + b.to_ndarray())
        assert_array_almost_equal_nulp((b + a).to_ndarray(),
                                       a.to_ndarray() + b.to_ndarray())
예제 #4
0
 def test_mul(self):
     ref = cache.refstate["h2o_sto3g"]
     a = OneParticleOperator(ref.mospaces, is_symmetric=True)
     a["o1o1"].set_random()
     a["o1v1"].set_random()
     assert_array_almost_equal_nulp((1.2 * a).to_ndarray(),
                                    1.2 * a.to_ndarray())
예제 #5
0
    def test_iadd(self):
        ref = cache.refstate["h2o_sto3g"]
        a = OneParticleOperator(ref.mospaces, is_symmetric=False)
        a.oo.set_random()
        a.vo.set_random()
        a.ov.set_random()
        a.vv.set_random()

        b = OneParticleOperator(ref.mospaces, is_symmetric=False)
        b.oo.set_random()
        b.ov.set_random()
        b.vv.set_random()

        ref = a.to_ndarray() + b.to_ndarray()
        a += b
        assert_array_almost_equal_nulp(a.to_ndarray(), ref)
예제 #6
0
 def test_rmul(self):
     ref = cache.refstate["h2o_sto3g"]
     a = OneParticleOperator(ref.mospaces, is_symmetric=False)
     a.oo.set_random()
     a.vo.set_random()
     a.ov.set_random()
     assert_array_almost_equal_nulp((a * -1.8).to_ndarray(),
                                    -1.8 * a.to_ndarray())
예제 #7
0
    def test_add_nosym(self):
        ref = cache.refstate["h2o_sto3g"]
        a = OneParticleOperator(ref.mospaces, is_symmetric=True)
        a.oo.set_random()
        a.ov.set_random()
        a.vv.set_random()

        b = OneParticleOperator(ref.mospaces, is_symmetric=False)
        b.oo.set_random()
        b.ov.set_random()
        b.vo.set_random()
        b.vv.set_random()

        assert_array_almost_equal_nulp((a + b).to_ndarray(),
                                       a.to_ndarray() + b.to_ndarray())
        assert_array_almost_equal_nulp((b + a).to_ndarray(),
                                       b.to_ndarray() + a.to_ndarray())
예제 #8
0
    def test_sub(self):
        ref = cache.refstate["h2o_sto3g"]
        a = OneParticleOperator(ref.mospaces, is_symmetric=True)
        a["o1o1"].set_random()
        a["o1v1"].set_random()
        a["v1v1"].set_random()

        b = OneParticleOperator(ref.mospaces, is_symmetric=True)
        b["o1o1"].set_random()
        b["o1v1"].set_random()
        b["v1v1"].set_random()

        assert_array_almost_equal_nulp((a - b).to_ndarray(),
                                       a.to_ndarray() - b.to_ndarray())
        assert_array_almost_equal_nulp((b - a).to_ndarray(),
                                       b.to_ndarray() - a.to_ndarray())
        assert_array_almost_equal_nulp((a - b).to_ndarray(),
                                       (a + (-1 * b)).to_ndarray())
        assert_array_almost_equal_nulp((b - a).to_ndarray(),
                                       (b + (-1 * a)).to_ndarray())
예제 #9
0
    def test_to_ndarray_nosym(self):
        ref = cache.refstate["h2o_sto3g"]
        dm = OneParticleOperator(ref.mospaces, is_symmetric=False)
        dm["o1o1"].set_random()
        dm["o1v1"].set_random()
        dm["v1o1"].set_random()
        dm["v1v1"].set_random()

        dm_oo = dm["o1o1"].to_ndarray()
        dm_ov = dm["o1v1"].to_ndarray()
        dm_vo = dm["v1o1"].to_ndarray()
        dm_vv = dm["v1v1"].to_ndarray()

        dm_o = np.hstack((dm_oo, dm_ov))
        dm_v = np.hstack((dm_vo, dm_vv))
        dm_full = np.vstack((dm_o, dm_v))

        assert_array_almost_equal_nulp(dm_full, dm.to_ndarray())