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
|
# -*- 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.
"""Abstract based class for cclib methods."""
import logging
import sys
class MissingAttributeError(Exception):
pass
class Method(object):
"""Abstract base class for all cclib method classes.
Subclasses defined by cclib:
CDA - charde decomposition analysis
CSPA - C-squared population analysis
Density - density matrix calculation
FragmentAnalysis - fragment analysis for ADF output
LPA - Löwdin population analysis
MBO - Mayer's bond orders
Moments - multipole moments calculations
MPA - Mulliken population analysis
Nuclear - properties of atomic nuclei
OPA - overlap population analysis
Population - base class for population analyses
Volume - volume/grid calculations
All the modules containing methods should be importable.
"""
required_attrs = ()
def __init__(self, data, progress=None, loglevel=logging.INFO, logname="Log"):
"""Initialise the Logfile object.
This constructor is typically called by the constructor of a subclass.
"""
self.data = data
self.progress = progress
self.loglevel = loglevel
self.logname = logname
self._check_required_attributes()
self.logger = logging.getLogger('%s %s' % (self.logname, self.data))
self.logger.setLevel(self.loglevel)
self.logformat = "[%(name)s %(levelname)s] %(message)s"
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(self.logformat))
self.logger.addHandler(handler)
def _check_required_attributes(self):
"""Check if required attributes are present in data."""
missing = [x for x in self.required_attrs
if not hasattr(self.data, x)]
if missing:
missing = ' '.join(missing)
raise MissingAttributeError(
'Could not parse required attributes to use method: ' + missing)
|