Exemple #1
0
    def test_ComplexCoordSys_pickling(self):

        calc = test_calc()

        x = cs.XYZ(file2str("H2.xyz"))
        a = cs.RotAndTrans(numpy.array([1., 0., 0., 3., 1., 1.]), parent=x)
        z = cs.ZMatrix(file2str("butane1.zmt"), anchor=a)

        parts = [x, z]

        ccs = cs.ComplexCoordSys(parts)
        ccs.set_calculator(calc)
        forces0 = ccs.get_forces()

        ccs_pickled = pickle.loads(pickle.dumps(ccs))
        ccs_pickled.set_calculator(calc)

        forces_pickled0 = ccs.get_forces()

        dyn = ase.LBFGS(ccs_pickled)
        dyn.run(steps=3)

        forces_pickled1 = ccs_pickled.get_forces()

        dyn = ase.LBFGS(ccs)
        dyn.run(steps=3)

        forces1 = ccs.get_forces()

        self.assert_((forces0 == forces_pickled0).all())
        self.assert_((forces1 == forces_pickled1).all())
        self.assert_((forces0 != forces1).any())
Exemple #2
0
    def test_ComplexCoordSys(self):

        x = cs.XYZ(file2str("H2.xyz"))

        a_h2o1 = cs.RotAndTrans(numpy.array([1., 0., 0., 3., 1., 1.]),
                                parent=x)
        a_h2o2 = cs.RotAndTrans(numpy.array([1., 0., 0., 1., 1., 1.]),
                                parent=x)
        a_ch4 = cs.RotAndTrans(numpy.array([1., 0., 0., 1., -1., 1.]),
                               parent=x)

        h2o1 = cs.ZMatrix(file2str("H2O.zmt"), anchor=a_h2o1)
        h2o2 = cs.ZMatrix(file2str("H2O.zmt"), anchor=a_h2o2)
        ch4 = cs.ZMatrix(file2str("CH4.zmt"), anchor=a_ch4)

        parts = [x, h2o1, h2o2, ch4]

        ccs = cs.ComplexCoordSys(parts)
        ccs.set_calculator(test_calc())

        dyn = ase.LBFGS(ccs)

        list = []
        for i in range(8):
            list.append(ccs.atoms.copy())
            dyn.run(steps=1, fmax=0.01)

        list.append(ccs.atoms.copy())

        if visual:
            ase.view(list)
Exemple #3
0
    def test_opts(self):
        z = cs.ZMatrix(file2str("butane1.zmt"))
        new_coords = z.get_internals() * 1.15

        z.set_internals(new_coords)

        string_rep = z.xyz_str()

        z.set_calculator(test_calc())
        dyn = ase.LBFGS(z)

        print "Running z-matrix optimisation"
        dyn.run(steps=5)

        e1 = z.get_potential_energy()

        xyz = cs.XYZ(string_rep)
        xyz.set_calculator(test_calc())
        dyn = ase.LBFGS(xyz)

        print "Running cartesian optimisation"
        dyn.run(steps=5)

        e2 = xyz.get_potential_energy()

        self.assert_(e1 < e2)
Exemple #4
0
    def test_gaussian_chkpointing(self):

        print """Testing that for a tricky wavefunction, the gaussian driver
will read in a guess and achieve speedier convergence the second time around."""
        print "This test will take around 20 seconds..."
        start = time.time()
        g = pts.gaussian.Gaussian(mult=2)
        b = cs.XYZ(file2str("benzyl.xyz"))
        b.set_calculator(g)
        b.get_potential_energy()
        t0 = time.time() - start
        coords = b.get_internals()
        coords *= 1.05

        start = time.time()
        b.set_internals(coords)
        b.get_potential_energy()
        t1 = time.time() - start

        print "Times for first calc and second calculations:", t0, t1
        print "Ratio of times", (t1 / t0)
        low, high = 0.3, 0.6
        print "Must be between %f and %f" % (low, high)

        self.assert_(low < t1 / t0 < high)
Exemple #5
0
    def form_ccs1(self):
        """Forms a complex coordinate system object from a few bits and pieces."""
        x = cs.XYZ(file2str("H2.xyz"))

        a_h2o1 = cs.RotAndTrans(numpy.array([1., 0., 0., 0., 1., 1.]),
                                parent=x)
        #        a_h2o2 = cs.RotAndTrans(numpy.array([1.,0.,0.,0.,1.,1.,1.]), parent=x)
        #        a_ch4  = cs.RotAndTrans(numpy.array([1.,0.,0.,0.,1.,-1.,1.]), parent=x)

        h2o1 = cs.ZMatrix(file2str("H2O.zmt"), anchor=a_h2o1)
        #        h2o2 = cs.ZMatrix(file2str("H2O.zmt"), anchor=a_h2o2)
        #        ch4  = cs.ZMatrix(file2str("CH4.zmt"), anchor=a_ch4)

        parts = [x, h2o1]  #, h2o2, ch4]

        ccs = cs.ComplexCoordSys(parts)

        return ccs, x, h2o1, a_h2o1  #, h2o2, ch4, a_h2o2, a_ch4
Exemple #6
0
    def test_ComplexCoordSys2(self):

        x = cs.XYZ(file2str("H2.xyz"))
        a = cs.RotAndTrans(numpy.array([1., 0., 0., 3., 1., 1.]), parent=x)
        z = cs.ZMatrix(file2str("butane1.zmt"), anchor=a)

        parts = [x, z]

        ccs = cs.ComplexCoordSys(parts)
        ccs.set_calculator(test_calc())

        print ccs.get_potential_energy()
        print ccs.get_forces()

        dyn = ase.LBFGS(ccs)

        list = []
        for i in range(8):
            dyn.run(steps=1, fmax=0.01)
            list.append(ccs.atoms.copy())

        if visual:
            ase.view(list)
Exemple #7
0
    def test_gaussian_benzyl(self):

        g = pts.gaussian.Gaussian(charge=0, mult=2)
        b = cs.XYZ(file2str("benzyl.xyz"))
        b.set_calculator(g)
        print b.get_forces()
Exemple #8
0
import sys
import pts
import pts.coord_sys as csys

file = sys.argv[1]
s = aof.common.file2str(file)

if csys.ZMatrix2.matches(s):
    mol = csys.ZMatrix2(s)

elif csys.XYZ.matches(s):
    mol = csys.XYZ(s)

elif csys.ComplexCoordSys.matches(s):
    mol = csys.ComplexCoordSys(s)

else:
    raise MolInterfaceException("Unrecognised geometry string:\n" + s)

print "Mol has type:", type(mol)
print "mask:", mol._var_mask
print "dims:", mol.dims