Example #1
0
    def testClockIncrement(self):
        """Make sure that clocks increment properly."""
        c = makeC60()
        m = c.GetScatterer("c60")

        ref = RefinableObjClock()
        mclock = m.GetClockScatterer()

        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m[0].X = 0.01
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m[1].X = 0.01
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m[1].Y = 0.01
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m.Q0 = 1.001
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )
Example #2
0
    def testClockIncrement(self):
        """Make sure that clocks increment properly."""
        c = makeC60()
        m = c.GetScatterer("c60")

        ref = RefinableObjClock()
        mclock = m.GetClockScatterer()

        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m[0].X = 0.01
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m[1].X = 0.01
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m[1].Y = 0.01
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )

        m.Q0 = 1.001
        self.assertTrue( mclock > ref )
        ref.Click()
        self.assertFalse( mclock > ref )
Example #3
0
 def testContainment(self):
     """Make sure we can still use the molecule if the crystal is out of
     scope."""
     c = makeC60()
     m = self.c.GetScatterer("c60")
     self.assertEqual("c60", m.GetName())
     del c
     self.assertEqual("c60", m.GetName())
     return
Example #4
0
    def setUp(self):
        c = makeC60()
        self.m = c.GetScatterer("c60")

        # Add a bond
        self.a1 = self.m.GetAtom(0)
        self.a2 = self.m.GetAtom(1)

        self.b = self.m.AddBond(self.a1, self.a2, 5, 1, 2)
        return
Example #5
0
 def testAddPar(self):
     """See if we crash if we add a parameter and delete the molecule."""
     c = makeC60()
     m = self.c.GetScatterer("c60")
     rpt = RefParType("test")
     par = RefinablePar("testpar", 3, 0, 10, rpt)
     m.AddPar(par)
     self.assertAlmostEqual(3, par.GetValue())
     del m
     self.assertAlmostEqual(3, par.GetValue())
     del c
     self.assertAlmostEqual(3, par.GetValue())
     return
Example #6
0
    def setUp(self):
        c = makeC60()
        self.m = c.GetScatterer("c60")

        # Add a bond
        self.a1 = self.m.GetAtom(0)
        self.a2 = self.m.GetAtom(1)
        self.a3 = self.m.GetAtom(2)
        self.a4 = self.m.GetAtom(3)

        self.da = self.m.AddDihedralAngle(self.a1, self.a2, self.a3, self.a4,
                                          5, 1, 2)
        return
Example #7
0
    def testAtoms(self):
        """Make sure the atoms are there.

        This tests AddAtom by association.
        This tests GetAtom.
        """
        self.assertEqual(60, self.m.GetNbAtoms())
        for i in range(60):
            a1 = self.m.GetAtom(i)
            self.assertEqual(a1.GetName(), "C%i" % i)

        a = self.m.GetAtom(0)
        x = a.X

        self.assertEqual(60, self.m.GetNbAtoms())

        self.m.RemoveAtom(a)

        self.assertEqual(59, self.m.GetNbAtoms())

        # Make sure the atom is still valid. We don't want RemoveAtom deleting
        # the memory for an object we still have access to.
        self.assertEqual(a.X, x)

        # Check to see if a is in our list
        for i in range(59):
            self.assertNotEqual(a.GetName(), self.m.GetAtom(i))

        # What happens if we try to remove an atom that is not in the molecule?
        # First, try the same atom again. This will throw an objcryst error.
        self.assertRaises(ObjCrystException, self.m.RemoveAtom, a)

        ## Try to remove an atom from another molecule
        c = makeC60()
        m = c.GetScatterer("c60")
        self.assertRaises(ObjCrystException, self.m.RemoveAtom, m.GetAtom(1))

        # Remove all the atoms.
        for a in self.m[:]:
            self.m.RemoveAtom(a)

        atoms = self.m.GetAtomList()
        self.assertEqual(0, len(atoms))

        self.assertEqual(0, self.m.GetNbAtoms())

        return
Example #8
0
 def setUp(self):
     c = makeC60()
     self.m = c.GetScatterer("c60")
     self.a = self.m.GetAtom("C0")
     return
Example #9
0
 def setUp(self):
     self.c = makeC60()
     self.m = self.c.GetScatterer("c60")
     return
Example #10
0
    def testDihedralAngles(self):
        """Test the FindDihedralAngle method."""
        a1 = self.m.GetAtom(0)
        a2 = self.m.GetAtom(1)
        a3 = self.m.GetAtom(2)
        a4 = self.m.GetAtom(3)
        a5 = self.m.GetAtom(5)

        # Check for a dihedral angle that doesn't exist
        da = self.m.FindDihedralAngle(a1, a2, a3, a4)
        self.assertTrue(da is None)

        # Make a da and try to find it
        self.m.AddDihedralAngle(a1, a2, a3, a4, 90, 0, 0)
        da1 = self.m.FindDihedralAngle(a1, a2, a3, a4)
        da2 = self.m.FindDihedralAngle(a1, a2, a3, a4)
        self.assertTrue(da1 is not None)
        self.assertEqual(da1.GetName(), da2.GetName())

        # Remove an atom, the dihedral angle should disappear as well.
        self.m.RemoveAtom(a1)
        da4 = self.m.FindDihedralAngle(a2, a1, a3, a4)
        self.assertTrue(da4 is None)

        # Try to find a dihedral angle from an atom outside of the molecule.
        m = makeC60().GetScatterer("c60")
        b1 = m.GetAtom(0)
        b2 = m.GetAtom(1)
        b3 = m.GetAtom(1)
        b4 = m.GetAtom(1)
        da5 = self.m.FindDihedralAngle(b1, b2, b3, b4)
        self.assertTrue(da5 is None)

        # make a good dihedral angle
        da6 = self.m.AddDihedralAngle(a2, a3, a4, a5, 5, 0, 0)
        da7 = self.m.GetDihedralAngle(0)
        self.assertEqual(da6.GetName(), da7.GetName())

        # Delete some dihedral angles and see what happens
        name = da6.GetName()
        del da6
        del da7
        da8 = self.m.GetDihedralAngle(0)
        self.assertEqual(name, da8.GetName())

        # Try to get a dihedral angle that doesn't exist by index
        self.assertRaises(IndexError, self.m.GetDihedralAngle, 1)

        # Remove the dihedral angle
        angles = self.m.GetDihedralAngleList()
        self.assertEqual(1, len(angles))
        self.m.RemoveDihedralAngle(angles[0])
        # is the object still in existance?
        self.assertEqual(name, da8.GetName())
        # Can we get it from the engine?
        self.assertRaises(IndexError, self.m.GetDihedralAngle, 0)
        da9 = self.m.FindDihedralAngle(a2, a3, a4, a5)
        self.assertTrue(da9 is None)

        # make a good dihedral angle again
        da10 = self.m.AddDihedralAngle(a2, a3, a4, a5, 5, 0, 0)
        # Get an atom from that
        a = da10.GetAtom1()
        # Try to remove that atom
        self.m.RemoveAtom(a)
        self.assertEqual(0, self.m.GetNbDihedralAngles())

        return
Example #11
0
    def testBondAngles(self):
        """Test the BondAngle accessors."""
        a1 = self.m.GetAtom(0)
        a2 = self.m.GetAtom(1)
        a3 = self.m.GetAtom(2)
        a4 = self.m.GetAtom(3)

        # Check for a bondangle angle that doesn't exist
        ba = self.m.FindBondAngle(a1, a2, a3)
        self.assertTrue(ba is None)

        # Make a ba and try to find it
        self.m.AddBondAngle(a2, a1, a3, 90, 0, 0)
        ba1 = self.m.FindBondAngle(a2, a1, a3)
        ba2 = self.m.FindBondAngle(a3, a1, a2)
        ba3 = self.m.FindBondAngle(a1, a2, a4)
        self.assertTrue(ba1 is not None)
        self.assertEqual(ba1.GetName(), ba2.GetName())

        # Try some bad bond angles
        self.assertTrue(ba3 is None)

        # Remove an atom, the bondangle should disappear as well.
        self.m.RemoveAtom(a1)
        ba4 = self.m.FindBondAngle(a2, a1, a3)
        self.assertTrue(ba4 is None)

        # Try to find a bondangle from an atom outside of the molecule.
        m = makeC60().GetScatterer("c60")
        b1 = m.GetAtom(0)
        b2 = m.GetAtom(1)
        b3 = m.GetAtom(1)
        ba5 = self.m.FindBondAngle(b1, b2, b3)
        self.assertTrue(ba5 is None)

        # make a good bond angle
        ba6 = self.m.AddBondAngle(a2, a3, a4, 5, 0, 0)
        ba7 = self.m.GetBondAngle(0)
        self.assertEqual(ba6.GetName(), ba7.GetName())

        # Delete some bond angles and see what happens
        name = ba6.GetName()
        del ba6
        del ba7
        ba8 = self.m.GetBondAngle(0)
        self.assertEqual(name, ba8.GetName())

        # Try to get a bond angle that doesn't exist by index
        self.assertRaises(IndexError, self.m.GetBondAngle, 1)

        # Remove the bond angle
        angles = self.m.GetBondAngleList()
        self.assertEqual(1, len(angles))
        self.m.RemoveBondAngle(angles[0])
        # is the object still in existance?
        self.assertEqual(name, ba8.GetName())
        # Can we get it from the engine?
        self.assertRaises(IndexError, self.m.GetBondAngle, 0)
        ba9 = self.m.FindBondAngle(a2, a3, a4)
        self.assertTrue(ba9 is None)

        # make a good bond angle again
        ba10 = self.m.AddBondAngle(a2, a3, a4, 5, 0, 0)
        # Get an atom from that
        a = ba10.GetAtom1()
        # Try to remove that atom
        self.m.RemoveAtom(a)
        self.assertEqual(0, self.m.GetNbBondAngles())
        return
Example #12
0
    def testBonds(self):
        """Test the Bond methods."""

        a1 = self.m.GetAtom(0)
        a2 = self.m.GetAtom(1)
        a3 = self.m.GetAtom(2)
        a4 = self.m.GetAtom(3)

        # Check for a bond that doesn't exist
        bond = self.m.FindBond(a1, a2)
        self.assertTrue(bond is None)

        # Make a bond and try to find it
        self.m.AddBond(a1, a2, 5, 0, 0)
        bond1 = self.m.FindBond(a1, a2)
        bond2 = self.m.FindBond(a2, a1)
        bond3 = self.m.FindBond(a1, a3)
        self.assertTrue(bond1 is not None)
        # Cannot expect the python objects to be the same, but they should point
        # to the same internal object
        self.assertEqual(bond1.GetName(), bond2.GetName())

        # Try some bad bonds
        self.assertTrue(bond3 is None)

        # Remove an atom, the bond should disappear as well.
        self.m.RemoveAtom(a1)
        bond4 = self.m.FindBond(a1, a2)
        self.assertTrue(bond4 is None)

        # Try to find a bond from an atom outside of the molecule.
        m = makeC60().GetScatterer("c60")
        b1 = m.GetAtom(0)
        b2 = m.GetAtom(1)
        bond5 = self.m.FindBond(b1, b2)
        self.assertTrue(bond5 is None)

        # Try to make a bond using an atom that is not in the structure...
        # This seems to be allowed by ObjCryst++, and causes no errors. This
        # might be necessary to constrain a distance between two molecules,
        # thus it is allowed.

        # make a good bond.
        bond6 = self.m.AddBond(a3, a4, 5, 0, 0)
        bond7 = self.m.GetBond(0)
        self.assertEqual(bond6.GetName(), bond7.GetName())

        # Delete some bonds and see what happens
        name = bond6.GetName()
        del bond6
        del bond7
        bond8 = self.m.GetBond(0)
        self.assertEqual(name, bond8.GetName())

        # Try to get a bond that doesn't exist by index
        self.assertRaises(IndexError, self.m.GetBond, 1)

        # Remove the bond
        bonds = self.m.GetBondList()
        self.assertEqual(1, len(bonds))
        self.m.RemoveBond(bonds[0])
        # is the bond still in existance?
        self.assertEqual(name, bond8.GetName())
        # Can we get it from the engine?
        self.assertRaises(IndexError, self.m.GetBond, 0)
        bond9 = self.m.FindBond(a3, a4)
        self.assertTrue(bond9 is None)

        # make a good bond again
        bond10 = self.m.AddBond(a3, a4, 5, 0, 0)
        # Get an atom from that
        a = bond10.GetAtom1()
        # Try to remove that atom
        self.m.RemoveAtom(a)
        self.assertEqual(0, self.m.GetNbBonds())

        return