Here not an answer but a reviewed version of your code because I am getting a different result than the one you posted. Please show us where I am wrong or edit your question:
from rdkit import Chem
from rdkit.Chem import Draw
def check_bredts_rule(molecule):
ring_info = molecule.GetRingInfo()
atom_rings = ring_info.AtomRings()
atom_ring_counts = {atom.GetIdx(): 0 for atom in molecule.GetAtoms()}
for ring in atom_rings:
for atom_idx in ring:
atom_ring_counts[atom_idx] += 1
bridgehead_atoms = [atom_idx for atom_idx, count in atom_ring_counts.items() if count > 1]
for atom_idx in bridgehead_atoms:
atom = molecule.GetAtomWithIdx(atom_idx)
is_part_of_alkene = any(
bond.GetBondType() == Chem.BondType.DOUBLE
and bond.GetBeginAtomIdx() == atom_idx
and bond.GetEndAtom().GetSymbol() == "C"
for bond in atom.GetBonds()
)
if not is_part_of_alkene:
continue
ring_sizes = [len(ring) for ring in atom_rings if atom_idx in ring]
if all(size < 8 for size in ring_sizes):
return 'violate'
return 'no violate'
mol1 = Chem.MolFromSmiles('C1C[C@H]2C[C@@H]1C=C2') #Bicyclo[2.2.1]hept-2-ene NO VIOLATION
mol2 = Chem.MolFromSmiles('C1CC2C1CC=C2') #Bicyclo[3.2.0]hept-2-ene NO VIOLATION
mol3 = Chem.MolFromSmiles('CC1=C2CC[C@@]2([C@H]3CC(C[C@H]3C1)(C)C)C') #Delta(6)-protoilludene VIOLATE
mol4 = Chem.MolFromSmiles('CC1=C2C[C@](C[C@H]2CC3=COC(=C13)C(=O)O)(C)CO') #Tsugicoline A VIOLATE
mol5 = Chem.MolFromSmiles('C[C@@H]1CC[C@@H]2CC3=C(CC[C@]13C2(C)C)C') #Cyperene VIOLATE
mol6 = Chem.MolFromSmiles('O=C1C2CCCCC1CC2') #Bicyclo(4.2.1)nonan-9-one No violation
mol7 = Chem.MolFromSmiles('O=C1CCC2CC1CCC2=O') # Bicyclo(3.3.1)nonane-2,6-dione no violation
mol8 = Chem.MolFromSmiles('O=C1C2CC3CC1CC(C2)C3=O') #2,6-Adamantandione no violation
mol9 = Chem.MolFromSmiles('C1CC2CCC1=C2') #violate
mols = [mol1, mol2, mol3, mol4, mol5 , mol6, mol7, mol8 , mol9]
for mol in mols:
print('\n\n', Chem.MolToSmiles(mol) ,'--> ', check_bredts_rule(mol))
img = Draw.MolsToGridImage(mols, molsPerRow=3, subImgSize=(200, 200), legends=[check_bredts_rule(mol) for mol in mols],
highlightAtomLists=None, highlightBondLists=None, useSVG=False, returnPNG=False)
img.show()
output:
C1=C[C@H]2CC[C@@H]1C2 --> no violate
C1=CC2CCC2C1 --> no violate
CC1=C2CC[C@]2(C)[C@H]2CC(C)(C)C[C@H]2C1 --> no violate
CC1=C2C[C@](C)(CO)C[C@H]2Cc2coc(C(=O)O)c21 --> no violate
CC1=C2C[C@H]3CC[C@@H](C)[C@]2(CC1)C3(C)C --> violate
O=C1C2CCCCC1CC2 --> no violate
O=C1CCC2CC1CCC2=O --> no violate
O=C1C2CC3CC1CC(C2)C3=O --> no violate
C1=C2CCC1CC2 --> violate
with image:
I am not a chemist, but according to this Anti-Bredt Olefins: Never Say Never! your mol9 should give a NO VIOLATE output