Exemplo n.º 1
0
    def setup(self):
        """Build a set of test particles"""
        IMP.test.TestCase.setUp(self)

        model = IMP.kernel.Model("particles model")
        particles = []

        # create particles 0 - 11
        for i in range(0, 12):
            particles.append(
                self.create_point_particle(model, i * 2, i * 3, i * 4))
            p1 = particles[i]
            p1.add_attribute(radkey, 1.5 * i, False)
            p1.add_attribute(idkey, i)
            p1.add_attribute(IMP.IntKey("six"), 6)
            p1.add_attribute(IMP.StringKey("id_str"), "name_" + str(i))
            p1.add_attribute(IMP.StringKey("six"), "b:0110")

        # add additional attributes to particle 11
        for i in range(0, 6):
            p1.add_attribute(IMP.FloatKey("attr_" + str(i)), 3.5 * i, False)
        # clear derivatives
        print(model.get_ref_count())
        model.evaluate(True)
        print(model.get_ref_count())
        return (model, particles)
Exemplo n.º 2
0
 def _test_bad_attributes(self):
     """Asking for non-existent attributes should cause an exception"""
     p1 = particles[0]
     self.assertRaises(IndexError, p1.get_value, IMP.FloatKey("notexist"))
     self.assertRaises(IndexError, p1.get_value, IMP.IntKey("notexist"))
     self.assertRaises(IndexError, p1.get_value, IMP.StringKey("notexist"))
     self.assertRaises(IndexError, p1.add_attribute, IMP.FloatKey(), 0)
Exemplo n.º 3
0
    def test_ms_connectivity_graph_2(self):
        """Test for the correctness of the graph 2."""
        IMP.set_log_level(IMP.SILENT)

        self.ds2[0].set_coordinates(IMP.algebra.Vector3D(1.0, 6.0, 0.0))  # A
        self.ds2[1].set_coordinates(IMP.algebra.Vector3D(3.0, 5.0, 0.0))  # A
        self.ds2[2].set_coordinates(IMP.algebra.Vector3D(0.0, 4.0, 0.0))  # A
        self.ds2[3].set_coordinates(IMP.algebra.Vector3D(1.0, 5.0, 0.0))  # B
        self.ds2[4].set_coordinates(IMP.algebra.Vector3D(1.0, 3.0, 0.0))  # B
        self.ds2[5].set_coordinates(IMP.algebra.Vector3D(0.0, 2.0, 0.0))  # C
        self.ds2[6].set_coordinates(IMP.algebra.Vector3D(0.0, 0.0, 0.0))  # C
        self.ds2[7].set_coordinates(IMP.algebra.Vector3D(1.0, 1.0, 0.0))  # D

        idk = IMP.StringKey("id")
        connections = list()
        pps = self.r2.get_connected_pairs()
        for p in pps:
            conn = sorted([p[0].get_value(idk), p[1].get_value(idk)])
            connections.append('%s <-> %s' % (conn[0], conn[1]))
        connections.sort()
        connections = ', '.join(connections)
        self.assertEqual(
            connections,
            'A <-> A, A <-> B, A <-> B, A <-> B, A <-> B, A <-> C, B <-> B, B <-> C, C <-> C, C <-> D, C <-> D'
        )
Exemplo n.º 4
0
    def __init__(self, ascii=True):
        global os, RMF, imprmf, cPickle, impatom, impcore, imp
        import cPickle as cPickle
        import os
        import IMP as imp
        import IMP.atom as impatom
        import IMP.core as impcore
        try:
            import RMF
            import IMP.rmf as imprmf
            self.rmf_library = True
        except ImportError:
            self.rmf_library = False

        self.dictionary_pdbs = {}
        self.dictionary_rmfs = {}
        self.dictionary_stats = {}
        self.dictionary_stats2 = {}
        self.best_score_list = None
        self.nbestscoring = None
        self.suffixes = []
        self.replica_exchange = False
        self.ascii = ascii
        self.initoutput = {}
        self.residuetypekey = imp.StringKey("ResidueName")
        self.chainids = "ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvxywz"
        self.dictchain = {}
        self.particle_infos_for_pdb = {}
Exemplo n.º 5
0
 def test_dect(self):
     """Check decorators traits"""
     m = IMP.Model("traits decorator")
     ps = IMP._TrivialTraitsDecorators()
     tr = IMP.StringKey("ttd")
     for i in range(10):
         ps.append(
             IMP._TrivialTraitsDecorator.setup_particle(
                 IMP.Particle(m), tr))
     pso = IMP._pass_decorator_traits(ps)
     self._equal_lists(ps, pso)
Exemplo n.º 6
0
    def test_particles(self):
        """Test that particle attributes are available and correct"""
        (model, particles) = self.setup()
        for (i, p) in enumerate(particles):
            self.assertTrue(p.has_attribute(xkey))
            # A Float "x" exists; make sure that has_attribute doesn't get
            # confused between different types of attribute:
            self.assertFalse(p.has_attribute(IMP.IntKey("x")))
            self.assertFalse(p.has_attribute(IMP.IntKey("notexist")))
            self.assertEqual(p.get_value(xkey), i * 2)
            self.assertEqual(p.get_value(ykey), i * 3)
            self.assertEqual(p.get_value(zkey), i * 4)
            self.assertEqual(p.get_value(idkey), i)
            self.assertEqual(p.get_value(IMP.StringKey("id_str")),
                             "name_" + str(i))
            self.assertEqual(p.get_value(IMP.IntKey("six")), 6)
            self.assertEqual(p.get_value(IMP.StringKey("six")), "b:0110")

        # test additional attributes in particle 11
        p = particles[11]
        for i in range(0, 6):
            val = p.get_value(IMP.FloatKey("attr_" + str(i)))
            self.assertEqual(val, 3.5 * i)
Exemplo n.º 7
0
 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.kernel.ParticleIndexKey("something"), p)
Exemplo n.º 8
0
 def __init__(self, ascii=True,atomistic=False):
     self.dictionary_pdbs = {}
     self.dictionary_rmfs = {}
     self.dictionary_stats = {}
     self.dictionary_stats2 = {}
     self.best_score_list = None
     self.nbestscoring = None
     self.suffixes = []
     self.replica_exchange = False
     self.ascii = ascii
     self.initoutput = {}
     self.residuetypekey = IMP.StringKey("ResidueName")
     self.chainids = "ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvxywz"
     self.dictchain = {}
     self.particle_infos_for_pdb = {}
     self.atomistic=atomistic
Exemplo n.º 9
0
    def test_ms_connectivity_graph_1(self):
        """Test for the correctness of the graph 1."""
        IMP.set_log_level(IMP.SILENT)

        self.ds[0].set_coordinates(IMP.algebra.Vector3D(0.0, 0.0, 0.0))  # A
        self.ds[1].set_coordinates(IMP.algebra.Vector3D(1.0, 1.0, 0.0))  # A
        self.ds[2].set_coordinates(IMP.algebra.Vector3D(2.0, 0.0, 0.0))  # B
        self.ds[3].set_coordinates(IMP.algebra.Vector3D(3.0, 0.0, 0.0))  # B
        self.ds[4].set_coordinates(IMP.algebra.Vector3D(4.0, -1.0, 0.0))  # C
        self.ds[5].set_coordinates(IMP.algebra.Vector3D(1000, 1000, 1000))  # D

        idk = IMP.StringKey("id")
        connections = list()
        pps = self.r.get_connected_pairs()
        for p in pps:
            conn = sorted([p[0].get_value(idk), p[1].get_value(idk)])
            connections.append('%s <-> %s' % (conn[0], conn[1]))
        connections.sort()
        connections = ', '.join(connections)
        self.assertEqual(connections,
                         'A <-> A, A <-> B, A <-> B, B <-> B, B <-> C',
                         'Bad connectivity graph')
Exemplo n.º 10
0
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.kernel.ParticleIndexKey("p0")
pk1 = IMP.kernel.ParticleIndexKey("p1")
pk2 = IMP.kernel.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)
Exemplo n.º 11
0
    def setUp(self):
        """Build test model."""
        IMP.test.TestCase.setUp(self)

        # Setup for example 1
        self.m = IMP.Model()
        self.ps = self.create_particles_in_box(self.m, 6)
        self.ds = [IMP.core.XYZ(p) for p in self.ps]
        ub = IMP.core.HarmonicUpperBound(1.0, 0.1)
        self.ss = IMP.core.DistancePairScore(ub)
        self.r = IMP.core.MSConnectivityRestraint(self.m, self.ss)
        pa = self.r.add_type([self.ds[0], self.ds[1]])
        pb = self.r.add_type([self.ds[2], self.ds[3]])
        pc = self.r.add_type([self.ds[4]])
        pd = self.r.add_type([self.ds[5]])
        i1 = self.r.add_composite([pa, pa, pb, pb, pc])
        i2 = self.r.add_composite([pa, pb, pb, pc], i1)
        i3 = self.r.add_composite([pa, pa, pb, pb], i1)
        i4 = self.r.add_composite([pa, pb], i1)
        i5 = self.r.add_composite([pa, pb, pb], i2)
        i6 = self.r.add_composite([pb, pc], i2)
        i7 = self.r.add_composite([pa, pa, pb], i3)
        i8 = self.r.add_composite([pa, pb], i5)
        idk = IMP.StringKey("id")
        self.ds[0].add_attribute(idk, "A")
        self.ds[1].add_attribute(idk, "A")
        self.ds[2].add_attribute(idk, "B")
        self.ds[3].add_attribute(idk, "B")
        self.ds[4].add_attribute(idk, "C")
        self.ds[5].add_attribute(idk, "D")
        self.sf = IMP.core.RestraintsScoringFunction([self.r])

        # Setup for example 2
        self.m2 = IMP.Model()
        self.ps2 = self.create_particles_in_box(self.m2, 8)
        self.ds2 = [IMP.core.XYZ(p) for p in self.ps2]
        self.r2 = IMP.core.MSConnectivityRestraint(self.m2, self.ss)
        ppa = self.r2.add_type([self.ds2[0], self.ds2[1], self.ds2[2]])
        ppb = self.r2.add_type([self.ds2[3], self.ds2[4]])
        ppc = self.r2.add_type([self.ds2[5], self.ds2[6]])
        ppd = self.r2.add_type([self.ds2[7]])
        ii1 = self.r2.add_composite([ppa, ppa, ppa, ppb, ppb, ppc, ppc, ppd])
        ii2 = self.r2.add_composite([ppa, ppa, ppb, ppc, ppd], ii1)
        ii3 = self.r2.add_composite([ppa, ppa, ppa, ppb, ppb, ppc, ppd], ii1)
        ii4 = self.r2.add_composite([ppa, ppa, ppb, ppb, ppc, ppc, ppd], ii1)
        ii5 = self.r2.add_composite([ppa, ppa, ppa, ppb, ppc, ppc, ppd], ii1)
        ii6 = self.r2.add_composite([ppa, ppa, ppb], ii2)
        ii7 = self.r2.add_composite([ppc, ppd], ii2)
        ii8 = self.r2.add_composite([ppa, ppb, ppc, ppd], ii3)
        ii9 = self.r2.add_composite([ppa, ppa, ppa, ppb, ppc, ppc], ii5)
        ii7pp = self.r2.add_composite([ppc, ppd], ii8)
        ii10 = self.r2.add_composite([ppa, ppb], ii6)
        ii11 = self.r2.add_composite([ppa, ppa, ppc, ppc], ii9)
        self.ds2[0].add_attribute(idk, "A")
        self.ds2[1].add_attribute(idk, "A")
        self.ds2[2].add_attribute(idk, "A")
        self.ds2[3].add_attribute(idk, "B")
        self.ds2[4].add_attribute(idk, "B")
        self.ds2[5].add_attribute(idk, "C")
        self.ds2[6].add_attribute(idk, "C")
        self.ds2[7].add_attribute(idk, "D")
        self.sf2 = IMP.core.RestraintsScoringFunction([self.r2])