def __init__(self, capital_lambda:float, nReplicas:int, system=perturbed_system.perturbedSystem(temperature=300.0, lam=0.0, potential=pot.OneD.linearCoupledPotentials(), integrator=stochastic.metropolisMonteCarloIntegrator()), build=False): ''' initialize Ensemble object :param capital_lambda: state of ensemble, 0 <= capital_lambda < pi :param num: number of replicas :param system: a system1D instance :param build: build memory?whconda ''' assert 0.0 <= capital_lambda <= 2 * np.pi, "capital_lambda not allowed" assert nReplicas >= 1, "At least one system is needed" self.nReplicas = nReplicas self.system = system self.capital_lambda = capital_lambda self.build = build #build self.dis = 2.0 * np.pi / nReplicas self.exchange_dimensions = {self._parameter_name: np.arange(0, 2*np.pi, self.dis )} self._temperature_exchange = system.temperature self.initialise() self.exchange_information: pd.DataFrame = pd.DataFrame(columns=["Step", "capital_lambda","TotE", "biasE", "doAccept"]) self.system_trajs: dict = {}
def testTraj(self): integrator = metropolisMonteCarloIntegrator() ha = OneD.harmonicOscillatorPotential(x_shift=-5) hb = OneD.harmonicOscillatorPotential(x_shift=5) pot = OneD.linearCoupledPotentials(Va=ha, Vb=hb) sys = perturbedSystem(temperature=300.0, potential=pot, sampler=integrator) lam = 0.5 sys.lam = lam ens = self.convBelt(0.0, 1, system=sys)
def __init__(self, capital_lambda: float, n_replicas: int, system:systemCls = perturbed_system.perturbedSystem( temperature=300.0, lam=0.0, potential=pot.OneD.linearCoupledPotentials( Va=pot.OneD.harmonicOscillatorPotential(k=1, x_shift=0), Vb=pot.OneD.harmonicOscillatorPotential(k=2, x_shift=0) ), sampler=stochastic.metropolisMonteCarloIntegrator() ), build: bool = False): """ initialize Ensemble object Parameters ---------- capital_lambda: float state of ensemble, 0 <= capital_lambda < pi n_replicas: int number of replicas system: systemCls, optional a system1D instance build:bool, optional build memory? """ assert 0.0 <= capital_lambda <= 2 * np.pi, "capital_lambda not allowed" assert n_replicas >= 1, "At least one system is needed" super().__init__() self.system = system self.capital_lambda = capital_lambda self.build = build # build self.dis = 2.0 * np.pi / n_replicas self.exchange_dimensions = { self._parameter_name: [ self.calculate_replica_lambda(self.capital_lambda, i) for i in range(n_replicas) ] } self._temperature_exchange = system.temperature self.initialise() self.system_trajs: dict = {}
def test_run_step(self): integrator = metropolisMonteCarloIntegrator() ha = OneD.harmonicOscillatorPotential(x_shift=-5) hb = OneD.harmonicOscillatorPotential(x_shift=5) pot = OneD.linearCoupledPotentials(Va=ha, Vb=hb) sys = perturbedSystem(temperature=300.0, potential=pot, sampler=integrator) ens = self.convBelt(0.0, 1, system=sys) ens.calculate_total_ensemble_energy() ens.run() ens.calculate_total_ensemble_energy() ens.get_replicas_positions()
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