| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2017, the cclib development team |
| 4 |
# |
| 5 |
# This file is part of cclib (http://cclib.github.io) and is distributed under |
| 6 |
# the terms of the BSD 3-Clause License. |
| 7 |
|
| 8 |
"""Abstract based class for cclib methods.""" |
| 9 |
|
| 10 |
import logging |
| 11 |
import sys |
| 12 |
|
| 13 |
class MissingAttributeError(Exception): |
| 14 |
pass |
| 15 |
|
| 16 |
class Method(object): |
| 17 |
"""Abstract base class for all cclib method classes. |
| 18 |
|
| 19 |
Subclasses defined by cclib: |
| 20 |
CDA - charde decomposition analysis |
| 21 |
CSPA - C-squared population analysis |
| 22 |
Density - density matrix calculation |
| 23 |
FragmentAnalysis - fragment analysis for ADF output |
| 24 |
LPA - Löwdin population analysis |
| 25 |
MBO - Mayer's bond orders |
| 26 |
Moments - multipole moments calculations |
| 27 |
MPA - Mulliken population analysis |
| 28 |
Nuclear - properties of atomic nuclei |
| 29 |
OPA - overlap population analysis |
| 30 |
Population - base class for population analyses |
| 31 |
Volume - volume/grid calculations |
| 32 |
|
| 33 |
All the modules containing methods should be importable. |
| 34 |
""" |
| 35 |
required_attrs = () |
| 36 |
def __init__(self, data, progress=None, loglevel=logging.INFO, logname="Log"): |
| 37 |
"""Initialise the Logfile object. |
| 38 |
|
| 39 |
This constructor is typically called by the constructor of a subclass. |
| 40 |
""" |
| 41 |
|
| 42 |
self.data = data |
| 43 |
self.progress = progress |
| 44 |
self.loglevel = loglevel |
| 45 |
self.logname = logname |
| 46 |
self._check_required_attributes() |
| 47 |
self.logger = logging.getLogger('%s %s' % (self.logname, self.data)) |
| 48 |
self.logger.setLevel(self.loglevel) |
| 49 |
self.logformat = "[%(name)s %(levelname)s] %(message)s" |
| 50 |
handler = logging.StreamHandler(sys.stdout) |
| 51 |
handler.setFormatter(logging.Formatter(self.logformat)) |
| 52 |
self.logger.addHandler(handler) |
| 53 |
|
| 54 |
def _check_required_attributes(self): |
| 55 |
"""Check if required attributes are present in data.""" |
| 56 |
missing = [x for x in self.required_attrs |
| 57 |
if not hasattr(self.data, x)] |
| 58 |
if missing: |
| 59 |
missing = ' '.join(missing) |
| 60 |
raise MissingAttributeError( |
| 61 |
'Could not parse required attributes to use method: ' + missing) |