Ejemplo n.º 1
0
def test_sandbox_dumbbell():
    print "***********************************"
    print "testing dumbbell molecule"
    print "***********************************"

    dbel, imatrix = molecule.dumbbell()
    nmol = 5
    print imatrix[0][0] == imatrix[0][1]
    print imatrix[1][0] == imatrix[0][1]

    #set up a list of molecules
    mols = [dbel for i in range(nmol)]

    #set up the RBSandbox object
    mysys = RBSandbox(mols, imatrix)
    nsites = mysys.nsites

    coords = random_coords(nmol, nsites)

    #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 pygmin.optimize import lbfgs_scipy
    coords, E, rms, funcalls = lbfgs_scipy(coords,
                                           mysys.getEnergyGradient,
                                           iprint=-1)
    print "postquench E", E, "rms", rms, "funtion calls", funcalls
Ejemplo n.º 2
0
def test_sandbox_dumbbell():
    print "***********************************"
    print "testing dumbbell molecule"
    print "***********************************"

    dbel, imatrix = molecule.dumbbell()
    nmol = 5
    print imatrix[0][0] == imatrix[0][1]
    print imatrix[1][0] == imatrix[0][1]
    
    #set up a list of molecules
    mols = [dbel for i in range(nmol)]

    #set up the RBSandbox object
    mysys = RBSandbox(mols, imatrix)
    nsites = mysys.nsites

    coords = random_coords(nmol, nsites)
    
    #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 pygmin.optimize import lbfgs_scipy
    coords, E, rms, funcalls =  lbfgs_scipy(coords, mysys.getEnergyGradient, iprint=-1)
    print "postquench E", E, "rms", rms, "funtion calls", funcalls
Ejemplo n.º 3
0
natoms = 12

# random initial coordinates
coords=np.random.random(3*natoms)
pot = lj.LJ()

print pot.getEnergy(coords) 

a,b = pot.getEnergyGradient(coords) 
print type(a) 

from pygmin.optimize import lbfgs_scipy, cg , fire 

# lbfgs 
ret = lbfgs_scipy( coords, pot.getEnergyGradient, iprint=-1 , tol = 1e-3, nsteps=100) 
     # core dump! 

# cg  
#    ret = cg( coordsVec, pot.getEnergyGradient) 
    # runtime error -- ValueError: The truth value of an array with more than ...
    
# fire   
#ret = fire( coords, pot.getEnergyGradient, tol = 1e-3, nsteps=20000) 
# ValueError: The truth value of an array with more than ...
    # works but after 1000 iterations gives an energy of -90.9378267921 higher than initial energy of -90.9364375726!
    
print "energy ", ret[1]
print "rms gradient", ret[2]
print "number of function calls", ret[3]    
Ejemplo n.º 4
0
def test_sandbox(nmol=6):
    import copy
    from pygmin.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 pygmin.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 pygmin.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)
Ejemplo n.º 5
0
natoms = 12

# random initial coordinates
coords = np.random.random(3 * natoms)
pot = lj.LJ()

print pot.getEnergy(coords)

a, b = pot.getEnergyGradient(coords)
print type(a)

from pygmin.optimize import lbfgs_scipy, cg, fire

# lbfgs
ret = lbfgs_scipy(coords, pot, iprint=-1, tol=1e-3, nsteps=100)
# core dump!

# cg
#    ret = cg( coordsVec, pot.getEnergyGradient)
# runtime error -- ValueError: The truth value of an array with more than ...

# fire
#ret = fire( coords, pot.getEnergyGradient, tol = 1e-3, nsteps=20000)
# ValueError: The truth value of an array with more than ...
# works but after 1000 iterations gives an energy of -90.9378267921 higher than initial energy of -90.9364375726!

print "energy ", ret.energy
print "rms gradient", ret.rms
print "number of function calls", ret.nfev
Ejemplo n.º 6
0
def test_sandbox(nmol = 6):
    import copy
    from pygmin.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 pygmin.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 pygmin.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)
Ejemplo n.º 7
0
natoms = 12

# random initial coordinates
coords = np.random.random(3 * natoms)
pot = lj.LJ()

print pot.getEnergy(coords)

a, b = pot.getEnergyGradient(coords)
print type(a)

from pygmin.optimize import lbfgs_scipy, cg, fire

# lbfgs
ret = lbfgs_scipy(coords, pot, iprint=-1, tol=1e-3, nsteps=100)
# core dump!

# cg
#    ret = cg( coordsVec, pot.getEnergyGradient)
# runtime error -- ValueError: The truth value of an array with more than ...

# fire
# ret = fire( coords, pot.getEnergyGradient, tol = 1e-3, nsteps=20000)
# ValueError: The truth value of an array with more than ...
# works but after 1000 iterations gives an energy of -90.9378267921 higher than initial energy of -90.9364375726!

print "energy ", ret.energy
print "rms gradient", ret.rms
print "number of function calls", ret.nfev