def test_no_model(self): """Check access of attributes from python""" m = IMP.Model() p = IMP.Particle(m) ik = IMP.IntKey("hi") m.add_attribute(ik, p.get_index(), 1) self.assertEqual(m.get_attribute(ik, p.get_index()), 1) pisk = IMP.ParticleIndexesKey("hi") m.add_attribute(pisk, p.get_index(), [p.get_index()]) self.assertEqual(m.get_attribute(pisk, p.get_index()), [p.get_index()]) pik = IMP.ParticleIndexKey("hi") m.add_attribute(pik, p.get_index(), p.get_index()) self.assertEqual(m.get_attribute(pik, p.get_index()), p.get_index())
def test_remove_attributes(self): """Test that attributes can be removed""" (model, particles) = self.setup() p = particles[0] fk = IMP.FloatKey("to_remove") p.add_attribute(fk, 0, False) self.assertTrue(p.has_attribute(fk)) self.assertFalse(p.get_is_optimized(fk)) p.set_is_optimized(fk, True) self.assertTrue(p.get_is_optimized(fk)) p.set_is_optimized(fk, False) self.assertFalse(p.get_is_optimized(fk)) self._test_add_remove(p, IMP.FloatKey("something"), 1.0) self._test_add_remove(p, IMP.StringKey("something"), "Hello") self._test_add_remove(p, IMP.IntKey("something"), 1) self._test_add_remove(p, IMP.ParticleIndexKey("something"), p)
from __future__ import print_function import IMP import IMP.test fk0 = IMP.FloatKey("f0") fk1 = IMP.FloatKey("f1") fk2 = IMP.FloatKey("f2") ik0 = IMP.IntKey("i0") ik1 = IMP.IntKey("i1") ik2 = IMP.IntKey("i2") sk0 = IMP.StringKey("s0") sk1 = IMP.StringKey("s1") sk2 = IMP.StringKey("s2") pk0 = IMP.ParticleIndexKey("p0") pk1 = IMP.ParticleIndexKey("p1") pk2 = IMP.ParticleIndexKey("p2") class Tests(IMP.test.TestCase): """Test particles""" def _force_set(self, p, k, v): if p.has_attribute(k): p.set_value(k, v) else: p.add_attribute(k, v) def _force_remove(self, p, k): if p.has_attribute(k): p.remove_attribute(k) def _add_attributes(self, p, n, op):