def test_singlet_vs_closed_shell(self): adjlist_singlet = """ 1 C u0 p0 c0 {2,D} {3,S} {4,S} 2 C u0 p0 c0 {1,D} {3,S} {5,S} 3 C u0 p1 c0 {1,S} {2,S} 4 H u0 p0 c0 {1,S} 5 H u0 p0 c0 {2,S} """ adjlist_closed_shell = """ 1 C u0 p0 c0 {2,D} {3,S} {4,S} 2 C u0 p0 c0 {1,D} {3,D} 3 C u0 p0 c0 {1,S} {2,D} {5,S} 4 H u0 p0 c0 {1,S} 5 H u0 p0 c0 {3,S} """ singlet = Species(molecule=[Molecule().fromAdjacencyList(adjlist_singlet)]) singlet.generateResonanceIsomers() closed_shell = Species(molecule=[Molecule().fromAdjacencyList(adjlist_closed_shell)]) closed_shell.generateResonanceIsomers() singlet_aug_inchi = singlet.getAugmentedInChI() closed_shell_aug_inchi = closed_shell.getAugmentedInChI() self.assertTrue(singlet_aug_inchi != closed_shell_aug_inchi)
def test_singlet_vs_closed_shell(self): adjlist_singlet = """ 1 C u0 p0 c0 {2,D} {3,S} {4,S} 2 C u0 p0 c0 {1,D} {3,S} {5,S} 3 C u0 p1 c0 {1,S} {2,S} 4 H u0 p0 c0 {1,S} 5 H u0 p0 c0 {2,S} """ adjlist_closed_shell = """ 1 C u0 p0 c0 {2,D} {3,S} {4,S} 2 C u0 p0 c0 {1,D} {3,D} 3 C u0 p0 c0 {1,S} {2,D} {5,S} 4 H u0 p0 c0 {1,S} 5 H u0 p0 c0 {3,S} """ singlet = Species( molecule=[Molecule().fromAdjacencyList(adjlist_singlet)]) singlet.generateResonanceIsomers() closed_shell = Species( molecule=[Molecule().fromAdjacencyList(adjlist_closed_shell)]) closed_shell.generateResonanceIsomers() singlet_aug_inchi = singlet.getAugmentedInChI() closed_shell_aug_inchi = closed_shell.getAugmentedInChI() self.assertTrue(singlet_aug_inchi != closed_shell_aug_inchi)
def compare(self, inchi, u_indices=None, p_indices=None): u_layer = U_LAYER_PREFIX + U_LAYER_SEPARATOR.join(map( str, u_indices)) if u_indices else None p_layer = P_LAYER_PREFIX + P_LAYER_SEPARATOR.join(map( str, p_indices)) if p_indices else None aug_inchi = compose_aug_inchi(inchi, u_layer, p_layer) mol = fromAugmentedInChI(Molecule(), aug_inchi) ConsistencyChecker.check_multiplicity(mol.getRadicalCount(), mol.multiplicity) for at in mol.atoms: ConsistencyChecker.check_partial_charge(at) spc = Species(molecule=[mol]) spc.generateResonanceIsomers() ignore_prefix = r"(InChI=1+)(S*)/" aug_inchi_expected = re.split(ignore_prefix, aug_inchi)[-1] aug_inchi_computed = re.split(ignore_prefix, spc.getAugmentedInChI())[-1] self.assertEquals(aug_inchi_expected, aug_inchi_computed) return mol
def compare(self, adjlist, aug_inchi): spc = Species(molecule=[Molecule().fromAdjacencyList(adjlist)]) spc.generateResonanceIsomers() ignore_prefix = r"(InChI=1+)(S*)/" exp = re.split(ignore_prefix, aug_inchi)[-1] comp = re.split(ignore_prefix, spc.getAugmentedInChI())[-1] self.assertEquals(exp, comp)
def test_singlet_vs_triplet(self): adjlist_singlet = """ 1 C u0 p1 c0 {2,S} {3,S} 2 H u0 p0 c0 {1,S} 3 H u0 p0 c0 {1,S} """ adjlist_triplet = """ multiplicity 3 1 C u2 p0 c0 {2,S} {3,S} 2 H u0 p0 c0 {1,S} 3 H u0 p0 c0 {1,S} """ singlet = Species(molecule=[Molecule().fromAdjacencyList(adjlist_singlet)]) triplet = Species(molecule=[Molecule().fromAdjacencyList(adjlist_triplet)]) singlet_aug_inchi = singlet.getAugmentedInChI() triplet_aug_inchi = triplet.getAugmentedInChI() self.assertTrue(singlet_aug_inchi != triplet_aug_inchi)
def test_CO_triplet(self): adjlist = """ multiplicity 3 1 C u2 p0 c0 {2,D} 2 O u0 p2 c0 {1,D} """ spc = Species(molecule=[Molecule().fromAdjacencyList(adjlist)]) aug_inchi = spc.getAugmentedInChI() self.assertEqual(Species(molecule=[Molecule().fromAugmentedInChI(aug_inchi)]).isIsomorphic(spc), True)
def test_CCCO_triplet(self): adjlist = """ multiplicity 3 1 C u0 p0 c0 {2,D} {5,S} {6,S} 2 C u0 p0 c0 {1,D} {3,S} {7,S} 3 C u1 p0 c0 {2,S} {4,S} {8,S} 4 O u1 p2 c0 {3,S} 5 H u0 p0 c0 {1,S} 6 H u0 p0 c0 {1,S} 7 H u0 p0 c0 {2,S} 8 H u0 p0 c0 {3,S} """ mol = Molecule().fromAdjacencyList(adjlist) spc = Species(molecule=[mol]) spc.generateResonanceIsomers() aug_inchi = spc.getAugmentedInChI() self.assertEqual(Species(molecule=[Molecule().fromAugmentedInChI(aug_inchi)]).isIsomorphic(spc), True)
def test_CCCO_triplet(self): adjlist = """ multiplicity 3 1 C u0 p0 c0 {2,D} {5,S} {6,S} 2 C u0 p0 c0 {1,D} {3,S} {7,S} 3 C u1 p0 c0 {2,S} {4,S} {8,S} 4 O u1 p2 c0 {3,S} 5 H u0 p0 c0 {1,S} 6 H u0 p0 c0 {1,S} 7 H u0 p0 c0 {2,S} 8 H u0 p0 c0 {3,S} """ mol = Molecule().fromAdjacencyList(adjlist) spc = Species(molecule=[mol]) spc.generate_resonance_structures() aug_inchi = spc.getAugmentedInChI() self.assertEqual(Species(molecule=[Molecule().fromAugmentedInChI(aug_inchi)]).isIsomorphic(spc), True)
def compare(self, inchi, u_indices=[], p_indices = []): u_layer = U_LAYER_PREFIX + U_LAYER_SEPARATOR.join(map(str, u_indices)) if u_indices else None p_layer = P_LAYER_PREFIX + P_LAYER_SEPARATOR.join(map(str, p_indices)) if p_indices else None aug_inchi = compose_aug_inchi(inchi, u_layer, p_layer) mol = fromAugmentedInChI(Molecule(), aug_inchi) ConsistencyChecker.check_multiplicity(mol.getRadicalCount(), mol.multiplicity) for at in mol.atoms: ConsistencyChecker.check_partial_charge(at) spc = Species(molecule=[mol]) spc.generateResonanceIsomers() ignore_prefix = r"(InChI=1+)(S*)/" aug_inchi_expected = re.split(ignore_prefix, aug_inchi)[-1] aug_inchi_computed = re.split(ignore_prefix, spc.getAugmentedInChI())[-1] self.assertEquals(aug_inchi_expected, aug_inchi_computed) return mol