Coverage for cclib/method/calculationmethod.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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.
8"""Abstract based class for cclib methods."""
10import logging
11import sys
13class MissingAttributeError(Exception):
14 pass
16class Method:
17 """Abstract base class for all cclib method classes.
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
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.
39 This constructor is typically called by the constructor of a subclass.
40 """
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)
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)