Esempio n. 1
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()
Esempio n. 2
0
def interactive_conveyor_belt(conveyorBelt=None, numsys:int=8, nbins:int=100, steps:int=100):
    
    #if none given build cvb
    if(isinstance(conveyorBelt, type(None))):
        import ensembler.potentials.OneD as pot
        import ensembler.system.perturbed_system as system
        import ensembler.ensemble.replicas_dynamic_parameters as cvb
        import ensembler.integrator as integ

        integrat = integ.stochastic.metropolisMonteCarloIntegrator()
        potential = pot.linearCoupledPotentials(Va=pot.harmonicOscillator(k=1.0), Vb=pot.harmonicOscillator(k=2.0))
        syst = system.perturbedSystem(potential=potential , integrator=integrat)
        conveyorBelt=cvb.ConveyorBelt(0.0, 8, system=syst, build=False)
        conveyorBelt.simulate(steps)

    (cvb_traj, systrajs) = conveyorBelt.get_trajs()

    if(len(cvb_traj)==0):
        raise IOError("Could not find any conveyor belt simulation in conveyorbelt traj. Please simulate first.")

    bins=np.zeros(nbins)
    dhdlbins=np.zeros(nbins)
    for i in systrajs:
        for j in range(systrajs[i].shape[0]):
            index=int(np.floor(systrajs[i].lam[j]*nbins))
            if index == nbins:
                index=nbins-1
            bins[index]+=1
            dhdlbins[index]+=systrajs[i].dhdlam[j]
    dhdlbins/=bins
    ene = np.cumsum(dhdlbins)/nbins

    lam = np.linspace(0, 1, nbins)
    nReps=conveyorBelt.nReplicas
    
    def redraw(CapLam, M):
        plotEnsembler(lam, ene, CapLam=np.deg2rad(CapLam), M=M)
        

    #build layout and components
 
    
    player = ipywidgets.Play(value=0, min=0, max=360, step=1,
                            description="rotate")
    capLam_slider = ipywidgets.IntSlider(value=0, min=0, max=360, step=1, 
                                         orientation='vertical',
                                         description="Capital Lambda", 
                                         continous_update=True)
    nReplicas_slider = ipywidgets.IntSlider(value=8, min=2, max=20, step=1, 
                                            orientation='vertical',
                                            description="number of Replicas")

    ipywidgets.jslink((capLam_slider, 'value'), (player, 'value'))

    interactive_plot = ipywidgets.interactive_output(redraw, 
                                   {'CapLam':capLam_slider, 
                                   'M':nReplicas_slider})

    controls = ipywidgets.VBox([player, ipywidgets.HBox([capLam_slider, nReplicas_slider])])
    
    app = ipywidgets.AppLayout(header=None,
          left_sidebar=controls,
          center=interactive_plot,
          right_sidebar=None,
          footer=None,
          align_items="center")
          
    
    display(app)
    return app