Example #1
0
    def _add_edge(self, key, first, second, rest=None):
        """Adds a single edge.

        Parameters
        ----------
        key : string
            The key associated with the given atom.
        first : string
            The key of one of the atoms in the bond
        second : string
            The key of the other atom in the bond
        rest : dict, optional
            Other information relevant to the bond.
        """

        if rest is None:
            rest = {}
        if key in self.bonds:
            raise KeyError("There is already a bond {}".format(key))
        else:
            bond = Bond(self.atoms[first], self.atoms[second], **rest)
            self.add_edge(first, second, key=key, bond_obj=bond)
            self.bonds[key] = bond
Example #2
0
 def test_add_lone_pair_raises_VE_if_bonded(self):
     oxygen = Atom('O')
     Bond(oxygen, self.atom, order=1)
     with self.assertRaises(ValenceError):
         self.atom.add_lone_pair()
Example #3
0
 def test_remove_bond(self):
     oxygen = Atom('O')
     bond = Bond(oxygen, self.atom, order=1)
     self.atom.remove_bond(bond, other=oxygen)
     self.assertNotIn(bond, self.atom.bonds)
     self.assertNotIn(bond, oxygen.bonds)
Example #4
0
 def test_bonded_hydrogen_steric_num(self):
     oxygen = Atom('O')
     Bond(oxygen, self.atom, order=1)
     self.assertEqual(self.atom.steric_num, 1)
Example #5
0
 def test_add_bond(self):
     oxygen = Atom('O')
     bond = Bond(oxygen, self.atom, order=1)
     self.assertIs(bond, oxygen.bonds[0])
     self.assertIs(bond, self.atom.bonds[0])
Example #6
0
 def test_hydrogen_bonded_charge(self):
     oxygen = Atom('O')
     oxygen.add_lone_pair(3)
     Bond(oxygen, self.atom, order=1)
     self.assertEqual(self.atom.charge, 0)
     self.assertEqual(oxygen.charge, -1)
Example #7
0
 def test_serialize_bond(self):
     self.assertEqual(
         json.dumps(Bond(Atom('H'), Atom('H')),
                    cls=compounds._ChemicalSerializer),
         '{"members": [{"symbol": "H"}, {"symbol": "H"}]}')