Example #1
0
    def test_cube(self):
        """Does the cube file written out for electron density on a Cartesian grid match
        expected values?
        """

        data, logfile = getdatafile(Psi4, "basicPsi4-1.2.1", ["water_mp2.out"])

        # Reference values were calculated using cubegen method in Psi4.
        # First six rows are information about the coordinates of the grid and comments.
        tmp = []

        with open(os.path.dirname(os.path.realpath(__file__)) + "/water_mp2.cube") as f:
            lines = f.readlines()
            for line in lines[6 : len(lines)]:
                tmp.extend(line.split())
        tmp = numpy.asanyarray(tmp, dtype=float)
        refcube = numpy.resize(tmp, (13, 13, 13))

        # Values for the grid below are constructed to match Psi4 cube file.
        vol = volume.Volume(
            (-1.587532, -1.587532, -1.356299),
            (1.58754, 1.58754, 1.81877),
            (0.26458860545, 0.26458860545, 0.26458860545),
        )
        density = volume.electrondensity(data, vol, [data.mocoeffs[0][: data.homos[0]]])

        assert_allclose(density.data, refcube, atol=0.5, rtol=0.1)
Example #2
0
 def testmissingrequiredattributes(self):
     """Is an error raised when required attributes are missing?"""
     for missing_attribute in DDEC6.required_attrs:
         self.parse()
         vol = volume.Volume((-4, -4, -4), (4, 4, 4), (0.2, 0.2, 0.2))
         delattr(self.data, missing_attribute)
         with self.assertRaises(MissingAttributeError):
             trial = DDEC6(self.data, vol,
                           os.path.dirname(os.path.realpath(__file__)))
Example #3
0
    def test_chgsum_hf(self):
        """Does the sum of charges equate to the number of electrons for a simple molecule?"""

        hfpath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                              "hf.out")
        data = ccread(hfpath)
        vol = volume.Volume((-6, -6, -6), (6, 6, 6), (0.2, 0.2, 0.2))
        analysis = Bader(data, vol)
        analysis.calculate()

        self.assertAlmostEqual(numpy.sum(analysis.fragcharges), 10, delta=1)
Example #4
0
    def test_roundtrip_cube(self):
        """Write a cube file and then read it back. Check if the volume object contains
           identical information on each grid point"""

        data, logfile = getdatafile(Psi4, "basicPsi4-1.2.1", ["water_mp2.out"])
        vol = volume.Volume((-1, -1, -1), (1, 1, 1), (0.4, 0.4, 0.4))
        density = volume.electrondensity(data, vol, [data.mocoeffs[0][: data.homos[0]]])

        density.writeascube("coarsewater.cube")
        density_recovered = volume.read_from_cube("coarsewater.cube")

        assert_allclose(density.data, density_recovered.data, rtol=0.05)
Example #5
0
    def test_chgsum_h2(self):
        """ Are Hirshfeld charges for hydrogen atoms in nonpolar H2 small as expected?
        """

        h2path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "h2.out")
        data = ccread(h2path)
        vol = volume.Volume((-3, -3, -3), (3, 3, 3), (0.1, 0.1, 0.1))
        analysis = Hirshfeld(data, vol, os.path.dirname(os.path.realpath(__file__)))
        analysis.calculate()

        self.assertAlmostEqual(numpy.sum(analysis.fragcharges), 0, delta=1e-2)
        self.assertAlmostEqual(analysis.fragcharges[0], analysis.fragcharges[1], delta=1e-6)
Example #6
0
    def test_val(self):
        """Do the calculated values match with known values?
        """

        self.data, logfile = getdatafile(Psi4, "basicPsi4-1.2.1",
                                         ["water_mp2.out"])
        self.volume = volume.Volume((-4, -4, -4), (4, 4, 4), (0.2, 0.2, 0.2))
        self.analysis = Bader(self.data, self.volume)
        self.analysis.calculate()

        refData = [6.9378, 0.3639, 0.3827]  # values from `bader` package

        assert_allclose(self.analysis.fragcharges, refData, atol=0.15)
Example #7
0
    def test_density(self):
        """Does the volume occupied by the combined electron density integrate
        to the correct value?
        """

        data_basis, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"])
        data_sp, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"])

        vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25))

        frontierorbs = [data_sp.mocoeffs[0][(data_sp.homos[0] - 3) : (data_sp.homos[0] + 1)]]
        density = volume.electrondensity(data_sp, vol, frontierorbs)
        integral = density.integrate()

        self.assertTrue(abs(integral - 8.00) < 1e-2)
        print("Combined Density of 4 Frontier orbitals=", integral)
Example #8
0
    def test_chgsum_h2(self):
        """ Are DDEC6 charges for hydrogen atoms in nonpolar H2 small as expected?
        
            Using much denser grid (spacing of 0.1 rather than 0.2 which is the cube file included
            in the test) gives [0.00046066, 0.00046066]. 
        """

        self.parse("h2")
        vol = volume.Volume((-2, -2, -2), (2, 2, 2), (0.2, 0.2, 0.2))
        analysis = DDEC6(self.data, vol,
                         os.path.dirname(os.path.realpath(__file__)))
        analysis.calculate()

        self.assertAlmostEqual(analysis.fragcharges[0],
                               analysis.fragcharges[1],
                               delta=1e-12)
Example #9
0
    def test_proatom_read(self):
        """Are proatom densities imported correctly?"""

        self.parse()
        vol = volume.Volume((-4, -4, -4), (4, 4, 4), (0.2, 0.2, 0.2))

        self.analysis = DDEC6(self.data, vol,
                              os.path.dirname(os.path.realpath(__file__)))

        refH_den = [
            2.66407645e-01,
            2.66407645e-01,
            2.66407643e-01,
            2.66407612e-01,
            2.66407322e-01,
        ]  # Hydrogen first five densities
        refH_r = [
            1.17745807e-07,
            4.05209491e-06,
            3.21078677e-05,
            1.39448474e-04,
            4.35643929e-04,
        ]  # Hydrogen first five radii
        refO_den = [
            2.98258510e02,
            2.98258510e02,
            2.98258509e02,
            2.98258487e02,
            2.98258290e02,
        ]  # Oxygen first five densities
        refO_r = [
            5.70916728e-09,
            1.97130512e-07,
            1.56506399e-06,
            6.80667366e-06,
            2.12872046e-05,
        ]  # Oxygen first five radii

        assert_allclose(self.analysis.proatom_density[0][0:5],
                        refO_den,
                        rtol=1e-3)
        assert_allclose(self.analysis.proatom_density[1][0:5],
                        refH_den,
                        rtol=1e-3)
        assert_allclose(self.analysis.proatom_density[2][0:5],
                        refH_den,
                        rtol=1e-3)
Example #10
0
    def test_wavefunction(self):
        """Does the volume occupied by the H**O integrate to the correct
        values?
        """

        data_basis, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"])
        data_sp, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"])

        vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25))

        wavefn = volume.wavefunction(data_sp, vol, data_sp.mocoeffs[0][data_sp.homos[0]])
        integral = wavefn.integrate()
        integral_square = wavefn.integrate_square()

        self.assertAlmostEqual(integral, 0, delta=1e-6)  # not necessarily true for all wavefns
        self.assertAlmostEqual(integral_square, 1.00, delta=1e-2)  # true for all wavefns
        print(integral, integral_square)
Example #11
0
    def test_wavefunction(self):
        """Does the volume occupied by the H**O integrate to the correct
        values?
        """

        data_basis, _ = getdatafile(Gaussian, "basicGaussian03", ["dvb_sp_basis.log"])
        data_sp, _ = getdatafile(Gaussian, "basicGaussian03", ["dvb_sp.out"])

        vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25))

        wavefn = volume.wavefunction(data_sp.atomcoords[0],
                                     data_sp.mocoeffs[0][data_sp.homos[0]],
                                     data_basis.gbasis, vol)
        integral = wavefn.integrate()
        integral_square = wavefn.integrate_square()

        self.assertTrue(abs(integral) < 1e-6) # not necessarily true for all wavefns
        self.assertTrue(abs(integral_square - 1.00) < 1e-3) #   true for all wavefns
        print(integral, integral_square)
Example #12
0
 def parse(self):
     self.data, self.logfile = getdatafile(Psi4, "basicPsi4-1.2.1",
                                           ["water_mp2.out"])
     self.volume = volume.Volume((-4, -4, -4), (4, 4, 4), (0.2, 0.2, 0.2))