Ejemplo n.º 1
0
def format_options_for_input():
    """Function to return a string of commands to replicate the
    current state of user-modified options. Used to capture C++
    options information for distributed (sow/reap) input files.

    .. caution:: Some features are not yet implemented. Buy a developer a coffee.

       - Does not cover local (as opposed to global) options.

       - Does not work with array-type options.

    """
    commands = ''
    commands += """\npsi4.set_memory(%s)\n\n""" % (psi4.get_memory())
    for chgdopt in psi4.get_global_option_list():
        if psi4.has_global_option_changed(chgdopt):
            chgdoptval = psi4.get_global_option(chgdopt)
            if isinstance(chgdoptval, basestring):
                commands += """psi4.set_global_option('%s', '%s')\n""" % (
                    chgdopt, chgdoptval)
            elif isinstance(chgdoptval, int) or isinstance(chgdoptval, float):
                commands += """psi4.set_global_option('%s', %s)\n""" % (
                    chgdopt, chgdoptval)
            else:
                raise ValidationError(
                    'Option \'%s\' is not of a type (string, int, float, bool) that can be processed.'
                    % (chgdopt))
    return commands
Ejemplo n.º 2
0
    def __init__(self, option, module=None):
        self.option = option.upper()
        if module:
            self.module = module.upper()
        else:
            self.module = None

        self.value_global = psi4.get_global_option(option)
        self.haschanged_global = psi4.has_global_option_changed(option)
        if self.module:
            self.value_local = psi4.get_local_option(self.module, option)
            self.haschanged_local = psi4.has_local_option_changed(self.module, option)
            self.value_used = psi4.get_option(self.module, option)
            self.haschanged_used = psi4.has_option_changed(self.module, option)
        else:
            self.value_local = None
            self.haschanged_local = None
            self.value_used = None
            self.haschanged_used = None
Ejemplo n.º 3
0
def format_options_for_input():
    """Function to return a string of commands to replicate the
    current state of user-modified options. Used to capture C++
    options information for distributed (sow/reap) input files.

    .. caution:: Some features are not yet implemented. Buy a developer a coffee.

       - Does not cover local (as opposed to global) options.

       - Does not work with array-type options.

    """
    commands = ''
    commands += """\npsi4.set_memory(%s)\n\n""" % (psi4.get_memory())
    for chgdopt in psi4.get_global_option_list():
        if psi4.has_global_option_changed(chgdopt):
            chgdoptval = psi4.get_global_option(chgdopt)
            if isinstance(chgdoptval, basestring):
                commands += """psi4.set_global_option('%s', '%s')\n""" % (chgdopt, chgdoptval)
            elif isinstance(chgdoptval, int) or isinstance(chgdoptval, float):
                commands += """psi4.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval)
            else:
                raise ValidationError('Option \'%s\' is not of a type (string, int, float, bool) that can be processed.' % (chgdopt))
    return commands
Ejemplo n.º 4
0
def _set_convergence_criterion(ptype, method_name, scf_Ec, pscf_Ec, scf_Dc, pscf_Dc, gen_Ec, verbose=1):
    r"""
    This function will set local SCF and global energy convergence criterion
    to the defaults listed at:
    http://www.psicode.org/psi4manual/master/scf.html#convergence-and-
    algorithm-defaults. SCF will be converged more tightly if a post-SCF
    method is select (pscf_Ec, and pscf_Dc) else the looser (scf_Ec, and
    scf_Dc convergence criterion will be used).

    ptype -         Procedure type (energy, gradient, etc). Nearly always test on
                    procedures['energy'] since that's guaranteed to exist for a method.
    method_name -   Name of the method
    scf_Ec -        E convergence criterion for scf target method
    pscf_Ec -       E convergence criterion for scf of post-scf target method
    scf_Dc -        D convergence criterion for scf target method
    pscf_Dc -       D convergence criterion for scf of post-scf target method
    gen_Ec -        E convergence criterion for post-scf target method

    """
    optstash = p4util.OptionsState(
        ['SCF', 'E_CONVERGENCE'],
        ['SCF', 'D_CONVERGENCE'],
        ['E_CONVERGENCE'])

    # Kind of want to move this out of here
    _method_exists(ptype, method_name)

    if verbose >= 2:
        print('      Setting convergence', end=' ')
    # Set method-dependent scf convergence criteria, check against energy routines
    if not psi4.has_option_changed('SCF', 'E_CONVERGENCE'):
        if procedures['energy'][method_name] in [proc.run_scf, proc.run_dft]:
            psi4.set_local_option('SCF', 'E_CONVERGENCE', scf_Ec)
            if verbose >= 2:
                print(scf_Ec, end=' ')
        else:
            psi4.set_local_option('SCF', 'E_CONVERGENCE', pscf_Ec)
            if verbose >= 2:
                print(pscf_Ec, end=' ')
    else:
        if verbose >= 2:
            print('CUSTOM', psi4.get_option('SCF', 'E_CONVERGENCE'), end=' ')

    if not psi4.has_option_changed('SCF', 'D_CONVERGENCE'):
        if procedures['energy'][method_name] in [proc.run_scf, proc.run_dft]:
            psi4.set_local_option('SCF', 'D_CONVERGENCE', scf_Dc)
            if verbose >= 2:
                print(scf_Dc, end=' ')
        else:
            psi4.set_local_option('SCF', 'D_CONVERGENCE', pscf_Dc)
            if verbose >= 2:
                print(pscf_Dc, end=' ')
    else:
        if verbose >= 2:
            print('CUSTOM', psi4.get_option('SCF', 'D_CONVERGENCE'), end=' ')

    # Set post-scf convergence criteria (global will cover all correlated modules)
    if not psi4.has_global_option_changed('E_CONVERGENCE'):
        if procedures['energy'][method_name] not in [proc.run_scf, proc.run_dft]:
            psi4.set_global_option('E_CONVERGENCE', gen_Ec)
            if verbose >= 2:
                print(gen_Ec, end=' ')
    else:
        if procedures['energy'][method_name] not in [proc.run_scf, proc.run_dft]:
            if verbose >= 2:
                print('CUSTOM', psi4.get_global_option('E_CONVERGENCE'), end=' ')

    if verbose >= 2:
        print('')
    return optstash