예제 #1
0
def check_output(fn_h5, grp_name, overwrite):
    '''Check if the output is already present in print a warning if --overwrite is not used

       **Arguments:**

       fn_h5
            The output HDF5 file

       grp_name
            The HDF5 group in which the output is stored.

       overwrite
            Whether the user wants to overwrite contents that were already
            present.
    '''
    if os.path.isfile(fn_h5):
        with LockedH5File(fn_h5, 'r') as f:
            if grp_name in f and len(f[grp_name]) > 0:
                if overwrite:
                    if log.do_warning:
                        log.warn('Overwriting the contents of "%s" in the file "%s".' % (grp_name, fn_h5))
                    return False
                else:
                    if log.do_warning:
                        log.warn('Skipping because the group "%s" is already present in the file "%s" and it is not empty.' % (grp_name, fn_h5))
                    return True
    return False
예제 #2
0
    def do_hartree_decomposition(self):
        if not self.local:
            if log.do_warning:
                log.warn(
                    'Skipping hartree decomposition because no local grids were found.'
                )
            return

        for index in xrange(self.natom):
            key = ('hartree_decomposition', index)
            if key not in self.cache:
                self.do_density_decomposition()
                if log.do_medium:
                    log('Computing hartree decomposition for atom %i' % index)
                density_decomposition = self.cache.load(
                    'density_decomposition', index)
                rho_splines = [
                    spline for foo, spline in sorted(
                        density_decomposition.iteritems())
                ]
                v_splines = solve_poisson_becke(rho_splines)
                hartree_decomposition = dict(
                    ('spline_%05i' % j, spline)
                    for j, spline in enumerate(v_splines))
                self.cache.dump(key, hartree_decomposition, tags='o')
예제 #3
0
    def do_density_decomposition(self):
        if not self.local:
            if log.do_warning:
                log.warn(
                    'Skipping density decomposition because no local grids were found.'
                )
            return

        for index in xrange(self.natom):
            atgrid = self.get_grid(index)
            assert isinstance(atgrid, AtomicGrid)
            key = ('density_decomposition', index)
            if key not in self.cache:
                moldens = self.get_moldens(index)
                self.do_partitioning()
                if log.do_medium:
                    log('Computing density decomposition for atom %i' % index)
                at_weights = self.cache.load('at_weights', index)
                splines = atgrid.get_spherical_decomposition(moldens,
                                                             at_weights,
                                                             lmax=self.lmax)
                density_decomposition = dict(
                    ('spline_%05i' % j, spline)
                    for j, spline in enumerate(splines))
                self.cache.dump(key, density_decomposition, tags='o')
예제 #4
0
def check_output(fn_h5, grp_name, overwrite):
    '''Check if the output is already present in print a warning if --overwrite is not used

       **Arguments:**

       fn_h5
            The output HDF5 file

       grp_name
            The HDF5 group in which the output is stored.

       overwrite
            Whether the user wants to overwrite contents that were already
            present.
    '''
    if os.path.isfile(fn_h5):
        with LockedH5File(fn_h5, 'r') as f:
            if grp_name in f and len(f[grp_name]) > 0:
                if overwrite:
                    if log.do_warning:
                        log.warn(
                            'Overwriting the contents of "%s" in the file "%s".'
                            % (grp_name, fn_h5))
                    return False
                else:
                    if log.do_warning:
                        log.warn(
                            'Skipping because the group "%s" is already present in the file "%s" and it is not empty.'
                            % (grp_name, fn_h5))
                    return True
    return False
예제 #5
0
    def do_dispersion(self):
        if self.lmax < 3:
            if log.do_warning:
                log.warn(
                    'Skipping the computation of dispersion coefficients because lmax=%i<3'
                    % self.lmax)
            return

        if log.do_medium:
            log.cite(
                'tkatchenko2009',
                'the method to evaluate atoms-in-molecules C6 parameters')
            log.cite('chu2004',
                     'the reference C6 parameters of isolated atoms')
            log.cite('yan1996', 'the isolated hydrogen C6 parameter')

        ref_c6s = { # reference C6 values in atomic units
            1: 6.499, 2: 1.42, 3: 1392.0, 4: 227.0, 5: 99.5, 6: 46.6, 7: 24.2,
            8: 15.6, 9: 9.52, 10: 6.20, 11: 1518.0, 12: 626.0, 13: 528.0, 14:
            305.0, 15: 185.0, 16: 134.0, 17: 94.6, 18: 64.2, 19: 3923.0, 20:
            2163.0, 21: 1383.0, 22: 1044.0, 23: 832.0, 24: 602.0, 25: 552.0, 26:
            482.0, 27: 408.0, 28: 373.0, 29: 253.0, 30: 284.0, 31: 498.0, 32:
            354.0, 33: 246.0, 34: 210.0, 35: 162.0, 36: 130.0, 37: 4769.0, 38:
            3175.0, 49: 779.0, 50: 659.0, 51: 492.0, 52: 445.0, 53: 385.0,
        }

        volumes, new_volumes = self._cache.load('volumes',
                                                alloc=self.natom,
                                                tags='o')
        volume_ratios, new_volume_ratios = self._cache.load('volume_ratios',
                                                            alloc=self.natom,
                                                            tags='o')
        c6s, new_c6s = self._cache.load('c6s', alloc=self.natom, tags='o')

        if new_volumes or new_volume_ratios or new_c6s:
            self.do_moments()
            radial_moments = self._cache.load('radial_moments')

            if log.do_medium:
                log('Computing atomic dispersion coefficients.')

            for i in xrange(self.natom):
                n = self.numbers[i]
                volumes[i] = radial_moments[i, 3]
                ref_volume = self.proatomdb.get_record(n, 0).get_moment(3)
                volume_ratios[i] = volumes[i] / ref_volume
                if n in ref_c6s:
                    c6s[i] = (volume_ratios[i])**2 * ref_c6s[n]
                else:
                    c6s[i] = -1  # This is just to indicate that no value is available.
예제 #6
0
파일: base.py 프로젝트: stevenvdb/horton
    def do_hartree_decomposition(self):
        if not self.local:
            if log.do_warning:
                log.warn('Skipping hartree decomposition because no local grids were found.')
            return

        for index in xrange(self.natom):
            key = ('hartree_decomposition', index)
            if key not in self.cache:
                self.do_density_decomposition()
                if log.do_medium:
                    log('Computing hartree decomposition for atom %i' % index)
                density_decomposition = self.cache.load('density_decomposition', index)
                rho_splines = [spline for foo, spline in sorted(density_decomposition.iteritems())]
                v_splines = solve_poisson_becke(rho_splines)
                hartree_decomposition = dict(('spline_%05i' % j, spline) for j, spline in enumerate(v_splines))
                self.cache.dump(key, hartree_decomposition, tags='o')
예제 #7
0
파일: base.py 프로젝트: stevenvdb/horton
    def do_density_decomposition(self):
        if not self.local:
            if log.do_warning:
                log.warn('Skipping density decomposition because no local grids were found.')
            return

        for index in xrange(self.natom):
            atgrid = self.get_grid(index)
            assert isinstance(atgrid, AtomicGrid)
            key = ('density_decomposition', index)
            if key not in self.cache:
                moldens = self.get_moldens(index)
                self.do_partitioning()
                if log.do_medium:
                    log('Computing density decomposition for atom %i' % index)
                at_weights = self.cache.load('at_weights', index)
                splines = atgrid.get_spherical_decomposition(moldens, at_weights, lmax=self.lmax)
                density_decomposition = dict(('spline_%05i' % j, spline) for j, spline in enumerate(splines))
                self.cache.dump(key, density_decomposition, tags='o')
예제 #8
0
    def do_dispersion(self):
        if self.lmax < 3:
            if log.do_warning:
                log.warn('Skipping the computation of dispersion coefficients because lmax=%i<3' % self.lmax)
            return

        if log.do_medium:
            log.cite('tkatchenko2009', 'the method to evaluate atoms-in-molecules C6 parameters')
            log.cite('chu2004', 'the reference C6 parameters of isolated atoms')
            log.cite('yan1996', 'the isolated hydrogen C6 parameter')

        ref_c6s = { # reference C6 values in atomic units
            1: 6.499, 2: 1.42, 3: 1392.0, 4: 227.0, 5: 99.5, 6: 46.6, 7: 24.2,
            8: 15.6, 9: 9.52, 10: 6.20, 11: 1518.0, 12: 626.0, 13: 528.0, 14:
            305.0, 15: 185.0, 16: 134.0, 17: 94.6, 18: 64.2, 19: 3923.0, 20:
            2163.0, 21: 1383.0, 22: 1044.0, 23: 832.0, 24: 602.0, 25: 552.0, 26:
            482.0, 27: 408.0, 28: 373.0, 29: 253.0, 30: 284.0, 31: 498.0, 32:
            354.0, 33: 246.0, 34: 210.0, 35: 162.0, 36: 130.0, 37: 4769.0, 38:
            3175.0, 49: 779.0, 50: 659.0, 51: 492.0, 52: 445.0, 53: 385.0,
        }

        volumes, new_volumes = self._cache.load('volumes', alloc=self.natom, tags='o')
        volume_ratios, new_volume_ratios = self._cache.load('volume_ratios', alloc=self.natom, tags='o')
        c6s, new_c6s = self._cache.load('c6s', alloc=self.natom, tags='o')

        if new_volumes or new_volume_ratios or new_c6s:
            self.do_populations()
            self.do_moments()
            radial_moments = self._cache.load('radial_moments')
            populations = self._cache.load('populations')

            if log.do_medium:
                log('Computing atomic dispersion coefficients.')

            for i in xrange(self.natom):
                n = self.numbers[i]
                volumes[i] = radial_moments[i,2]/populations[i]
                ref_volume = self.proatomdb.get_record(n, 0).get_moment(3)/n
                volume_ratios[i] = volumes[i]/ref_volume
                if n in ref_c6s:
                    c6s[i] = (volume_ratios[i])**2*ref_c6s[n]
                else:
                    c6s[i] = -1 # This is just to indicate that no value is available.
예제 #9
0
    def write_input(self, number, charge, mult, template, do_overwrite):
        # Directory stuff
        nel = number - charge
        dn_mult = '%03i_%s_%03i_q%+03i/mult%02i' % (
            number, periodic[number].symbol.lower().rjust(
                2, '_'), nel, charge, mult)

        # Figure out if we want to write
        fn_inp = '%s/atom.in' % dn_mult
        exists = os.path.isfile(fn_inp)
        do_write = not exists or do_overwrite

        if do_write:
            try:
                subs = template.get_subs(number, nel, mult)
            except KeyError:
                if log.do_warning:
                    log.warn(
                        'Could not find all subs for %03i.%03i.%03i. Skipping.'
                        % (number, nel, mult))
                return dn_mult, False
            if not os.path.isdir(dn_mult):
                os.makedirs(dn_mult)
            with open(fn_inp, 'w') as f:
                f.write(
                    template.substitute(
                        subs,
                        charge=str(charge),
                        mult=str(mult),
                        number=str(number),
                        element=periodic[number].symbol,
                    ))
            if log.do_medium:
                if exists:
                    log('Overwritten:      ', fn_inp)
                else:
                    log('Written new:      ', fn_inp)
        elif log.do_medium:
            log('Not overwriting:  ', fn_inp)

        return dn_mult, do_write
예제 #10
0
파일: atomdb.py 프로젝트: stevenvdb/horton
    def write_input(self, number, charge, mult, template, do_overwrite):
        # Directory stuff
        nel = number - charge
        dn_mult = '%03i_%s_%03i_q%+03i/mult%02i' % (
            number, periodic[number].symbol.lower().rjust(2, '_'), nel, charge, mult)

        # Figure out if we want to write
        fn_inp = '%s/atom.in' % dn_mult
        exists = os.path.isfile(fn_inp)
        do_write = not exists or do_overwrite

        if do_write:
            try:
                subs = template.get_subs(number, nel, mult)
            except KeyError:
                if log.do_warning:
                    log.warn('Could not find all subs for %03i.%03i.%03i. Skipping.' % (number, nel, mult))
                return dn_mult, False
            if not os.path.isdir(dn_mult):
                os.makedirs(dn_mult)
            with open(fn_inp, 'w') as f:
                f.write(template.substitute(
                    subs,
                    charge=str(charge),
                    mult=str(mult),
                    number=str(number),
                    element=periodic[number].symbol,
                ))
            if log.do_medium:
                if exists:
                    log('Overwritten:      ', fn_inp)
                else:
                    log('Written new:      ', fn_inp)
        elif log.do_medium:
            log('Not overwriting:  ', fn_inp)

        return dn_mult, do_write