/usr/share/psi/python/qcdb/options.py is in psi4-data 1:0.3-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | #
#@BEGIN LICENSE
#
# PSI4: an ab initio quantum chemistry software package
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#@END LICENSE
#
import math
from exceptions import *
def format_option_for_cfour(opt, val):
"""Function to reformat value *val* for option *opt* from python
into cfour-speak. Arrays are the primary target.
"""
text = ''
# Transform list from [[3, 0, 1, 1], [2, 0, 1, 0]] --> 3-0-1-1/2-0-1-0
if isinstance(val, list):
if type(val[0]).__name__ == 'list':
if type(val[0][0]).__name__ == 'list':
raise ValidationError('Option has level of array nesting inconsistent with CFOUR.')
else:
# option is 2D array
for no in range(len(val)):
for ni in range(len(val[no])):
text += str(val[no][ni])
if ni < (len(val[no]) - 1):
text += '-'
if no < (len(val) - 1):
text += '/'
else:
# option is plain 1D array
for n in range(len(val)):
text += str(val[n])
if n < (len(val) - 1):
text += '-'
# Transform booleans into integers
elif str(val) == 'True':
text += '1'
elif str(val) == 'False':
text += '0'
# Transform the basis sets that *must* be lowercase (dratted c4 input)
elif (opt == 'CFOUR_BASIS') and (val.upper() in ['SVP', 'DZP', 'TZP', 'TZP2P', 'QZ2P', 'PZ3D2F', '13S9P4D3F']):
text += str(val.lower())
# No Transform
else:
text += str(val)
return opt[6:], text
def prepare_options_for_cfour(options):
"""Function to take the full snapshot of the liboptions object
encoded in dictionary *options*, find the options directable toward
Cfour (options['CFOUR']['CFOUR_**']) that aren't default, then write
a CFOUR deck with those options.
"""
text = ''
for opt, val in options['CFOUR'].items():
if opt.startswith('CFOUR_'):
if val['has_changed']:
if not text:
text += """*CFOUR("""
text += """%s=%s\n""" % (format_option_for_cfour(opt, val['value']))
if text:
text = text[:-1] + ')\n\n'
return text
def prepare_options_for_psi4(options):
"""Function to take the full snapshot of the liboptions object
encoded in dictionary *options*, find the options directable toward
Cfour (options['CFOUR']['CFOUR_**']) that aren't default, then write
a CFOUR deck with those options.
Note that unlike the cfour version, this uses complete options deck.
"""
text = ''
for mod, moddict in options.items():
for opt, val in moddict.items():
#print mod, opt, val['value']
if not text:
text += """\n"""
if mod == 'GLOBALS':
text += """set %s %s\n""" % (opt.lower(), val['value'])
else:
text += """set %s %s %s\n""" % (mod.lower(), opt.lower(), val['value'])
if text:
text += '\n'
return text
def reconcile_options(full, partial):
"""Function to take the full snapshot of the liboptions object
encoded in dictionary *full* and reconcile it with proposed options
value changes in *partial*. Overwrites *full* with *partial* if
option untouched, touches *full* if *full* and *partial* are in
agreement, balks if *full* and *partial* conflict. Returns *full*.
"""
try:
for module, modopts in partial.items():
for kw, kwprop in modopts.items():
if full[module][kw]['has_changed']:
if full[module][kw]['value'] != kwprop['value']:
if 'clobber' in kwprop and kwprop['clobber']:
if 'superclobber' in kwprop and kwprop['superclobber']:
# kw in full is touched, conflicts with value in partial,
# but value in partial is paramount, overwrite full with
# value in partial
full[module][kw]['value'] = kwprop['value']
full[module][kw]['has_changed'] = True
#print '@P4C4 Overwriting %s with %s' % (kw, kwprop['value'])
else:
raise ValidationError("""
Option %s value `%s` set by options block incompatible with
value `%s` in memory/molecule/command/psi4options block.""" %
(kw, full[module][kw]['value'], kwprop['value']))
else:
# kw in full is touched, conflicts with value in partial,
# but value in partial is recommended, not required, no change
pass
else:
# kw in full is touched, but in agreement with value in partial, no change
pass
else:
# If kw in full is untouched, overwrite it with value in partial
full[module][kw]['value'] = kwprop['value']
full[module][kw]['has_changed'] = True
#print '@P4C4 Overwriting %s with %s' % (kw, kwprop['value'])
except KeyError as e: # not expected but want to trap
raise ValidationError("""Unexpected KeyError reconciling keywords: %s.""" % (repr(e)))
return full
def reconcile_options2(full, partial):
"""Function to take the full snapshot of the liboptions object
encoded in dictionary *full* and reconcile it with proposed options
value changes in *partial*. Overwrites *full* with *partial* if
option untouched, touches *full* if *full* and *partial* are in
agreement, balks if *full* and *partial* conflict. Returns *full*.
Note: this is surprisingly similar to reconcile_options except
that full is essentially empty and lacking in has_changed keys
so presence is enough to satisfy has_changed. consider merging
once mature.
"""
try:
for module, modopts in partial.items():
for kw, kwprop in modopts.items():
#if full[module][kw]['has_changed']:
if full[module][kw]:
if full[module][kw]['value'] != kwprop['value']:
if 'clobber' in kwprop and kwprop['clobber']:
if 'superclobber' in kwprop and kwprop['superclobber']:
# kw in full is touched, conflicts with value in partial,
# but value in partial is paramount, overwrite full with
# value in partial
full[module][kw]['value'] = kwprop['value']
full[module][kw]['has_changed'] = True
#print '@P4C4 Overwriting %s with %s' % (kw, kwprop['value'])
else:
raise ValidationError("""
Option %s value `%s` set by options block incompatible with
value `%s` in memory/molecule/command/psi4options block.""" %
(kw, full[module][kw]['value'], kwprop['value']))
else:
# kw in full is touched, conflicts with value in partial,
# but value in partial is recommended, not required, no change
pass
else:
# kw in full is touched, but in agreement with value in partial, no change
pass
else:
# If kw in full is absent, overwrite it with value in partial
full[module][kw]['value'] = kwprop['value']
full[module][kw]['has_changed'] = True
#print '@P4C4 Overwriting %s with %s' % (kw, kwprop['value'])
except KeyError as e: # not expected but want to trap
raise ValidationError("""Unexpected KeyError reconciling keywords: %s.""" % (repr(e)))
return full
def conv_float2negexp(val):
"""Returns the least restrictive negative exponent of the power 10
that would achieve the floating point convergence criterium *val*.
"""
return -1 * int(math.floor(math.log(val, 10)))
|