def test(): np.random.seed(0) natoms = 20 radii = np.random.uniform(.9, 1.2, natoms) L = 3 boxvec = np.ones(3) * L x = np.random.uniform(0,L, 3*natoms) pot = MyPotFortran(boxvec, radii) pot.test_potential(x) e, g, hess = pot.getEnergyGradientHessian(x) hnum = pot.NumericalHessian(x) print hess print hnum print hess.shape, hnum.shape print hess[0,0] print hnum[0,0] x = x.reshape(-1,3) np.savetxt("coords", x, fmt="%.12f") np.savetxt("radii", radii, fmt="%.12f") print "energy", e from pele.utils.hessian import get_sorted_eig a, b = get_sorted_eig(hess) print a
def analyticalLowestEigenvalue(coords, pot): """return the lowest eigenvalue and eigenvector of the hessian computed directly""" from pele.utils.hessian import get_sorted_eig """for testing""" hess = pot.getHessian(coords) vals, vecs = get_sorted_eig(hess) return vals[0], vecs[:, 0]
def analyticalLowestEigenvalue(coords, pot): """return the lowest eigenvalue and eigenvector of the hessian computed directly""" from pele.utils.hessian import get_sorted_eig """for testing""" hess = pot.getHessian(coords) vals, vecs = get_sorted_eig(hess) return vals[0], vecs[:,0]
#system.params.structural_quench_params.debug = True #system.params.structural_quench_params.iprint = 100 db = system.create_database() bh = system.get_basinhopping(db) bh.run(1) m = db.minima()[0] coords = m.coords potential = system.get_potential() energy, gradient, hessian = potential.getEnergyGradientHessian(coords) dummy_vec = ts.gramm_schmidt(ts.zeroEV_cluster(coords)) shifted_hess = hessian.copy() for i in range(6): shifted_hess += np.outer(dummy_vec[i], dummy_vec[i]) shifted_eval, shifted_evec = get_sorted_eig(shifted_hess) print "First log sum: ", np.sum(np.log(shifted_eval[6:])) sparse_hess = scipy.sparse.csc_matrix(shifted_hess) factor = cholmod.cholesky(sparse_hess) diagonal = np.diagonal(factor.L().todense()) logar = 2 * np.log(diagonal) log_sum = np.sum(logar) print "Second log sum: ", log_sum
db.session.commit() if __name__ == "__main__": from pele.systems import LJCluster from pele.utils.hessian import get_sorted_eig system = LJCluster(20) db = system.create_database()#"test.sqlite") coords, energy = system.get_random_minimized_configuration()[:2] print energy m = db.addMinimum(energy, coords) pot = system.get_potential() e, g, hess = pot.getEnergyGradientHessian(coords) eval, evec = get_sorted_eig(hess) epair = NormalModes(m, eval, evec, nzero=6, nnegative=0) db.session.commit() print m.normal_modes[0].vectors.shape if False: print m.normal_modes print m.normal_modes[0].freq, eval[0] epair = NormalModes(m, eval[1], evec[:,1]) print m.normal_modes print m.normal_modes[0].freq, eval[0] print m.normal_modes[1].freq, eval[1] elif False: for i in range(len(eval)): epair = NormalModes(m, eval[i], evec[:,i])
#system.params.structural_quench_params.debug = True #system.params.structural_quench_params.iprint = 100 db = system.create_database() bh = system.get_basinhopping(db) bh.run(1) m = db.minima()[0] coords = m.coords potential = system.get_potential() energy, gradient, hessian = potential.getEnergyGradientHessian(coords) dummy_vec = ts.gramm_schmidt(ts.zeroEV_cluster(coords)) shifted_hess = hessian.copy() for i in range(6): shifted_hess += np.outer(dummy_vec[i], dummy_vec[i]) shifted_eval, shifted_evec = get_sorted_eig(shifted_hess) print("First log sum: ", np.sum(np.log(shifted_eval[6:]))) sparse_hess = scipy.sparse.csc_matrix(shifted_hess) factor = cholmod.cholesky(sparse_hess) diagonal = np.diagonal(factor.L().todense()) logar = 2 * np.log(diagonal) log_sum = np.sum(logar) print("Second log sum: ", log_sum)
# nm = HessianEigs(m, eval, evec) db.session.commit() if __name__ == "__main__": from pele.systems import LJCluster from pele.utils.hessian import get_sorted_eig system = LJCluster(20) db = system.create_database() #"test.sqlite") coords, energy = system.get_random_minimized_configuration()[:2] print energy m = db.addMinimum(energy, coords) pot = system.get_potential() e, g, hess = pot.getEnergyGradientHessian(coords) eval, evec = get_sorted_eig(hess) epair = NormalModes(m, eval, evec, nzero=6, nnegative=0) db.session.commit() print m.normal_modes[0].vectors.shape if False: print m.normal_modes print m.normal_modes[0].freq, eval[0] epair = NormalModes(m, eval[1], evec[:, 1]) print m.normal_modes print m.normal_modes[0].freq, eval[0] print m.normal_modes[1].freq, eval[1] elif False: for i in range(len(eval)): epair = NormalModes(m, eval[i], evec[:, i]) # print m.normal_modes