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
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#***********************************************************************
# This file is part of OpenMolcas. *
# *
# OpenMolcas is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Lesser General Public License, v. 2.1. *
# OpenMolcas is distributed in the hope that it will be useful, but it *
# is provided "as is" and without any express or implied warranties. *
# For more details see the full text of the license in the file *
# LICENSE or in <http://www.gnu.org/licenses/>. *
# *
# Copyright (C) 2022, Ignacio Fdez. Galván *
#***********************************************************************
import sys
from os.path import join
from os import environ
try:
from colorama import init, Fore, Style
except ImportError:
def init(*args, **kwargs):
pass
class Dummy(object):
pass
Fore = Dummy()
Fore.RED = ''
Fore.BLUE = ''
Fore.GREEN = ''
Style = Dummy()
Style.RESET_ALL = ''
helptext = '''
{1}################################################################################
# Density functionals in OpenMolcas #
################################################################################{0}
Use with a command-line argument that is a basis label in Molcas format:
{2}[element].[name].[author].[primitives].[contraction].[aux. labels]*
(1) (2) (3) (4) (5) (6){0}
trailing dots can be omitted.
Examples:
In the simplest form, just write an element symbol to get a list of basis sets
for that element:
{3}Fe{0} lists all basis sets for iron
Additional fields can be included to restrict the search:
{3}Fe..jensen{0} lists all basis sets for iron, with "jensen" in the author
field (case insensitive)
{3}Fe.....ECP{0} lists all basis sets for silver that use ECP
Wildcards are supported:
{3}Fe.*cc-p*v?z*{0} lists all basis sets for iron belonging to the "cc" families
A single space matches empty fields (needs quotes):
{3}"Fe..... ."{0} lists all basis sets for silver with an empty 6th field
(probably all-electron)
Minimum number of functions for ANO-type basis sets can be specified:
{3}Fe....8s7p7d4f{0} lists all basis sets for iron with a [8s7p7d4f] contraction or
larger if the basis set supports using fewer functions
Exact matches are printed in green, "fuzzy" matches in red
'''.format(Style.RESET_ALL, Fore.BLUE, Fore.RED, Fore.GREEN)
compat = False
try:
flag = sys.argv[1]
except IndexError:
flag = None
pass
if (flag == '-bw'):
sys.argv.pop(1)
compat = True
# First get the template from the command line,
# Use colors in terminal, not if output is redirected to file
if (sys.stdout.isatty() and not compat):
init()
else:
init(strip=True)
try:
MOLCAS = environ['MOLCAS']
except KeyError:
MOLCAS = '.'
funcs = {}
n = 0
name = ''
with open(join(MOLCAS, 'data', 'functionals.txt'), 'r') as f:
for l in f:
if l.strip().startswith('#') or (len(l.strip()) == 0):
continue
parts = l.split()
if n == 0:
name = parts[0]
try:
n = int(parts[1])
funcs[name] = []
except ValueError:
funcs[name] = [[1.0, parts[1]]]
else:
parts = l.split()
coeff = float(parts[0])
label = parts[1].upper()
funcs[name].append([coeff, label])
n -= 1
try:
name = sys.argv[1].upper()
for k in funcs.keys():
if k.upper() == name:
print(f'\nDefinition of {Fore.GREEN}{k}{Style.RESET_ALL}:\n')
print(f'{Fore.BLUE}factor Libxc name{Style.RESET_ALL}')
print(f'{Fore.BLUE}====== =========={Style.RESET_ALL}')
for i in funcs[k]:
if i[1] == 'HF_X':
print(f'{i[0]:6.4f} exact exchange')
else:
print(f'{i[0]:6.4f} {Fore.RED}{i[1]}{Style.RESET_ALL}')
break
else:
print(f'\nFunctional {Fore.RED}{name}{Style.RESET_ALL} not found')
except IndexError:
print(f'{Fore.BLUE}################################################################################')
print('# Density functionals in OpenMolcas #')
print(f'################################################################################{Style.RESET_ALL}')
print('')
print('Specify the functional name as an argument to see its definition')
print('(in terms of Libxc functionals)')
print('')
for k in sorted(funcs.keys(), key=lambda x: x.upper()):
print(f' {Fore.GREEN}{k}{Style.RESET_ALL}')
|