def setUp(self): boxv = np.array([10.] * 3) natoms = 30 rcut = 2. self.x0 = np.array([ 1.39757936, 1.83281398, 2.32259516, 1.60560537, 3.11214842, 2.61582972, 4.76275273, 3.37651599, 4.66292907, 6.12541448, 3.75706966, 0.54669172, 4.55566734, 7.41983351, 3.0333311 , 3.5405557 , 0.71801575, 1.71847253, 2.17861941, 5.70588003, 6.74642534, 3.43588101, 2.0687562 , 5.55499349, 3.27452166, 3.96526201, 6.61476763, 0.64229015, 1.27522777, 1.21875002, 0.99191894, 4.41664435, 1.97658992, 6.41180268, 2.15398194, 4.2636531 , 6.95210635, 2.75332174, 7.29174054, 6.53110874, 4.64505199, 6.90914585, 2.9151178 , 6.28565612, 7.95207857, 6.06415512, 4.92514773, 2.53285987, 3.72928997, 0.53255714, 6.51884144, 1.2042502 , 7.34367396, 4.25806453, 2.06642627, 4.83650925, 1.29926411, 3.12454566, 2.71078146, 2.99731328]) # use a random configuration that is quenched slightly so the energy is not crazy x = np.random.uniform(0, boxv[0], natoms*3) self.pot_true = _lj_cpp.LJCut(boxvec=boxv, rcut=rcut) self.pot = _lj_cpp.LJCutCellLists(boxvec=boxv, rcut=rcut, ncellx_scale=1.) from pele.optimize import lbfgs_cpp ret = lbfgs_cpp(x, self.pot_true, tol=10.) self.x0 = ret.coords # print repr(self.x0) self.e0 = self.pot_true.getEnergy(self.x0) print("true energy", self.e0) self.ae_kwargs = dict(places=6) self.rcut = rcut self.boxvec = boxv
def test_quench(self): ret = lbfgs_cpp(self.x0, self.pot) eblj = self.blj.getEnergy(ret.coords) self.assertAlmostEqual(eblj, ret.energy, places=6) # ensure the frozen atoms have not moved frozen_dof = self.pot.frozen1d self.compare_arrays(self.x0[frozen_dof], ret.coords[frozen_dof])
def get_minimizer(self, **kwargs): """return a function to minimize the structure Notes The function should be one of the optimizers in `pele.optimize`, or have similar structure. See Also -------- pele.optimize """ pot = self.get_potential() kwargs = dict_copy_update(self.params["structural_quench_params"], kwargs) return lambda coords: lbfgs_cpp(coords, pot, **kwargs)
np.random.seed(0) x = x0_cpp.copy().ravel() natoms = x.size / 3 density = 1.2 L = (natoms * (4. / 3 * np.pi) / density)**(1. / 3) print "box length", L boxvec = np.array([L] * 3) rcut = 2. pot = LJCutCellLists(boxvec=boxvec, rcut=rcut, ncellx_scale=1.) #x = np.random.uniform(0, boxvec[0], natoms*3) if False: res = lbfgs_cpp(x, pot, tol=100) x = res.coords print "coords" np.set_printoptions(threshold=np.nan, precision=16, linewidth=100) print repr(res.coords.reshape(-1, 3)) raise Exception("stopping early") print "initial energy", pot.getEnergy(x) lbfgs_cpp(x, pot, iprint=100) #for i in xrange(1): # print "displacement", i # x += np.random.uniform(-.2, .2, x.size) # lbfgs_cpp(x, pot, iprint=50)
def get_minimizer(self, **kwargs): """return a function to minimize the structure""" pot = self.get_potential() kwargs = dict_copy_update(self.params["structural_quench_params"], kwargs) return lambda coords: lbfgs_cpp(coords, pot, **kwargs)
def minimize(coords, pot): result = lbfgs_cpp(coords, pot) return result.coords, result.energy, result.grad, result.rms
x = x0_cpp.copy().ravel() natoms = x.size / 3 density = 1.2 L = (natoms * (4./3*np.pi) / density)**(1./3) print "box length", L boxvec = np.array([L]*3) rcut = 2. pot = LJCutCellLists(boxvec=boxvec, rcut=rcut, ncellx_scale=1.) #x = np.random.uniform(0, boxvec[0], natoms*3) if False: res = lbfgs_cpp(x, pot, tol=100) x = res.coords print "coords" np.set_printoptions(threshold=np.nan, precision=16, linewidth=100) print repr(res.coords.reshape(-1,3)) raise Exception("stopping early") print "initial energy", pot.getEnergy(x) lbfgs_cpp(x, pot, iprint=100) #for i in xrange(1): # print "displacement", i # x += np.random.uniform(-.2, .2, x.size) # lbfgs_cpp(x, pot, iprint=50)