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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017, the cclib development team
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
from __future__ import print_function
import argparse
import logging
import os.path
import sys
from cclib.parser import ccData
from cclib.io import ccopen
from cclib.io import ccwrite
def main():
parser = argparse.ArgumentParser()
parser.add_argument('outputtype',
choices=('json', 'cjson', 'cml', 'xyz', 'molden', 'wfx'),
help='the output format to write (json/cjson are identical)')
parser.add_argument('compchemlogfile',
nargs='+',
help='one or more computational chemistry output files to parse and convert')
parser.add_argument('-v', '--verbose',
action='store_true',
help='more verbose parsing output (only errors by default)')
parser.add_argument('-g', '--ghost',
type=str,
default=None,
help='Symbol to use for ghost atoms')
parser.add_argument('-t', '--terse',
action='store_true',
help='CJSON by default is not indented for readability, saves space (indented for readability\'s sake)')
parser.add_argument('-u', '--future',
action='store_true',
help='use experimental features (currently optdone_as_list)')
parser.add_argument('-i', '--index',
type=int,
default=None,
help='optional zero-based index for which structure to extract')
args = parser.parse_args()
outputtype = args.outputtype
filenames = args.compchemlogfile
verbose = args.verbose
terse = args.terse
future = args.future
index = args.index
ghost = args.ghost
for filename in filenames:
# We might want to use this option in the near future.
ccopen_kwargs = dict()
if future:
ccopen_kwargs['future'] = True
print("Attempting to parse {}".format(filename))
log = ccopen(filename, **ccopen_kwargs)
if not log:
print("Cannot figure out what type of computational chemistry output file '{}' is.".format(filename))
print("Report this to the cclib development team if you think this is an error.")
sys.exit()
if verbose:
log.logger.setLevel(logging.INFO)
else:
log.logger.setLevel(logging.ERROR)
data = log.parse()
print("cclib can parse the following attributes from {}:".format(filename))
hasattrs = [' {}'.format(attr) for attr in ccData._attrlist if hasattr(data, attr)]
print('\n'.join(hasattrs))
# Write out to disk.
outputdest = '.'.join([os.path.splitext(os.path.basename(filename))[0], outputtype])
ccwrite_kwargs = dict()
if future:
ccwrite_kwargs['future'] = True
if ghost:
ccwrite_kwargs['ghost'] = ghost
# For XYZ files, write the last geometry unless otherwise
# specified.
if not index:
index = -1
ccwrite_kwargs['jobfilename'] = filename
# The argument terse presently is only applicable to
# CJSON/JSON formats
ccwrite(data, outputtype, outputdest, indices=index, terse=terse,
**ccwrite_kwargs)
if __name__ == "__main__":
main()
|