示例#1
0
    def test_check_positions_1DNPosSameState_IterableIterable_multiPos(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.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.")
示例#2
0
    def test_check_positions_2DIterable(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

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

        #print(checked)
        np.testing.assert_equal(checked, expected, "not the same sorry.")
示例#3
0
    def test_check_positions_1D1Pos_float_singlePos(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

        position = 4
        expected = np.array([[4], [4]])
        checked = potential._check_positions_type_singlePos(position=position)

        #print(checked)
        np.testing.assert_equal(checked, expected, "not the same sorry.")
示例#4
0
    def test_check_positionsNDPoscorrectType_singlePos(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

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

        #print(checked)
        np.testing.assert_equal(checked, expected, "not the same sorry.")
示例#5
0
    def test_check_positionsND1Pos_multPos(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)
        potential = pot.envelopedPotential(V_is=[ha, hb])

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

        #print(checked)
        np.testing.assert_equal(checked, expected, "not the same sorry.")
示例#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_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)
示例#8
0
    def test_energies1D1Pos_multipos(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)
        s = (1, 1)
        positions = [5, -5, 0]
        expected_result = np.array(61.80685281944005)
        potential = pot.envelopedPotentialMultiS(V_is=[ha, hb], s=s)

        energies = potential.ene(positions)

        #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)
示例#9
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)
示例#10
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)
示例#11
0
    def test_dHdpos2D(self):
        x_range = [0, 1]
        y_max = 10
        y_min = 0
        positions = [(0, 0), (1, 2), (1, 10)]
        potential = pot.flat_well(x_range=x_range, y_max=y_max, y_min=y_min)
        expected_result = np.array([(0, 0), (0, 0), (0, 0)])

        energies = potential.dhdpos(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=list(expected_result),
                                       actual=list(energies),
                                       err_msg="The results of " +
                                       potential.name + " are not correct!",
                                       decimal=8)
示例#12
0
    def test_energies2D(self):
        fc = 1.0
        x_shift = 0.0
        y_shift = 0.0
        positions = [(0, 1), (1, 2), (3, 4)]
        expected_result = np.array([0.5, 2.5, 12.5])

        potential = pot.harmonicOsc(fc=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"
        )
        np.testing.assert_almost_equal(desired=list(expected_result),
                                       actual=list(energies),
                                       err_msg="The results of " +
                                       potential.name + " are not correct!",
                                       decimal=8)
示例#13
0
    def test_energiesND1Pos(self):
        fc = 1.0
        x_shift = 0.0
        y_shift = 0.0
        positions = [0, 1, 2, 0.5]
        expected_result = np.array(2.625, ndmin=1)

        potential = pot.harmonicOsc(fc=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"
        )
        np.testing.assert_almost_equal(desired=expected_result,
                                       actual=energies,
                                       err_msg="The results of " +
                                       potential.name + " are not correct!",
                                       decimal=8)
示例#14
0
    def test_energies2D(self):
        x_range = [0, 1]
        y_max = 10
        y_min = 0
        positions = [(-1, -1), (1, 0.5), (1, 10)]
        expected_result = np.array([(10, 10), (0, 0), (0, 10)])

        potential = pot.flat_well(x_range=x_range, y_max=y_max, y_min=y_min)

        energies = potential.ene(positions)
        #print("HA",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)
示例#15
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)
示例#16
0
    def test_constructor(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)
        s = (1, 1)

        potential = pot.envelopedPotentialMultiS(V_is=[ha, hb], s=s)
示例#17
0
 def test_constructor(self):
     potential = pot.harmonicOsc()
示例#18
0
    def __init__(self, nstates=2, s=100, Eoff=None):
        self.nstates=2
        self.s=s
        
        if(isinstance(Eoff, type(None))):
            self.Eoffs=[0 for state in range(self.nstates)]
        else:
            self.Eoffs=Eoff
            
        self.V_is=[pot.harmonicOscillator(x_shift=state*4, k=10) for state in range(self.nstates)]
        self.eds_pot = potN.envelopedPotential(V_is=self.V_is, s=self.s, Eoff_i=self.Eoffs)

        ##Parameters
        self.positions_state = np.arange(-4, 4*self.nstates, 0.5)
        self.positions = np.arange(-4, 4*self.nstates, 0.5) #[x for x in  self.positions_state]

        energies = [V.ene(self.positions_state) for V in self.V_is]
        eds_enes = self.eds_pot.ene(self.positions)
        
        #plot
        self.fig= plt.figure()#dpi=300)
        ax = self.fig.add_subplot()
        ax.set_ylim([-50, 50])
        ax.set_xlim([-4,(4*self.nstates)])
        ax.set_xlabel("x")
        ax.set_ylabel("V")

        ##init plots
        ax.plot(self.positions, energies[0], "C1",alpha=0.8, lw=5)
        ax.plot(self.positions, energies[1], "C2",alpha=0.8, lw=5)
        self.eds_line = ax.plot(self.positions, eds_enes, "C3",lw=2,zorder=100)[0]
        
        self.ax = ax
        
        #sliders
        ##states
        state_label = ipywidgets.Label("Number of States")
        state_slider = ipywidgets.IntSlider(value=2, min=2, max=10, step=1, 
                                             orientation='horizontal')
        state_slider.observe(self.redraw_states, names="value")

        ##svals

        s_slider = ipywidgets.FloatSlider(value=100, min=0.1, max=101, step=1, 
                                             orientation='horizontal', 
                                             continous_update=True)
        self.s_label = ipywidgets.Label("smoothing Parameter:  "+str(np.log10(1+(s_slider.value**1.5/1000))))
        s_slider.observe(self.redraw_s, names="value")

        player = ipywidgets.Play(value=100, min=0.1, max=100, step=1,
                                description="s_values")
        
        ipywidgets.jslink((s_slider, 'value'), (player, 'value'))

        ##eoffs
        eoff_sliders = self.make_eoff_sliders(self.nstates)
        
        #listeners

        #layout
        state_slider = ipywidgets.HBox([state_label, state_slider])
        s_box = ipywidgets.HBox([self.s_label, player,s_slider])
        self.eoff_sliders_box = ipywidgets.HBox(eoff_sliders)
        controls = ipywidgets.VBox([state_slider, s_box, self.eoff_sliders_box])
        self.redraw_s({"new": 100})
        display(controls)
        self.fig.show()
示例#19
0
 def test_constructor(self):
     pot.flat_well()
示例#20
0
    def test_constructor(self):
        ha = pot.harmonicOsc(x_shift=-5)
        hb = pot.harmonicOsc(x_shift=5)

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