Source code for schrodinger.application.jaguar.mmjag
"""
Convenience classes/functions for working with mmjag
MmJag provides a wrapper to the C mmjag functions.
MMJagManager provides a context manager and mmjag_function
a decorator for initializing/terminating mmjag
"""
# Copyright Schrodinger, LLC. All rights reserved.
import schrodinger.infra.mm as mm
import schrodinger.infra.mmobject
[docs]class MmJag(schrodinger.infra.mmobject.MmObject):
"""
A reference counting class for dealing with mmjag handles.
"""
[docs] def __init__(self, handle):
mm.mmjag_initialize(mm.error_handler)
super(MmJag, self).__init__(handle)
mm.mmjag_terminate()
[docs] def initialize(error_handler=None):
if error_handler is None:
error_handler = mm.error_handler
mm.mmjag_initialize(error_handler)
initialize = staticmethod(initialize)
[docs] def terminate():
mm.mmjag_terminate()
terminate = staticmethod(terminate)
def _delete(self):
mm.mmjag_delete(self.handle)
[docs]class MMJagManager():
[docs] def __init__(self, handler=mm.MMERR_DEFAULT_HANDLER):
self.handler = handler
def __enter__(self):
mm.mmjag_initialize(self.handler)
def __exit__(self, exc_type, exc_val, exc_tb):
mm.mmjag_terminate()
[docs]def mmjag_function(func):
"""
A decorator that wraps functions with mmjag_initialize and mmjag_terminate.
"""
def dec(*args, **kwargs):
mm.mmjag_initialize(mm.MMERR_DEFAULT_HANDLER)
try:
return func(*args, **kwargs)
finally:
mm.mmjag_terminate()
return dec