Esempio n. 1
0
def main():
    import glob
    from molmod import angstrom
    from hipart.atoms import AtomTable
    from hipart.context import Context, Options
    from hipart.schemes import HirshfeldScheme

    # load the atom table from the first example
    atom_table = AtomTable("../001-usage/atoms/densities.txt")

    # select formatted checkpoint files from the first example
    fns_fchk = glob.glob("../001-usage/*.fchk")

    f = file("all.txt", "w")
    # loop over all formatted checkpoint files
    for fn_fchk in fns_fchk:
        # setup a HiPart computation
        options = Options(lebedev=266, do_work=False, do_output=False)
        context = Context(fn_fchk, options)
        scheme = HirshfeldScheme(context, atom_table)
        # the following line does the computation
        scheme.do_charges()
        # print output to the file all.txt
        m = scheme.molecule
        print >> f, "XXX", m.size
        for i in xrange(m.size):
            print >> f, "%3i % 15.10f % 15.10f % 15.10f % 9.5f" % (
                m.numbers[i], m.coordinates[i,0]/angstrom,
                m.coordinates[i,1]/angstrom, m.coordinates[i,2]/angstrom,
                scheme.charges[i]
            )
    f.close()
Esempio n. 2
0
def estimate_errors(atom_tables, fns_fchk):
    from hipart.context import Context, Options
    from hipart.schemes import HirshfeldScheme
    from hipart.log import log
    import numpy, time

    configs = []
    ref_config = None
    # The loops below one jobs for each grid configuration, i.e. combination
    # of radial and angular grid.
    for size, atom_table in sorted(atom_tables.iteritems()):
        for lebedev in 26, 50, 110, 230, 434, 770, 1454, 2702:
            all_charges = []
            start = time.clock()
            for fn_fchk in fns_fchk:
                log.begin("Config size=%i lebedev=%i fchk=%s" %
                          (size, lebedev, fn_fchk))
                # Make a new working environment for every sample
                options = Options(lebedev=lebedev,
                                  do_work=False,
                                  do_output=False,
                                  do_random=True)
                context = Context(fn_fchk, options)
                scheme = HirshfeldScheme(context, atom_table)
                scheme.do_charges()
                all_charges.append(scheme.charges)
                del scheme
                log.end()
            cost = time.clock() - start
            log("cost=%.2e" % cost)
            config = Config(size, lebedev, numpy.concatenate(all_charges),
                            cost)
            configs.append(config)
            if ref_config is None or (ref_config.size <= config.size and
                                      ref_config.lebedev <= config.lebedev):
                ref_config = config

    # Compute the errors
    ref_charges = configs[-1].charges
    for config in configs:
        config.error = (ref_charges - config.charges).std()

    # Log all
    log.begin("All configs")
    for config in configs:
        log(str(config))
    log.end()
    return configs
Esempio n. 3
0
def estimate_errors(atom_tables, fns_fchk):
    from hipart.context import Context, Options
    from hipart.schemes import HirshfeldScheme
    from hipart.log import log
    import numpy, time

    configs = []
    ref_config = None
    # The loops below one jobs for each grid configuration, i.e. combination
    # of radial and angular grid.
    for size, atom_table in sorted(atom_tables.iteritems()):
        for lebedev in 26, 50, 110, 230, 434, 770, 1454, 2702:
            all_charges = []
            start = time.clock()
            for fn_fchk in fns_fchk:
                log.begin("Config size=%i lebedev=%i fchk=%s" % (size, lebedev, fn_fchk))
                # Make a new working environment for every sample
                options = Options(lebedev=lebedev, do_work=False,
                                  do_output=False, do_random=True)
                context = Context(fn_fchk, options)
                scheme = HirshfeldScheme(context, atom_table)
                scheme.do_charges()
                all_charges.append(scheme.charges)
                del scheme
                log.end()
            cost = time.clock() - start
            log("cost=%.2e" % cost)
            config = Config(size, lebedev, numpy.concatenate(all_charges), cost)
            configs.append(config)
            if ref_config is None or (ref_config.size <= config.size and ref_config.lebedev <= config.lebedev):
                ref_config = config

    # Compute the errors
    ref_charges = configs[-1].charges
    for config in configs:
        config.error = (ref_charges - config.charges).std()

    # Log all
    log.begin("All configs")
    for config in configs:
        log(str(config))
    log.end()
    return configs
Esempio n. 4
0
def estimate_errors(atom_tables, fn_fchk):
    from hipart.context import Context, Options
    from hipart.schemes import HirshfeldScheme
    from hipart.log import log
    import numpy, time

    configs = []
    # The loops below run 40 jobs for each grid configuration, i.e. combination
    # of radial and angular grid. Due to the random rotations of the angular
    # integration grids, the resulting charges will differ in each run. The
    # standard devation on each charge over the 40 runs is computed, and then
    # the error over all atoms is averaged. This error is used as 'the' error on
    # the charges. The cost is the cpu time consumed for computing this error.
    for size, atom_table in sorted(atom_tables.iteritems()):
        for lebedev in 26, 50, 110, 170, 266, 434:
            log.begin("Config size=%i lebedev=%i" % (size, lebedev))
            start = time.clock()
            all_charges = []
            for counter in xrange(40):
                log.begin("Sample counter=%i" % counter)
                # Make a new working environment for every sample
                options = Options(lebedev=lebedev,
                                  do_work=False,
                                  do_output=False)
                context = Context(fn_fchk, options)
                scheme = HirshfeldScheme(context, atom_table)
                scheme.do_charges()
                all_charges.append(scheme.charges)
                del scheme
                log.end()
            all_charges = numpy.array(all_charges)
            error = all_charges.std(axis=0).mean()
            cost = time.clock() - start
            log("error=%.2e cost=%.2e" % (error, cost))
            configs.append(Config(size, lebedev, error, cost))
            log.end()
    log.begin("All configs")
    for config in configs:
        log(str(config))
    log.end()
    return configs
Esempio n. 5
0
def estimate_errors(atom_tables, fn_fchk):
    from hipart.context import Context, Options
    from hipart.schemes import HirshfeldScheme
    from hipart.log import log
    import numpy, time

    configs = []
    # The loops below run 40 jobs for each grid configuration, i.e. combination
    # of radial and angular grid. Due to the random rotations of the angular
    # integration grids, the resulting charges will differ in each run. The
    # standard devation on each charge over the 40 runs is computed, and then
    # the error over all atoms is averaged. This error is used as 'the' error on
    # the charges. The cost is the cpu time consumed for computing this error.
    for size, atom_table in sorted(atom_tables.iteritems()):
        for lebedev in 26, 50, 110, 170, 266, 434:
            log.begin("Config size=%i lebedev=%i" % (size, lebedev))
            start = time.clock()
            all_charges = []
            for counter in xrange(40):
                log.begin("Sample counter=%i" % counter)
                # Make a new working environment for every sample
                options = Options(lebedev=lebedev, do_work=False,
                                  do_output=False)
                context = Context(fn_fchk, options)
                scheme = HirshfeldScheme(context, atom_table)
                scheme.do_charges()
                all_charges.append(scheme.charges)
                del scheme
                log.end()
            all_charges = numpy.array(all_charges)
            error = all_charges.std(axis=0).mean()
            cost = time.clock() - start
            log("error=%.2e cost=%.2e" % (error, cost))
            configs.append(Config(size, lebedev, error, cost))
            log.end()
    log.begin("All configs")
    for config in configs:
        log(str(config))
    log.end()
    return configs