Source code for Chemistry.exceptions.ReactionErrors

# Copyright (c) 2014 Dan Obermiller
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# You should have received a copy of the MIT License along with this program.
# If not, see <http://opensource.org/licenses/MIT>


"""Errors associated with chemical reactions."""


[docs]class ReactionError(Exception): """A generic error to be thrown when there is an error with a reaction that does not have any specific error to be thrown. """ err_message = "There was an error with the reaction" pka = """ AcidBase reaction between {} and {} failed because of pka difference {} ({} to {}) """ def __init__(self, message=None, **kwargs): if message: self.err_message = message elif 'pka' in kwargs: self.err_message = ReactionError.pka.format(*kwargs['reactants'] *kwargs['pka']) def __str__(self): return self.err_message def __repr__(self): return str(self)
[docs]class NoReactionError(ReactionError): """A specific reaction error that should be thrown if the given scenario would not give rise to that specific type of reaction. Parameters ---------- msg : string, optional The error message. """ err_message = "No reaction occurred" def __init__(self, msg=err_message): super(NoReactionError, self).__init__(msg)