def test_molecule(): otp = setupLWOTP() xyz = otp.getxyz() from pele.printing.print_atoms_xyz import printAtomsXYZ as printxyz import sys #with open("out.xyz", "w") as fout: printxyz(sys.stdout, xyz) aa = np.array([.2, .3, .4]) for xyz, aanew in otp.getSymmetries( np.zeros(3), aa): printxyz(sys.stdout, xyz, line2="symmetry") xyz = otp.getxyz(aa = aanew) printxyz(sys.stdout, xyz, line2="symmetry from returned aa")
def test_sandbox(nmol = 6): import copy from pele.potentials.lj import LJ #define the molecule types. #here use only one type, LWOTP otp = molecule.setupLWOTP() # define the interaction matrix for the system. # for LWOTP there is only one atom type, so this is trivial lj = LJ() interaction_matrix = [[lj]] #set up a list of molecules mols = [otp for i in range(nmol)] #set up the RBSandbox object mysys = RBSandbox(mols, interaction_matrix) nsites = mysys.nsites #get an initial set of coordinates comcoords = np.random.uniform(-1,1,[nmol*3]) * 1.3*(nsites)**(1./3) aacoords = np.array( [copy.copy(rot.random_aa()) for i in range(nmol)] ) aacoords = aacoords.reshape(3*nmol) coords = np.zeros(2*3*nmol, np.float64) coords[0:3*nmol] = comcoords[:] coords[3*nmol:2*3*nmol] = aacoords[:] print "lencoords, len aacoords", len (coords), len(aacoords), len(comcoords) #print "xyz coords", mysys.transformToXYZ(coords) #save the initial set of coords printlist = [] xyz = mysys.getxyz( coords ) printlist.append( (xyz.copy(), "initial")) #calculate the initial energy Einit = mysys.getEnergy(coords) print "initial energy", Einit #test the gradient numericV = mysys.NumericalDerivative(coords, 1e-10) numericV = numericV.copy() print "numeric V", numericV E, V = mysys.getEnergyGradient(coords) print "energy from gradient", E, "difference", E - Einit #print "analytic gradient", V maxgrad_relative = np.max(np.abs(V-numericV)/np.abs(V)) maxgraddiff = np.max(np.abs(V - numericV)) print "max error in gradient", maxgraddiff, "max relative", maxgrad_relative #do a quench to make sure everything is working well from pele.optimize import lbfgs_scipy coords, E, rms, funcalls = lbfgs_scipy(coords, mysys.getEnergyGradient, iprint=-1) print "postquench E", E, "rms", rms, "funtion calls", funcalls xyz = mysys.getxyz(coords ) printlist.append( (xyz.copy(), "post quench")) #print the saved coords fname = "otp.xyz" print "saving xyz coords to", fname from pele.printing.print_atoms_xyz import printAtomsXYZ as printxyz with open(fname, "w") as fout: for xyz, line2 in printlist: printxyz( fout, xyz, line2=line2, atom_type=["N", "O", "O"]) test_symmetries(coords, mysys)