Created
August 3, 2018 19:08
-
-
Save berquist/610f5245ec17d8da98e38f0c97fbdf3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from cclib.io import ccread | |
from cclib.parser import data | |
from cclib.parser import logfileparser | |
def ccframe(ccobjs, *args, **kwargs): | |
"""Write data parsed by cclib from one or more outputfiles to a | |
pandas.DataFrame. | |
Inputs: | |
ccobjs - An iterable of either cclib jobs (from ccopen) or data (from | |
job.parse()) objects | |
Returns: | |
a pandas.DataFrame | |
""" | |
outputs = [] | |
for ccobj in ccobjs: | |
# Is ccobj an job object (unparsed), or is it a ccdata object (parsed)? | |
if isinstance(ccobj, logfileparser.Logfile): | |
ccdata = ccobj.parse() | |
elif isinstance(ccobj, data.ccData): | |
ccdata = ccobj | |
else: | |
raise ValueError | |
outputs.append(pd.Series(ccdata.getattributes())) | |
return pd.DataFrame(outputs) | |
if __name__ == "__main__": | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('outputfilename', nargs='*') | |
args = parser.parse_args() | |
ccobjs = [ccread(outputfilename) | |
for outputfilename in args.outputfilename] | |
df = ccframe(ccobjs) | |
print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment