Skip to content

Commit

Permalink
Small method tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
avirshup committed Aug 3, 2017
1 parent fb9b268 commit 04f9160
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion moldesign/_tests/test_gaussian_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
21 changes: 14 additions & 7 deletions moldesign/utils/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,36 @@

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')
>>> child = dict()
>>>
>>> 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):
Expand Down
9 changes: 5 additions & 4 deletions moldesign/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 04f9160

Please sign in to comment.