def test_topology_atom_element(self): """Test getters of TopologyAtom element and atomic number""" topology = Topology() topology.add_molecule(self.toluene_from_sdf) first_element = topology.atom(0).element eighth_element = topology.atom(7).element # Check if types/instances are correct assert isinstance(first_element, element.Element) assert isinstance(eighth_element, element.Element) # Make sure first is a carbon element and eighth is a hydrogen element assert first_element == element.carbon assert eighth_element == element.hydrogen
def test_get_atom(self): """Test Topology.atom function (atom lookup from index)""" topology = Topology() topology.add_molecule(self.ethane_from_smiles) with self.assertRaises(Exception) as context: topology_atom = topology.atom(-1) # Make sure we get 2 carbons and 8 hydrogens n_carbons = 0 n_hydrogens = 0 for index in range(8): if topology.atom(index).atomic_number == 6: n_carbons += 1 if topology.atom(index).atomic_number == 1: n_hydrogens += 1 assert n_carbons == 2 assert n_hydrogens == 6 with self.assertRaises(Exception) as context: topology_atom = topology.atom(8)