def test_basis_set_parser_gaussian(tmpdir): tmpdir.chdir() fpath = tmpdir.join('augtz.gaussian') fpath.write(AUGTZ_GAUSSIAN) bsd = BasisSet.from_file(str(fpath), fmt='gaussian') assert isinstance(bsd, dict) assert 'H' in bsd.keys() assert 'Li' in bsd.keys() assert 'Be' in bsd.keys() assert isinstance(bsd['H'], BasisSet) assert isinstance(bsd['Li'], BasisSet) assert isinstance(bsd['Be'], BasisSet) assert bsd['H'].nf() == 9 assert bsd['Li'].nf() == 23 assert bsd['Be'].nf() == 23
def test_basis_set_parser_molpro(tmpdir): tmpdir.chdir() fpath = tmpdir.join('augtz.molpro') fpath.write(AUGTZ_MOLPRO) bsd = BasisSet.from_file(str(fpath), fmt='molpro') assert isinstance(bsd, dict) assert 'H' in bsd.keys() assert 'Li' in bsd.keys() assert 'Be' in bsd.keys() assert isinstance(bsd['H'], BasisSet) assert isinstance(bsd['Li'], BasisSet) assert isinstance(bsd['Be'], BasisSet) assert bsd['H'].nf() == 9 assert bsd['Li'].nf() == 23 assert bsd['Be'].nf() == 23
def bsconvert(): ''' CLI script to convert between different basis set formats ''' parser = ArgumentParser( description='Convert basis set between formats of different programs') parser.add_argument("filename", help="file name with a basis set, default='pickle'") parser.add_argument( "-from", "--inputformat", choices=["gamessus", "gaussian", "json", "molpro", "pickle"], help="Basis set input format", default="pickle") parser.add_argument("-to", "--outputformat", choices=[ "cfour", "dalton", "gamessus", "gaussian", "json", "molpro", "nwchem", "pickle" ], help="Basis set output format", default="molpro") parser.add_argument('-o', '--output', help='name of the output file') args = parser.parse_args() name = os.path.splitext(args.filename)[0] if args.inputformat == "pickle": bsets = BasisSet.from_pickle(args.filename) elif args.inputformat == "json": bsets = BasisSet.from_json(args.filename) else: bsets = BasisSet.from_file(fname=args.filename, fmt=args.inputformat, name=name) if args.outputformat == "pickle": if isinstance(bsets, dict): for elem, bset in bsets.items(): bset.to_pickle(name + '_' + elem + '.pkl') elif isinstance(bsets, BasisSet): bsets.to_pickle(name + '_' + bsets.element + '.pkl') else: writer_name = "to_" + args.outputformat writer_objs = [] if isinstance(bsets, dict): for elem, bset in bsets.items(): writer_objs.append(getattr(bset, writer_name)) elif isinstance(bsets, BasisSet): writer_objs.append(getattr(bsets, writer_name)) else: raise ValueError('Something went wrong') if args.output: fobj = open(args.output, 'w') else: fobj = sys.stdout for writer in writer_objs: print(writer(), file=fobj)