def test_pack_molecule(self): from mogli import Molecule, LGFIOConfig, pack_molecule, unpack_molecule mol1 = Molecule() mol2 = Molecule() config = LGFIOConfig('label', 'atomType') config.add_string_node_prop("label2")\ .add_bool_node_prop("isC")\ .add_int_node_prop("iNum")\ .add_double_node_prop("dNum") mol1.read_lgf(ETHANE_PROPS, config) mol2 = unpack_molecule(pack_molecule(mol1)) self.assertEqual(mol1.get_atom_count(), mol2.get_atom_count()) def s(e): id1 = mol1.get_id(mol1.get_u(e)) id2 = mol1.get_id(mol1.get_v(e)) return (id1, id2) if id1 < id2 else (id2, id1) edges1 = sorted([s(e) for e in mol1.get_edge_iter()]) edges2 = sorted([s(e) for e in mol2.get_edge_iter()]) self.assertEqual(edges1, edges2) props = mol2.get_properties() self.assertIn('label2', props) self.assertIn('isC', props) self.assertIn('iNum', props) self.assertIn('dNum', props) for v1 in mol1.get_node_iter(): v2 = mol2.get_node_by_id(mol1.get_id(v1)) self.assertEqual(mol1.get_property(v1, 'label2'), mol2.get_property(v2, 'label2')) self.assertEqual(mol1.get_property(v1, 'isC'), mol2.get_property(v2, 'isC')) self.assertEqual(mol1.get_property(v1, 'iNum'), mol2.get_property(v2, 'iNum')) self.assertEqual(mol1.get_property(v1, 'dNum'), mol2.get_property(v2, 'dNum'))
def test_read_lgf(self): from mogli import Molecule mol = Molecule() mol.read_lgf(ETHANE_1) self.assertEqual(mol.get_atom_count(), 8) c1 = mol.get_node_by_id(0) c2 = mol.get_node_by_id(1) props = mol.get_properties() self.assertIn('label2', props) self.assertEqual(mol.get_property(c1, 'label2'), 'C1') self.assertEqual(mol.get_property(c2, 'label2'), 'C2') c1_edges = {(0, 1), (0, 2), (0, 3), (0, 4)} c2_edges = {(0, 1), (1, 5), (1, 6), (1, 7)} edges = c1_edges | c2_edges for e in mol.get_inc_edge_iter(c1): id1 = mol.get_id(mol.get_u(e)) id2 = mol.get_id(mol.get_v(e)) edge = (id1, id2) if id1 < id2 else (id2, id1) self.assertIn(edge, c1_edges) for e in mol.get_inc_edge_iter(c2): id1 = mol.get_id(mol.get_u(e)) id2 = mol.get_id(mol.get_v(e)) edge = (id1, id2) if id1 < id2 else (id2, id1) self.assertIn(edge, c2_edges) for e in mol.get_edge_iter(): id1 = mol.get_id(mol.get_u(e)) id2 = mol.get_id(mol.get_v(e)) edge = (id1, id2) if id1 < id2 else (id2, id1) self.assertIn(edge, edges)
def test_read_lgf_properties(self): from mogli import LGFIOConfig, Molecule config = LGFIOConfig("label", "atomType") config.add_string_node_prop("label2")\ .add_bool_node_prop("isC")\ .add_int_node_prop("iNum")\ .add_double_node_prop("dNum") mol = Molecule() mol.read_lgf(ETHANE_PROPS, config) self.assertEqual(mol.get_atom_count(), 8) props = mol.get_properties() self.assertEqual(len(props), 4) self.assertIn("label2", props) self.assertIn("isC", props) self.assertIn("iNum", props) self.assertIn("dNum", props) v = mol.get_node_by_id(0) self.assertEqual(mol.get_property(v, "label2"), "C1") self.assertTrue(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 1) self.assertEqual(mol.get_property(v, "dNum"), 1.0) v = mol.get_node_by_id(1) self.assertEqual(mol.get_property(v, "label2"), "C2") self.assertTrue(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 2) self.assertEqual(mol.get_property(v, "dNum"), 2.0) v = mol.get_node_by_id(2) self.assertEqual(mol.get_property(v, "label2"), "H3") self.assertFalse(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 3) self.assertEqual(mol.get_property(v, "dNum"), 3.0) v = mol.get_node_by_id(3) self.assertEqual(mol.get_property(v, "label2"), "H4") self.assertFalse(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 4) self.assertEqual(mol.get_property(v, "dNum"), 4.0) v = mol.get_node_by_id(4) self.assertEqual(mol.get_property(v, "label2"), "H5") self.assertFalse(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 5) self.assertEqual(mol.get_property(v, "dNum"), 5.0) v = mol.get_node_by_id(5) self.assertEqual(mol.get_property(v, "label2"), "H6") self.assertFalse(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 6) self.assertEqual(mol.get_property(v, "dNum"), 6.0) v = mol.get_node_by_id(6) self.assertEqual(mol.get_property(v, "label2"), "H7") self.assertFalse(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 7) self.assertEqual(mol.get_property(v, "dNum"), 7.0) v = mol.get_node_by_id(7) self.assertEqual(mol.get_property(v, "label2"), "H8") self.assertFalse(mol.get_property(v, "isC")) self.assertEqual(mol.get_property(v, "iNum"), 8) self.assertEqual(mol.get_property(v, "dNum"), 8.0)