コード例 #1
0
ファイル: cost.py プロジェクト: rmcgibbo/horton
def setup_weights(system, grid, dens=None, near=None, far=None):
    '''Define a weight function for the ESPCost

       **Arguments:**

       system
            The system for which the weight function must be defined

       grid
            A UniformGrid object.

       **Optional arguments:**

       dens
            The density-based criterion. This is a three-tuple with rho, lnrho0
            and sigma. rho is the atomic or the pro-atomic electron density on
            the same grid as the ESP data. lnrho0 and sigma are parameters
            defined in JCTC, 3, 1004 (2007), DOI:10.1021/ct600295n. The weight
            function takes the form::

                exp(-sigma*(ln(rho) - lnrho0)**2)

            Note that the density, rho, should not contain depletions in the
            atomic cores, as is often encountered with pseudo-potential
            computations. In that case it is recommended to construct a
            promolecular density as input for this option.

       near
            Exclude points near the nuclei. This is a dictionary with as items
            (number, (R0, gamma)).

       far
            Exclude points far away. This is a two-tuple: (R0, gamma).
    '''
    weights = np.ones(grid.shape)

    # combine three possible mask functions
    if dens is not None:
        log.cite('hu2007', 'for the ESP fitting weight function')
        rho, lnrho0, sigma = dens
        assert (rho.shape == grid.shape).all()
        multiply_dens_mask(rho, lnrho0, sigma, weights)
    if near is not None:
        for i in xrange(system.natom):
            pair = near.get(system.numbers[i])
            if pair is None:
                pair = near.get(0)
            if pair is None:
                continue
            r0, gamma = pair
            if r0 > 5*angstrom:
                raise ValueError('The wnear radius is excessive. Please keep it below 5 angstrom.')
            multiply_near_mask(system.coordinates[i], grid, r0, gamma, weights)
    if far is not None:
        r0, gamma = far
        multiply_far_mask(system.coordinates, grid, r0, gamma, weights)

    # double that weight goes to zero at non-periodic edges
    return weights
コード例 #2
0
ファイル: cost.py プロジェクト: susilehtola/horton
def setup_weights(coordinates, numbers, grid, dens=None, near=None, far=None):
    '''Define a weight function for the ESPCost

       **Arguments:**

       coordinates
            An array with shape (N, 3) containing atomic coordinates.

       numbers
            A vector with shape (N,) containing atomic numbers.

       grid
            A UniformGrid object.

       **Optional arguments:**

       dens
            The density-based criterion. This is a three-tuple with rho, lnrho0
            and sigma. rho is the atomic or the pro-atomic electron density on
            the same grid as the ESP data. lnrho0 and sigma are parameters
            defined in JCTC, 3, 1004 (2007), DOI:10.1021/ct600295n. The weight
            function takes the form::

                exp(-sigma*(ln(rho) - lnrho0)**2)

            Note that the density, rho, should not contain depletions in the
            atomic cores, as is often encountered with pseudo-potential
            computations. In that case it is recommended to construct a
            promolecular density as input for this option.

       near
            Exclude points near the nuclei. This is a dictionary with as items
            (number, (R0, gamma)).

       far
            Exclude points far away. This is a two-tuple: (R0, gamma).
    '''
    natom, coordinates, numbers = typecheck_geo(coordinates,
                                                numbers,
                                                need_pseudo_numbers=False)
    weights = np.ones(grid.shape)

    # combine three possible mask functions
    if dens is not None:
        biblio.cite('hu2007', 'for the ESP fitting weight function')
        rho, lnrho0, sigma = dens
        assert (rho.shape == grid.shape).all()
        multiply_dens_mask(rho, lnrho0, sigma, weights)
    if near is not None:
        for i in xrange(natom):
            pair = near.get(numbers[i])
            if pair is None:
                pair = near.get(0)
            if pair is None:
                continue
            r0, gamma = pair
            if r0 > 5 * angstrom:
                raise ValueError(
                    'The wnear radius is excessive. Please keep it below 5 angstrom.'
                )
            multiply_near_mask(coordinates[i], grid, r0, gamma, weights)
    if far is not None:
        r0, gamma = far
        multiply_far_mask(coordinates, grid, r0, gamma, weights)

    # double that weight goes to zero at non-periodic edges
    return weights