1# coding: utf-8 2# Copyright (c) Pymatgen Development Team. 3# Distributed under the terms of the MIT License. 4 5 6""" 7This module contains the error classes for the chemenv package. 8""" 9 10__author__ = "David Waroquiers" 11__copyright__ = "Copyright 2012, The Materials Project" 12__credits__ = "Geoffroy Hautier" 13__version__ = "2.0" 14__maintainer__ = "David Waroquiers" 15__email__ = "david.waroquiers@gmail.com" 16__date__ = "Feb 20, 2016" 17 18 19class AbstractChemenvError(Exception): 20 """ 21 Abstract class for Chemenv errors. 22 """ 23 24 def __init__(self, cls, method, msg): 25 """ 26 :param cls: 27 :param method: 28 :param msg: 29 """ 30 self.cls = cls 31 self.method = method 32 self.msg = msg 33 34 def __str__(self): 35 return str(self.cls) + ": " + self.method + "\n" + repr(self.msg) 36 37 38class NeighborsNotComputedChemenvError(AbstractChemenvError): 39 """ 40 Neighbors not computed error. 41 """ 42 43 def __init__(self, site): 44 """ 45 :param site: 46 """ 47 self.site = site 48 49 def __str__(self): 50 return "The neighbors were not computed for the following site : \n" + str(self.site) 51 52 53class EquivalentSiteSearchError(AbstractChemenvError): 54 """ 55 Equivalent site search error. 56 """ 57 58 def __init__(self, site): 59 """ 60 :param site: 61 """ 62 self.site = site 63 64 def __str__(self): 65 return "Equivalent site could not be found for the following site : {}".format(str(self.site)) 66 67 68class SolidAngleError(AbstractChemenvError): 69 """ 70 Solid angle error. 71 """ 72 73 def __init__(self, cosinus): 74 """ 75 :param cosinus: 76 """ 77 self.cosinus = cosinus 78 79 def __str__(self): 80 return "Value of cosinus ({}) from which an angle should be retrieved" "is not between -1.0 and 1.0".format( 81 self.cosinus 82 ) 83 84 85class ChemenvError(Exception): 86 """ 87 Chemenv error. 88 """ 89 90 def __init__(self, cls, method, msg): 91 """ 92 :param cls: 93 :param method: 94 :param msg: 95 """ 96 self.cls = cls 97 self.method = method 98 self.msg = msg 99 100 def __str__(self): 101 return str(self.cls) + ": " + self.method + "\n" + repr(self.msg) 102