def run_bse_cli(): ################################################################################################ # NOTE: I am deliberately not using the 'choices' argument in add_argument. I could use it # for formats, etc, however I wouldn't want to use it for basis set names. Therefore, I handle # all of that manually so that error output is consistent and clean ################################################################################################ ######################################## # Main global options ######################################## parser = argparse.ArgumentParser(description='Description of your program') parser.add_argument('-V', action='version', version='basis_set_exchange ' + version()) parser.add_argument('-d', '--data-dir', metavar='PATH', help='Override which data directory to use') parser.add_argument('-o', '--output', metavar='PATH', help='Output to given file rather than stdout') subparsers = parser.add_subparsers(metavar='subcommand', dest='subcmd') subparsers.required = True # https://bugs.python.org/issue9253#msg186387 ######################################## # Listing of data-independent info ######################################## # list-formats subcommand subp = subparsers.add_parser( 'list-formats', help= 'Output a list of basis set formats that can be used with obtaining a basis set' ) subp.add_argument('-n', '--no-description', action='store_true', help='Print only the format names') # list-writer-formats subcommand subp = subparsers.add_parser( 'list-writer-formats', help='Output a list available basis set formats that can be written') subp.add_argument('-n', '--no-description', action='store_true', help='Print only the format names') # list-reader-formats subp = subparsers.add_parser( 'list-reader-formats', help='Output a list of basis set formats that can be read') subp.add_argument('-n', '--no-description', action='store_true', help='Print only the format names') # list-ref-formats subcommand subp = subparsers.add_parser( 'list-ref-formats', help='Output a list all available reference formats and descriptions') subp.add_argument('-n', '--no-description', action='store_true', help='Print only the reference format names') # list-roles subcommand subp = subparsers.add_parser( 'list-roles', help='Output a list all available roles and descriptions') subp.add_argument('-n', '--no-description', action='store_true', help='Print only the role names') ######################################## # Listing of general info and metadata ######################################## # get-data-dir subparsers.add_parser( 'get-data-dir', help='Output the default data directory of this package') # list-basis-sets subcommand subp = subparsers.add_parser( 'list-basis-sets', help='Output a list all available basis sets and descriptions') subp.add_argument('-n', '--no-description', action='store_true', help='Print only the basis set names') subp.add_argument( '-f', '--family', help='Limit the basis set list to only the specified family' ).completer = cli_family_completer subp.add_argument( '-r', '--role', help='Limit the basis set list to only the specified role' ).completer = cli_role_completer subp.add_argument( '-s', '--substr', help= 'Limit the basis set list to only basis sets whose name contains the specified substring' ) subp.add_argument( '-e', '--elements', help= 'Limit the basis set list to only basis sets that contain all the given elements' ) # list-families subcommand subparsers.add_parser( 'list-families', help='Output a list all available basis set families') # lookup-by-role subp = subparsers.add_parser( 'lookup-by-role', help='Lookup a companion/auxiliary basis by primary basis and role') subp.add_argument( 'basis', help='Name of the primary basis we want the auxiliary basis for' ).completer = cli_bsname_completer subp.add_argument('role', help='Role of the auxiliary basis to look for' ).completer = cli_role_completer ################################# # Output of info ################################# # get-basis subcommand subp = subparsers.add_parser('get-basis', help='Output a formatted basis set') subp.add_argument('basis', help='Name of the basis set to output' ).completer = cli_bsname_completer subp.add_argument('fmt', help='Which format to output the basis set as' ).completer = cli_write_fmt_completer subp.add_argument( '--elements', help= 'Which elements of the basis set to output. Default is all defined in the given basis' ) subp.add_argument( '--version', help= 'Which version of the basis set to output. Default is the latest version' ) subp.add_argument('--noheader', action='store_true', help='Do not output the header at the top') subp.add_argument('--unc-gen', action='store_true', help='Remove general contractions') subp.add_argument('--unc-spdf', action='store_true', help='Remove combined sp, spd, ... contractions') subp.add_argument('--unc-seg', action='store_true', help='Remove general contractions') subp.add_argument('--rm-free', action='store_true', help='Remove free primitives') subp.add_argument('--opt-gen', action='store_true', help='Optimize general contractions') subp.add_argument( '--make-gen', action='store_true', help='Make the basis set as generally-contracted as possible') subp.add_argument('--aug-steep', type=int, default=0, help='Augment with n steep functions') subp.add_argument('--aug-diffuse', type=int, default=0, help='Augment with n diffuse functions') subp.add_argument( '--get-aux', type=int, default=0, help= 'Instead of the orbital basis, get an automatically formed auxiliary basis' ) # get-refs subcommand subp = subparsers.add_parser('get-refs', help='Output references for a basis set') subp.add_argument('basis', help='Name of the basis set to output the references for' ).completer = cli_bsname_completer subp.add_argument('reffmt', help='Which format to output the references as' ).completer = cli_reffmt_completer subp.add_argument( '--elements', help= 'Which elements to output the references for. Default is all defined in the given basis.' ) subp.add_argument( '--version', help='Which version of the basis set to get the references for') # get-info subcommand subp = subparsers.add_parser( 'get-info', help='Output general info and metadata for a basis set') subp.add_argument('basis', help='Name of the basis set to output the info for' ).completer = cli_bsname_completer # get-notes subcommand subp = subparsers.add_parser('get-notes', help='Output the notes for a basis set') subp.add_argument('basis', help='Name of the basis set to output the notes for' ).completer = cli_bsname_completer # get-family subcommand subp = subparsers.add_parser('get-family', help='Output the family of a basis set') subp.add_argument('basis', help='Name of the basis set to output the family for' ).completer = cli_bsname_completer # get-versions subcommand subp = subparsers.add_parser( 'get-versions', help='Output a list all available versions of a basis set') subp.add_argument('basis', help='Name of the basis set to list the versions of' ).completer = cli_bsname_completer subp.add_argument('-n', '--no-description', action='store_true', help='Print only the version numbers') # get-family-notes subcommand subp = subparsers.add_parser( 'get-family-notes', help='Get the notes of a family of basis sets') subp.add_argument('family', type=str.lower, help='The basis set family to the get the notes of' ).completer = cli_family_completer ################################# # Converting basis sets ################################# subp = subparsers.add_parser( 'convert-basis', help='Convert basis set files from one format to another') subp.add_argument('input_file', type=str, help='Basis set file to convert') subp.add_argument('output_file', type=str, help='Converted basis set file') subp.add_argument( '--in-fmt', type=str, default=None, help='Input format (default: autodetected from input filename' ).completer = cli_read_fmt_completer subp.add_argument( '--out-fmt', type=str, default=None, help='Output format (default: autodetected from output filename' ).completer = cli_write_fmt_completer subp.add_argument( '--make-gen', action='store_true', help='Make the basis set as generally-contracted as possible') ################################# # Auxiliary basis sets ################################# subp = subparsers.add_parser('autoaux-basis', help='Form AutoAux auxiliary basis') subp.add_argument('input_file', type=str, help='Orbital basis to load') subp.add_argument('output_file', type=str, help='AutoAux basis to write') subp.add_argument( '--in-fmt', type=str, default=None, help='Input format (default: autodetected from input filename' ).completer = cli_read_fmt_completer subp.add_argument( '--out-fmt', type=str, default=None, help='Output format (default: autodetected from output filename' ).completer = cli_write_fmt_completer subp = subparsers.add_parser('autoabs-basis', help='Form AutoABS auxiliary basis') subp.add_argument('input_file', type=str, help='Orbital basis to load') subp.add_argument('output_file', type=str, help='AutoABS basis to write') subp.add_argument( '--in-fmt', type=str, default=None, help='Input format (default: autodetected from input filename' ).completer = cli_read_fmt_completer subp.add_argument( '--out-fmt', type=str, default=None, help='Output format (default: autodetected from output filename' ).completer = cli_write_fmt_completer ################################# # Creating bundles ################################# subp = subparsers.add_parser('create-bundle', help='Create a bundle of basis sets') subp.add_argument('fmt', help='Which format to output the basis set as' ).completer = cli_write_fmt_completer subp.add_argument('reffmt', help='Which format to output the references as' ).completer = cli_reffmt_completer subp.add_argument('bundle_file', help='Bundle/Archive file to create') subp.add_argument( '--archive-type', help='Override the type of archive to create (zip or tbz)') ############################# # DONE WITH SUBCOMMANDS ############################# # setup autocomplete argcomplete.autocomplete(parser, validator=cli_case_insensitive_validator) # Now parse and handle the args args = parser.parse_args() # Check and make sure basis sets, roles, etc, are valid args = cli_check_normalize_args(args) # Actually generate the output output = bse_cli_handle_subcmd(args) if args.output: with open(args.output, 'w', encoding='utf-8') as outfile: outfile.write(output) else: print(output) return 0
def run_bsecurate_cli(): ################################################################################################ # NOTE: I am deliberately not using the 'choices' argument in add_argument. I could use it # for formats, etc, however I wouldn't want to use it for basis set names. Therefore, I handle # all of that manually so that error output is consistent and clean ################################################################################################ ######################################## # Main global options ######################################## parser = argparse.ArgumentParser(description='Description of your program') parser.add_argument('-V', action='version', version='basis_set_exchange ' + version()) parser.add_argument('-d', '--data-dir', metavar='PATH', help='Override which data directory to use') parser.add_argument('-o', '--output', metavar='PATH', help='Output to given file rather than stdout') subparsers = parser.add_subparsers(metavar='subcommand', dest='subcmd') subparsers.required = True # https://bugs.python.org/issue9253#msg186387 ######################################## # Listing of general info and metadata ######################################## # elements-in-files subp = subparsers.add_parser( 'elements-in-files', help='For a list of JSON files, output what elements are in each file') subp.add_argument('files', nargs='+', help='List of files to inspect') # elements-in-files subp = subparsers.add_parser( 'component-file-refs', help= 'For a list of component JSON files, output what elements/references are in each file' ) subp.add_argument('files', nargs='+', help='List of files to inspect') ######################################## # Updating metadata ######################################## subparsers.add_parser('update-metadata', help='Update the metadata in the repository') ######################################## # Printing data ######################################## subp = subparsers.add_parser( 'print-component-file', help='(Pretty) print the contents of a component file') subp.add_argument('file', help='File to print') subp.add_argument( '--elements', help= 'Which elements of the basis set to output. Default is all defined in the given basis' ) ######################################## # Manipulating basis set data ######################################## # make-diff subp = subparsers.add_parser( 'make-diff', help='Find/Store the differences between two groups of files') subp.add_argument('-l', '--left', nargs='+', required=True, help='Base JSON files') subp.add_argument( '-r', '--right', nargs='+', required=True, help='JSON files with data to subtract from the base files') ######################################## # Comparing ######################################## # compare-basis-sets subp = subparsers.add_parser( 'compare-basis-sets', help='Compare two basis sets in the data directory') subp.add_argument( 'basis1', help='First basis set to compare').completer = cli_bsname_completer subp.add_argument( 'basis2', help='Second basis set to compare').completer = cli_bsname_completer subp.add_argument( '--version1', help='Version of the first basis set to compare with. Default is latest' ) subp.add_argument( '--version2', help= 'Version of the second basis set to compare with. Default is latest') subp.add_argument('--uncontract-general', action='store_true', help='Remove general contractions before comparing') # compare-basis-files subp = subparsers.add_parser('compare-basis-files', help='Compare two formatted basis set files') subp.add_argument('file1', help='First basis set file to compare') subp.add_argument('file2', help='Second basis set file to compare') subp.add_argument('--readfmt1', help='Override the file format of file 1' ).completer = cli_readerfmt_completer subp.add_argument('--readfmt2', help='Override the file format of file 2' ).completer = cli_readerfmt_completer subp.add_argument('--uncontract-general', action='store_true', help='Remove general contractions before comparing') # compare-basis-to-file subp = subparsers.add_parser( 'compare-basis-to-file', help='Compare basis set in data directory to file') subp.add_argument('basis', help='Basis set to compare') subp.add_argument('file', help='Basis set file to compare to') subp.add_argument( '--readfmt', help='Override the file format').completer = cli_readerfmt_completer subp.add_argument( '--version', help='Version of the basis set to compare with. Default is latest') subp.add_argument('--uncontract-general', action='store_true', help='Remove general contractions before comparing') ######################################## # Making graphs ######################################## # view-graph subp = subparsers.add_parser('view-graph', help='View a file graph for a basis set') subp.add_argument( 'basis', help='Name of the basis set inspect').completer = cli_bsname_completer subp.add_argument( '--version', help= 'Which version of the basis set to inspect. Default is the latest version' ) # make-graph-file subp = subparsers.add_parser( 'make-graph-file', help='Make a dot file (and png file) for a basis set file graph') subp.add_argument( 'basis', help='Name of the basis set inspect').completer = cli_bsname_completer subp.add_argument('outfile', help='Output DOT file to create') subp.add_argument('--render', action='store_true', help='Render the DOT file into a corresponding png file') subp.add_argument( '--version', help= 'Which version of the basis set to inspect. Default is the latest version' ) ############################# # DONE WITH SUBCOMMANDS ############################# # setup autocomplete argcomplete.autocomplete(parser, validator=cli_case_insensitive_validator) # Now parse and handle the args args = parser.parse_args() # Check and make sure basis sets, roles, etc, are valid args = cli_check_normalize_args(args) # Actually generate the output output = bsecurate_cli_handle_subcmd(args) if args.output: with open(args.output, 'w', encoding='utf-8') as outfile: outfile.write(output) elif output: # Don't print if output is empty print(output) return 0
#get version and list of elements version_bs = md[bas_name]['latest_version'] elements_list = md[bas_name]['versions'][version_bs]['elements'] #open file # get rid of asterisks file_name = bas_name.replace("*", "s") #get rid of parenthesis file_name = file_name.replace("(", "") file_name = file_name.replace(")", "") #replace commas with underscore file_name = file_name.replace(",", "_") #replace whitespace with underscore file_name = file_name.replace(" ", "_") print(' file name is ' + file_name + "\n") output_file = open(file_name, 'w') output_file.write('# BSE Version ' + bse.version() + '\n') output_file.write('# Data downloaded at ' + today + '\n') output_file.write('# ' + bas_name + ' version number ' + version_bs + '\n') output_file.write('# Description: ' + md[bas_name]['description'] + '\n') output_file.write('# Role: ' + md[bas_name]['role'] + '\n') output_file.write( '# ' + bse.get_references(bas_name, fmt='txt').replace('\n', '\n# ')) output_file.write('# \n') for element in elements_list: #element='h' try: bs_str = bse.get_basis(bas_name, header=False, elements=element, fmt='nwchem', optimize_general=True)
def writebs(md, bas_name, summary_file, get_aux=0): md_bas_name = bas_name.lower() md_bas_name = md_bas_name.replace("*", "_st_") md_bas_name = md_bas_name.replace("/", "_sl_") print(' md_bas_name ' + md_bas_name + "\n") print(' bas_name ' + bas_name + "\n") version_bs = md[md_bas_name]['latest_version'] elements_list = md[md_bas_name]['versions'][version_bs]['elements'] #open file # get rid of asterisks file_name = bas_name.replace("*", "s") #get rid of parenthesis file_name = file_name.replace("(", "") file_name = file_name.replace(")", "") #replace commas with underscore file_name = file_name.replace(",", "_") #replace whitespace with underscore file_name = file_name.replace(" ", "_") #replace forward slash with underscore file_name = file_name.replace("/", "_") #lowercase file_name = file_name.lower() if get_aux == 1: file_name = file_name + "-autoaux" print(' file name is ' + file_name + "\n") output_file = open(file_name, 'w') output_file.write('# BSE Version ' + bse.version() + '\n') output_file.write('# Data downloaded on ' + today + '\n') if get_aux == 0: output_file.write('# ' + bas_name + ' version number ' + version_bs + '\n') output_file.write('# Description: ' + md[md_bas_name]['description'] + '\n') output_file.write('# Role: ' + md[md_bas_name]['role'] + '\n') output_file.write( '# ' + bse.get_references(bas_name, fmt='txt').replace('\n', '\n# ')) output_file.write('# \n') elif get_aux == 1: output_file.write('# ' + bas_name + ' version number ' + version_bs + ' AutoAux \n') output_file.write('# Role: JK Fitting \n') output_file.write( '# Stoychev GL, Auer AA, Neese F. \n# Automatic Generation of Auxiliary Basis Sets.\n# J Chem Theory Comput. 2017 Feb 14;13(2):554-562.\n# doi: 10.1021/acs.jctc.6b01041.\n' ) output_file.write('# \n') n_elements = 0 for element in elements_list: n_elements = n_elements + 1 if get_aux == 1: summary_file.write('Basis set \"' + bas_name + '-autoaux\" (number of atoms ' + str(n_elements) + ')\n') else: summary_file.write('Basis set \"' + bas_name + '\" (number of atoms ' + str(n_elements) + ')\n') for element in elements_list: #element='h' try: bs_str = bse.get_basis(bas_name, header=False, elements=element, fmt='nwchem', optimize_general=True, uncontract_general=True, get_aux=get_aux) except: # print("failed for"+element) pass else: bs_str = bs_str.replace("BASIS", "basis") bs_str = bs_str.replace("END", "end") bs_str = bs_str.replace("PRINT", "") element_str = bse.misc.compact_elements([element]) if get_aux == 1: bs_str = bs_str.replace( "ao basis", element_str + "_" + bas_name + "-autoaux") else: bs_str = bs_str.replace("ao basis", element_str + "_" + bas_name) #ECP bs_str = bs_str.replace( "ECP", "ecp \"" + element_str + "_" + bas_name + "\"") output_file.write(bs_str) # print(bas_name + " " + element_str) return