Beispiel #1
0
# along with this program; if not, see <http://www.gnu.org/licenses/>
#
# --


from glob import glob
from cStringIO import StringIO
import os
from horton.periodic import periodic
from horton.log import log
from horton.gbasis.gobasis import go_basis_families_list

from common import write_rst_table, write_if_changed


log.set_level(log.silent)


table = [['Basis set name', 'Supported elements']]
for family in go_basis_families_list:
    family.load()
    numbers = sorted(family.basis_atom_map.keys())
    s = []
    for i in xrange(len(numbers)):
        if (i > 0 and i < len(numbers)-1) and numbers[i-1] == numbers[i]-1 \
           and numbers[i+1] == numbers[i]+1:
            if s[-1] != '-':
                s.append('-')
        else:
            s.append(periodic[numbers[i]].symbol)
    range_str = ' '.join(s).replace(' - ', '--').replace(' ', ', ')
Beispiel #2
0
def main():
    """Main program."""
    # Get command-line args
    example_paths, do_update, do_force, do_verbose = parse_args()

    # Silence the logger
    if not do_verbose:
        log.set_level(log.silent)

    # Exit status becomes 1 when some test results have changed beyond the thresholds, or
    # when previous or reference values are missing.
    exit_status = 0

    # Run all examples.
    for example_path in example_paths:
        print example_path

        # Sanity checks
        if not example_path.endswith(".py"):
            raise RegressionTestError('Example path should end with ".py": {}.'
                                      .format(example_path))
        with open(example_path) as f:
            example_lines = f.readlines()
            try:
                example_lines.index(comment_regtest)
            except ValueError:
                raise RegressionTestError('Missing regression-testing comment in example {}.'
                                          .format(example_path))

        # Run example and collect results.
        example_globals = {}
        with numpy_seed():
            print '   First random number:', np.random.rand()
        with open(example_path) as fh, numpy_seed():
            exec fh in example_globals  # pylint: disable=exec-used

        # Check that rt_results is defined in the example.
        if 'rt_results' not in example_globals:
            raise RegressionTestError('No rt_results defined in example {}.'
                                      .format(example_path))

        # Extract relevant variables from example.
        rt_results = example_globals['rt_results']
        rt_atols = example_globals.get('rt_atols', {})
        rt_rtols = example_globals.get('rt_rtols', {})
        rt_references = example_globals.get('rt_references', {})
        rt_previous = example_globals.get('rt_previous', {})
        known_keys = ['rt_results', 'rt_atols', 'rt_rtols', 'rt_references', 'rt_previous']
        for key in example_globals:
            if key.startswith('rt_') and key not in known_keys:
                print 'Unrecognized variable starting with rt_: {}.' % key

        # Compare results with expected or previous values, if previous values are present.
        rt_status = {}
        for key, result in rt_results.iteritems():
            target = rt_references.get(key, rt_previous.get(key))
            if target is None:
                rt_status[key] = 'PREVIOUS OR REFERENCE MISSING'
            else:
                atol = rt_atols.get(key, default_atol)
                rtol = rt_rtols.get(key, default_rtol)
                if not isinstance(result, target.__class__):
                    rt_status[key] = 'WRONG TYPE'
                elif isinstance(result, np.ndarray) and (result.shape != target.shape):
                    rt_status[key] = 'WRONG SHAPE'
                elif np.allclose(result, target, atol=atol, rtol=rtol):
                    rt_status[key] = 'OK'
                else:
                    rt_status[key] = 'BOUNDS EXCEEDED'

        if do_update:
            update_example(example_path, example_lines, rt_previous, rt_results,
                           rt_status, do_force)
        else:
            exit_status |= report_regressions(rt_results, rt_atols, rt_rtols, rt_references,
                                              rt_previous, rt_status)

    # Stop with proper exit code.
    sys.exit(exit_status)
def main():
    """Main program."""
    # Get command-line args
    example_paths, do_update, do_force, do_verbose = parse_args()

    # Silence the logger
    if not do_verbose:
        log.set_level(log.silent)

    # Exit status becomes 1 when some test results have changed beyond the thresholds, or
    # when previous or reference values are missing.
    exit_status = 0

    # Run all examples.
    for example_path in example_paths:
        print example_path

        # Sanity checks
        if not example_path.endswith(".py"):
            raise RegressionTestError('Example path should end with ".py": {}.'
                                      .format(example_path))
        with open(example_path) as f:
            example_lines = f.readlines()
            try:
                example_lines.index(comment_regtest)
            except ValueError:
                raise RegressionTestError('Missing regression-testing comment in example {}.'
                                          .format(example_path))

        # Run example and collect results.
        example_globals = {}
        with numpy_seed():
            print '   First random number:', np.random.rand()
        with open(example_path) as fh, numpy_seed():
            exec fh in example_globals  # pylint: disable=exec-used

        # Check that rt_results is defined in the example.
        if 'rt_results' not in example_globals:
            raise RegressionTestError('No rt_results defined in example {}.'
                                      .format(example_path))

        # Extract relevant variables from example.
        rt_results = example_globals['rt_results']
        rt_atols = example_globals.get('rt_atols', {})
        rt_rtols = example_globals.get('rt_rtols', {})
        rt_references = example_globals.get('rt_references', {})
        rt_previous = example_globals.get('rt_previous', {})
        known_keys = ['rt_results', 'rt_atols', 'rt_rtols', 'rt_references', 'rt_previous']
        for key in example_globals:
            if key.startswith('rt_') and key not in known_keys:
                print 'Unrecognized variable starting with rt_: {}.' % key

        # Compare results with expected or previous values, if previous values are present.
        rt_status = {}
        for key, result in rt_results.iteritems():
            target = rt_references.get(key, rt_previous.get(key))
            if target is None:
                rt_status[key] = 'PREVIOUS OR REFERENCE MISSING'
            else:
                atol = rt_atols.get(key, default_atol)
                rtol = rt_rtols.get(key, default_rtol)
                if not isinstance(result, target.__class__):
                    rt_status[key] = 'WRONG TYPE'
                elif isinstance(result, np.ndarray) and (result.shape != target.shape):
                    rt_status[key] = 'WRONG SHAPE'
                elif np.allclose(result, target, atol=atol, rtol=rtol):
                    rt_status[key] = 'OK'
                else:
                    rt_status[key] = 'BOUNDS EXCEEDED'

        if do_update:
            update_example(example_path, example_lines, rt_previous, rt_results,
                           rt_status, do_force)
        else:
            exit_status |= report_regressions(rt_results, rt_atols, rt_rtols, rt_references,
                                              rt_previous, rt_status)

    # Stop with proper exit code.
    sys.exit(exit_status)
Beispiel #4
0
from horton.transformorbs.quasi import *
from horton.meanfield.project import ProjectExp, project_mol, measure_span
import horton.part.mulliken as mul
from horton.gbasis.lcgobasis import LCGOBasis
from horton import context
import pickle
from os.path import splitext
import itertools as it
import numpy as np
from horton.log import log

log.set_level(2)

# TODO: probably smarter to use h5py instead of pickle (since i'm using dictionary of dictionaries anyways)
def run_calc(fchkfile):
    mol = Molecule.from_file(fchkfile)
    mol.orthogonalize()
    outname = splitext(fchkfile)[0]+'_pop.p'
    basis_list = ['aambs', 'anorcc', 'minao', 'sto-6g', '631g']
    quasi_list = ['quambo','quao','iao1','iao2']
    orth_list = ['orth', 'north']
    names = ['atomic basis', 'orth atomic basis',]
    newbasis_flat = [LCGOBasis(mol.obasis).normalized, LCGOBasis(mol.obasis).orth_all,]
    # TODO: NORMALIZE and INTRATOMICALLY ORTHOGONALIZE AB's!
    # transformations
    newbasis = {k:{j:{i:{h:None for h in orth_list} for i in ['quambo','quao','iao1','iao2','quasi']} for j in ['normal','special']} for k in basis_list} 
    for obasis in basis_list:
        quasi = QuasiTransformation(mol, obasis2=obasis, minimal=True)
        names.append(obasis)
        obasis2 = LCGOBasis(quasi.obasis2).normalized
        newbasis_flat.append(obasis2)