def test_generate_resonance_structures2(self): adj = """1 C u0 p0 c0 {2,D} {10,S} {11,S} 2 C u0 p0 c0 {1,D} {3,S} {12,S} 3 C u0 p0 c0 {2,S} {4,D} {13,S} 4 C u0 p0 c0 {3,D} {5,S} {9,S} 5 C u0 p0 c0 {4,S} {6,D} {14,S} 6 C u0 p0 c0 {5,D} {7,S} {15,S} 7 C u0 p0 c0 {6,S} {8,D} {16,S} 8 C u0 p0 c0 {7,D} {9,S} {17,S} 9 C u0 p0 c0 {4,S} {8,S} {10,D} 10 C u0 p0 c0 {1,S} {9,D} {18,S} 11 H u0 p0 c0 {1,S} 12 H u0 p0 c0 {2,S} 13 H u0 p0 c0 {3,S} 14 H u0 p0 c0 {5,S} 15 H u0 p0 c0 {6,S} 16 H u0 p0 c0 {7,S} 17 H u0 p0 c0 {8,S} 18 H u0 p0 c0 {10,S} """ fragment = afm.fragment.Fragment().fromAdjacencyList(adj) frag_res = resonance.generate_resonance_structures(fragment, clarStructures=True) self.assertEqual(len(frag_res), 3)
def generate_resonance_structures(self, keep_isomorphic=False, filter_structures=True): """Returns a list of resonance structures of the fragment.""" return resonance.generate_resonance_structures( self, keep_isomorphic=keep_isomorphic, filter_structures=filter_structures)
def penalty_for_o4tc_test(self): """Test that an O4tc atomtype with octet 8 gets penalized in the electronegativity heuristic""" adj = """ 1 S u0 p1 c0 {2,S} {3,T} 2 O u0 p3 c-1 {1,S} 3 O u0 p1 c+1 {1,T} """ mol = Molecule().from_adjacency_list(adj) octet_deviation = get_octet_deviation(mol) self.assertEqual(octet_deviation, 0) self.assertEqual(mol.vertices[2].atomtype.label, 'O4tc') mol_list = generate_resonance_structures(mol) self.assertEqual(len(mol_list), 2) for mol in mol_list: if mol.reactive: for atom in mol.vertices: self.assertTrue(atom.charge == 0)
def penalty_for_O4tc_test(self): """Test that an O4tc atomType with octet 8 gets penalized in the electronegativity heuristic""" adj = """ 1 S u0 p1 c0 {2,S} {3,T} 2 O u0 p3 c-1 {1,S} 3 O u0 p1 c+1 {1,T} """ mol = Molecule().fromAdjacencyList(adj) octet_deviation = get_octet_deviation(mol) self.assertEqual(octet_deviation, 0) self.assertEqual(mol.vertices[2].atomType.label, 'O4tc') mol_list = generate_resonance_structures(mol) self.assertEqual(len(mol_list), 2) for mol in mol_list: if mol.reactive: for atom in mol.vertices: self.assertTrue(atom.charge == 0)
def penalty_birads_replacing_lone_pairs_test(self): """Test that birads on `S u2 p0` are penalized""" adj = """ multiplicity 3 1 S u2 p0 c0 {2,D} {3,D} 2 O u0 p2 c0 {1,D} 3 O u0 p2 c0 {1,D} """ mol = Molecule().fromAdjacencyList(adj) mol.update() mol_list = generate_resonance_structures(mol, keep_isomorphic=False, filter_structures=True) for mol in mol_list: if mol.reactive: for atom in mol.vertices: if atom.isSulfur(): self.assertNotEquals(atom.radicalElectrons, 2) self.assertEqual(len(mol_list), 3) self.assertEqual(sum([1 for mol in mol_list if mol.reactive]), 2)
def penalty_birads_replacing_lone_pairs_test(self): """Test that birads on `S u2 p0` are penalized""" adj = """ multiplicity 3 1 S u2 p0 c0 {2,D} {3,D} 2 O u0 p2 c0 {1,D} 3 O u0 p2 c0 {1,D} """ mol = Molecule().from_adjacency_list(adj) mol.update() mol_list = generate_resonance_structures(mol, keep_isomorphic=False, filter_structures=True) for mol in mol_list: if mol.reactive: for atom in mol.vertices: if atom.is_sulfur(): self.assertNotEquals(atom.radical_electrons, 2) self.assertEqual(len(mol_list), 3) self.assertEqual(sum([1 for mol in mol_list if mol.reactive]), 2)