diff --git a/openmmtools/storage/iodrivers.py b/openmmtools/storage/iodrivers.py index a3b30096a..ef61d0e8e 100644 --- a/openmmtools/storage/iodrivers.py +++ b/openmmtools/storage/iodrivers.py @@ -26,6 +26,11 @@ import netCDF4 as nc from sys import getsizeof +try: + from yaml import CLoader as Loader, CDumper as Dumper +except ImportError: + from yaml import Loader, Dumper + from simtk import unit from ..utils import typename, quantity_from_string @@ -1535,7 +1540,7 @@ def storage_type(self): # NETCDF DICT YAML HANDLERS # ============================================================================= -class _DictYamlLoader(yaml.CLoader): +class _DictYamlLoader(Loader): """PyYAML Loader that recognized !Quantity nodes, converts YAML output -> Python type""" def __init__(self, *args, **kwargs): super(_DictYamlLoader, self).__init__(*args, **kwargs) @@ -1549,7 +1554,7 @@ def quantity_constructor(loader, node): return data_value * data_unit -class _DictYamlDumper(yaml.CDumper): +class _DictYamlDumper(Dumper): """PyYAML Dumper that convert from Python -> YAML output""" def __init__(self, *args, **kwargs): super(_DictYamlDumper, self).__init__(*args, **kwargs)