Ejemplo n.º 1
0
class TestOrcaEngradKnownGood(SuperOrcaEngrad):
    # Testing errors related to file parsing of a known-good ENGRAD file

    @classmethod
    def setUpClass(cls):
        from opan.test.utils import setUpTestDir

        # Set up the directory
        setUpTestDir(cls.testdir)

        # Write the file
        with open(cls.file_name, 'w') as f:
            f.write(cls.file_text_good)


    @classmethod
    def tearDownClass(cls):
        import os
        from opan.test.utils import tearDownTestDir

        # Delete the engrad file
        os.remove(cls.file_name)

        # Remove the working directory
        tearDownTestDir(cls.testdir)

    def setUp(self):
        # Load the object

        # Imports
        from opan.grad import OrcaEngrad

        # Create the object
        self.oe = OrcaEngrad(path=self.file_name)

        # Enable long messages
        self.longMessage = True

    def test_ENGRAD_KnownGoodAtomVec(self):
        # Confirm the values coming out of the ENGRAD match the known-good
        #  example file.

        # Confirm the atom list is good
        for i in range(len(self.oe.atom_syms)):
            self.assertEqual(self.oe.atom_syms[i], self.atoms[i])

    def test_ENGRAD_KnownGoodGradient(self):
        # Confirm the known-good gradient matches what's expected.

        # Confirm the gradient vector is good
        for i in range(self.oe.gradient.shape[0]):
            self.assertAlmostEqual(self.oe.gradient[i],
                        self.gradient[i], delta=1e-10,
                        msg="Gradient index " + str(i))

    def test_ENGRAD_KnownGoodEnergy(self):
        # Confirm the known-good energy matches what's expected
        self.assertAlmostEqual(self.energy, self.oe.energy, delta=1e-12)

    def test_ENGRAD_KnownGoodGeom(self):
        for i in range(self.oe.geom.shape[0]):
            self.assertAlmostEqual(self.oe.geom[i],
                        self.geom[i], delta=1e-7,
                        msg="Coordinate index " + str(i))

    def test_ENGRAD_KnownGoodCheckGeomMatches(self):
        self.assertTrue(self.oe.check_geom(self.oe.geom, self.oe.atom_syms))