private static bool UnsaturateByDecreasingBondOrder(IBond bond) { if (bond.Order != BondOrder.Single) { bond.Order = BondManipulator.DecreaseBondOrder(bond.Order); return(true); } else { return(false); } }
/// <summary> /// Initiates the process for the given mechanism. The atoms and bonds to apply are mapped between /// reactants and products. /// </summary> /// <param name="atomContainerSet"></param> /// <param name="atomList">The list of atoms taking part in the mechanism. Only allowed three atoms</param> /// <param name="bondList">The list of bonds taking part in the mechanism. Only allowed one bond</param> /// <returns>The Reaction mechanism</returns> public IReaction Initiate(IChemObjectSet <IAtomContainer> atomContainerSet, IList <IAtom> atomList, IList <IBond> bondList) { var atMatcher = CDK.AtomTypeMatcher; if (atomContainerSet.Count != 2) { throw new CDKException("AdductionPBMechanism expects two IAtomContainer's"); } if (atomList.Count != 3) { throw new CDKException("AdductionPBMechanism expects two atoms in the List"); } if (bondList.Count != 1) { throw new CDKException("AdductionPBMechanism don't expect bonds in the List"); } IAtomContainer molecule1 = atomContainerSet[0]; IAtomContainer molecule2 = atomContainerSet[1]; IAtomContainer reactantCloned; reactantCloned = (IAtomContainer)atomContainerSet[0].Clone(); reactantCloned.Add((IAtomContainer)atomContainerSet[1].Clone()); IAtom atom1 = atomList[0]; // Atom 1: to be deficient in charge IAtom atom1C = reactantCloned.Atoms[molecule1.Atoms.IndexOf(atom1)]; IAtom atom2 = atomList[1]; // Atom 2: receive the adduct IAtom atom2C = reactantCloned.Atoms[molecule1.Atoms.IndexOf(atom2)]; IAtom atom3 = atomList[2]; // Atom 2: deficient in charge IAtom atom3C = reactantCloned.Atoms[molecule1.Atoms.Count + molecule2.Atoms.IndexOf(atom3)]; IBond bond1 = bondList[0]; int posBond1 = atomContainerSet[0].Bonds.IndexOf(bond1); BondManipulator.DecreaseBondOrder(reactantCloned.Bonds[posBond1]); IBond newBond = molecule1.Builder.NewBond(atom2C, atom3C, BondOrder.Single); reactantCloned.Bonds.Add(newBond); int charge = atom1C.FormalCharge.Value; atom1C.FormalCharge = charge + 1; atom1C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); IAtomType type = atMatcher.FindMatchingAtomType(reactantCloned, atom1C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } atom2C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); type = atMatcher.FindMatchingAtomType(reactantCloned, atom2C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } charge = atom3C.FormalCharge.Value; atom3C.FormalCharge = charge - 1; atom3C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); type = atMatcher.FindMatchingAtomType(reactantCloned, atom3C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } IReaction reaction = atom1C.Builder.NewReaction(); reaction.Reactants.Add(molecule1); /* mapping */ foreach (var atom in molecule1.Atoms) { IMapping mapping = atom1C.Builder.NewMapping(atom, reactantCloned.Atoms[molecule1.Atoms.IndexOf(atom)]); reaction.Mappings.Add(mapping); } foreach (var atom in molecule2.Atoms) { IMapping mapping = atom1C.Builder.NewMapping(atom, reactantCloned.Atoms[molecule2.Atoms.IndexOf(atom)]); reaction.Mappings.Add(mapping); } reaction.Products.Add(reactantCloned); return(reaction); }
/// <summary> /// Initiates the process for the given mechanism. The atoms to apply are mapped between /// reactants and products. /// </summary> /// <param name="atomContainerSet"></param> /// <param name="atomList">The list of atoms taking part in the mechanism. Only allowed two atoms. The first atom receives the charge and the second the single electron</param> /// <param name="bondList">The list of bonds taking part in the mechanism. Only allowed one bond</param> /// <returns>The Reaction mechanism</returns> public IReaction Initiate(IChemObjectSet <IAtomContainer> atomContainerSet, IList <IAtom> atomList, IList <IBond> bondList) { var atMatcher = CDKAtomTypeMatcher.GetInstance(CDKAtomTypeMatcher.Mode.RequireExplicitHydrogens); if (atomContainerSet.Count != 1) { throw new CDKException("RemovingSEofBMechanism only expects one IAtomContainer"); } if (atomList.Count != 2) { throw new CDKException("RemovingSEofBMechanism expects two atoms in the List"); } if (bondList.Count != 1) { throw new CDKException("RemovingSEofBMechanism only expects one bond in the List"); } var molecule = atomContainerSet[0]; var reactantCloned = (IAtomContainer)molecule.Clone(); var atom1 = atomList[0]; var atom1C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom1)]; var atom2 = atomList[1]; var atom2C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom2)]; var bond1 = bondList[0]; var posBond1 = molecule.Bonds.IndexOf(bond1); if (bond1.Order == BondOrder.Single) { reactantCloned.Bonds.Remove(reactantCloned.Bonds[posBond1]); } else { BondManipulator.DecreaseBondOrder(reactantCloned.Bonds[posBond1]); } var charge = atom1C.FormalCharge.Value; atom1C.FormalCharge = charge + 1; reactantCloned.SingleElectrons.Add(atom1C.Builder.NewSingleElectron(atom2C)); // check if resulting atom type is reasonable atom1C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); var type = atMatcher.FindMatchingAtomType(reactantCloned, atom1C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } atom2C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); type = atMatcher.FindMatchingAtomType(reactantCloned, atom2C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } var reaction = atom1C.Builder.NewReaction(); reaction.Reactants.Add(molecule); /* mapping */ foreach (var atom in molecule.Atoms) { IMapping mapping = atom1C.Builder.NewMapping(atom, reactantCloned.Atoms[molecule.Atoms.IndexOf(atom)]); reaction.Mappings.Add(mapping); } if (bond1.Order != BondOrder.Single) { reaction.Products.Add(reactantCloned); } else { var moleculeSetP = ConnectivityChecker.PartitionIntoMolecules(reactantCloned); foreach (var moleculeP in moleculeSetP) { reaction.Products.Add(moleculeP); } } return(reaction); }
/// <summary> /// Initiates the process for the given mechanism. The atoms to apply are mapped between /// reactants and products. /// </summary> /// <param name="atomContainerSet"></param> /// <param name="atomList">The list of atoms taking part in the mechanism. Only allowed two three. /// The first atom is the atom which must contain the charge to be moved, the second /// is the atom which is in the middle and the third is the atom which acquires the new charge /// <param name="bondList">The list of bonds taking part in the mechanism. Only allowed two bond.</param> /// The first bond is the bond to increase the order and the second is the bond /// to decrease the order /// It is the bond which is moved</param> /// <returns>The Reaction mechanism</returns> public IReaction Initiate(IChemObjectSet <IAtomContainer> atomContainerSet, IList <IAtom> atomList, IList <IBond> bondList) { var atMatcher = CDK.AtomTypeMatcher; if (atomContainerSet.Count != 1) { throw new CDKException("RearrangementChargeMechanism only expects one IAtomContainer"); } if (atomList.Count != 3) { throw new CDKException("RearrangementChargeMechanism expects three atoms in the List"); } if (bondList.Count != 2) { throw new CDKException("RearrangementChargeMechanism only expect one bond in the List"); } IAtomContainer molecule = atomContainerSet[0]; IAtomContainer reactantCloned; reactantCloned = (IAtomContainer)molecule.Clone(); IAtom atom1 = atomList[0]; // Atom with the charge IAtom atom1C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom1)]; IAtom atom3 = atomList[2]; // Atom which acquires the charge IAtom atom3C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom3)]; IBond bond1 = bondList[0]; // Bond with single bond int posBond1 = molecule.Bonds.IndexOf(bond1); IBond bond2 = bondList[1]; // Bond with double bond int posBond2 = molecule.Bonds.IndexOf(bond2); BondManipulator.IncreaseBondOrder(reactantCloned.Bonds[posBond1]); if (bond2.Order == BondOrder.Single) { reactantCloned.Bonds.Remove(reactantCloned.Bonds[posBond2]); } else { BondManipulator.DecreaseBondOrder(reactantCloned.Bonds[posBond2]); } //Depending of the charge moving (radical, + or -) there is a different situation if (reactantCloned.GetConnectedSingleElectrons(atom1C).Any()) { var selectron = reactantCloned.GetConnectedSingleElectrons(atom1C); reactantCloned.SingleElectrons.Remove(selectron.Last()); reactantCloned.SingleElectrons.Add(bond2.Builder.NewSingleElectron(atom3C)); } else if (atom1C.FormalCharge > 0) { int charge = atom1C.FormalCharge.Value; atom1C.FormalCharge = charge - 1; charge = atom3C.FormalCharge.Value; atom3C.FormalCharge = charge + 1; } else if (atom1C.FormalCharge < 1) { int charge = atom1C.FormalCharge.Value; atom1C.FormalCharge = charge + 1; var ln = reactantCloned.GetConnectedLonePairs(atom1C); reactantCloned.LonePairs.Remove(ln.Last()); atom1C.IsAromatic = false; charge = atom3C.FormalCharge.Value; atom3C.FormalCharge = charge - 1; reactantCloned.LonePairs.Add(bond2.Builder.NewLonePair(atom3C)); atom3C.IsAromatic = false; } else { return(null); } atom1C.Hybridization = Hybridization.Unset; atom3C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); IAtomType type = atMatcher.FindMatchingAtomType(reactantCloned, atom1C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } type = atMatcher.FindMatchingAtomType(reactantCloned, atom3C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } IReaction reaction = bond2.Builder.NewReaction(); reaction.Reactants.Add(molecule); /* mapping */ foreach (var atom in molecule.Atoms) { IMapping mapping = bond2.Builder.NewMapping(atom, reactantCloned.Atoms[molecule.Atoms.IndexOf(atom)]); reaction.Mappings.Add(mapping); } if (bond2.Order != BondOrder.Single) { reaction.Products.Add(reactantCloned); } else { IChemObjectSet <IAtomContainer> moleculeSetP = ConnectivityChecker.PartitionIntoMolecules(reactantCloned); for (int z = 0; z < moleculeSetP.Count(); z++) { reaction.Products.Add((IAtomContainer)moleculeSetP[z]); } } return(reaction); }
/// <summary> /// Initiates the process for the given mechanism. The atoms to apply are mapped between /// reactants and products. /// </summary> /// <param name="atomContainerSet"></param> /// <param name="atomList">The list of atoms taking part in the mechanism. Only allowed two atoms. Both atoms acquire a ISingleElectron</param> /// <param name="bondList">The list of bonds taking part in the mechanism. Only allowed one bond</param> /// <returns>The Reaction mechanism</returns> public IReaction Initiate(IChemObjectSet <IAtomContainer> atomContainerSet, IList <IAtom> atomList, IList <IBond> bondList) { var atMatcher = CDK.AtomTypeMatcher; if (atomContainerSet.Count != 1) { throw new CDKException("TautomerizationMechanism only expects one IAtomContainer"); } if (atomList.Count != 2) { throw new CDKException("HomolyticCleavageMechanism expects two atoms in the List"); } if (bondList.Count != 1) { throw new CDKException("HomolyticCleavageMechanism only expect one bond in the List"); } IAtomContainer molecule = atomContainerSet[0]; IAtomContainer reactantCloned; reactantCloned = (IAtomContainer)molecule.Clone(); IAtom atom1 = atomList[0]; IAtom atom1C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom1)]; IAtom atom2 = atomList[1]; IAtom atom2C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom2)]; IBond bond1 = bondList[0]; int posBond1 = molecule.Bonds.IndexOf(bond1); if (bond1.Order == BondOrder.Single) { reactantCloned.Bonds.Remove(reactantCloned.Bonds[posBond1]); } else { BondManipulator.DecreaseBondOrder(reactantCloned.Bonds[posBond1]); } reactantCloned.SingleElectrons.Add(bond1.Builder.NewSingleElectron(atom1C)); reactantCloned.SingleElectrons.Add(bond1.Builder.NewSingleElectron(atom2C)); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); // check if resulting atom type is reasonable atom1C.Hybridization = Hybridization.Unset; IAtomType type = atMatcher.FindMatchingAtomType(reactantCloned, atom1C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } // check if resulting atom type is reasonable: an acceptor atom cannot be charged positive*/ atom2C.Hybridization = Hybridization.Unset; type = atMatcher.FindMatchingAtomType(reactantCloned, atom2C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } IReaction reaction = atom2C.Builder.NewReaction(); reaction.Reactants.Add(molecule); /* mapping */ foreach (var atom in molecule.Atoms) { IMapping mapping = atom2C.Builder.NewMapping(atom, reactantCloned.Atoms[molecule.Atoms.IndexOf(atom)]); reaction.Mappings.Add(mapping); } if (bond1.Order != BondOrder.Single) { reaction.Products.Add(reactantCloned); } else { var moleculeSetP = ConnectivityChecker.PartitionIntoMolecules(reactantCloned); foreach (var moleculeP in moleculeSetP) { reaction.Products.Add(moleculeP); } } return(reaction); }
/// <summary> /// Initiates the process for the given mechanism. The atoms and bonds to apply are mapped between /// reactants and products. /// </summary> /// <param name="atomContainerSet"></param> /// <param name="atomList">The list of atoms taking part in the mechanism. Only allowed fourth atoms.</param> /// <param name="bondList">The list of bonds taking part in the mechanism. Only allowed two bond. /// The first bond is the bond to decrease the order and the second is the bond to increase the order. /// It is the bond which is moved</param> /// <returns>The Reaction mechanism</returns> public IReaction Initiate(IChemObjectSet <IAtomContainer> atomContainerSet, IList <IAtom> atomList, IList <IBond> bondList) { var atMatcher = CDK.AtomTypeMatcher; if (atomContainerSet.Count != 1) { throw new CDKException("TautomerizationMechanism only expects one IAtomContainer"); } if (atomList.Count != 4) { throw new CDKException("TautomerizationMechanism expects four atoms in the List"); } if (bondList.Count != 3) { throw new CDKException("TautomerizationMechanism expects three bonds in the List"); } var molecule = atomContainerSet[0]; IAtomContainer reactantCloned; reactantCloned = (IAtomContainer)molecule.Clone(); IAtom atom1 = atomList[0]; // Atom to be added the hydrogen IAtom atom1C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom1)]; IAtom atom2 = atomList[1]; // Atom 2 IAtom atom2C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom2)]; IAtom atom3 = atomList[2]; // Atom 3 IAtom atom3C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom3)]; IAtom atom4 = atomList[3]; // hydrogen Atom IAtom atom4C = reactantCloned.Atoms[molecule.Atoms.IndexOf(atom4)]; IBond bond1 = bondList[0]; // Bond with double bond int posBond1 = molecule.Bonds.IndexOf(bond1); IBond bond2 = bondList[1]; // Bond with single bond int posBond2 = molecule.Bonds.IndexOf(bond2); IBond bond3 = bondList[2]; // Bond to be removed int posBond3 = molecule.Bonds.IndexOf(bond3); BondManipulator.DecreaseBondOrder(reactantCloned.Bonds[posBond1]); BondManipulator.IncreaseBondOrder(reactantCloned.Bonds[posBond2]); reactantCloned.Bonds.Remove(reactantCloned.Bonds[posBond3]); IBond newBond = molecule.Builder.NewBond(atom1C, atom4C, BondOrder.Single); reactantCloned.Bonds.Add(newBond); atom1C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); IAtomType type = atMatcher.FindMatchingAtomType(reactantCloned, atom1C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } atom3C.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactantCloned); type = atMatcher.FindMatchingAtomType(reactantCloned, atom3C); if (type == null || type.AtomTypeName.Equals("X", StringComparison.Ordinal)) { return(null); } IReaction reaction = atom2C.Builder.NewReaction(); reaction.Reactants.Add(molecule); /* mapping */ foreach (var atom in molecule.Atoms) { IMapping mapping = atom2C.Builder.NewMapping(atom, reactantCloned.Atoms[molecule.Atoms.IndexOf(atom)]); reaction.Mappings.Add(mapping); } reaction.Products.Add(reactantCloned); return(reaction); }
/// <summary> /// Initiate process. /// It is needed to call the addExplicitHydrogensToSatisfyValency /// from the class tools.HydrogenAdder. /// </summary> /// <exception cref="CDKException"> Description of the Exception</exception> /// <param name="reactants">reactants of the reaction.</param> /// <param name="agents">agents of the reaction (Must be in this case null).</param> public IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents) { CheckInitiateParams(reactants, agents); var setOfReactions = reactants.Builder.NewReactionSet(); var reactant = reactants[0]; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactant); // if the parameter hasActiveCenter is not fixed yet, set the active centers var ipr = base.GetParameterClass(typeof(SetReactionCenter)); if (ipr != null && !ipr.IsSetParameter) { SetActiveCenters(reactant); } var arf = new AllRingsFinder(); var ringSet = arf.FindAllRings((IAtomContainer)reactant); for (int ir = 0; ir < ringSet.Count; ir++) { var ring = ringSet[ir]; //only rings with even number of atoms int nrAtoms = ring.Atoms.Count; if (nrAtoms % 2 == 0) { int nrSingleBonds = 0; foreach (var bond in ring.Bonds) { if (bond.Order == BondOrder.Single) { nrSingleBonds++; } } //if exactly half (nrAtoms/2==nrSingleBonds) if (nrSingleBonds != 0 && nrAtoms / 2 == nrSingleBonds) { bool ringCompletActive = false; foreach (var bond in ring.Bonds) { if (bond.IsReactiveCenter) { ringCompletActive = true; } else { ringCompletActive = false; break; } } if (!ringCompletActive) { continue; } IReaction reaction = reactants.Builder.NewReaction(); reaction.Reactants.Add(reactant); IAtomContainer reactantCloned; reactantCloned = (IAtomContainer)reactant.Clone(); foreach (var bondi in ring.Bonds) { int bondiP = reactant.Bonds.IndexOf(bondi); if (bondi.Order == BondOrder.Single) { BondManipulator.IncreaseBondOrder(reactantCloned.Bonds[bondiP]); } else { BondManipulator.DecreaseBondOrder(reactantCloned.Bonds[bondiP]); } } reaction.Products.Add(reactantCloned); setOfReactions.Add(reaction); } } } return(setOfReactions); }