Ejemplo n.º 1
0
def test_populated_attrs():
    class Dummy(object):
        def __init__(self, **kwds):
            self.attr_lst = ['a','b','c', 'd']
            for name in self.attr_lst:
                setattr(self, name, None)
            for k,v in kwds.iteritems():
                setattr(self, k, v)
    
    x = Dummy(a=1,b=2,c=3,d=8)
    y = Dummy(a=4)
    z = Dummy(d=7)
    assert crys.populated_attrs([x,y]) == set(['a'])
    assert crys.populated_attrs([x,y,z]) == set([])
Ejemplo n.º 2
0
def test_populated_attrs():
    class Dummy(object):
        def __init__(self, **kwds):
            self.attr_lst = ['a', 'b', 'c', 'd']
            for name in self.attr_lst:
                setattr(self, name, None)
            for k, v in kwds.items():
                setattr(self, k, v)

    x = Dummy(a=1, b=2, c=3, d=8)
    y = Dummy(a=4)
    z = Dummy(d=7)
    assert crys.populated_attrs([x, y]) == set(['a'])
    assert crys.populated_attrs([x, y, z]) == set([])
Ejemplo n.º 3
0
{st}

only in Trajectory:
{onlytr}

only in Structure:
{onlyst}

Attributes which are None w.r.t. the Trajectory API after the following
operation, starting with a fully populated struct or traj (all attrs not None):
""".format(st=st.attr_lst, tr=tr.attr_lst, onlytr=list(onlytr), 
           onlyst=list(onlyst))

items = [\
    ('tr', tr),
    ('tr.copy', tr.copy()),
    ('tr[0:5]', tr[0:5]),
    ('st', st),
    ('st.copy', st.copy()),
    ('tr[0]', tr[0]),
    ('mean(tr)', crys.mean(tr)),
    ('concatenate([st,st])', crys.concatenate([st,st])),
    ('concatenate([st,tr])', crys.concatenate([st,tr])),
    ('concatenate([tr,tr])', crys.concatenate([tr,tr])),
    ]
for name,obj in items:
    none_attrs = set.difference(set(tr.attr_lst),
                                crys.populated_attrs([obj]))
    typ = 'traj' if obj.is_traj else 'struct'                                          
    print "{:25} {:7} {}".format(name, typ, list(none_attrs))
Ejemplo n.º 4
0
{st}

only in Trajectory:
{onlytr}

only in Structure:
{onlyst}

Attributes which are None w.r.t. the Trajectory API after the following
operation, starting with a fully populated struct or traj (all attrs not None):
""".format(st=st.attr_lst, tr=tr.attr_lst, onlytr=list(onlytr), 
           onlyst=list(onlyst)))

items = [\
    ('tr', tr),
    ('tr.copy', tr.copy()),
    ('tr[0:5]', tr[0:5]),
    ('st', st),
    ('st.copy', st.copy()),
    ('tr[0]', tr[0]),
    ('mean(tr)', crys.mean(tr)),
    ('concatenate([st,st])', crys.concatenate([st,st])),
    ('concatenate([st,tr])', crys.concatenate([st,tr])),
    ('concatenate([tr,tr])', crys.concatenate([tr,tr])),
    ]
for name,obj in items:
    none_attrs = set.difference(set(tr.attr_lst),
                                crys.populated_attrs([obj]))
    typ = 'traj' if obj.is_traj else 'struct'                                          
    print("{:25} {:7} {}".format(name, typ, list(none_attrs)))