/// <summary> /// Creates a new instance of MolHandler /// </summary> /// <param name="molFile">atomContainer file name</param> public MolHandler(string molFile, bool removeHydrogen, bool cleanMolecule) { MDLReader molRead = null; this.removeHydrogen = removeHydrogen; try { Stream readMolecule = null; readMolecule = new FileStream(molFile, FileMode.Open, FileAccess.Read); molRead = new MDLReader(new StreamReader(readMolecule)); this.atomContainer = (IAtomContainer)molRead.Read(new AtomContainer()); molRead.Close(); readMolecule.Close(); /* Remove Hydrogen by Asad */ if (removeHydrogen) { atomContainer = ExtAtomContainerManipulator.RemoveHydrogensExceptSingleAndPreserveAtomID(atomContainer); } if (cleanMolecule) { if (!IsPseudoAtoms()) { atomContainer = canonLabeler.GetCanonicalMolecule(atomContainer); } // percieve atoms, set valency etc ExtAtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(atomContainer); //Add implicit Hydrogens var adder = CDK.HydrogenAdder; adder.AddImplicitHydrogens(atomContainer); // figure out which atoms are in aromatic rings: Aromaticity.CDKLegacy.Apply(atomContainer); BondTools.MakeUpDownBonds(atomContainer); } } catch (IOException ex) { Debug.WriteLine(ex); } catch (CDKException e) { Console.Error.WriteLine(e); } finally { if (molRead != null) { try { molRead.Close(); } catch (IOException ioe) { Trace.TraceWarning("Couldn't close molReader: ", ioe.Message); Debug.WriteLine(ioe); } } } }
public IReaction LabelReaction(IReaction reaction, ICanonicalMoleculeLabeller labeller) { Console.Out.WriteLine("labelling"); var canonReaction = new Reaction(); var permutationMap = new Dictionary <IAtomContainer, int[]>(); var canonicalProducts = ChemObjectBuilder.Instance.NewChemObjectSet <IAtomContainer>(); foreach (var product in reaction.Products) { var canonicalForm = labeller.GetCanonicalMolecule(product); if (fixAtomMappingCastType) { FixAtomMapping(canonicalForm); } var canonicalMolecule = canonicalForm.Builder.NewAtomContainer(canonicalForm); permutationMap[canonicalMolecule] = labeller.GetCanonicalPermutation(product); canonicalProducts.Add(canonicalMolecule); } var canonicalReactants = ChemObjectBuilder.Instance.NewChemObjectSet <IAtomContainer>(); foreach (var reactant in reaction.Reactants) { var canonicalForm = labeller.GetCanonicalMolecule(reactant); if (fixAtomMappingCastType) { FixAtomMapping(canonicalForm); } var canonicalMolecule = canonicalForm.Builder.NewAtomContainer(canonicalForm); permutationMap[canonicalMolecule] = labeller.GetCanonicalPermutation(reactant); canonicalReactants.Add(canonicalMolecule); } canonReaction.Products.AddRange(canonicalProducts); canonReaction.Reactants.AddRange(canonicalReactants); CloneAndSortMappings(reaction, canonReaction, permutationMap); return(canonReaction); }