Debian Codegraph @

cclib/method/orbitals.py

raw
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of cclib (http://cclib.github.io), a library for parsing
4 # and interpreting the results of computational chemistry packages.
5 #
6 # Copyright (C) 2017, the cclib development team
7 #
8 # The library is free software, distributed under the terms of
9 # the GNU Lesser General Public version 2.1 or later. You should have
10 # received a copy of the license along with cclib. You can also access
11 # the full license online at http://www.gnu.org/copyleft/lgpl.html.
12
13 """Analyses related to orbitals."""
14
15 import logging
16
17 import numpy
18
19 from cclib.method.calculationmethod import Method
20
21
22 class Orbitals(Method):
23 """A class for orbital related methods."""
24
25 def __init__(self, data, progress=None, \
26 loglevel=logging.INFO, logname="Log"):
27
28 self.required_attrs = ('mocoeffs','moenergies','homos')
29 # Call the __init__ method of the superclass.
30 super(Orbitals, self).__init__(data, progress, loglevel, logname)
31 self.fragresults = None
32
33 def __str__(self):
34 """Return a string representation of the object."""
35 return "Orbitals"
36
37 def __repr__(self):
38 """Return a representation of the object."""
39 return "Orbitals"
40
41 def closed_shell(self):
42 """Return Boolean indicating if system is closed shell."""
43
44 # If there are beta orbitals, we can assume the system is closed
45 # shell if the orbital energies are identical within numerical accuracy.
46 if len(self.data.mocoeffs) == 2:
47 precision = 10e-6
48 return numpy.allclose(*self.data.moenergies, atol=precision)
49
50 # Restricted open shell will have one set of MOs but two HOMO indices,
51 # and the indices should be different (otherwise it's still closed shell).
52 if len(self.data.homos) == 2 and self.data.homos[0] != self.data.homos[1]:
53 return False
54
55 return True