How to use the cclib.io.ccopen function in cclib

To help you get started, we’ve selected a few cclib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cclib / cclib / test / regression.py View on Github external
fname_norm = normalisefilename(fname.replace(__regression_dir__, ''))

            funcname = "test" + fname_norm
            test_this = funcname in globals()

            funcname_noparse = "testnoparse" + fname_norm
            test_noparse = not test_this and funcname_noparse in globals()

            if not test_noparse:
                datatype = parser_class.datatype if hasattr(parser_class, 'datatype') else ccData
                job_filenames = glob.glob(fname)
                try:
                    if len(job_filenames) == 1:
                        logfile = ccopen(job_filenames[0], datatype=datatype, loglevel=loglevel)
                    else:
                        logfile = ccopen(job_filenames, datatype=datatype, loglevel=loglevel)
                except Exception as e:
                    errors += 1
                    print("ccopen error: ", e)
                    if opt_traceback:
                        print(traceback.format_exc())
                else:
                    if type(logfile) == parser_class:
                        try:
                            logfile.data = logfile.parse()
                        except KeyboardInterrupt:
                            sys.exit(1)
                        except Exception as e:
                            print("parse error:", e)
                            errors += 1
                            if opt_traceback:
                                print(traceback.format_exc())
github cclib / cclib / test / regression.py View on Github external
# to be additionaly prepended with 'testnoparse'.
            test_this = test_noparse = False
            fname_norm = normalisefilename(fname.replace(__regression_dir__, ''))

            funcname = "test" + fname_norm
            test_this = funcname in globals()

            funcname_noparse = "testnoparse" + fname_norm
            test_noparse = not test_this and funcname_noparse in globals()

            if not test_noparse:
                datatype = parser_class.datatype if hasattr(parser_class, 'datatype') else ccData
                job_filenames = glob.glob(fname)
                try:
                    if len(job_filenames) == 1:
                        logfile = ccopen(job_filenames[0], datatype=datatype, loglevel=loglevel)
                    else:
                        logfile = ccopen(job_filenames, datatype=datatype, loglevel=loglevel)
                except Exception as e:
                    errors += 1
                    print("ccopen error: ", e)
                    if opt_traceback:
                        print(traceback.format_exc())
                else:
                    if type(logfile) == parser_class:
                        try:
                            logfile.data = logfile.parse()
                        except KeyboardInterrupt:
                            sys.exit(1)
                        except Exception as e:
                            print("parse error:", e)
                            errors += 1
github cclib / cclib / test / io / testcjsonwriter.py View on Github external
def test_zero_dipole_moment(self):
        """Does the CJSON writer handle zero dipole moment correctly?"""
        fpath = os.path.join(__datadir__, "data/GAMESS/basicGAMESS-US2017/C_bigbasis.out")
        data = cclib.io.ccopen(fpath).parse()

        cjson = cclib.io.cjsonwriter.CJSON(data).generate_repr()

        json_data = json.loads(cjson)
        self.assertAlmostEqual(json_data["properties"]['total dipole moment'], 0.0)
github cclib / cclib / cclib / scripts / ccwrite.py View on Github external
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))
github ReactionMechanismGenerator / ARC / arc / scheduler.py View on Github external
def troubleshoot_negative_freq(self, label, job):
        """
        Troubleshooting cases where stable species (not TS's) have negative frequencies.
        We take  +/-1.1 displacements, generating several initial geometries, and running them as conformers
        """
        factor = 1.1
        ccparser = cclib.io.ccopen(str(job.local_path_to_output_file))
        data = ccparser.parse()
        vibfreqs = data.vibfreqs
        vibdisps = data.vibdisps
        atomnos = data.atomnos
        atomcoords = data.atomcoords
        if len(self.species_dict[label].neg_freqs_trshed) > 10:
            logging.error('Species {0} was troubleshooted for negative frequencies too many times.')
            if not self.job_types['1d_rotors']:
                logging.error('Rotor scan is turned off, cannot troubleshoot geometry using dihedral modifications.')
                self.output[label]['status'] = '1d_rotors = False; '
            logging.error('Invalidating species.')
            self.output[label]['status'] = 'Error: Encountered negative frequencies too many times; '
            return
        neg_freqs_idx = list()  # store indices w.r.t. vibfreqs
        largest_neg_freq_idx = 0  # index in vibfreqs
        for i, freq in enumerate(vibfreqs):
github cclib / cclib / cclib / scripts / ccframe.py View on Github external
parser.add_argument('compchemlogfiles', metavar='compchemlogfile',
                        nargs='+',
                        help=('one or more computational chemistry output '
                              'files to parse and convert'))
    parser.add_argument('--identifier',
                        default='logfiles',
                        help=('name of sheet which will contain DataFrame, if '
                              'writing to an Excel file, or identifier for '
                              'the group in HDFStore, if writing a HDF file'))
    args = parser.parse_args()

    output = args.output
    identifier = args.identifier
    filenames = args.compchemlogfiles

    df = ccframe([ccopen(path) for path in filenames])

    if output is not None:
        outputtype = os.path.splitext(os.path.basename(output))[1][1:]

        if outputtype in {'csv'}:
            df.to_csv(output)
        elif outputtype in {'h5', 'hdf', 'hdf5'}:
            df.to_hdf(output, key=identifier)
        elif outputtype in {'json'}:
            df.to_json(output)
        elif outputtype in {'pickle', 'pkl'}:
            df.to_pickle(output)
        elif outputtype in {'xlsx'}:
            writer = pd.ExcelWriter(output)
            # This overwrites previous sheets
            # (see https://stackoverflow.com/a/42375263/4039050)
github cclib / cclib / cclib / __init__.py View on Github external
from cclib import parser
from cclib import progress
from cclib import method
from cclib import bridge
from cclib import io

# The test module can be imported if it was installed with cclib.
try:
    from cclib import test
except ImportError:
    pass

# The objects below constitute our public API. These names will not change
# over time. Names in the sub-modules will typically also be backwards
# compatible, but may sometimes change when code is moved around.
ccopen = io.ccopen
ccwrite = io.ccwrite