def load(filename_or_basisname, symb, optimize=OPTIMIZE_CONTRACTION): '''Convert the basis of the given symbol to internal format Args: filename_or_basisname : str Case insensitive basis set name. Special characters will be removed. or a string of "path/to/file" which stores the basis functions symb : str Atomic symbol, Special characters will be removed. Examples: Load STO 3G basis of carbon to oxygen atom >>> mol = gto.Mole() >>> mol.basis = {'O': load('sto-3g', 'C')} ''' symb = ''.join([i for i in symb if i.isalpha()]) if os.path.isfile(filename_or_basisname): # read basis from given file try: return parse_nwchem.load(filename_or_basisname, symb, optimize) except RuntimeError: with open(filename_or_basisname, 'r') as fin: return parse_nwchem.parse(fin.read(), symb) name = _format_basis_name(filename_or_basisname) if not (name in ALIAS or _is_pople_basis(name)): try: return parse_nwchem.parse(filename_or_basisname, symb) except KeyError: try: return parse_nwchem.parse(filename_or_basisname) except IndexError: raise KeyError('Invalid basis name %s' % filename_or_basisname) except IndexError: raise KeyError('Basis %s not found' % filename_or_basisname) if name in ALIAS: basmod = ALIAS[name] elif _is_pople_basis(name): basmod = _parse_pople_basis(name, symb) else: raise RuntimeError('Basis %s not found' % filename_or_basisname) if 'dat' in basmod: b = parse_nwchem.load(os.path.join(_BASIS_DIR, basmod), symb, optimize) elif isinstance(basmod, (tuple, list)) and isinstance(basmod[0], str): b = [] for f in basmod: b += parse_nwchem.load(os.path.join(_BASIS_DIR, f), symb, optimize) else: if sys.version_info < (2, 7): fp, pathname, description = imp.find_module(basmod, __path__) mod = imp.load_module(name, fp, pathname, description) b = mod.__getattribute__(symb) fp.close() else: mod = importlib.import_module('.' + basmod, __package__) b = mod.__getattribute__(symb) return b
def load(filename_or_basisname, symb): '''Convert the basis of the given symbol to internal format Args: filename_or_basisname : str Case insensitive basis set name. Special characters will be removed. or a string of "path/to/file" which stores the basis functions symb : str Atomic symbol, Special characters will be removed. Examples: Load STO 3G basis of carbon to oxygen atom >>> mol = gto.Mole() >>> mol.basis = {'O': load('sto-3g', 'C')} ''' if os.path.isfile(filename_or_basisname): # read basis from given file return parse_nwchem.load(filename_or_basisname, symb) name = filename_or_basisname.lower().replace(' ', '').replace('-', '').replace('_', '') basmod = ALIAS[name] symb = ''.join([i for i in symb if i.isalpha()]) if 'dat' in basmod: b = parse_nwchem.load(os.path.join(os.path.dirname(__file__), basmod), symb) else: fp, pathname, description = imp.find_module(basmod, __path__) mod = imp.load_module(name, fp, pathname, description) #mod = __import__(basmod, globals={'__path__': __path__, '__name__': __name__}) b = mod.__getattribute__(symb) fp.close() return b
def load(filename_or_basisname, symb): '''Convert the basis of the given symbol to internal format Args: filename_or_basisname : str Case insensitive basis set name. Special characters will be removed. or a string of "path/to/file" which stores the basis functions symb : str Atomic symbol, Special characters will be removed. Examples: Load STO 3G basis of carbon to oxygen atom >>> mol = gto.Mole() >>> mol.basis = {'O': load('sto-3g', 'C')} ''' if os.path.isfile(filename_or_basisname): # read basis from given file try: return parse_nwchem.load(filename_or_basisname, symb) except RuntimeError: with open(filename_or_basisname, 'r') as fin: return parse_nwchem.parse(fin.read()) name = filename_or_basisname.lower().replace(' ', '').replace('-', '').replace( '_', '') if name not in ALIAS: try: return parse(filename_or_basisname) except IndexError: raise RuntimeError('basis %s not found' % filename_or_basisname) basmod = ALIAS[name] symb = ''.join([i for i in symb if i.isalpha()]) if 'dat' in basmod: b = parse_nwchem.load(os.path.join(os.path.dirname(__file__), basmod), symb) else: if sys.version_info < (2, 7): fp, pathname, description = imp.find_module(basmod, __path__) mod = imp.load_module(name, fp, pathname, description) b = mod.__getattribute__(symb) fp.close() else: mod = importlib.import_module('.' + basmod, __package__) b = mod.__getattribute__(symb) return b
def load(filename_or_basisname, symb): '''Convert the basis of the given symbol to internal format Args: filename_or_basisname : str Case insensitive basis set name. Special characters will be removed. or a string of "path/to/file" which stores the basis functions symb : str Atomic symbol, Special characters will be removed. Examples: Load STO 3G basis of carbon to oxygen atom >>> mol = gto.Mole() >>> mol.basis = {'O': load('sto-3g', 'C')} ''' if os.path.isfile(filename_or_basisname): # read basis from given file try: return parse_nwchem.load(filename_or_basisname, symb) except RuntimeError: with open(filename_or_basisname, 'r') as fin: return parse_nwchem.parse(fin.read()) name = filename_or_basisname.lower().replace(' ', '').replace('-', '').replace('_', '') if name not in ALIAS: return parse(filename_or_basisname) basmod = ALIAS[name] symb = ''.join([i for i in symb if i.isalpha()]) if 'dat' in basmod: b = parse_nwchem.load(os.path.join(os.path.dirname(__file__), basmod), symb) else: if sys.version_info < (2,7): fp, pathname, description = imp.find_module(basmod, __path__) mod = imp.load_module(name, fp, pathname, description) b = mod.__getattribute__(symb) fp.close() else: mod = importlib.import_module('.'+basmod, __package__) b = mod.__getattribute__(symb) return b
def load(filename_or_basisname, symb, optimize=OPTIMIZE_CONTRACTION): '''Convert the basis of the given symbol to internal format Args: filename_or_basisname : str Case insensitive basis set name. Special characters will be removed. or a string of "path/to/file" which stores the basis functions symb : str Atomic symbol, Special characters will be removed. Examples: Load STO 3G basis of carbon to oxygen atom >>> mol = gto.Mole() >>> mol.basis = {'O': load('sto-3g', 'C')} ''' symb = ''.join([i for i in symb if i.isalpha()]) if os.path.isfile(filename_or_basisname): # read basis from given file try: return parse_nwchem.load(filename_or_basisname, symb, optimize) except RuntimeError: with open(filename_or_basisname, 'r') as fin: return parse_nwchem.parse(fin.read(), symb) name = _format_basis_name(filename_or_basisname) if '@' in name: split_name = name.split('@') assert len(split_name) == 2 name = split_name[0] contr_scheme = _convert_contraction(split_name[1]) else: contr_scheme = 'Full' if not (name in ALIAS or _is_pople_basis(name)): try: return parse_nwchem.parse(filename_or_basisname, symb) except KeyError: try: return parse_nwchem.parse(filename_or_basisname) except IndexError: raise KeyError('Invalid basis name %s' % filename_or_basisname) except IndexError: raise KeyError('Basis %s not found' % filename_or_basisname) if name in ALIAS: basmod = ALIAS[name] elif _is_pople_basis(name): basmod = _parse_pople_basis(name, symb) else: raise RuntimeError('Basis %s not found' % filename_or_basisname) if 'dat' in basmod: b = parse_nwchem.load(os.path.join(_BASIS_DIR, basmod), symb, optimize) elif isinstance(basmod, (tuple, list)) and isinstance(basmod[0], str): b = [] for f in basmod: b += parse_nwchem.load(os.path.join(_BASIS_DIR, f), symb, optimize) else: if sys.version_info < (2,7): fp, pathname, description = imp.find_module(basmod, __path__) mod = imp.load_module(name, fp, pathname, description) b = mod.__getattribute__(symb) fp.close() else: mod = importlib.import_module('.'+basmod, __package__) b = mod.__getattribute__(symb) if contr_scheme != 'Full': b = _truncate(b, contr_scheme, symb, split_name) return b