Commit c66e086e authored by peastman's avatar peastman
Browse files

Merge pull request #773 from rmcgibbo/bytes-2

stripUnits behavior with bytes
parents 85494077 e197379c
...@@ -9,6 +9,10 @@ import sys ...@@ -9,6 +9,10 @@ import sys
import math import math
RMIN_PER_SIGMA=math.pow(2, 1/6.0) RMIN_PER_SIGMA=math.pow(2, 1/6.0)
RVDW_PER_SIGMA=math.pow(2, 1/6.0)/2.0 RVDW_PER_SIGMA=math.pow(2, 1/6.0)/2.0
if sys.version_info[0] == 2:
_string_types = (basestring,)
else:
_string_types = (bytes, str)
import simtk.unit as unit import simtk.unit as unit
from simtk.openmm.vec3 import Vec3 from simtk.openmm.vec3 import Vec3
...@@ -215,25 +219,6 @@ class State(_object): ...@@ -215,25 +219,6 @@ class State(_object):
return self._paramMap return self._paramMap
# Strings can cause trouble
# as can any container that has infinite levels of containment
def _is_string(x):
# step 1) String is always a container
# and its contents are themselves containers.
try:
first_item = iter(x).next()
inner_item = iter(first_item).next()
if first_item == inner_item:
return True
else:
return False
except TypeError:
return False
except StopIteration:
return False
except ValueError:
return False
def stripUnits(args): def stripUnits(args):
""" """
getState(self, quantity) getState(self, quantity)
...@@ -282,15 +267,14 @@ def stripUnits(args): ...@@ -282,15 +267,14 @@ def stripUnits(args):
if arg.unit.is_compatible(unit.bar): if arg.unit.is_compatible(unit.bar):
arg = arg / unit.bar arg = arg / unit.bar
else: else:
arg=arg.value_in_unit_system(unit.md_unit_system) arg = arg.value_in_unit_system(unit.md_unit_system)
# JDC: End workaround. # JDC: End workaround.
elif isinstance(arg, dict): elif isinstance(arg, dict):
newKeys = stripUnits(arg.keys()) newKeys = stripUnits(arg.keys())
newValues = stripUnits(arg.values()) newValues = stripUnits(arg.values())
arg = dict(zip(newKeys, newValues)) arg = dict(zip(newKeys, newValues))
elif not _is_string(arg): elif not isinstance(arg, _string_types):
try: try:
iter(arg)
# Reclusively strip units from all quantities # Reclusively strip units from all quantities
arg=stripUnits(arg) arg=stripUnits(arg)
except TypeError: except TypeError:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment