本文整理汇总了Python中pele.optimize.LBFGS_CPP.get_result方法的典型用法代码示例。如果您正苦于以下问题:Python LBFGS_CPP.get_result方法的具体用法?Python LBFGS_CPP.get_result怎么用?Python LBFGS_CPP.get_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pele.optimize.LBFGS_CPP
的用法示例。
在下文中一共展示了LBFGS_CPP.get_result方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pele.optimize import LBFGS_CPP [as 别名]
# 或者: from pele.optimize.LBFGS_CPP import get_result [as 别名]
def __init__(self, boxdim=2, nr_particles=100, hard_phi=0.4,
nr_steps=1e6, epsilon=1, alpha=0.1, verbose=False):
# Settings.
np.random.seed(42)
# Input parameters.
self.boxdim = boxdim
self.nr_particles = nr_particles
self.hard_phi = hard_phi
self.nr_steps = nr_steps
self.epsilon = epsilon
self.alpha = alpha
self.verbose = verbose
# Derived quantities.
self.hard_radii = np.ones(self.nr_particles)
def volume_nball(radius, n):
return np.power(np.pi, n / 2) * np.power(radius, n) / gamma(n / 2 + 1)
self.box_length = np.power(np.sum(np.asarray([volume_nball(r, self.boxdim) for r in self.hard_radii])) / self.hard_phi, 1 / self.boxdim)
self.box_vector = np.ones(self.boxdim) * self.box_length
# HS-WCA potential.
self.potential = HS_WCA(use_periodic=True, use_cell_lists=True,
ndim=self.boxdim, eps=self.epsilon,
sca=self.alpha, radii=self.hard_radii,
boxvec=self.box_vector)
# Initial configuration by minimization.
self.nr_dof = self.boxdim * self.nr_particles
self.x = np.random.uniform(-0.5 * self.box_length, 0.5 * self.box_length, self.nr_dof)
optimizer = LBFGS_CPP(self.x, self.potential)
optimizer.run()
if not optimizer.get_result().success:
print ("warning: minimization has not converged")
self.x = optimizer.get_result().coords.copy()
# Potential and MC rules.
self.temperature = 1
self.mc = MC(self.potential, self.x, self.temperature, self.nr_steps)
self.step = RandomCoordsDisplacement(42, 1, single=True, nparticles=self.nr_particles, bdim=self.boxdim)
if self.verbose:
print ("initial MC stepsize")
print self.step.get_stepsize()
self.mc.set_takestep(self.step)
self.eq_steps = self.nr_steps / 2
self.mc.set_report_steps(self.eq_steps)
self.gr_quench = RecordPairDistHistogram(self.box_vector, 50, self.eq_steps, self.nr_particles, optimizer=optimizer)
self.gr = RecordPairDistHistogram(self.box_vector, 50, self.eq_steps, self.nr_particles)
self.mc.add_action(self.gr_quench)
self.mc.add_action(self.gr)
self.test = MetropolisTest(44)
self.mc.add_accept_test(self.test)
示例2: MinimizeUniformHardsSpheres
# 需要导入模块: from pele.optimize import LBFGS_CPP [as 别名]
# 或者: from pele.optimize.LBFGS_CPP import get_result [as 别名]
class MinimizeUniformHardsSpheres(object):
def __init__(self, nr_particles=42, hard_volume_fraction=0.5, epsilon=1, alpha=0.2):
np.random.seed(42)
self.nr_particles = nr_particles
self.hard_volume_fraction = hard_volume_fraction
self.epsilon = epsilon
self.alpha = alpha
self.hard_radii = np.random.normal(loc=1, scale=0.1, size=self.nr_particles)
self.box_length = np.power(np.sum(np.asarray([4 * np.pi * r**3 / 3 for r in self.hard_radii])) / self.hard_volume_fraction, 1/3)
self.nr_dof = 3 * self.nr_particles
self.x = np.random.uniform(-0.5 * self.box_length, 0.5 * self.box_length, self.nr_dof)
self.box_vector = np.ones(3) * self.box_length
self.rcut = 2 * (1 + alpha) * np.amax(self.hard_radii)
self.potential = HS_WCA(use_periodic=True, use_cell_lists=False, eps=self.epsilon, sca=self.alpha, radii=self.hard_radii, boxvec=self.box_vector, rcut=self.rcut)
self.optimizer = LBFGS_CPP(self.x, self.potential)
print "energy before:", self.potential.getEnergy(self.x)
self.optimizer.run()
print "minimization converged", self.optimizer.get_result().success
print "energy after:", self.potential.getEnergy(self.optimizer.get_result().coords)
示例3: test_reset
# 需要导入模块: from pele.optimize import LBFGS_CPP [as 别名]
# 或者: from pele.optimize.LBFGS_CPP import get_result [as 别名]
def test_reset(self):
lbfgs1 = LBFGS_CPP(self.x0, self.pot)
lbfgs1.run()
res1 = lbfgs1.get_result()
x2 = self.x0.copy()
x2[1] = 2.
lbfgs2 = LBFGS_CPP(x2, self.pot)
H0 = lbfgs2.get_result()["H0"]
lbfgs2.run()
lbfgs2.reset(self.x0)
lbfgs2.set_H0(H0)
lbfgs2.run()
res2 = lbfgs2.get_result()
self.assertEqual(res1.rms, res2.rms)
self.assertEqual(res1.H0, res2.H0)
self.assertEqual(res1.nfev, res2.nfev)
self.assertEqual(res1.nsteps, res2.nsteps)
self.assertTrue(np.all(res1.coords == res2.coords))
示例4: Config2D
# 需要导入模块: from pele.optimize import LBFGS_CPP [as 别名]
# 或者: from pele.optimize.LBFGS_CPP import get_result [as 别名]
class Config2D(object):
def __init__(self, nparticles_x, amplitude):
self.ndim = 2
self.LX = nparticles_x
self.LY = self.LX
self.nparticles_x = nparticles_x
self.N = self.nparticles_x ** self.ndim
self.dof = self.ndim * self.N
self.amplitude = amplitude
self.x = np.zeros(self.dof)
for particle in xrange(self.N):
pid = self.ndim * particle
self.x[pid] = particle % self.LX
self.x[pid + 1] = int(particle / self.LX)
self.x_initial = np.asarray([xi + np.random.uniform(- self.amplitude, self.amplitude) for xi in self.x])
self.x_initial = np.reshape(self.x_initial, (self.N,2))
self.x_initial[:,0] -= np.mean(self.x_initial[:,0])
self.x_initial[:,1] -= np.mean(self.x_initial[:,1])
self.x_initial = self.x_initial.flatten()
#self.radius = 0.3
#self.sca = 1.5
self.radius = 0.25
self.sca = 1.8
self.radii = np.ones(self.N) * self.radius
self.eps = 1.0
self.boxvec = np.array([self.LX, self.LY])
self.potential = HS_WCA(use_periodic=use_periodic, eps=self.eps,
sca=self.sca, radii=self.radii.copy(), ndim=self.ndim, boxvec=self.boxvec.copy())
self.potential_ = HS_WCA(use_periodic=use_periodic, eps=self.eps,
sca=self.sca, radii=self.radii.copy(), ndim=self.ndim, boxvec=self.boxvec.copy())
self.rcut = 2 * (1 + self.sca) * self.radius
self.ncellx_scale = 1
self.potential_cells = HS_WCA(use_periodic=use_periodic,
use_cell_lists=True, eps=self.eps,
sca=self.sca, radii=self.radii.copy(),
boxvec=self.boxvec.copy(),
rcut=self.rcut, ndim=self.ndim,
ncellx_scale=self.ncellx_scale)
self.potential_cells_ = HS_WCA(use_periodic=use_periodic,
use_cell_lists=True, eps=self.eps,
sca=self.sca, radii=self.radii.copy(),
boxvec=self.boxvec.copy(),
rcut=self.rcut, ndim=self.ndim,
ncellx_scale=self.ncellx_scale)
self.tol = 1e-7
self.maxstep = np.amax(self.radii)
self.nstepsmax = int(1e6)
assert(self.boxvec[0]==self.boxvec[1])
print "x_initial energy:", self.potential.getEnergy(self.x_initial)
print "x_initial cells energy:", self.potential_cells.getEnergy(self.x_initial)
assert(self.potential.getEnergy(self.x_initial) == self.potential_.getEnergy(self.x_initial))
assert(self.potential_cells.getEnergy(self.x_initial) == self.potential_cells_.getEnergy(self.x_initial))
#assert abs(self.potential.getEnergy(self.x_initial) - self.potential_cells.getEnergy(self.x_initial)) < 1e-10
assert np.allclose(self.potential.getEnergy(self.x_initial), self.potential_cells.getEnergy(self.x_initial), rtol=1e-10)
print self.boxvec
#plot_disks(self.x_initial, self.radii, self.boxvec, sca=self.sca)
def optimize(self, nr_samples = 1):
self.optimizer = ModifiedFireCPP(self.x_initial.copy(), self.potential,
dtmax=1, maxstep=self.maxstep,
tol=self.tol, nsteps=1e8, verbosity=-1, iprint=-1)
self.optimizer_ = LBFGS_CPP(self.x_initial.copy(), self.potential_)
self.optimizer_cells = ModifiedFireCPP(self.x_initial.copy(), self.potential_cells,
dtmax=1, maxstep=self.maxstep,
tol=self.tol, nsteps=1e8, verbosity=-1, iprint=-1)
self.optimizer_cells_ = LBFGS_CPP(self.x_initial.copy(), self.potential_cells_)
print "initial E, x:", self.potential.getEnergy(self.x_initial.copy())
print "initial E, x_:", self.potential_cells.getEnergy(self.x_initial.copy())
t0 = time.time()
print "self.optimizer.run(self.nstepsmax)", self.nstepsmax
self.optimizer.run(self.nstepsmax)
self.res_x_final = self.optimizer.get_result()
t1 = time.time()
self.optimizer_cells.run(self.nstepsmax)
self.res_x_final_cells = self.optimizer_cells.get_result()
t2 = time.time()
self.x_final = self.res_x_final.coords
self.x_final_cells = self.res_x_final_cells.coords
print "fire final E, x:", self.optimizer.get_result().energy
print "fire final E, x_cells:", self.optimizer_cells.get_result().energy
print "fire final E, plain: ", self.potential.getEnergy(self.x_final)
print "fire final E, cell: ", self.potential_cells.getEnergy(self.x_final_cells)
print "fire number of particles:", self.N
print "fire time no cell lists:", t1 - t0, "sec"
print "fire time cell lists:", t2 - t1, "sec"
print "fire ratio:", (t1 - t0) / (t2 - t1)
if not self.res_x_final.success or not self.res_x_final_cells.success:
print "-------------"
print "res_x_final.rms:", self.res_x_final.rms
print "res_x_final.nfev:", self.res_x_final.nfev
print "res_x_final_cells.rms:", self.res_x_final_cells.rms
print "res_x_final_cells.nfev:", self.res_x_final_cells.nfev
print "self.res_x_final.success", self.res_x_final.success
print "self.res_x_final_cells.success", self.res_x_final_cells.success
print "-------------"
plot_disks(self.x_initial, self.radii, self.boxvec, sca=self.sca)
plot_disks(self.x_final, self.radii, self.boxvec, sca=self.sca)
#.........这里部分代码省略.........
示例5: Config2DFrozenBoundary
# 需要导入模块: from pele.optimize import LBFGS_CPP [as 别名]
# 或者: from pele.optimize.LBFGS_CPP import get_result [as 别名]
class Config2DFrozenBoundary(object):
def __init__(self, nparticles_x, amplitude):
self.ndim = 2
self.LX = nparticles_x
self.LY = self.LX
self.nparticles_x = nparticles_x
self.N = self.nparticles_x ** self.ndim
self.amplitude = amplitude
self.dof = self.ndim * self.N
self.x = np.zeros(self.dof)
self.frozen_atoms = []
for particle in xrange(self.N):
pid = self.ndim * particle
xcoor = particle % self.LX
ycoor = int(particle / self.LX)
self.x[pid] = xcoor
self.x[pid + 1] = ycoor
if xcoor == 0 or xcoor == self.LX - 1 or ycoor == 0 or ycoor == self.LY - 1:
self.frozen_atoms.append(particle)
self.x_initial = copy.copy(self.x)
for particle in xrange(self.N):
if particle not in self.frozen_atoms:
pid = self.ndim * particle
self.x_initial[pid] += np.random.uniform(- self.amplitude, self.amplitude)
self.x_initial[pid + 1] += np.random.uniform(- self.amplitude, self.amplitude)
self.x_initial = np.reshape(self.x_initial, (self.N,2))
self.x_initial[:,0] -= np.mean(self.x_initial[:,0])
self.x_initial[:,1] -= np.mean(self.x_initial[:,1])
self.x_initial = self.x_initial.flatten()
min_x = np.amin(self.x_initial)
if min_x < 0:
self.x_initial -= min_x
#self.radius = 0.3
#self.sca = 1.5
self.radius = 0.25
self.sca = 1.8
self.radii = np.ones(self.N) * self.radius
self.eps = 1.0
max_edge = np.amax([np.amax(self.x_initial), np.abs(np.amin(self.x_initial))]) + 2 * self.amplitude + (1 + self.sca) * self.radius
self.boxvec = np.array([max_edge, max_edge])
self.frozen_atoms1 = np.array(self.frozen_atoms)
self.frozen_atoms2 = np.array(self.frozen_atoms)
print "self.frozen_atoms1", self.frozen_atoms1
self.potential = HS_WCA(use_frozen=True, use_periodic=use_periodic_frozen,
reference_coords=self.x_initial,
frozen_atoms=self.frozen_atoms1,
eps=self.eps, sca=self.sca, radii=self.radii,
ndim=self.ndim, boxvec=self.boxvec)
self.rcut = 2 * (1 + self.sca) * self.radius
self.ncellx_scale = 1.0
self.potential_cells = HS_WCA(use_frozen=True,
use_periodic=use_periodic_frozen, use_cell_lists=True,
eps=self.eps, sca=self.sca,
radii=self.radii, boxvec=self.boxvec,
reference_coords=self.x_initial,
rcut=self.rcut, ndim=self.ndim,
ncellx_scale=self.ncellx_scale,
frozen_atoms=self.frozen_atoms2)
self.tol = 1e-7
self.maxstep = np.amax(self.radii)
self.nstepsmax = int(1e6)
assert(self.boxvec[0]==self.boxvec[1])
self.x_initial_red = reduce_coordinates(self.x_initial,self.frozen_atoms,self.ndim)
print "x_initial energy:", self.potential.getEnergy(self.x_initial_red)
print "x_initial cells energy:", self.potential_cells.getEnergy(self.x_initial_red)
#assert abs(self.potential.getEnergy(self.x_initial_red) - self.potential_cells.getEnergy(self.x_initial_red)) < 1e-10
assert np.allclose(self.potential.getEnergy(self.x_initial_red), self.potential_cells.getEnergy(self.x_initial_red), rtol=1e-10)
print self.boxvec
def optimize(self, nr_samples=1):
self.x_initial_red = reduce_coordinates(self.x_initial,self.frozen_atoms,self.ndim)
self.optimizer = ModifiedFireCPP(self.x_initial_red.copy(), self.potential, tol = self.tol, maxstep = self.maxstep)
self.optimizer_ = LBFGS_CPP(self.x_initial_red.copy(), self.potential)
self.optimizer_cells = ModifiedFireCPP(self.x_initial_red.copy(), self.potential_cells, tol = self.tol, maxstep = self.maxstep)
self.optimizer_cells_ = LBFGS_CPP(self.x_initial_red.copy(), self.potential_cells)
t0 = time.time()
print "self.optimizer.run(self.nstepsmax)", self.nstepsmax
self.optimizer.run(self.nstepsmax)
self.res_x_final = self.optimizer.get_result()
t1 = time.time()
self.optimizer_cells.run(self.nstepsmax)
self.res_x_final_cells = self.optimizer_cells.get_result()
t2 = time.time()
self.x_final = self.res_x_final.coords
self.x_final_cells = self.res_x_final_cells.coords
print "fire final E, x:", self.optimizer.get_result().energy
print "fire final E, x_cells:", self.optimizer_cells.get_result().energy
print "fire final E, plain: ", self.potential.getEnergy(self.x_final)
print "fire final E, cell: ", self.potential_cells.getEnergy(self.x_final_cells)
print "fire number of particles:", self.N
print "fire time no cell lists:", t1 - t0, "sec"
print "fire time cell lists:", t2 - t1, "sec"
print "fire ratio:", (t1 - t0) / (t2 - t1)
if not self.res_x_final.success or not self.res_x_final_cells.success:
print "-------------"
print "res_x_final.rms:", self.res_x_final.rms
print "res_x_final.nfev:", self.res_x_final.nfev
print "res_x_final_cells.rms:", self.res_x_final_cells.rms
#.........这里部分代码省略.........