Пример #1
0
    def test_dhdpos1DNPos(self):
        ha = pot1.harmonicOsc(x_shift=-5)
        hb = pot1.harmonicOsc(x_shift=5)
        setattr(ha, "nDim", 1)
        setattr(hb, "nDim", 1)

        positions = [5, -5, 2, 0]
        expected_result = np.array(
            [[[10.], [0.], [10.]], [[0.], [0.], [0.]],
             [[7.], [1.0862069], [5.9137931]], [[5.], [2.5], [2.5]]],
            ndmin=2)

        potential = pot.envelopedPotential(V_is=[ha, hb])
        dhdpos = potential.dhdpos(positions)

        self.assertEqual(
            type(expected_result),
            type(dhdpos),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_almost_equal(desired=expected_result,
                                       actual=dhdpos,
                                       err_msg="The results of " +
                                       potential.name + " are not correct!",
                                       decimal=8)
Пример #2
0
    def test_dHdlam(self):
        ha = pot.harmonicOsc(k=1.0, x_shift=-5.0)
        hb = pot.harmonicOsc(k=1.0, x_shift=5.0)
        potential = pot.expCoupledHosc(ha=ha, hb=hb, lam=0)

        positions = np.linspace(-10, 10, num=5)

        # energies only for pot HA
        lam = 0
        potential.set_lam(lam=lam)
        expected_result = np.array([
            4.009080e-001, 4.009080e-001, 0.000, -5.846620e+053, -8.526387e+107
        ])

        energies = potential.dhdlam(positions)

        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_allclose(desired=expected_result,
                                   actual=energies,
                                   err_msg="The results of " + potential.name +
                                   " are not correct wit lambda " + str(lam) +
                                   "!\n\tPositions: " + str(positions) +
                                   "\n\tEnergies: " + str(energies))
Пример #3
0
    def test_check_positions_1DNPosSameState_Iterable_multiPos(self):
        ha = pot1.harmonicOsc(x_shift=-5)
        hb = pot1.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

        positions = np.array([4, 2, 3])
        expected = np.array([[[4], [4]], [[2], [2]], [[3], [3]]], ndmin=3)
        checked = potential._check_positions_type_multiPos(positions=positions)

        #print(checked)
        np.testing.assert_equal(checked, expected, "not the same sorry.")
Пример #4
0
    def test_energies_1DNPos(self):
        ha = pot1.harmonicOsc(x_shift=-5)
        hb = pot1.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

        positions = [0, 0.5, 1, 2]
        expected = np.array([11.80685282, 10.11828465, 7.9999546, 4.5])
        energies = potential.ene(positions)

        np.testing.assert_almost_equal(energies,
                                       expected,
                                       err_msg="not the same sorry.",
                                       decimal=5)
Пример #5
0
    def test_check_positions1DNPos(self):
        ha = pot1.harmonicOsc(x_shift=-5)
        hb = pot1.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

        positions = [0, 0.5, 1, 2]
        expected = np.array(
            [[[0], [0]], [[0.5], [0.5]], [[1], [1]], [[2], [2]]], ndmin=2)
        checked = potential._check_positions_type(positions=positions)

        #print(checked)
        np.testing.assert_equal(checked, expected, "not the same sorry.")

        energies = potential.ene(positions)
Пример #6
0
    def redraw_states(self,nstates_event):
        self.nstates = nstates_event["new"]
        
        #Plotting stuff

        for line in self.ax.lines:
            if(line != self.eds_line):
                self.ax.lines.remove(line)
            del line
        
        self.positions_state = np.arange(-4, 4*self.nstates, 0.5)
        self.positions = [[x] for x in  self.positions_state]

        V_is=[pot.harmonicOsc(x_shift=state*4, k=10) for state in range(self.nstates)]
        for state_e in [V.ene(self.positions_state) for V in V_is]:
            self.ax.plot(self.positions_state, state_e, alpha=0.8, lw=5)
        self.ax.set_xlim([-4,(4*self.nstates)])

        
        #pot
        self.Eoffs = self.eds_pot.Eoff_i
        if(len(self.Eoffs)<self.nstates):
            for x in range(len(self.Eoffs), self.nstates):
                self.Eoffs.append(0)
        elif(len(self.Eoffs)>self.nstates):
            self.Eoffs= self.Eoffs[:self.nstates]
        
        self.eoff_sliders_box.children=self.make_eoff_sliders(self.nstates)

        self.eds_pot = potN.envelopedPotential(V_is=V_is, s=np.log10(1+(self.s**1.5/1000)), Eoff_i=self.Eoffs)
        eds_enes = self.eds_pot.ene(self.positions)
        self.eds_line.set_data(self.positions, eds_enes)
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
Пример #7
0
    def test_energiesND1Pos_singlePos(self):
        ha = pot1.harmonicOsc(x_shift=-5)
        hb = pot1.harmonicOsc(x_shift=5)

        position = [5, -5]
        expected_result = 61.80685281944005

        potential = pot.envelopedPotential(V_is=[ha, hb])
        potential._set_singlePos_mode()
        energies = potential.ene(position)

        #print(energies)
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_almost_equal(desired=expected_result,
                                       actual=energies,
                                       err_msg="The results of " +
                                       potential.name + " are not correct!",
                                       decimal=8)
Пример #8
0
    def test_energies(self):
        fc = 1.0
        x_shift = 0.0
        y_shift = 0.0
        positions = [0, 2, 1, 0.5]
        expected_result = np.array([0, 2, 0.5, 0.125])

        potential = pot.harmonicOsc(k=fc, x_shift=x_shift, y_shift=y_shift)
        energies = potential.ene(positions)

        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        self.assertListEqual(list(expected_result),
                             list(energies),
                             msg="The results of " + potential.name +
                             " are not correct!")
Пример #9
0
    def test_dHdpos(self):
        ha = pot.harmonicOsc(k=1.0, x_shift=-5.0)
        hb = pot.harmonicOsc(k=1.0, x_shift=5.0)
        potential = pot.expCoupledHosc(ha=ha, hb=hb, lam=0)

        positions = np.linspace(-10, 10, num=5)

        #energies only for pot HA
        lam = 0
        potential.set_lam(lam=lam)
        expected_result = np.array([
            -1304235.5118838537, 0.0, 1.9168317203608185e-05,
            1.469697537672566e-10, 8.451488578640889e-16
        ])

        energies = potential.dhdpos(positions)
        ##print("GOT",  list(energies))
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        #np.testing.assert_almost_equal(desired=expected_result, actual=energies, err_msg="The results of "+potential.name+" are not correct wit lambda "+str(lam)+"!\n\tPositions: "+str(positions)+"\n\tEnergies: "+str(energies), decimal=2)

        #energies only for pot HB
        lam = 1
        expected_result = np.array([
            -2.6622529026263318e+17, -680412108183.5752, -1304235.5118838537,
            0.0, 1.9168317203608185e-05
        ])

        potential.set_lam(lam=lam)
        energies = potential.dhdpos(positions)

        ##print("GOT2",  list(energies))
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        #np.testing.assert_almost_equal(desired=expected_result, actual=energies, err_msg="The results of "+potential.name+" are not correct wit lambda "+str(lam)+"!\n\tPositions: "+str(positions)+"\n\tEnergies: "+str(energies), decimal=2)

        #energies merged for pot HB and HA
        lam = 0.5
        expected_result = np.array([
            -1.331126451319687e+17, -340206054091.7876, -652117.7559323427,
            7.34848768836283e-11, 9.584158602226667e-06
        ])

        potential.set_lam(lam=lam)
        energies = potential.dhdpos(positions)

        ##print("GOT3",  list(energies))
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_almost_equal(
            desired=expected_result,
            actual=energies,
            err_msg="The results of " + potential.name +
            " are not correct wit lambda " + str(lam) + "!\n\tPositions: " +
            str(positions) + "\n\tEnergies: " + str(energies),
            decimal=2)
Пример #10
0
    def test_energies(self):
        ha = pot.harmonicOsc(k=1.0, x_shift=-5.0)
        hb = pot.harmonicOsc(k=1.0, x_shift=5.0)
        potential = pot.expCoupledHosc(ha=ha, hb=hb, lam=0)

        positions = np.linspace(-10, 10, num=5)

        # energies only for pot HA
        lam = 0
        expected_result = np.array([12.5, 0, 12.5, 50, 112.5])

        potential.set_lam(lam=lam)
        energies = potential.ene(positions)
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_almost_equal(
            desired=expected_result,
            actual=energies,
            err_msg="The results of " + potential.name +
            " are not correct wit lambda " + str(lam) + "!\n\tPositions: " +
            str(positions) + "\n\tEnergies: " + str(energies),
            decimal=2)

        # energies only for pot HB
        lam = 1
        expected_result = np.array([112.5, 50, 12.5, 0, 12.5])

        potential.set_lam(lam=lam)
        energies = potential.ene(positions)
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_almost_equal(
            desired=expected_result,
            actual=energies,
            err_msg="The results of " + potential.name +
            " are not correct wit lambda " + str(lam) + "!\n\tPositions: " +
            str(positions) + "\n\tEnergies: " + str(energies),
            decimal=2)

        # energies merged for pot HB and HA
        lam = 0.5
        expected_result = np.array([12.78, 0.28, 12.5, 0.28, 12.78])

        potential.set_lam(lam=lam)
        energies = potential.ene(positions)
        self.assertEqual(
            type(expected_result),
            type(energies),
            msg=
            "returnType of potential was not correct! it should be an np.array"
        )
        np.testing.assert_almost_equal(
            desired=expected_result,
            actual=energies,
            err_msg="The results of " + potential.name +
            " are not correct wit lambda " + str(lam) + "!\n\tPositions: " +
            str(positions) + "\n\tEnergies: " + str(energies),
            decimal=2)
Пример #11
0
 def test_constructor(self):
     potential = pot.harmonicOsc()