Ejemplo n.º 1
0
 def setUp(self):
     self.natoms = 4
     self.k = 1
     self.Emax = 2  #this choice is fundamentally arbitrary, it's only used to generate the initial configuration
     #self.temperatures = [0.2,0.27,0.362,0.487,0.65,0.88,1.18,1.6]
     self.temperatures = [0.2, 0.362, 0.65, 1.18]
     self.stepsize = 1
     self.niter = 2e6
     self.adjustf = 0.9
     self.adjust_niter = 0.3 * self.niter
     self.radius = 1e10
     self.tolerance = 2e-1
     self.bdim = 3
     self.ndim = self.natoms * self.bdim
     self.origin = np.zeros(self.ndim)
     self.seeds = dict(takestep=42, metropolis=44)
     self.potential = Harmonic(self.origin,
                               self.k,
                               bdim=self.bdim,
                               com=False)
     self.mcrunner = Metropolis_MCrunner(self.potential,
                                         self.origin,
                                         1,
                                         self.stepsize,
                                         self.niter,
                                         hEmax=100,
                                         adjustf=self.adjustf,
                                         adjustf_niter=self.adjust_niter,
                                         radius=self.radius,
                                         bdim=self.bdim,
                                         single=False,
                                         seeds=self.seeds)
Ejemplo n.º 2
0
    def test_heat_capacity_2D(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin,
                                  self.k,
                                  bdim=self.bdim,
                                  com=False)

        print "2D"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(self.potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = self.natoms * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))
Ejemplo n.º 3
0
    def test_heat_capacity_2D_com(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=True)
        #self.start_coords = vector_random_uniform_hypersphere(self.ndim) * np.sqrt(2*self.Emax) #coordinates sampled from Pow(ndim)

        print "2D com"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = (self.natoms - 1) * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))
Ejemplo n.º 4
0
 def test_composite_moves(self):
     self.bdim = 2
     self.ndim = self.natoms * self.bdim
     self.origin = np.zeros(self.ndim)
     self.potential = Harmonic(self.origin,
                               self.k,
                               bdim=self.bdim,
                               com=False)
Ejemplo n.º 5
0
    res.nsteps = n
    res.nhev = function_evaluate_pot.nhev
    res.success = converged
    # res.nhev = function_evaluate_pot.nhev
    return res


# u0 = 0.5
# pot = potclass()
# tspan = (0, 1.0)
# print(pot.get_negative_grad(1, 1, 1))
# prob = de.ODEProblem(pot.get_negative_grad,u0, tspan)
# de.init(prob, de.Tsit5())

if __name__ == "__main__":
    pot = Harmonic(np.zeros(3), 2)
    res = ode_julia_naive([1.0, 1.0, 1.0], pot)
    print(res.nfev)
    print(res.coords)
    print(res.nfev)
    print(res.nhev)
    print(res.niter)

# def initialize_ode(get_negative_grad, x0):
#     tspan = (0, float('inf'))
#     prob = de.ODEProblem(get_negative_grad,x0, tspan)
#     return de.init(prob, de.Tsit5())

# def one_iteration(integrator):
#     de.step_b(integrator)
#     return (integrator.t, integrator.u, de.get_du(integrator))
Ejemplo n.º 6
0
if __name__ == "__main__":

    parser = argparse.ArgumentParser(
        description="do nested sampling on a Lennard Jones cluster")
    parser.add_argument("base_directory",
                        type=str,
                        help="directory in which to save results")
    #parser.add_argument("-K", "--nreplicas", type=int, help="number of replicas", default=300)
    args = parser.parse_args()

    natoms = 4
    bdim = 3
    k = 1
    origin = np.zeros(natoms * bdim)
    potential = Harmonic(origin, k, bdim=bdim, com=False)
    path = args.base_directory

    #Parallel Tempering
    temperature = 1.0
    stepsize = 1
    niter = 1e4
    mcrunner = Metropolis_MCrunner(potential,
                                   origin,
                                   temperature,
                                   stepsize,
                                   niter,
                                   hEmax=100,
                                   adjustf=0.9,
                                   adjustf_niter=3000,
                                   radius=100000,
Ejemplo n.º 7
0
from pele.potentials import Harmonic
import numpy as np

a = np.zeros(3)
b = np.ones(3)
pot = Harmonic(a, 2)

print(pot.getEnergyGradientHessian(b))