예제 #1
0
    def testMultiEndGroups(self):
        """Test we can move correctly"""
        # Try with no settings
        f = ab_fragment.fragmentFactory('A', self.ch4_1Car)
        m1 = Block(initFragment=f)
        m2 = m1.copy()
        eg1 = m1.freeEndGroups()[0]
        eg2 = m2.freeEndGroups()[0]
        m1.positionGrowBlock(eg1, eg2)
        bond = Bond(eg1, eg2)
        bond.engage()
        self.assertEqual(6, len(m1.freeEndGroups()))

        # Try with specifying bond
        f = ab_fragment.fragmentFactory('A', self.ch4_1Car)
        m1 = Block(initFragment=f)
        f.setMaxBond("A:a", 1)
        m2 = m1.copy()
        eg1 = m1.freeEndGroups()[0]
        eg2 = m2.freeEndGroups()[0]
        m1.positionGrowBlock(eg1, eg2)
        bond = Bond(eg1, eg2)
        bond.engage()
        self.assertEqual(4, len(m1.freeEndGroups()))
        return
예제 #2
0
 def testBodyConfigStr(self):
     ch4ca = os.path.join(BLOCKS_DIR, "ch4Ca2.car")
     ftype = "A"
     f1 = ab_fragment.fragmentFactory(ftype, ch4ca)
     for i, b in enumerate(f1.bodies()):
         bstr = "{}{}{}".format(i, ftype, "0000")
         self.assertEqual(bstr, b.rigidConfigStr)
예제 #3
0
    def testConfig(self):
        rigidParticleMgr = ab_rigidparticle.RigidParticleManager()
        ch4ca = os.path.join(BLOCKS_DIR, "ch4Ca2.car")
        ftype = "A"
        f1 = ab_fragment.fragmentFactory(ftype, ch4ca)
        rigidParticles = []
        for body in f1.bodies():
            rigidParticles.append(rigidParticleMgr.createParticle(body))

        pfx = rigidParticleMgr.PREFIX_STR
        configStr = {
            "1A0000": pfx + "AB",
            "2A0000": pfx + "AC",
            "0A0000": pfx + "AA"
        }
        self.assertEqual(rigidParticleMgr._configStr, configStr)
        self.assertEqual(len(rigidParticleMgr._configStr),
                         len(rigidParticleMgr._positions))

        b1 = list(f1.bodies())[0]
        quat_origin = np.array([1.0, 0.0, 0.0, 0.0])
        self.assertEqual(rigidParticleMgr.configStr(b1), pfx + "AA")

        # Rotate fragment and see if we get a different orientation
        axis = np.array([1, 0, 0])
        angle = math.pi / 3
        rotationMatrix = xyz_core.rotation_matrix(axis, angle)
        f1.rotate(rotationMatrix, f1._centerOfMass)
        b1 = list(f1.bodies())[0]
        ref_q = np.array([0.866, 0.5, 0.0, 0.0])
        self.assertTrue(
            np.allclose(rigidParticles[0].orientation,
                        quat_origin,
                        rtol=0.0001))
        return
예제 #4
0
    def testConfigStr(self):
        ch4 = os.path.join(BLOCKS_DIR, "ch4.car")
        ftype = 'A'
        f1 = ab_fragment.fragmentFactory(ftype, ch4)
        cstr = ftype + "0000"
        self.assertEqual(cstr, f1.configStr)

        for eg in f1.endGroups():
            eg.bonded = True
        f1.update()
        cstr = ftype + "1111"
        self.assertEqual(cstr, f1.configStr)
예제 #5
0
 def testPickleRoundtrip(self):
     ch4 = os.path.join(BLOCKS_DIR, "ch4.car")
     ftype = 'A'
     f1 = ab_fragment.fragmentFactory(ftype, ch4)
     f2 = f1.copy()
     labels = ['A', 'A', 'A', 'A', 'A']
     f2._labels = labels
     fname = 'f1.pkl.gz'
     ab_util.pickleObj(f2, fname)
     f3 = ab_util.unpickleObj(fname)
     self.assertEqual(f3._labels, labels)
     os.unlink(fname)
예제 #6
0
    def testPrincipalMoments(self):
        """Test principal moments don't change with rotation"""
        ch4 = os.path.join(BLOCKS_DIR, "ch4.car")
        frag = ab_fragment.fragmentFactory('A', ch4)

        body = list(frag.bodies())[0]
        pi1 = body.principalMoments

        axis = [1, 0, 1]
        angle = math.pi / 3
        rotationMatrix = xyz_core.rotation_matrix(axis, angle)
        center = body.centreOfMass
        frag.rotate(rotationMatrix, center)
        pi2 = body.principalMoments

        self.assertTrue(np.allclose(pi1, pi2))
예제 #7
0
    def testBondingFunction(self):
        carfile = os.path.join(BLOCKS_DIR, "benzene6.car")
        f = ab_fragment.fragmentFactory('A', carfile)

        def x(endGroup):
            fragment = endGroup.fragment
            egt = endGroup.type()
            for eg in fragment.endGroups():
                if egt == "A:a":
                    if not eg.bonded and eg.type() in ["A:c", "A:e"]:
                        eg.blocked = True
                elif egt == "A:b":
                    if not eg.bonded and eg.type() in ["A:d", "A:f"]:
                        eg.blocked = True
                elif egt == "A:c":
                    if not eg.bonded and eg.type() in ["A:a", "A:e"]:
                        eg.blocked = True
                elif egt == "A:d":
                    if not eg.bonded and eg.type() in ["A:b", "A:f"]:
                        eg.blocked = True
                elif egt == "A:e":
                    if not eg.bonded and eg.type() in ["A:a", "A:c"]:
                        eg.blocked = True
                elif egt == "A:f":
                    if not eg.bonded and eg.type() in ["A:b", "A:d"]:
                        eg.blocked = True
            return

        f.onbondFunction = x
        block1 = Block(initFragment=f)

        block2 = Block(filePath=self.ch4Car, fragmentType="B")

        # Check we have 6 free endGroups at the start
        self.assertEqual(len(block1.freeEndGroups()), 6)
        self.assertEqual(len(block2.freeEndGroups()), 4)

        # Create a bond to the first endGroup
        eg1 = block1.freeEndGroups(endGroupTypes="A:a")[0]
        eg2 = block2.freeEndGroups()[0]
        bond = Bond(eg1, eg2)
        bond.engage()

        # Now see if the other two are blocked - we need to include the three from the second block
        self.assertEqual(len(block1.freeEndGroups()), 6)
        return
예제 #8
0
    def testMaxBond(self):
        f = ab_fragment.fragmentFactory('A', self.ch4_1Car)
        f.setMaxBond("A:b", 1)
        block1 = Block(initFragment=f)
        block2 = Block(filePath=self.ch4Car, fragmentType="B")

        self.assertEqual(len(block1.freeEndGroups()), 4)
        self.assertEqual(len(block2.freeEndGroups()), 4)

        # Create a bond to the maxBonded type
        eg1 = block1.freeEndGroups(endGroupTypes="A:b")[0]
        eg2 = block2.freeEndGroups()[0]
        bond = Bond(eg1, eg2)
        bond.engage()

        # Now see if the other three are blocked - we need to include the three from the second block
        self.assertEqual(len(block1.freeEndGroups()), 5)
        return
예제 #9
0
 def testCoords(self):
     ch4ca = os.path.join(BLOCKS_DIR, "ch4.car")
     ftype = "A"
     frag = ab_fragment.fragmentFactory(ftype, ch4ca)
     body = list(frag.bodies())[0]
     assert np.array_equal(body.coords, frag._coords)
예제 #10
0
 def testMultipleCapAtoms(self):
     h3car = os.path.join(BLOCKS_DIR, "H3.car")
     with self.assertRaises(RuntimeError):
         ab_fragment.fragmentFactory('A', h3car)
예제 #11
0
 def testDisallowedFragmentType(self):
     ch4 = os.path.join(BLOCKS_DIR, "ch4.car")
     ftype = 'Fragment'
     with self.assertRaises(AssertionError):
         f1 = ab_fragment.fragmentFactory(ftype, ch4)
예제 #12
0
 def testFragmentType(self):
     ch4 = os.path.join(BLOCKS_DIR, "ch4.car")
     ftype = 'A'
     f1 = ab_fragment.fragmentFactory(ftype, ch4)
     self.assertEqual(ftype, f1.fragmentType)