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 = from_augmented_inchi(Molecule(), aug_inchi) ConsistencyChecker.check_multiplicity(mol.get_radical_count(), mol.multiplicity) for at in mol.atoms: ConsistencyChecker.check_partial_charge(at) spc = Species(molecule=[mol]) spc.generate_resonance_structures() ignore_prefix = r"(InChI=1+)(S*)/" aug_inchi_expected = re.split(ignore_prefix, aug_inchi)[-1] aug_inchi_computed = re.split(ignore_prefix, spc.get_augmented_inchi())[-1] self.assertEquals(aug_inchi_expected, aug_inchi_computed) return mol
def _check_molecule(mol, aug_inchi): """ Check if the molecular structure is correct. Checks whether the multiplicity contained in the augmented inchi, corresponds to the number of unpaired electrons + 1 found in the molecule. Checks whether the valence of each atom is compatible with the bond order, number of unpaired electrons, lone pairs and charge. """ cython.declare(inchi=str, at=Atom) ConsistencyChecker.check_multiplicity(mol.get_radical_count(), mol.multiplicity) _, u_indices, _ = decompose_aug_inchi(str(aug_inchi)) assert (mol.get_radical_count() == len(u_indices)) for at in mol.atoms: ConsistencyChecker.check_partial_charge(at)