Esempio n. 1
0
    def test_symms_benzene(self):
        """ Do the carbons in benzene ring get assigned with roughly equal charges?
        
            Discrepancy between carbons do exist in this test due to grid coarseness and limited
            size of the grid. One can do a larger test, for example, using 160x170x80 size grid to
            obtain [5.63728706, 5.89862956, 5.73956182, 5.63728706, 5.73963179, 5.8996759].
            In comparison, `bader`, which is implemented by Henkelman group which proposed
            the algorithm, reports [5.947370, 6.032509, 5.873431, 5.947370, 5.873431, 6.033485].
            `bader` uses fuzzy boundaries which result in slightly higher carbon charges.
        """

        benzenepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   "benzene.out")
        data = ccread(benzenepath)
        vol = volume.read_from_cube(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "benzene.cube"))
        assert_allclose(vol.origin,
                        numpy.array([-4.1805, -4.498006, -2.116709]),
                        atol=1e-3)

        analysis = Bader(data, vol)
        analysis.calculate()

        self.assertAlmostEqual(analysis.fragcharges[0:6].max(),
                               analysis.fragcharges[0:6].min(),
                               delta=0.5)
Esempio n. 2
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)
Esempio n. 3
0
    def test_chgsum_co(self):
        """ Are Hirshfeld charges for carbon monoxide reported as expected?
        
            Note. Table 1 in doi:10.1007/BF01113058 reports Hirshfeld charge for Carbon atom as
                  0.06 when STO-3G basis set was used and
                  0.14 when 6-311G** basis set was used.
                  Here, Psi4 calculation was done using STO-3G.
        """

        copath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "co.out")
        data = ccread(copath)
        vol = volume.read_from_cube(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), "co.cube")
        )
        analysis = Hirshfeld(data, vol, os.path.dirname(os.path.realpath(__file__)))
        analysis.calculate()

        self.assertAlmostEqual(numpy.sum(analysis.fragcharges), 0, delta=1e-2)
        assert_allclose(analysis.fragcharges, [ 0.10590126, -0.11277786], atol=1e-3)
Esempio n. 4
0
    def test_chg_nh3(self):
        """ Are DDEC6 charges for ammonia reported as expected?
        
            Deviation from a total of zero (0.026545) occurs because the integrated value of total
            density (9.973453129261163) is slightly smaller than number of electrons.
            
            Using a finer grid reduces this discrepancy.
        """

        self.parse("nh3")
        imported_vol = volume.read_from_cube(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "nh3.cube"))
        analysis = DDEC6(self.data, imported_vol,
                         os.path.dirname(os.path.realpath(__file__)))
        analysis.calculate()

        assert_allclose(analysis.fragcharges,
                        [-0.7824003, 0.26854388, 0.26959206, 0.27081123],
                        atol=1e-3)
Esempio n. 5
0
    def test_chgsum_co(self):
        """ Are DDEC6 charges for carbon monoxide reported as expected?
        
            Deviation from a total of zero (-0.00682) occurs because the integrated value of total
            density (14.006876594937234) is slightly larger than # of electrons.
            
            Using a finer grid reduces this discrepancy.
        """

        self.parse("co")
        imported_vol = volume.read_from_cube(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "co.cube"))
        analysis = DDEC6(self.data, imported_vol,
                         os.path.dirname(os.path.realpath(__file__)))
        analysis.calculate()

        self.assertAlmostEqual(numpy.sum(analysis.fragcharges), 0, delta=1e-2)
        assert_allclose(analysis.fragcharges, [0.13221636, -0.13903595],
                        atol=1e-3)
Esempio n. 6
0
    def test_water_charges(self):
        """ Are Hirshfeld charges calculated correctly for water?
        
            Note. Table 1 in doi:10.1007/BF01113058 reports Hirshfeld charge for Hydrogen atom as
                  0.11 when STO-3G basis set was used and
                  0.18 when 6-311G** basis set was used.
                  Here, Psi4 calculation was done using STO-3G.
        """

        self.parse()
        # use precalculated fine cube file
        imported_vol = volume.read_from_cube(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), "water_fine.cube")
        )

        analysis = Hirshfeld(self.data, imported_vol, os.path.dirname(os.path.realpath(__file__)))
        analysis.calculate()

        # Check assigned charges
        assert_allclose(analysis.fragcharges, [-0.29084274,  0.14357639,  0.14357639], atol=0.1)
Esempio n. 7
0
    def test_water_charges(self):
        """Are charges and quantities in each step of DDEC6 algorithm calculated correctly
        for water?
        
        Here, values are compared against `chargemol` calculations.
        Due to the differences in basis set used for calculation and slightly different integration
        grid, some discrepancy is inevitable in the comparison.
        """

        self.parse()
        # use precalculated fine cube file
        imported_vol = volume.read_from_cube(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "water_fine.cube"))

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

        radial_indices = []
        for atomi in range(len(self.data.atomnos)):
            lst = []
            for radius in [0.05, 0.10, 0.15, 0.20, 0.25]:
                # find closest radius index
                lst.append(
                    numpy.abs(analysis.radial_grid_r[atomi] - radius).argmin())
            radial_indices.append(lst)

        # values from `chargemol` calculation
        # which is based on proatomic densities calculated with different basis set.
        # discrepancy comes from the fact that `chargemol` grid & `horton` grid don't exactly match
        # (rtol is adjusted to account for this inevitable discrepancy)
        # STEP 1
        # Check assigned charges.
        assert_allclose(analysis.reference_charges[0],
                        [-0.513006, 0.256231, 0.256775],
                        rtol=0.10)
        # STEP 2
        # Check assigned charges.
        assert_allclose(analysis.reference_charges[1],
                        [-0.831591, 0.415430, 0.416161],
                        rtol=0.20)
        # STEP 3
        # Check integrated charge density (rho^cond(r)) on grid with integrated values (=nelec).
        self.assertAlmostEqual(analysis.charge_density.integrate(),
                               analysis.rho_cond.integrate(),
                               delta=1)
        for atomi in range(len(analysis.data.atomnos)):
            self.assertAlmostEqual(
                analysis._integrate_from_radial(
                    [analysis._cond_density[atomi]], [atomi]) +
                analysis.reference_charges[-1][atomi],
                analysis.data.atomnos[atomi],
                delta=0.5,
            )
        # Also compare with data from `chargemol`
        # discrepancy comes from the fact that `chargemol` grid and `horton` grid do not exactly match
        assert_allclose(
            analysis.tau[0][radial_indices[0]],
            [0.999846160, 0.999739647, 0.999114037, 0.997077942, 0.994510889],
            rtol=0.10,
        )
        assert_allclose(
            analysis.tau[1][radial_indices[1]],
            [0.864765882, 0.848824620, 0.805562019, 0.760402501, 0.736949861],
            rtol=0.10,
        )
        assert_allclose(
            analysis.tau[2][radial_indices[2]],
            [0.845934391, 0.839099407, 0.803699493, 0.778428137, 0.698628724],
            rtol=0.10,
        )
        # STEP 4-7
        # Check values assigned to u_A
        assert_allclose(
            analysis.u_A,
            [
                [0.572349429, 0.296923935, 0.296520531],
                [0.563154399, 0.291919678, 0.291376710],
                [0.563475132, 0.292007655, 0.291508794],
                [0.565816045, 0.293131322, 0.292902112],
            ],
            atol=0.05,
        )
        # Check assigned charges
        assert_allclose(analysis.fragcharges, [-0.757097, 0.378410, 0.378687],
                        atol=0.2)