def testAxisSymmetryNumberAllyl(self): """ Test the Molecule.calculateAxisSymmetryNumber() on [CH2]C=C """ spc = Species(molecule=[Molecule().fromSMILES('[CH2]C=C')]) molecule = spc.getResonanceHybrid() self.assertEqual(calculateAxisSymmetryNumber(molecule), 1)
def testGetResonanceHybrid(self): """ Tests that getResonanceHybrid returns an isomorphic structure which has intermediate bond orders. This check is for C=C[CH]CC which has another resonance structure, [CH2]C=CC. When these structures are merged, the bond structure should be, C~C~CC, where '~' is a hybrid bond of order 1.5. """ spec = Species().fromSMILES('C=C[CH]CC') hybridMol = spec.getResonanceHybrid() self.assertTrue(hybridMol.toSingleBonds().isIsomorphic(spec.molecule[0].toSingleBonds())) # a rough check for intermediate bond orders expected_orders = [1,1.5] bonds = [] # ensure all bond orders are expected for atom in hybridMol.atoms: for atom2 in atom.bonds: bond = hybridMol.getBond(atom,atom2) self.assertTrue(any([bond.isOrder(otherOrder) for otherOrder in expected_orders]), 'Unexpected bond order {}'.format(bond.getOrderNum())) bonds.append(bond) # ensure all expected orders are present for expected_order in expected_orders: self.assertTrue(any([bond.isOrder(expected_order) for bond in bonds]),'No bond of order {} found'.format(expected_order))
def testGetResonanceHybrid(self): """ Tests that getResonanceHybrid returns an isomorphic structure which has intermediate bond orders. This check is for C=C[CH]CC which has another resonance structure, [CH2]C=CC. When these structures are merged, the bond structure should be, C~C~CC, where '~' is a hybrid bond of order 1.5. """ spec = Species().fromSMILES('C=C[CH]CC') hybridMol = spec.getResonanceHybrid() self.assertTrue(hybridMol.toSingleBonds().isIsomorphic( spec.molecule[0].toSingleBonds())) # a rough check for intermediate bond orders expected_orders = [1, 1.5] bonds = [] # ensure all bond orders are expected for atom in hybridMol.atoms: for atom2 in atom.bonds: bond = hybridMol.getBond(atom, atom2) self.assertTrue( any([ bond.isOrder(otherOrder) for otherOrder in expected_orders ]), 'Unexpected bond order {}'.format(bond.getOrderNum())) bonds.append(bond) # ensure all expected orders are present for expected_order in expected_orders: self.assertTrue( any([bond.isOrder(expected_order) for bond in bonds]), 'No bond of order {} found'.format(expected_order))
def testDrawNonStandardBonds(self): spec = Species().fromSMILES('[CH2]C=C[CH2]') hybrid = spec.getResonanceHybrid() try: from cairocffi import PDFSurface except ImportError: from cairo import PDFSurface surface, cr, (xoff, yoff, width, height) = self.drawer.draw(hybrid, format='pdf') self.assertIsInstance(surface, PDFSurface)
def testAtomSymmetryNumberAllyl(self): """ Test the Molecule.calculateAtomSymmetryNumber() on [CH2]C=C """ spc = Species(molecule=[Molecule().fromSMILES('[CH2]C=C')]) molecule = spc.getResonanceHybrid() symmetryNumber = 1 for atom in molecule.atoms: if not molecule.isAtomInCycle(atom): symmetryNumber *= calculateAtomSymmetryNumber(molecule, atom) self.assertEqual(symmetryNumber, 2)
def testBondSymmetryNumberAllyl(self): """ Test the Molecule.calculateBondSymmetryNumber() on [CH2]C=C """ spc = Species(molecule=[Molecule().fromSMILES('[CH2]C=C')]) molecule = spc.getResonanceHybrid() symmetryNumber = 1 for atom1 in molecule.atoms: for atom2 in atom1.bonds: if molecule.atoms.index(atom1) < molecule.atoms.index(atom2): symmetryNumber *= calculateBondSymmetryNumber(molecule, atom1, atom2) self.assertEqual(symmetryNumber, 1)
def testEdgeCarbonAtomSymmetryNumberAllyl(self): """ Test the Molecule.calculateAtomSymmetryNumber() for the edge carbons on [CH2]C=C """ spc = Species(molecule=[Molecule().fromSMILES('[CH2]C=C')]) molecule = spc.getResonanceHybrid() for atom in molecule.atoms: if atom.symbol =='C': number_carbon_bonds = sum([1 for bond in atom.bonds if bond.symbol=='C']) if number_carbon_bonds == 1: atom.label = 'edge' symmetryNumber = calculateAtomSymmetryNumber(molecule, atom) self.assertEqual(symmetryNumber, 1)
def testMiddleCarbonAtomSymmetryNumberAllylUsingResonanceHybrid(self): """ Test the Molecule.calculateAtomSymmetryNumber() for the middle carbon on [CH2]C=C using the resonance hybrid structure """ molecule = Molecule().fromSMILES('[CH2]C=C') species = Species(molecule=[molecule]) resonanceHybrid = species.getResonanceHybrid() for atom in resonanceHybrid.atoms: if atom.symbol == 'C': number_carbon_bonds = sum([1 for bond in atom.bonds if bond.symbol=='C']) if number_carbon_bonds == 2: atom.label = 'center' symmetryNumber = calculateAtomSymmetryNumber(resonanceHybrid, atom) self.assertEqual(symmetryNumber, 2) pass