def prepare_options_for_set_options(): """Capture current state of C++ psi4.core.Options information for reloading by `psi4.set_options()`. Returns ------- dict Dictionary where keys are option names to be set globally or module__option mangled names to be set locally. Values are option values. """ flat_options = {} has_changed_snapshot = {module: core.options_to_python(module) for module in _modules} for opt in core.get_global_option_list(): handled_locally = False ghoc = core.has_global_option_changed(opt) opt_snapshot = {k: v[opt] for k, v in has_changed_snapshot.items() if opt in v} for module, (lhoc, ohoc) in opt_snapshot.items(): if ohoc: if lhoc: key = module + '__' + opt val = core.get_local_option(module, opt) else: key = opt val = core.get_global_option(opt) handled_locally = True flat_options[key] = val if ghoc and not handled_locally: # some options are globals section (not level) so not in any module flat_options[opt] = core.get_global_option(opt) return flat_options
def format_options_for_input(molecule=None, **kwargs): """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. """ if molecule is not None: symmetry = molecule.find_point_group(0.00001).symbol() commands = '' commands += """\ncore.set_memory_bytes(%s)\n\n""" % (core.get_memory()) for chgdopt in core.get_global_option_list(): if core.has_global_option_changed(chgdopt): chgdoptval = core.get_global_option(chgdopt) if molecule is not None: if chgdopt.lower() in kwargs: if symmetry in kwargs[chgdopt.lower()]: chgdoptval = kwargs[chgdopt.lower()][symmetry] if isinstance(chgdoptval, str): commands += """core.set_global_option('%s', '%s')\n""" % (chgdopt, chgdoptval) # Next four lines were conflict between master and roa branches (TDC, 10/29/2014) elif isinstance(chgdoptval, int) or isinstance(chgdoptval, float): commands += """core.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval) elif isinstance(chgdoptval, list): commands += """core.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval) else: commands += """core.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval) return commands
def format_options_for_input(molecule=None, **kwargs): """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. """ if molecule is not None: symmetry = molecule.find_point_group(0.00001).symbol() commands = '' commands += """\ncore.set_memory_bytes(%s)\n\n""" % (core.get_memory()) for chgdopt in core.get_global_option_list(): if core.has_global_option_changed(chgdopt): chgdoptval = core.get_global_option(chgdopt) if molecule is not None: if chgdopt.lower() in kwargs: if symmetry in kwargs[chgdopt.lower()]: chgdoptval = kwargs[chgdopt.lower()][symmetry] if isinstance(chgdoptval, str): commands += """core.set_global_option('%s', '%s')\n""" % (chgdopt, chgdoptval) # Next four lines were conflict between master and roa branches (TDC, 10/29/2014) elif isinstance(chgdoptval, int) or isinstance(chgdoptval, float): commands += """core.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval) elif isinstance(chgdoptval, list): commands += """core.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval) else: commands += """core.set_global_option('%s', %s)\n""" % (chgdopt, chgdoptval) return commands
def prepare_options_for_modules(changedOnly=False, commandsInsteadDict=False): """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. - Need some option to get either all or changed - Need some option to either get dict or set string or psimod command list - command return doesn't revoke has_changed setting for unchanged with changedOnly=False """ options = collections.defaultdict(dict) commands = '' for opt in core.get_global_option_list(): if core.has_global_option_changed(opt) or not changedOnly: if opt in ['DFT_CUSTOM_FUNCTIONAL', 'EXTERN']: # Feb 2017 hack continue val = core.get_global_option(opt) options['GLOBALS'][opt] = { 'value': val, 'has_changed': core.has_global_option_changed(opt) } if isinstance(val, str): commands += """core.set_global_option('%s', '%s')\n""" % (opt, val) else: commands += """core.set_global_option('%s', %s)\n""" % (opt, val) #if changedOnly: # print('Appending module %s option %s value %s has_changed %s.' % \ # ('GLOBALS', opt, core.get_global_option(opt), core.has_global_option_changed(opt))) for module in _modules: if core.option_exists_in_module(module, opt): hoc = core.has_option_changed(module, opt) if hoc or not changedOnly: val = core.get_option(module, opt) options[module][opt] = {'value': val, 'has_changed': hoc} if isinstance(val, str): commands += """core.set_local_option('%s', '%s', '%s')\n""" % ( module, opt, val) else: commands += """core.set_local_option('%s', '%s', %s)\n""" % ( module, opt, val) #if changedOnly: # print('Appending module %s option %s value %s has_changed %s.' % \ # (module, opt, core.get_option(module, opt), hoc)) if commandsInsteadDict: return commands else: return options
def prepare_options_for_modules(changedOnly=False, commandsInsteadDict=False): """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. - Need some option to get either all or changed - Need some option to either get dict or set string or psimod command list - command return doesn't revoke has_changed setting for unchanged with changedOnly=False """ options = collections.defaultdict(dict) commands = '' for opt in core.get_global_option_list(): if core.has_global_option_changed(opt) or not changedOnly: if opt in ['DFT_CUSTOM_FUNCTIONAL', 'EXTERN']: # Feb 2017 hack continue val = core.get_global_option(opt) options['GLOBALS'][opt] = {'value': val, 'has_changed': core.has_global_option_changed(opt)} if isinstance(val, basestring): commands += """core.set_global_option('%s', '%s')\n""" % (opt, val) else: commands += """core.set_global_option('%s', %s)\n""" % (opt, val) #if changedOnly: # print('Appending module %s option %s value %s has_changed %s.' % \ # ('GLOBALS', opt, core.get_global_option(opt), core.has_global_option_changed(opt))) for module in _modules: if core.option_exists_in_module(module, opt): hoc = core.has_option_changed(module, opt) if hoc or not changedOnly: val = core.get_option(module, opt) options[module][opt] = {'value': val, 'has_changed': hoc} if isinstance(val, str): commands += """core.set_local_option('%s', '%s', '%s')\n""" % (module, opt, val) else: commands += """core.set_local_option('%s', '%s', %s)\n""" % (module, opt, val) #if changedOnly: # print('Appending module %s option %s value %s has_changed %s.' % \ # (module, opt, core.get_option(module, opt), hoc)) if commandsInsteadDict: return commands else: return options
def prepare_options_for_modules( changedOnly: bool = False, commandsInsteadDict: bool = False, globalsOnly: bool = False, stateInsteadMediated: bool = False, ) -> Union[Dict, str]: """Capture current state of C++ psi4.core.Options information. Parameters ---------- changedOnly Record info only for options that have been set (may still be default). When False, records values for every option. commandsInsteadDict Return string of commands to exec to reset options in current form. When False, return nested dictionary with globals in 'GLOBALS' subdictionary and locals in subdictionaries by module. globalsOnly Record only global options to save time querying the psi4.core.Options object. When False, record module-level options, too. stateInsteadMediated When ``True``, querying this function for options to be later *reset* into the same state -- the raw values and has_changed status at the global and local levels. When ``False``, querying this function for mediated options to be *used* -- the results of the globals/locals handshake as computed by the Options object itself. Here, ``dict[module][option][value]`` is the value to be used by module. Returns ------- dict When ``commandsInsteadDict=False``. str When ``commandsInsteadDict=True``. .. caution:: Some features are not yet implemented. Buy a developer a coffee. - command return doesn't revoke has_changed setting for unchanged with changedOnly=False - not all kwargs are independent """ has_changed_snapshot = {module: core.options_to_python(module) for module in _modules} options = collections.defaultdict(dict) commands = '' for opt in core.get_global_option_list(): hoc = core.has_global_option_changed(opt) if hoc or not changedOnly: if opt in ['DFT_CUSTOM_FUNCTIONAL', 'EXTERN']: # Feb 2017 hack continue val = core.get_global_option(opt) options['GLOBALS'][opt] = {'value': val, 'has_changed': hoc} if isinstance(val, str): commands += """core.set_global_option('%s', '%s')\n""" % (opt, val) else: commands += """core.set_global_option('%s', %s)\n""" % (opt, val) if globalsOnly: continue opt_snapshot = {k: v[opt] for k, v in has_changed_snapshot.items() if opt in v} for module, (lhoc, ohoc) in opt_snapshot.items(): if stateInsteadMediated: hoc = lhoc else: hoc = ohoc if hoc or not changedOnly: if stateInsteadMediated: val = core.get_local_option(module, opt) else: val = core.get_option(module, opt) options[module][opt] = {'value': val, 'has_changed': hoc} if isinstance(val, str): commands += """core.set_local_option('%s', '%s', '%s')\n""" % (module, opt, val) else: commands += """core.set_local_option('%s', '%s', %s)\n""" % (module, opt, val) if commandsInsteadDict: return commands else: return options