From 04f91602bd468c27504c5be2d35621c1d04585c7 Mon Sep 17 00:00:00 2001 From: Aaron Virshup Date: Wed, 2 Aug 2017 21:29:37 -0700 Subject: [PATCH] Small method tweaks --- moldesign/_tests/test_gaussian_math.py | 2 +- moldesign/utils/descriptors.py | 21 ++++++++++++++------- moldesign/widgets.py | 9 +++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/moldesign/_tests/test_gaussian_math.py b/moldesign/_tests/test_gaussian_math.py index db80898..d2fc817 100644 --- a/moldesign/_tests/test_gaussian_math.py +++ b/moldesign/_tests/test_gaussian_math.py @@ -177,7 +177,7 @@ def _assert_numerical_analytical_overlaps_match(g1, g2): with np.errstate(under='ignore'): prodvals = g1(allpoints) * g2(allpoints) numsum = prodvals.sum() * grid.dx * grid.dy * grid.dz - helpers.assert_almost_equal(numsum, olap, decimal=5) + helpers.assert_almost_equal(numsum, olap, decimal=4) @pytest.mark.parametrize('withunits', [False, True]) diff --git a/moldesign/utils/descriptors.py b/moldesign/utils/descriptors.py index 206ef6a..b46c5e0 100644 --- a/moldesign/utils/descriptors.py +++ b/moldesign/utils/descriptors.py @@ -19,7 +19,7 @@ class Alias(object): """ - Descriptor that calls a child object's method. + Descriptor that delegates to a child's attribute or method. e.g. >>> class A(object): >>> childkeys = Alias('child.keys') @@ -27,21 +27,28 @@ class Alias(object): >>> >>> a = A() >>> a.child['key'] = 'value' - >>> a.childkeys() #calls a.child.keys(), returns ['key'] + >>> a.childkeys() # calls a.child.keys(), returns ['key'] ['key'] """ - def __init__(self, objmethod): - objname, methodname = objmethod.split('.') + def __init__(self, objattr): + objname, attrname = objattr.split('.') self.objname = objname - self.methodname = methodname + self.attrname = attrname def __get__(self, instance, owner): if instance is None: assert owner is not None - return _unbound_getter(self.objname, self.methodname) + return _unbound_getter(self.objname, self.attrname) else: proxied = getattr(instance, self.objname) - return getattr(proxied,self.methodname) + return getattr(proxied, self.attrname) + + def __set__(self, instance, value): + if instance is None: + raise NotImplementedError() + else: + proxied = getattr(instance, self.objname) + setattr(proxied, self.attrname, value) def _unbound_getter(objname, methodname): diff --git a/moldesign/widgets.py b/moldesign/widgets.py index d3d9165..a0f99f7 100644 --- a/moldesign/widgets.py +++ b/moldesign/widgets.py @@ -19,11 +19,12 @@ from .helpers.widgets import nbmolviz_installed if nbmolviz_installed: - from nbmolviz.widgets import BondSelector, GeometryBuilder, ResidueSelector, Symmetrizer + from nbmolviz.widgets import (BondSelector, GeometryBuilder, ResidueSelector, Symmetrizer, + AtomSelector) from nbmolviz.widgets.computeconfig import configure, about else: from .helpers.widgets import not_installed_method - BondSelector = GeometryBuilder = ResidueSelector = Symmetrizer = configure = about = \ - not_installed_method + BondSelector = GeometryBuilder = ResidueSelector = AtomSelector = Symmetrizer = configure \ + = about = not_installed_method -__all__ = 'BondSelector GeometryBuilder ResidueSelector Symmetrizer'.split() +__all__ = 'BondSelector GeometryBuilder ResidueSelector Symmetrizer AtomSelector'.split()