Esempio n. 1
0
 def testScattererB(self):
     """Test Biso and Bij of scatterer."""
     sp1, junk = makeScatterer()
     self.assertTrue(sp1.IsIsotropic())
     sp2, junk = makeScattererAnisotropic()
     self.assertFalse(sp2.IsIsotropic())
     return
Esempio n. 2
0
 def testGetScatterer(self):
     """Test GetScatterer."""
     sp, atom = makeScatterer()
     c = makeCrystal(sp, atom)
     for i in range(c.GetNbScatterer()):
         c.GetScatterer(i)
     return
Esempio n. 3
0
 def testScattererB(self):
     """Test Biso and Bij of scatterer."""
     sp1, junk = makeScatterer()
     self.assertTrue(sp1.IsIsotropic())
     sp2, junk = makeScattererAnisotropic()
     self.assertFalse(sp2.IsIsotropic())
     return
Esempio n. 4
0
    def testDummyAtom(self):
        """Test dummy atoms."""
        c = makeCrystal(*makeScatterer())

        c.AddScatterer(Atom(0, 0, 0, "dummy", None))

        d = c.GetScatterer("dummy")
        self.assertTrue(d.GetScatteringPower() is None)
        return
Esempio n. 5
0
    def testDummyAtom(self):
        """Test dummy atoms."""
        c = makeCrystal(*makeScatterer())

        c.AddScatterer(Atom(0, 0, 0, "dummy", None))

        d = c.GetScatterer("dummy")
        self.assertTrue(d.GetScatteringPower() is None)
        return
Esempio n. 6
0
    def testCrystalScope(self):
        """Test to see if the the crystal survives after it is out of scope."""
        sp, atom = makeScatterer()
        makeCrystal(sp, atom)

        # The crystal is out of scope. Since the lifetime of the atom and
        # scatterer are linked, the crystal should stay alive in memory.
        self.assertEqual("Ni", sp.GetName())
        self.assertEqual("Ni", atom.GetName())
        return
Esempio n. 7
0
    def testCrystalScope(self):
        """Test to see if the the crystal survives after it is out of scope."""
        sp, atom = makeScatterer()
        makeCrystal(sp, atom)

        # The crystal is out of scope. Since the lifetime of the atom and
        # scatterer are linked, the crystal should stay alive in memory.
        self.assertEqual("Ni", sp.GetName())
        self.assertEqual("Ni", atom.GetName())
        return
Esempio n. 8
0
    def testRemoveFunctions(self):
        """Test the RemoveScatterer and RemoveScatteringPower method."""
        sp, atom = makeScatterer()
        c = makeCrystal(sp, atom)

        # You can add scatterers with the same name. That should be a no-no.
        sp2, atom2 = makeScatterer()
        c.AddScatterer(atom2)
        c.AddScatteringPower(sp2)

        # These act according to the library. You can try to remove an object
        # that is not in the crystal, and it will gladly do nothing for you.

        # Remove the scatterers
        c.RemoveScatterer(atom)
        c.RemoveScatteringPower(sp)
        # Remove again
        c.RemoveScatterer(atom)
        c.RemoveScatteringPower(sp)

        # Try to remove scatterers that are not in the crystal
        c.RemoveScatterer(atom2)
        c.RemoveScatteringPower(sp2)
        return
Esempio n. 9
0
    def testRemoveFunctions(self):
        """Test the RemoveScatterer and RemoveScatteringPower method."""
        sp, atom = makeScatterer()
        c = makeCrystal(sp, atom)

        # You can add scatterers with the same name. That should be a no-no.
        sp2, atom2 = makeScatterer()
        c.AddScatterer(atom2)
        c.AddScatteringPower(sp2)

        # These act according to the library. You can try to remove an object
        # that is not in the crystal, and it will gladly do nothing for you.

        # Remove the scatterers
        c.RemoveScatterer(atom)
        c.RemoveScatteringPower(sp)
        # Remove again
        c.RemoveScatterer(atom)
        c.RemoveScatteringPower(sp)

        # Try to remove scatterers that are not in the crystal
        c.RemoveScatterer(atom2)
        c.RemoveScatteringPower(sp2)
        return
Esempio n. 10
0
    def testGetScatteringComponentList(self):
        """Test the RemoveScatterer and RemoveScatteringPower method."""
        sp, atom = makeScatterer()
        c = makeCrystal(sp, atom)
        scl = c.GetScatteringComponentList()
        self.assertEqual(1, len(scl))

        sclcopy = scl[:]
        self.assertEqual(1, len(scl))

        del sclcopy[0]
        self.assertEqual(0, len(sclcopy))
        self.assertEqual(1, len(scl))

        del scl[0]
        self.assertEqual(0, len(scl))

        return
Esempio n. 11
0
    def testGetScatteringComponentList(self):
        """Test the RemoveScatterer and RemoveScatteringPower method."""
        sp, atom = makeScatterer()
        c = makeCrystal(sp, atom)
        scl = c.GetScatteringComponentList()
        self.assertEqual(1, len(scl))

        sclcopy = scl[:]
        self.assertEqual(1, len(scl))

        del sclcopy[0]
        self.assertEqual(0, len(sclcopy))
        self.assertEqual(1, len(scl))

        del scl[0]
        self.assertEqual(0, len(scl))

        return
Esempio n. 12
0
 def testGetScatterer(self):
     """Test GetScatterer and GetScatt."""
     sp, atom = makeScatterer()
     c = makeCrystal(sp, atom)
     for fget in (c.GetScatterer, c.GetScatt):
         for i in range(c.GetNbScatterer()):
             fget(i)
         a = fget(0)
         ani = fget("Ni")
         self.assertEqual([a.X, a.Y, a.Z], [ani.X, ani.Y, ani.Z])
         a.X = 0.112
         self.assertEqual(a.X, ani.X)
         aneg = fget(-1)
         self.assertEqual(a.X, aneg.X)
         self.assertRaises(ValueError, fget, 'invalid')
         self.assertRaises(IndexError, fget, 10)
         self.assertRaises(IndexError, fget, -2)
     return
Esempio n. 13
0
    def testToFromPython(self):
        """See if refinable parameters can be created from within python and
        within c++."""
        c = makeCrystal(*makeScatterer())

        # Get a parameter created from c++
        par = c.GetPar("a")
        self.assertAlmostEqual(3.52, par.GetValue())

        # pass a parameter and pass it into c++
        c.AddPar(self.testpar);

        # get it back
        testpar2 = c.GetPar("test")

        self.assertAlmostEqual(self.testpar.GetValue(), testpar2.GetValue())

        testpar2.SetValue(2.17)
        self.assertAlmostEqual(2.17, testpar2.GetValue(), places = 6)
        self.assertAlmostEqual(self.testpar.GetValue(), testpar2.GetValue())
        return
Esempio n. 14
0
    def testEmbedding(self):
        """Test integrity of mutually-embedded objects."""

        c = makeCrystal(*makeScatterer())

        class Level1(object):
            def __init__(self, c):
                self.c = c
                self.level2 = Level2(self)
                return

        class Level2(object):
            def __init__(self, level1):
                self.level1 = level1
                return

        l1 = Level1(c)

        del l1

        return
Esempio n. 15
0
    def testEmbedding(self):
        """Test integrity of mutually-embedded objects."""

        c = makeCrystal(*makeScatterer())

        class Level1(object):
            def __init__(self, c):
                self.c = c
                self.level2 = Level2(self)
                return

        class Level2(object):
            def __init__(self, level1):
                self.level1 = level1
                return

        l1 = Level1(c)

        del l1

        return