Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit 48c9fbf

Browse files
committed
add one more unittest for resonance structure generation for fragment
1 parent 0c29a14 commit 48c9fbf

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

afm/fragment.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,20 @@ def saturate_radicals(self):
910910

911911
return added
912912

913+
def isArylRadical(self, aromaticRings=None):
914+
"""
915+
Return ``True`` if the fragment only contains aryl radicals,
916+
ie. radical on an aromatic ring, or ``False`` otherwise.
917+
"""
918+
if aromaticRings is None:
919+
aromaticRings = self.getAromaticRings()[0]
920+
921+
total = self.getRadicalCount()
922+
aromaticAtoms = set([atom for atom in itertools.chain.from_iterable(aromaticRings)])
923+
aryl = sum([atom.radicalElectrons for atom in aromaticAtoms])
924+
925+
return total == aryl
926+
913927
# this variable is used to name atom IDs so that there are as few conflicts by
914928
# using the entire space of integer objects
915929
atom_id_counter = -2**15

test/fragment_test.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import unittest
33

44
from rmgpy.species import Species
5-
from rmgpy.molecule.molecule import Atom, Bond, Molecule
6-
from rmgpy.molecule.element import getElement
5+
from rmgpy.molecule import resonance
76
from rmgpy.molecule.atomtype import atomTypes
7+
from rmgpy.molecule.element import getElement
8+
from rmgpy.molecule.molecule import Atom, Bond, Molecule
89

910
import afm.fragment
1011

@@ -627,4 +628,35 @@ def test_getAromaticRings(self):
627628
self.assertEqual(aromaticRing_atomSet, expected_aromaticRing_atomSet)
628629
self.assertEqual(aromaticBonds_set, expected_aromaticBonds_set)
629630

630-
631+
def test_generate_resonance_structures(self):
632+
633+
adj = """1 C u0 p0 c0 {2,S} {3,S} {11,S} {12,S}
634+
2 C u0 p0 c0 {1,S} {4,S} {13,S} {14,S}
635+
3 C u0 p0 c0 {1,S} {5,S} {15,S} {16,S}
636+
4 C u0 p0 c0 {2,S} {17,S} {18,S} {19,S}
637+
5 C u0 p0 c0 {3,S} {6,S} {7,D}
638+
6 C u0 p0 c0 {5,S} {8,D} {20,S}
639+
7 C u1 p0 c0 {5,D} {10,S}
640+
8 C u0 p0 c0 {6,D} {9,S} {21,S}
641+
9 C u0 p0 c0 {8,S} {10,D} {22,S}
642+
10 C u0 p0 c0 {7,S} {9,D} {23,S}
643+
11 H u0 p0 c0 {1,S}
644+
12 H u0 p0 c0 {1,S}
645+
13 H u0 p0 c0 {2,S}
646+
14 H u0 p0 c0 {2,S}
647+
15 H u0 p0 c0 {3,S}
648+
16 H u0 p0 c0 {3,S}
649+
17 R u0 p0 c0 {4,S}
650+
18 H u0 p0 c0 {4,S}
651+
19 H u0 p0 c0 {4,S}
652+
20 H u0 p0 c0 {6,S}
653+
21 H u0 p0 c0 {8,S}
654+
22 H u0 p0 c0 {9,S}
655+
23 H u0 p0 c0 {10,S}
656+
"""
657+
fragment = afm.fragment.Fragment().fromAdjacencyList(adj)
658+
659+
frag_res = resonance.generate_resonance_structures(fragment,
660+
clarStructures=False)
661+
662+
self.assertEqual(len(frag_res), 3)

0 commit comments

Comments
 (0)