Example #1
0
 def opt(s):
     sm, info = minimize(e,
                         s,
                         maxit=50,
                         ftol=1.0e-2,
                         xtol=1.0e-2,
                         algo=1)
     print("converged=", info["converged"], "in",
           info["iterations"])
     return sm
Example #2
0
def test_uranyl ():
    e = compose (uo2, uranyl)
    e = Memoize (e, DirStore (salt="XXX YYY"))
    # s = array ([1.79, 1.79, pi])
    s = zeros (6) # + 0.1
    print (uranyl (s))
    # print (e(s))
    # exit (0)
    sm, info = minimize (e, s, ftol=1.0e-2, xtol=1.0e-2, algo=1)
    print (uranyl (sm))
    print ("e(0)=", e (s), "e(1)=", e(sm), "iterations=", info["iterations"])
Example #3
0
def test_uranyl():
    e = compose(uo2, uranyl)
    e = Memoize(e, DirStore(salt="XXX YYY"))
    # s = array ([1.79, 1.79, pi])
    s = zeros(6)  # + 0.1
    print(uranyl(s))
    # print (e(s))
    # exit (0)
    sm, info = minimize(e, s, ftol=1.0e-2, xtol=1.0e-2, algo=1)
    print(uranyl(sm))
    print("e(0)=", e(s), "e(1)=", e(sm), "iterations=", info["iterations"])
Example #4
0
def initial_path (f, s, c):
    """
    This  is  called  with  pure  MM  PES f(s)  to  get  some  initial
    path. Somewhat ad-hoc.
    """
    # The input  geometry s may  be reasonable, but  it may not  be an
    # exact minimum. Reoptimize:
    s, info = minimize (f, s, maxit=100, ftol=5.0e-4, xtol=5.0e-4, algo=1)
    print ("converged=", info["converged"], "in", info["iterations"])

    # The value of reaction coordinate in the initial geometry:
    c0 = c(s)
    print ("XXX: rc(0)=", c0)

    it = 0
    ss = []
    qs = []
    algo = 1
    while c(s) > -c0:
        it += 1
        # write_xyz ("in-%03d.xyz" % it, trafo (s))
        print ("XXX: rc(0)=", c(s))
        s, info = cminimize (f, s, Array (c), maxit=200, ftol=5.0e-3, xtol=5.0e-3, algo=algo)
        # Collect optimized geometries and the corresponding
        # values of reaction coordinate:
        ss.append (s)
        qs.append (c(s))
        print ("converged=", info["converged"], "in", info["iterations"])
        print ("XXX: rc(1)=", c(s))
        # write_xyz ("out-%03d.xyz" % it, trafo (s))
        # Here  c.fprime(s) is how  much that  reaction coordinate
        # will change if you  modify the coordinates. Hacky way to
        # chage a geometry so that the RC is modified too:
        s = s - 0.1 * c.fprime (s)

    ss = asarray (ss)
    qs = asarray (qs)
    print ("qs=", qs)
    p = Path (ss, qs)
    print ("path=", p)
    qs = linspace (c0, -c0, 21)
    print ("qs=", qs)
    ss = map (p, qs)
    res = map (lambda s: cminimize (f, s, Array (c), maxit=200, ftol=1.0e-3, xtol=1.0e-3, algo=algo), ss)
    infos = [inf for _, inf in res]
    ss = [s for s, _ in res]
    for info in infos:
        print ("converged=", info["converged"], "in", info["iterations"])
    for i, s in enumerate (ss):
        write_xyz ("out-%03d.xyz" % i, trafo (s))

    return qs, ss
Example #5
0
        def opt (e, s, name, **kwargs):
            print ("XXX: " + name + "...")

            print (name + ": e(0)=", e (s) / kcal, "kcal, |g|=", max (abs (e.fprime (s))) / kcal, "kcal/Unit")

            s, info = minimize (e, s, **kwargs)

            print (name + ": converged =", info["converged"], "in", info["iterations"], "iterations")
            write_xyz (name + ".xyz", trafo (s))

            # print info
            if "trajectory" in info:
                traj = info["trajectory"]
                print (map(e, traj))
                for i, si in enumerate (traj):
                    # write_xyz ("traj-%s-%03d.xyz" % (name, i), trafo (si))
                    pass

            return s, info
Example #6
0
        def opt(e, s, name, **kwargs):
            print("XXX: " + name + "...")

            print(name + ": e(0)=",
                  e(s) / kcal, "kcal, |g|=",
                  max(abs(e.fprime(s))) / kcal, "kcal/Unit")

            s, info = minimize(e, s, **kwargs)

            print(name + ": converged =", info["converged"], "in",
                  info["iterations"], "iterations")
            write_xyz(name + ".xyz", trafo(s))

            # print info
            if "trajectory" in info:
                traj = info["trajectory"]
                print(map(e, traj))
                for i, si in enumerate(traj):
                    # write_xyz ("traj-%s-%03d.xyz" % (name, i), trafo (si))
                    pass

            return s, info
Example #7
0
def main(argv):
    from ase.io import read, write
    from pts.fopt import minimize
    from sys import stdout, stderr

    for path in argv[1:]:
        atoms = read(path)
        symbols = atoms.get_chemical_symbols()
        x = atoms.get_positions()

        f = Gupta(symbols)
        xm, info = minimize(f, x)

        # print >> stderr, "e=", f(xm), \
        #     "converged=", info["converged"], \
        #     "in", info["iterations"], "iterations"

        if not info["converged"]:
            print >> stderr, "Not converged:", path

        atoms.set_positions(xm)
        write(stdout, atoms, format="xyz")
Example #8
0
def main(argv):
    from ase.io import read, write
    from pts.fopt import minimize
    from sys import stdout, stderr

    for path in argv[1:]:
        atoms = read(path)
        symbols = atoms.get_chemical_symbols()
        x = atoms.get_positions()

        f = Gupta(symbols)
        xm, info = minimize(f, x)

        # print >> stderr, "e=", f(xm), \
        #     "converged=", info["converged"], \
        #     "in", info["iterations"], "iterations"

        if not info["converged"]:
            print >> stderr, "Not converged:", path

        atoms.set_positions(xm)
        write(stdout, atoms, format="xyz")
Example #9
0
def initial_path(f, s, c):
    """
    This  is  called  with  pure  MM  PES f(s)  to  get  some  initial
    path. Somewhat ad-hoc.
    """
    # The input  geometry s may  be reasonable, but  it may not  be an
    # exact minimum. Reoptimize:
    s, info = minimize(f, s, maxit=100, ftol=5.0e-4, xtol=5.0e-4, algo=1)
    print("converged=", info["converged"], "in", info["iterations"])

    # The value of reaction coordinate in the initial geometry:
    c0 = c(s)
    print("XXX: rc(0)=", c0)

    it = 0
    ss = []
    qs = []
    algo = 1
    while c(s) > -c0:
        it += 1
        # write_xyz ("in-%03d.xyz" % it, trafo (s))
        print("XXX: rc(0)=", c(s))
        s, info = cminimize(f,
                            s,
                            Array(c),
                            maxit=200,
                            ftol=5.0e-3,
                            xtol=5.0e-3,
                            algo=algo)
        # Collect optimized geometries and the corresponding
        # values of reaction coordinate:
        ss.append(s)
        qs.append(c(s))
        print("converged=", info["converged"], "in", info["iterations"])
        print("XXX: rc(1)=", c(s))
        # write_xyz ("out-%03d.xyz" % it, trafo (s))
        # Here  c.fprime(s) is how  much that  reaction coordinate
        # will change if you  modify the coordinates. Hacky way to
        # chage a geometry so that the RC is modified too:
        s = s - 0.1 * c.fprime(s)

    ss = asarray(ss)
    qs = asarray(qs)
    print("qs=", qs)
    p = Path(ss, qs)
    print("path=", p)
    qs = linspace(c0, -c0, 21)
    print("qs=", qs)
    ss = map(p, qs)
    res = map(
        lambda s: cminimize(
            f, s, Array(c), maxit=200, ftol=1.0e-3, xtol=1.0e-3, algo=algo),
        ss)
    infos = [inf for _, inf in res]
    ss = [s for s, _ in res]
    for info in infos:
        print("converged=", info["converged"], "in", info["iterations"])
    for i, s in enumerate(ss):
        write_xyz("out-%03d.xyz" % i, trafo(s))

    return qs, ss
Example #10
0
             (1, 2, None)], base=1)

#
# Initial values of internal coordinates:
#
s = zmt.pinv (x)
assert max (abs (s - zmt.pinv (zmt (s)))) < 1.0e-10

clean ()

with QFunc (atoms, calc) as f:
    f = Memoize (f, DirStore (salt="h2o, qm"))
    e = compose (f, zmt)

    print s, e (s)
    s, info = minimize (e, s, algo=1, ftol=1.0e-2, xtol=1.0e-2)
    print s, e (s), info["converged"]

#
# Internal coordinates:
#
# In:  0.97843364  0.97826543  1.87152024
# Out: 0.98477091  0.98477695  1.88111918
#
# Rigid water with optimized internal coordinates:
#
X = Rigid (zmt (s))

# Five optimized  rigid waters, actual location and  orientation to be
# specified ...
waters = [X] * 5
Example #11
0
 def opt (s):
     sm, info = minimize (e, s, maxit=50, ftol=1.0e-2, xtol=1.0e-2, algo=1)
     print ("converged=", info["converged"], "in", info["iterations"])
     return sm
Example #12
0
zmt = ZMat([(None, None, None), (1, None, None), (1, 2, None)], base=1)

#
# Initial values of internal coordinates:
#
s = zmt.pinv(x)
assert max(abs(s - zmt.pinv(zmt(s)))) < 1.0e-10

clean()

with QFunc(atoms, calc) as f:
    f = Memoize(f, DirStore(salt="h2o, qm"))
    e = compose(f, zmt)

    print s, e(s)
    s, info = minimize(e, s, algo=1, ftol=1.0e-2, xtol=1.0e-2)
    print s, e(s), info["converged"]

#
# Internal coordinates:
#
# In:  0.97843364  0.97826543  1.87152024
# Out: 0.98477091  0.98477695  1.88111918
#
# Rigid water with optimized internal coordinates:
#
X = Rigid(zmt(s))

# Five optimized  rigid waters, actual location and  orientation to be
# specified ...
waters = [X] * 5