Ejemplo n.º 1
0
 def test_rings(self):
     # benzene molecule
     benzene = chemkit.Molecule("c1ccccc1", "smiles")
     self.assertEqual(benzene.formula(), "C6H6")
     self.assertEqual(benzene.ringCount(), 1)
     ring = benzene.ring(0)
     self.assertEqual(ring.size(), 6)
Ejemplo n.º 2
0
    def test_name(self):
        molecule = chemkit.Molecule()
        atom = molecule.addAtom("C")
        self.assertEqual(atom.name(), "Carbon")

        atom.setAtomicNumber(8)
        self.assertEqual(atom.name(), "Oxygen")
Ejemplo n.º 3
0
    def test_symbol(self):
        molecule = chemkit.Molecule()
        atom = molecule.addAtom("C")
        self.assertEqual(atom.symbol(), "C")

        atom.setAtomicNumber(2)
        self.assertEqual(atom.symbol(), "He")
Ejemplo n.º 4
0
    def test_atoms(self):
        molecule = chemkit.Molecule()
        a = molecule.addAtom("C")
        b = molecule.addAtom("C")

        bond = molecule.addBond(a, b)
        self.assertEqual(bond.atom(0), a)
        self.assertEqual(bond.atom(1), b)
        self.assertEqual(bond.atoms(), [a, b])
Ejemplo n.º 5
0
    def test_formula(self):
        # empty molecule
        empty = chemkit.Molecule()
        self.assertEqual(empty.formula(), "")

        # ethanol molecule
        ethanol = chemkit.Molecule()
        C1 = ethanol.addAtom("C")
        C2 = ethanol.addAtom("C")
        O3 = ethanol.addAtom("O")
        ethanol.addBond(C1, C2)
        ethanol.addBond(C2, O3)

        for atom in ethanol.atoms():
            while (atom.formalCharge() < 0):
                hydrogen = ethanol.addAtom("H")
                ethanol.addBond(atom, hydrogen)

        self.assertEqual(ethanol.formula(), "C2H6O")
Ejemplo n.º 6
0
 def test_atom(self):
     molecule = chemkit.Molecule()
     C1 = molecule.addAtom("C")
     self.assertEqual(C1.atomicNumber(), 6)
     C2 = molecule.addAtom(6)
     self.assertEqual(C2.atomicNumber(), 6)
     C3 = molecule.addAtom(chemkit.Atom.Carbon)
     self.assertEqual(C3.atomicNumber(), 6)
     self.assertEqual(molecule.atomCount(), 3)
     self.assertEqual(molecule.formula(), "C3")
Ejemplo n.º 7
0
 def test_bond(self):
     molecule = chemkit.Molecule()
     self.assertEqual(molecule.bondCount(), 0)
     C1 = molecule.addAtom("C")
     C2 = molecule.addAtom("C")
     C3 = molecule.addAtom("C")
     C1_C2 = molecule.addBond(C1, C2)
     self.assertEqual(molecule.bondCount(), 1)
     C2_C3 = molecule.addBond(C2, C3, 2)
     self.assertEqual(molecule.bondCount(), 2)
     self.assertEqual(C2_C3.order(), 2)
Ejemplo n.º 8
0
    def test_benzene_mmff(self):
        molecule = chemkit.Molecule("c1ccccc1", "smiles")
        self.assertEqual(molecule.formula(), "C6H6")

        typer = chemkit.AtomTyper.create("mmff")
        typer.setMolecule(molecule)

        for atom in molecule.atoms():
            if atom.symbol() == "C":
                self.assertEqual(typer.type(atom), "37")
            elif atom.symbol() == "H":
                self.assertEqual(typer.type(atom), "5")
Ejemplo n.º 9
0
    def test_length(self):
        molecule = chemkit.Molecule()
        a = molecule.addAtom("C")
        a.setPosition(2, 0, 0)
        b = molecule.addAtom("C")
        b.setPosition(5, 0, 0)

        bond = molecule.addBond(a, b)
        self.assertEqual(round(bond.length()), 3)

        b.setPosition(-2, 0, 0)
        self.assertEqual(round(bond.length()), 4)
Ejemplo n.º 10
0
    def test_order(self):
        molecule = chemkit.Molecule()
        a = molecule.addAtom("C")
        b = molecule.addAtom("C")

        bond = molecule.addBond(a, b)
        self.assertEqual(bond.order(), 1)
        self.assertEqual(bond.order(), chemkit.Bond.Single)

        bond.setOrder(2)
        self.assertEqual(bond.order(), 2)
        self.assertEqual(bond.order(), chemkit.Bond.Double)
Ejemplo n.º 11
0
    def test_assign_types(self):
        molecule = chemkit.Molecule("CCO", "smiles")
        self.assertEqual(molecule.formula(), "C2H6O")

        for atom in molecule.atoms():
            self.assertEqual(atom.type(), "")

        chemkit.AtomTyper.assignAtomTypes(molecule, "element-name")

        for atom in molecule.atoms():
            if atom.symbol() == "C":
                self.assertEqual(atom.type(), "Carbon")
            elif atom.symbol() == "H":
                self.assertEqual(atom.type(), "Hydrogen")
            elif atom.symbol() == "O":
                self.assertEqual(atom.type(), "Oxygen")