Organic Chemical Reactions in the Wolfram Language
Organic Synthesis Project
Organic Synthesis Project
Reactions Completed So Far
[This, my second notebook, is a continuation of the research started in my first notebook, “Wolfram Summer School Project 2020”.]Reactions that Form Carbon-Carbon BondsNote that for chemical reactions that form new C-C, C-N, C-O, or C-S bonds, a third parameter “default_” specifies which of the two reactants will be passed through the function unchanged when the reaction does not apply. “Does not apply” means that at least one of the necesarry functional groups (structural patterns) is absent among the reactants.
Reaction 4: Alkylation of Alkynes
ChemAlkyneAlkylation[alkyne_,primaryalkylhalide_,default_]:=Module[{yne=alkyne,hal=primaryalkylhalide,def=default},termalkynepat=MoleculePattern[{"C","C","H","C"},{Bond[{1,2},"Triple"],Bond[{1,3},"Single"],Bond[{2,4},"Single"]}];ethynepat=MoleculePattern[{"C","C","H","H"},{Bond[{1,2},"Triple"],Bond[{1,3},"Single"],Bond[{2,4},"Single"]}];primalkylhalidepat=MoleculePattern[{"C","Br","H","H"},{Bond[{1,2},"Single"],Bond[{1,3},"Single"],Bond[{1,4},"Single"]}];methylhalidepat=MoleculePattern[{"C","Br","H","H","H"},{Bond[{1,2},"Single"],Bond[{1,3},"Single"],Bond[{1,4},"Single"],Bond[{1,5},"Single"]}];If[def==2,flask=hal,flask=yne];If[Length[hal]==0,start=yne,alist=Join[AtomList[yne],AtomList[hal]];f[x_]:=x+AtomCount[yne];primalkylhalidebondlist2=Map[f,BondList[hal],{-2}];blist=Join[BondList[yne],primalkylhalidebondlist2];start=Molecule[alist,blist];];If[MoleculeContainsQ[start,termalkynepat],termalkynefindlist=FindMoleculeSubstructure[start,termalkynepat];If[MoleculeContainsQ[start,primalkylhalidepat],primalkylhalidefindlist=FindMoleculeSubstructure[start,primalkylhalidepat];flask=MoleculeModify[start,{"ReplaceAtom",primalkylhalidefindlist[[1]][[2]]"H"}];flask=MoleculeModify[flask,{"AddBond",Bond[{termalkynefindlist[[1]][[1]],primalkylhalidefindlist[[1]][[1]]},"Single"]}];];If[MoleculeContainsQ[start,methylhalidepat],methylhalidefindlist=FindMoleculeSubstructure[start,methylhalidepat];flask=MoleculeModify[start,{"ReplaceAtom",methylhalidefindlist[[1]][[2]]"H"}];flask=MoleculeModify[flask,{"AddBond",Bond[{termalkynefindlist[[1]][[1]],methylhalidefindlist[[1]][[1]]},"Single"]}];];];If[MoleculeContainsQ[start,ethynepat],ethynefindlist=FindMoleculeSubstructure[start,ethynepat];If[MoleculeContainsQ[start,primalkylhalidepat],primalkylhalidefindlist=FindMoleculeSubstructure[start,primalkylhalidepat];flask=MoleculeModify[start,{"ReplaceAtom",primalkylhalidefindlist[[1]][[2]]"H"}];flask=MoleculeModify[flask,{"AddBond",Bond[{ethynefindlist[[1]][[1]],primalkylhalidefindlist[[1]][[1]]},"Single"]}];];If[MoleculeContainsQ[start,methylhalidepat],methylhalidefindlist=FindMoleculeSubstructure[start,methylhalidepat];flask=MoleculeModify[start,{"ReplaceAtom",methylhalidefindlist[[1]][[2]]"H"}];flask=MoleculeModify[flask,{"AddBond",Bond[{ethynefindlist[[1]][[1]],methylhalidefindlist[[1]][[1]]},"Single"]}];];];]alkyne=Molecule["1-octyne"];primaryalkylhalide=Molecule["benzyl bromide"];ChemAlkyneAlkylation[alkyne,primaryalkylhalide,1];MoleculePlot[start]MoleculePlot[flask]
Out[]=
Out[]=
The function above accepts either a primary halide or methyl halide, and performs both intermolecular and intramolecular versions of the reaction. The second molecule parameter can be left null if the first molecule contains both needed functional group patterns.
Reaction 7: Grignard Reaction of Aldehydes and Ketones [original version]
Reaction 7: Grignard Reaction of Aldehydes and Ketones [original version]
ChemGrignardAldKet[aldehydeketone_,organichalide_,default_]:=Module[{aldket=aldehydeketone,hal=organichalide,def=default},ketonepat=MoleculePattern[{"C","O","C","C"},{Bond[{1,2},"Double"],Bond[{1,3},"Single"],Bond[{1,4},"Single"]}];aldehydepat=MoleculePattern[{"C","O","H","C"},{Bond[{1,2},"Double"],Bond[{1,3},"Single"],Bond[{1,4},"Single"]}];formaldehydepat=MoleculePattern[{"C","O","H","H"},{Bond[{1,2},"Double"],Bond[{1,3},"Single"],Bond[{1,4},"Single"]}];organichalidepat=MoleculePattern[{"C","Br"},{Bond[{1,2},"Single"]}];secalcoholpat=MoleculePattern[{"C","O","H","C","C","H"},{Bond[{1,2},"Single"],Bond[{2,3},"Single"],Bond[{1,4},"Single"],Bond[{1,5},"Single"],Bond[{1,6},"Single"]}];primalcoholpat=MoleculePattern[{"C","O","H","C","H","H"},{Bond[{1,2},"Single"],Bond[{2,3},"Single"],Bond[{1,4},"Single"],Bond[{1,5},"Single"],Bond[{1,6},"Single"]}];methylalcoholpat=MoleculePattern[{"C","O","H","H","H","H"},{Bond[{1,2},"Single"],Bond[{2,3},"Single"],Bond[{1,4},"Single"],Bond[{1,5},"Single"],Bond[{1,6},"Single"]}];If[def==2,flask=hal,flask=aldket];If[Length[hal]==0,start=aldket,alist=Join[AtomList[aldket],AtomList[hal]];f[x_]:=x+AtomCount[aldket];organichalidebondlist2=Map[f,BondList[hal],{-2}];blist=Join[BondList[aldket],organichalidebondlist2];start=Molecule[alist,blist];];If[MoleculeContainsQ[start,organichalidepat],organichalidefindlist=FindMoleculeSubstructure[start,organichalidepat];If[MoleculeContainsQ[start,ketonepat],ketonefindlist=FindMoleculeSubstructure[start,ketonepat];flask=MoleculeModify[start,{"DeleteBond",Bond[{ketonefindlist[[1]][[1]],ketonefindlist[[1]][[2]]},"Double"]}];flask=MoleculeModify[flask,{"AddBond",Bond[{ketonefindlist[[1]][[1]],ketonefindlist[[1]][[2]]},"Single"]}];flask=MoleculeModify[flask,{"ReplaceAtom",organichalidefindlist[[1]][[2]]"H"}];secalcoholfindlist=FindMoleculeSubstructure[flask,secalcoholpat];flask=MoleculeModify[flask,{"AddBond",Bond[{secalcoholfindlist[[1]][[1]],organichalidefindlist[[1]][[1]]},"Single"]}];];If[MoleculeContainsQ[start,aldehydepat],aldehydefindlist=FindMoleculeSubstructure[start,aldehydepat];flask=MoleculeModify[start,{"DeleteBond",Bond[{aldehydefindlist[[1]][[1]],aldehydefindlist[[1]][[2]]},"Double"]}];flask=MoleculeModify[flask,{"AddBond",Bond[{aldehydefindlist[[1]][[1]],aldehydefindlist[[1]][[2]]},"Single"]}];flask=MoleculeModify[flask,{"ReplaceAtom",organichalidefindlist[[1]][[2]]"H"}];primalcoholfindlist=FindMoleculeSubstructure[flask,primalcoholpat];flask=MoleculeModify[flask,{"AddBond",Bond[{primalcoholfindlist[[1]][[1]],organichalidefindlist[[1]][[1]]},"Single"]}];];If[MoleculeContainsQ[start,formaldehydepat],formaldehydefindlist=FindMoleculeSubstructure[start,formaldehydepat];flask=MoleculeModify[start,{"DeleteBond",Bond[{formaldehydefindlist[[1]][[1]],formaldehydefindlist[[1]][[2]]},"Double"]}];flask=MoleculeModify[flask,{"AddBond",Bond[{formaldehydefindlist[[1]][[1]],formaldehydefindlist[[1]][[2]]},"Single"]}];organichalidefindlist=FindMoleculeSubstructure[flask,organichalidepat];flask=MoleculeModify[flask,{"ReplaceAtom",organichalidefindlist[[1]][[2]]"H"}];methylalcoholfindlist=FindMoleculeSubstructure[flask,methylalcoholpat];flask=MoleculeModify[flask,{"AddBond",Bond[{methylalcoholfindlist[[1]][[1]],organichalidefindlist[[1]][[1]]},"Single"]}];];];]aldket=Molecule["p-(8,8-dimethyl-8-bromooctyl)benzaldehyde"];hal="";ChemGrignardAldKet[aldket,hal,1];MoleculePlot[start]MoleculePlot[flask]
Reaction 7: Grignard Reaction of Aldehydes and Ketones [alternate version]
Reaction 13: Carboxylation of Grignard Reagent (to Carboxylic Acid)
Reaction 13: Carboxylation of Grignard Reagent (to Carboxylic Acid)
Reactions that Form C-O, C-N, and C-S Bonds
Reactions that Form C-O, C-N, and C-S Bonds
Reaction 8: Alkylation of Alcohols (Williamson Ether Synthesis)
Reaction 8: Alkylation of Alcohols (Williamson Ether Synthesis)
Reaction 9: Mono-Alkylation of Ammonia (Gabriel Synthesis of Primary Amines)
Reaction 9: Mono-Alkylation of Ammonia (Gabriel Synthesis of Primary Amines)
Reaction 10: Fischer Ester Synthesis from Alcohols and Carboxylic Acids
Reaction 10: Fischer Ester Synthesis from Alcohols and Carboxylic Acids
Functional Group Interconversions
Functional Group Interconversions
Reaction 1: H2 Reduction of Aldehydes/Ketones to Alcohols
Reaction 1: H2 Reduction of Aldehydes/Ketones to Alcohols
Reaction 2: Bromination of Alcohols
Reaction 2: Bromination of Alcohols
Reaction 3: Oxidation of Alcohols to Aldehyde/Ketones
Reaction 3: Oxidation of Alcohols to Aldehyde/Ketones
Reaction 5: H2 Reduction of Alkyne to Alkene
Reaction 5: H2 Reduction of Alkyne to Alkene
Reaction 6: H2 Reduction of Alkenes and Alkynes to Alkanes
Reaction 6: H2 Reduction of Alkenes and Alkynes to Alkanes
Reaction 11: Alkene Hydration (to Alcohol)
Reaction 11: Alkene Hydration (to Alcohol)
Reaction 12: Alkene HydroHalogenation (to Alkyl Halide)
Reaction 12: Alkene HydroHalogenation (to Alkyl Halide)