""" Exceptions used in parmed script """
__all__ = ['ParmedError', 'ParmedWarning', 'InputError', 'ParmError',
'ParmWarning', 'SeriousParmWarning', 'ChangeRadiiError',
'WriteOFFError', 'ParmedUtilsError', 'ParmedChangeError',
'ParmedAddLJTypeError', 'ChangeLJPairError', 'LJ_TypeError',
'ParmedMoleculeError', 'CoarseGrainError', 'ChangeStateError',
'DeleteDihedralError', 'ArgumentError', 'NoArgument',
'InterpreterError', 'AmberIncompatibleWarning', 'BadParmWarning',
'FixableParmWarning', 'NonfatalWarning', 'NonUniversalWarning',
'MissingDisulfide', 'LongBondWarning', 'NonexistentParm',
'ParmFileNotFound', 'DuplicateParm', 'AmbiguousParmError',
'IncompatibleParmsError', 'AddPDBWarning', 'AddPDBError',
'LJ12_6_4Error', 'DuplicateParamWarning', 'HMassRepartitionError',
'SimulationError', 'SimulationWarning', 'UnhandledArgumentWarning',
'ParmIndexError', 'FileExists', 'FileDoesNotExist', 'ChamberError',
'TiMergeError', 'WarningList']
from sys import stderr
from parmed.exceptions import ParmedError, ParmedWarning, InputError
from parmed.utils.six import PY2
import warnings
if PY2:
FileNotFoundError = IOError
[docs]class ParmError(ParmedError):
""" Base parmed error """
def __init__(self, msg='parmed error'):
self.msg = msg
def __str__(self):
return self.msg
[docs]class ParmWarning(ParmedWarning):
""" Base parmed warning """
def __init__(self, msg='parmed warning'):
self.msg = msg
def __str__(self):
return self.msg
[docs]class SeriousParmWarning(ParmWarning):
""" These warnings are more serious, and are fatal in strict operation """
# By default, make SeriousParmWarning fatal
warnings.filterwarnings('error', category=SeriousParmWarning)
[docs]class ChangeRadiiError(ParmError):
pass
[docs]class WriteOFFError(ParmError):
pass
[docs]class ParmedUtilsError(ParmError):
pass
[docs]class ParmedChangeError(ParmError):
pass
[docs]class ParmedAddLJTypeError(ParmError):
pass
[docs]class ChangeLJPairError(ParmError):
pass
[docs]class LJ_TypeError(ParmError):
pass
[docs]class ParmedMoleculeError(ParmError):
pass
[docs]class CoarseGrainError(ParmError):
pass
[docs]class ChangeStateError(ParmError):
pass
class SetParamError(ParmError):
pass
[docs]class DeleteDihedralError(ParmError):
pass
[docs]class ArgumentError(ParmError):
pass
[docs]class NoArgument(ParmError):
pass
[docs]class InterpreterError(ParmError):
pass
[docs]class AmberIncompatibleWarning(ParmWarning):
pass
[docs]class BadParmWarning(ParmWarning):
pass
[docs]class FixableParmWarning(ParmWarning):
pass
[docs]class NonfatalWarning(ParmWarning):
pass
[docs]class NonUniversalWarning(ParmWarning):
pass
[docs]class MissingDisulfide(ParmWarning):
pass
[docs]class LongBondWarning(ParmWarning):
pass
[docs]class NonexistentParm(ParmError):
pass
[docs]class ParmFileNotFound(ParmError, FileNotFoundError):
pass
[docs]class DuplicateParm(ParmError):
pass
[docs]class AmbiguousParmError(ParmError):
pass
[docs]class IncompatibleParmsError(ParmError):
pass
[docs]class AddPDBWarning(ParmWarning):
pass
[docs]class AddPDBError(ParmError):
pass
[docs]class LJ12_6_4Error(ParmError):
pass
[docs]class DuplicateParamWarning(SeriousParmWarning):
pass
[docs]class HMassRepartitionError(ParmError):
pass
[docs]class SimulationError(ParmError):
pass
[docs]class SimulationWarning(ParmWarning):
pass
[docs]class UnhandledArgumentWarning(SeriousParmWarning):
pass
[docs]class ParmIndexError(ParmError, IndexError):
pass
[docs]class FileExists(ParmError):
pass
[docs]class FileDoesNotExist(ParmError, IOError):
pass
[docs]class ChamberError(ParmError):
pass
[docs]class TiMergeError(ParmError):
pass
[docs]class WarningList(list):
""" List of warnings """
def __init__(self, empty_msg='No warnings found'):
self._empty_msg = empty_msg
list.__init__(self)
[docs] def append(self, *args):
raise NotImplemented('Use warn() to add to WarningList!')
extend = append
[docs] def warn(self, msg, exc_type=ParmWarning):
""" Adds a warning to the list """
list.append(self, (exc_type, msg))
[docs] def dump(self, dest=stderr, ncols=80):
""" Dump a list of all warnings to the destination """
if len(self) == 0:
dest.write(self._empty_msg + '\n')
return
dest.write('%d total warnings\n\n' % len(self))
for w in self:
words = ('%s: %s' % (w[0].__name__, w[1])).split()
prstr = words[0] + ' '
indent_chars = len(words[0]) + 1
i = 1
while i < len(words):
if prstr and len(prstr) + len(words[i]) > ncols:
dest.write(prstr + '\n')
prstr = ' ' * indent_chars
prstr += words[i] + ' '
i += 1
if prstr:
dest.write(prstr + '\n')
dest.write('\n')
# dest.write('%s: %s\n' % (w[0].__name__, w[1]))