<jupyter_start><jupyter_text>Demo on how to use Basis-Set-Exchange library to interconvert between Basis Set formats of various QC softwares  The following imports the library and returns the list of basis set dictionaries available in the library for pob-tzvp. Unfortunately not all the elements provided on the Crystal website are available in this list.<jupyter_code>import basis_set_exchange as bse
print(bse.api.get_basis('pob-tzvp'))<jupyter_output>{'molssi_bse_schema': {'schema_type': 'complete', 'schema_version': '0.1'}, 'revision_description': "Data from Bredow's web site", 'revision_date': '2020-11-05', 'elements': {'1': {'electron_shells': [{'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['34.061341000', '5.1235746000', '1.1646626000'], 'coefficients': [['0.00602519780', '0.04502109400', '0.20189726000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['0.4157455100'], 'coefficients': [['1.00000000000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['0.1795111000'], 'coefficients': [['1.00000000000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [1], 'exponents': ['0.8000000000'], 'coefficients': [['1.00000000000']]}], 'references': [{'reference_description': 'pob-TZVP', 'reference_keys': ['Peintinger2013a']}]}, '3': {'electron_shells': [{'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['[...]<jupyter_text>The following returns the Basis set dictionary in BSE format for Carbon pob-TZVP-rev2<jupyter_code>bse.api.get_basis('pob-tzvp-rev2', elements='C')<jupyter_output><empty_output><jupyter_text>The following returns the Basis set formatted string in Turbomole format for Carbon pob-TZVP-rev2 from the library. Note: Not all elements from Crystal website are available this way.<jupyter_code>turbomole_pob_tzvp_rev2 = bse.api.get_basis(name='pob-tzvp-rev2', elements='C', fmt='turbomole')
print(turbomole_pob_tzvp_rev2)<jupyter_output>#----------------------------------------------------------------------
# Basis Set Exchange
# Version 0+unknown
# https://www.basissetexchange.org
#----------------------------------------------------------------------
#   Basis set: pob-TZVP-rev2
# Description: pob-TZVP-rev2
#        Role: orbital
#     Version: 1  (Data from Bredow's web site)
#----------------------------------------------------------------------


$basis
*
c pob-TZVP-rev2
*
    6   s
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
    2   s
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
    1   s
      0.4941102000           1.00000000000000
    1   s
      0.1644071000           1.00000000000000
    4   p
     34.697232244            0.005333365[...]<jupyter_text>The following is same as above, but without the header of BSSE<jupyter_code>turbomole_pob_tzvp_rev2 = bse.api.get_basis(name='pob-tzvp', elements='C', fmt='turbomole',header=False)
print(turbomole_pob_tzvp_rev2)<jupyter_output>$basis
*
c pob-TZVP
*
    6   s
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
    2   s
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
    1   s
      0.4941102000           1.00000000000000
    1   s
      0.1644071000           1.00000000000000
    4   p
     34.697232244            0.00533336578050
      7.9582622826           0.03586410909200
      2.3780826883           0.14215873329000
      0.8143320818           0.34270471845000
    1   p
      0.5662417100           1.00000000000000
    1   p
      0.2673545000           1.00000000000000
    1   d
      0.8791584200           1.00000000000000
*
$end<jupyter_text>The following is same as above, but this time we get the output in crystal format<jupyter_code>crystal_pob_tzvp_rev2 = bse.api.get_basis(name='pob-tzvp', elements='C', fmt='crystal',header=False)
print(crystal_pob_tzvp_rev2)<jupyter_output>6 8
0 0 6 0 1.0
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
0 0 2 0 1.0
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
0 0 1 0 1.0
      0.4941102000           1.00000000000000
0 0 1 0 1.0
      0.1644071000           1.00000000000000
0 2 4 0 1.0
     34.697232244            0.00533336578050
      7.9582622826           0.03586410909200
      2.3780826883           0.14215873329000
      0.8143320818           0.34270471845000
0 2 1 0 1.0
      0.5662417100           1.00000000000000
0 2 1 0 1.0
      0.2673545000           1.00000000000000
0 3 1 0 1.0
      0.8791584200           1.00000000000000
99 0<jupyter_text>ConversionWhile, the above functions seem to work well, they are not what we really want. Because they require the basis set to have already been added to the library. But what if some basis sets are not already in the library, or someone doesn't know the name or just a have a basis set file. In that case we should provide a way to convert the provided string to a given format.  Example 1:The following is a multiline string of Carbon pob-TZVP basis set in the Crystal format.<jupyter_code>C_pob_TZVP = '''
6 8
0 0 6 2.0 1.0
  13575.349682      0.00022245814352
  2035.2333680      0.00172327382520
  463.22562359      0.00892557153140
  131.20019598      0.03572798450200
  42.853015891      0.11076259931000
  15.584185766      0.24295627626000
0 0 2 2.0 1.0
  6.2067138508      0.41440263448000
  2.5764896527      0.23744968655000
0 0 1 0.0 1.0
  0.4941102000      1.00000000000000
0 0 1 0.0 1.0
  0.1644071000      1.00000000000000
0 2 4 2.0 1.0
  34.697232244      0.00533336578050
  7.9582622826      0.03586410909200
  2.3780826883      0.14215873329000
  0.8143320818      0.34270471845000
0 2 1 0.0 1.0
  0.5662417100      1.00000000000000
0 2 1 0.0 1.0
  0.1973545000      1.00000000000000
0 3 1 0.0 1.0
  0.5791584200      1.00000000000000
'''
## Remove any empty lines from the user enter basis set strings
import os
C_pob_TZVP = os.linesep.join([s for s in C_pob_TZVP.splitlines() if s])
# Basis set formatted string without empty lines
print(C_pob_TZVP)

# Parse the processed list of basis set lines (use .splitlines)
basis_read_from_crystal_format = bse.readers.crystal.read_crystal(C_pob_TZVP.splitlines())
print(basis_read_from_crystal_format)<jupyter_output>6 8
0 0 6 2.0 1.0
  13575.349682      0.00022245814352
  2035.2333680      0.00172327382520
  463.22562359      0.00892557153140
  131.20019598      0.03572798450200
  42.853015891      0.11076259931000
  15.584185766      0.24295627626000
0 0 2 2.0 1.0
  6.2067138508      0.41440263448000
  2.5764896527      0.23744968655000
0 0 1 0.0 1.0
  0.4941102000      1.00000000000000
0 0 1 0.0 1.0
  0.1644071000      1.00000000000000
0 2 4 2.0 1.0
  34.697232244      0.00533336578050
  7.9582622826      0.03586410909200
  2.3780826883      0.14215873329000
  0.8143320818      0.34270471845000
0 2 1 0.0 1.0
  0.5662417100      1.00000000000000
0 2 1 0.0 1.0
  0.1973545000      1.00000000000000
0 3 1 0.0 1.0
  0.5791584200      1.00000000000000
{'6': {'electron_shells': [{'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['13575.349682', '2035.2333680', '463.22562359', '131.20019598', '42.853015891', '15.584185766'], 'coefficients': [['0.0002224[...]<jupyter_text>In the above we get a basis set dictionary in the BSE format, however, this is not enough to convert to any other format as you will see below.<jupyter_code>basis_turbomole = bse.writers.turbomole.write_turbomole(basis_read_from_crystal_format)
print(basis_turbomole)<jupyter_output><empty_output><jupyter_text>We see that the previous code didn't work because the basis set dictionary was not exactly as expected byt the code.Similarly, the following won't work either.<jupyter_code>basis_turbomole = bse.writers.write.write_formatted_basis_str(basis_read_from_crystal_format, fmt='turbomole')<jupyter_output><empty_output><jupyter_text>In order to make it work, we should read the formatted string of basis set, without empty lines, in the following manner instead.This will return the correct dictionary in the BSE format.<jupyter_code># print(C_pob_TZVP)
basis_read_from_crystal_format = bse.readers.read.read_formatted_basis_str(C_pob_TZVP, basis_fmt='crystal')
print(basis_read_from_crystal_format)<jupyter_output>{'molssi_bse_schema': {'schema_type': 'minimal', 'schema_version': '0.1'}, 'elements': {'6': {'electron_shells': [{'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['13575.349682', '2035.2333680', '463.22562359', '131.20019598', '42.853015891', '15.584185766'], 'coefficients': [['0.00022245814352', '0.00172327382520', '0.00892557153140', '0.03572798450200', '0.11076259931000', '0.24295627626000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['6.2067138508', '2.5764896527'], 'coefficients': [['0.41440263448000', '0.23744968655000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['0.4941102000'], 'coefficients': [['1.00000000000000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['0.1644071000'], 'coefficients': [['1.00000000000000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [1], 'exponents': ['34.697232244', '7.9582622826', '2.3780826883', [...]<jupyter_text>Finally, the following is the correct way to convert to the turbomole format<jupyter_code>basis_turbomole = bse.writers.write.write_formatted_basis_str(basis_read_from_crystal_format, fmt='turbomole')
print(basis_turbomole)<jupyter_output>$basis
*
c unknown_basis
*
    6   s
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
    2   s
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
    1   s
      0.4941102000           1.00000000000000
    1   s
      0.1644071000           1.00000000000000
    4   p
     34.697232244            0.00533336578050
      7.9582622826           0.03586410909200
      2.3780826883           0.14215873329000
      0.8143320818           0.34270471845000
    1   p
      0.5662417100           1.00000000000000
    1   p
      0.1973545000           1.00000000000000
    1   d
      0.5791584200           1.00000000000000
*
$end<jupyter_text>The following is the list of writer formats available<jupyter_code>bse.writers.get_writer_formats()<jupyter_output><empty_output><jupyter_text>The following is the list of reader formats available<jupyter_code>bse.readers.get_reader_formats()
bse.writers.get_format_extension('turbomole')<jupyter_output><empty_output><jupyter_text>Example 2 Let us try to take a string of basis set in Turbomole format and convert it to Crystal now<jupyter_code>basis_turbomole_str = '''
$basis
*
c unknown_basis
*
    6   s
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
    2   s
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
    1   s
      0.4941102000           1.00000000000000
    1   s
      0.1644071000           1.00000000000000
    4   p
     34.697232244            0.00533336578050
      7.9582622826           0.03586410909200
      2.3780826883           0.14215873329000
      0.8143320818           0.34270471845000
    1   p
      0.5662417100           1.00000000000000
    1   p
      0.1973545000           1.00000000000000
    1   d
      0.5791584200           1.00000000000000
*
$end
'''<jupyter_output><empty_output><jupyter_text>Get the BSE dict<jupyter_code># remove empty lines
basis_turbomole_str = os.linesep.join([s for s in basis_turbomole_str.splitlines() if s])

basis_read_from_turbomole_format = bse.readers.read.read_formatted_basis_str(basis_turbomole_str, 'turbomole')
print(basis_read_from_turbomole_format)<jupyter_output>{'molssi_bse_schema': {'schema_type': 'minimal', 'schema_version': '0.1'}, 'elements': {'6': {'electron_shells': [{'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['13575.349682', '2035.2333680', '463.22562359', '131.20019598', '42.853015891', '15.584185766'], 'coefficients': [['0.00022245814352', '0.00172327382520', '0.00892557153140', '0.03572798450200', '0.11076259931000', '0.24295627626000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['6.2067138508', '2.5764896527'], 'coefficients': [['0.41440263448000', '0.23744968655000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['0.4941102000'], 'coefficients': [['1.00000000000000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [0], 'exponents': ['0.1644071000'], 'coefficients': [['1.00000000000000']]}, {'function_type': 'gto', 'region': '', 'angular_momentum': [1], 'exponents': ['34.697232244', '7.9582622826', '2.3780826883', [...]<jupyter_text>Convert to crystal<jupyter_code>basis_crystal_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='crystal')
print(basis_crystal_str)<jupyter_output>6 8
0 0 6 0 1.0
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
0 0 2 0 1.0
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
0 0 1 0 1.0
      0.4941102000           1.00000000000000
0 0 1 0 1.0
      0.1644071000           1.00000000000000
0 2 4 0 1.0
     34.697232244            0.00533336578050
      7.9582622826           0.03586410909200
      2.3780826883           0.14215873329000
      0.8143320818           0.34270471845000
0 2 1 0 1.0
      0.5662417100           1.00000000000000
0 2 1 0 1.0
      0.1973545000           1.00000000000000
0 3 1 0 1.0
      0.5791584200           1.00000000000000
99 0<jupyter_text>Now try converting to all available formats<jupyter_code>basis_psi4_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='psi4')
print('PSI4')
print(basis_psi4_str)
basis_orca_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='orca')
print('ORCA')
print(basis_orca_str)
basis_nwchem_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='nwchem')
print('NWChem')
print(basis_nwchem_str)
basis_g94_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='gaussian94')
print('Gaussian94')
print(basis_g94_str)
basis_qchem_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='qchem')
print('Qchem')
print(basis_qchem_str)
basis_molcas_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='molcas')
print('MOLCAS')
print(basis_molcas_str)
basis_dalton_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='dalton')
print('DALTON')
print(basis_dalton_str)
basis_gamessuk_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='gamess_uk')
print('GAMESS-UK')
print(basis_gamessuk_str)
basis_gamessus_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='gamess_us')
print('GAMESS_US')
print(basis_gamessus_str)
basis_c4_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='cfour')
print('Cfour')
print(basis_c4_str)
basis_cp2k_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='cp2k')
print('CP2K')
print(basis_cp2k_str)
basis_demon2k_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='demon2k')
print('Demon2k')
print(basis_demon2k_str)
basis_pqs_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='pqs')
print('PQS')
print(basis_pqs_str)
basis_molpro_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='molpro')
print('MOLPRO')
print(basis_molpro_str)
basis_xtron_str = bse.writers.write.write_formatted_basis_str(basis_read_from_turbomole_format, fmt='xtron')
print('XTRON')
print(basis_xtron_str)<jupyter_output>XTRON
C     0
S    6   1.00
  13575.349682               0.00022245814352
   2035.2333680              0.00172327382520
    463.22562359             0.00892557153140
    131.20019598             0.03572798450200
     42.853015891            0.11076259931000
     15.584185766            0.24295627626000
S    2   1.00
      6.2067138508           0.41440263448000
      2.5764896527           0.23744968655000
S    1   1.00
      0.4941102000           1.00000000000000
S    1   1.00
      0.1644071000           1.00000000000000
P    4   1.00
     34.697232244            0.00533336578050
      7.9582622826           0.03586410909200
      2.3780826883           0.14215873329000
      0.8143320818           0.34270471845000
P    1   1.00
      0.5662417100           1.00000000000000
P    1   1.00
      0.1973545000           1.00000000000000
D    1   1.00
      0.5791584200           1.00000000000000
****
{'fraction_non_alphanumeric': 0.11722435545803621, 'fraction_numerical': 0.2730115194733955, 'mean_word_length': 3.084005376344086, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 50, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '59582', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 9885, 'n_tokens_neox': 6753, 'n_words': 1306, 'path': 'Demo_BasisSet_Format_Conversion.ipynb', 'repo_name': 'manassharma07/Basis_Set_Format_Converter', 'size': '18230'}