コード例 #1
0
def test_agspec_string():
    agspec = AtomicGridSpec('power:0.001:10.0:20:26')
    for number in 1, 4, 10:
        rgrid, nlls = agspec.get(number, number)
        assert isinstance(rgrid.rtransform, PowerRTransform)
        assert rgrid.rtransform.rmin == 0.001 * angstrom
        assert rgrid.rtransform.rmax == 10.0 * angstrom
        assert rgrid.size == 20
        assert (nlls == [26] * 20).all()
コード例 #2
0
def test_atgrid_medium_contents():
    for agspec in AtomicGridSpec('medium'), AtomicGridSpec():
        rgrid, nlls = agspec.get(1, 1)
        assert rgrid.rtransform.to_string(
        ) == 'PowerRTransform 3.69705074304963e-06 19.279558946793685 24'
        assert (nlls == np.array([
            6, 6, 6, 6, 6, 6, 6, 6, 14, 14, 26, 38, 50, 86, 110, 110, 110, 110,
            86, 50, 50, 14, 6, 6
        ])).all()
コード例 #3
0
def test_agspec_tuple2():
    rtf = ExpRTransform(0.1, 1e1, 4)
    rgrid = RadialGrid(rtf)

    agspec = AtomicGridSpec((rgrid, [6, 14, 26, 6]))
    rgrid0, nlls0 = agspec.get(1, 1)
    assert rgrid is rgrid0
    assert (nlls0 == [6, 14, 26, 6]).all()

    with assert_raises(ValueError):
        AtomicGridSpec((rgrid, [6, 14, 26, 6, 6]))
コード例 #4
0
def test_agspec_tuple1():
    rtf = ExpRTransform(0.1, 1e1, 4)
    rgrid = RadialGrid(rtf)

    agspec = AtomicGridSpec((rgrid, 6))
    rgrid0, nlls0 = agspec.get(1, 1)
    assert rgrid is rgrid0
    assert (nlls0 == [6, 6, 6, 6]).all()
    rgrid0, nlls0 = agspec.get(2, 2)
    assert rgrid is rgrid0
    assert (nlls0 == [6, 6, 6, 6]).all()
コード例 #5
0
def test_agspec_list():
    agspec = AtomicGridSpec([
        (1, 1, RadialGrid(ExpRTransform(0.1, 1e1, 4)), [6, 14, 26, 6]),
        (2, 2, RadialGrid(ExpRTransform(0.2, 1e1, 4)), [6, 14, 26, 14]),
        (10, 8, RadialGrid(ExpRTransform(0.3, 1e1, 4)), [6, 14, 26, 26]),
        (10, 10, RadialGrid(ExpRTransform(0.4, 1e1, 4)), [6, 14, 26, 38]),
    ])
    rgrid, nlls = agspec.get(1, 1)
    assert rgrid.rtransform.rmin == 0.1
    assert (nlls == [6, 14, 26, 6]).all()
    rgrid, nlls = agspec.get(2, 2)
    assert rgrid.rtransform.rmin == 0.2
    assert (nlls == [6, 14, 26, 14]).all()
    rgrid, nlls = agspec.get(10, 8)
    assert rgrid.rtransform.rmin == 0.3
    assert (nlls == [6, 14, 26, 26]).all()
    rgrid, nlls = agspec.get(10, 10)
    assert rgrid.rtransform.rmin == 0.4
    assert (nlls == [6, 14, 26, 38]).all()
    rgrid, nlls = agspec.get(10, 6)
    assert rgrid.rtransform.rmin == 0.3
    assert (nlls == [6, 14, 26, 26]).all()
    rgrid, nlls = agspec.get(2, 1)
    assert rgrid.rtransform.rmin == 0.2
    assert (nlls == [6, 14, 26, 14]).all()
コード例 #6
0
def test_agspec_local_file():
    with tmpdir('grid.scripts.test.test_espfit.test_scripts_symmetry') as dn:
        fn_dest = os.path.join(dn, 'mygrid.txt')
        shutil.copy(
            pkg_resources.resource_filename('grid.grid.data', 'tv-13.7-4.txt'),
            fn_dest)
        agspec = AtomicGridSpec(fn_dest)
        rgrid, nlls = agspec.get(1, 1)
        assert rgrid.rtransform.to_string(
        ) == 'PowerRTransform 3.69705074304963e-06 19.279558946793685 24'
        assert (nlls == np.array([
            6, 6, 6, 6, 6, 6, 6, 6, 14, 14, 26, 38, 50, 86, 110, 110, 110, 110,
            86, 50, 50, 14, 6, 6
        ])).all()
コード例 #7
0
def test_agspec_coarse_contents():
    rgrid, nlls = AtomicGridSpec('coarse').get(1, 1)
    assert rgrid.rtransform.to_string(
    ) == 'PowerRTransform 7.0879993828935345e-06 16.05937640019924 20'
    assert (nlls == np.array([
        6, 6, 6, 6, 6, 6, 6, 14, 14, 26, 38, 50, 86, 86, 86, 86, 50, 14, 6, 6
    ])).all()
コード例 #8
0
def test_agspec_get_size():
    agspec = AtomicGridSpec()
    assert agspec.get_size(1, 1) == 928
    assert agspec.get_size(8, 8) == 3754
コード例 #9
0
def test_agspec_load_names():
    nrads = [20, 24, 34, 41, 49, 59]
    for name in 'tv-13.7-3', 'tv-13.7-4', 'tv-13.7-5', 'tv-13.7-6', 'tv-13.7-7', 'tv-13.7-8':
        agspec = AtomicGridSpec(name)
        assert len(agspec.get(1, 1)[1]) == nrads.pop(0)
コード例 #10
0
def test_agspec_load_simple_names():
    nrads = [20, 24, 34, 41, 49, 59]
    for name in 'coarse', 'medium', 'fine', 'veryfine', 'ultrafine', 'insane':
        agspec = AtomicGridSpec(name)
        assert len(agspec.get(1, 1)[1]) == nrads.pop(0)
コード例 #11
0
def test_agspec_wrong_string():
    with assert_raises(ValueError):
        AtomicGridSpec('power:0.001:10.0:20')
コード例 #12
0
ファイル: molgrid.py プロジェクト: tovrstra/grid
    def __init__(self,
                 centers,
                 numbers,
                 pseudo_numbers=None,
                 agspec='medium',
                 k=3,
                 random_rotate=True,
                 mode='discard'):
        """
           **Arguments:**

           centers
                An array (N, 3) with centers for the atom-centered grids.

           numbers
                An array (N,) with atomic numbers.

           **Optional arguments:**

           pseudo_numbers
                An array (N,) with effective core charges. When not given, this
                defaults to ``numbers``.

           agspec
                A specifications of the atomic grid. This can either be an
                instance of the AtomicGridSpec object, or the first argument
                of its constructor.

           k
                The order of the switching function in Becke's weighting scheme.

           random_rotate
                Flag to control random rotation of spherical grids.

           mode
                Select one of the following options regarding atomic subgrids:

                * ``'discard'`` (the default) means that all information about
                  subgrids gets discarded.

                * ``'keep'`` means that a list of subgrids is kept, including
                  the integration weights of the local grids.

                * ``'only'`` means that only the subgrids are constructed and
                  that the computation of the molecular integration weights
                  (based on the Becke partitioning) is skipped.
        """
        natom, centers, numbers, pseudo_numbers = typecheck_geo(
            centers, numbers, pseudo_numbers)
        self._centers = centers
        self._numbers = numbers
        self._pseudo_numbers = pseudo_numbers

        # check if the mode argument is valid
        if mode not in ['discard', 'keep', 'only']:
            raise ValueError(
                'The mode argument must be \'discard\', \'keep\' or \'only\'.')

        # transform agspec into a usable format
        if not isinstance(agspec, AtomicGridSpec):
            agspec = AtomicGridSpec(agspec)
        self._agspec = agspec

        # assign attributes
        self._k = k
        self._random_rotate = random_rotate
        self._mode = mode

        # allocate memory for the grid
        size = sum(
            agspec.get_size(self.numbers[i], self.pseudo_numbers[i])
            for i in range(natom))
        points = np.zeros((size, 3), float)
        weights = np.zeros(size, float)
        self._becke_weights = np.ones(size, float)

        # construct the atomic grids
        if mode != 'discard':
            atgrids = []
        else:
            atgrids = None
        offset = 0

        if mode != 'only':
            # More recent covalent radii are used than in the original work of Becke.
            # No covalent radius is defined for elements heavier than Curium and a
            # default value of 3.0 Bohr is used for heavier elements.
            cov_radii = np.array([(periodic[n].cov_radius or 3.0)
                                  for n in self.numbers])

        # The actual work:
        logging.info('Preparing Becke-Lebedev molecular integration grid.')
        for i in range(natom):
            atsize = agspec.get_size(self.numbers[i], self.pseudo_numbers[i])
            atgrid = AtomicGrid(self.numbers[i], self.pseudo_numbers[i],
                                self.centers[i], agspec, random_rotate,
                                points[offset:offset + atsize])
            if mode != 'only':
                atbecke_weights = self._becke_weights[offset:offset + atsize]
                becke_helper_atom(points[offset:offset + atsize],
                                  atbecke_weights, cov_radii, self.centers, i,
                                  self._k)
                weights[offset:offset +
                        atsize] = atgrid.weights * atbecke_weights
            if mode != 'discard':
                atgrids.append(atgrid)
            offset += atsize

        # finish
        IntGrid.__init__(self, points, weights, atgrids)

        # Some screen info
        self._log_init()