public void Ctor() { { #region 1 IAtomContainer methane = new AtomContainer(); IAtom carbon = new Atom("C"); methane.Atoms.Add(carbon); CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.GetInstance(); foreach (var atom in methane.Atoms) { IAtomType type = matcher.FindMatchingAtomType(methane, atom); AtomTypeManipulator.Configure(atom, type); } var adder = CDK.HydrogenAdder; adder.AddImplicitHydrogens(methane); #endregion } { #region 2 IAtomContainer ethane = new AtomContainer(); IAtom carbon1 = new Atom("C"); IAtom carbon2 = new Atom("C"); ethane.Atoms.Add(carbon1); ethane.Atoms.Add(carbon2); CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.GetInstance(); IAtomType type = matcher.FindMatchingAtomType(ethane, carbon1); AtomTypeManipulator.Configure(carbon1, type); var adder = CDK.HydrogenAdder; adder.AddImplicitHydrogens(ethane, carbon1); #endregion } }
/// <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); }