void Main() { IAtomContainer container = null; #region // Generate factory - if native code does not load InChIGeneratorFactory factory = new InChIGeneratorFactory(); // Get InChIGenerator InChIGenerator gen = factory.GetInChIGenerator(container); InChIReturnCode ret = gen.ReturnStatus; if (ret == InChIReturnCode.Warning) { // InChI generated, but with warning message Console.WriteLine($"InChI warning: {gen.Message}"); } else if (ret != InChIReturnCode.Ok) { // InChI generation failed throw new CDKException($"InChI failed: {ret.ToString()} [{gen.Message}]"); } string inchi = gen.InChI; string auxinfo = gen.AuxInfo; #endregion }
public void TestInChIGenerator_AromaticBonds() { try { // create a fairly complex aromatic molecule IAtomContainer tetrazole = TestMoleculeFactory.MakeTetrazole(); foreach (IAtom atom in tetrazole.Atoms) { atom.ImplicitHydrogenCount = null; } AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(tetrazole); Aromaticity.CDKLegacy.Apply(tetrazole); InChIGeneratorFactory inchiFactory = InChIGeneratorFactory.Instance; inchiFactory.IgnoreAromaticBonds = false; // include aromatic bonds by default InChIGenerator genAromaticity1 = inchiFactory.GetInChIGenerator(tetrazole); // exclude aromatic bonds Assert.IsFalse(inchiFactory.IgnoreAromaticBonds); inchiFactory.IgnoreAromaticBonds = true; Assert.IsTrue(inchiFactory.IgnoreAromaticBonds); InChIGenerator genNoAromaticity = inchiFactory.GetInChIGenerator(tetrazole); // include aromatic bonds again inchiFactory.IgnoreAromaticBonds = false; Assert.IsFalse(inchiFactory.IgnoreAromaticBonds); InChIGenerator genAromaticity2 = inchiFactory.GetInChIGenerator(tetrazole); // with the aromatic bonds included, no InChI can be generated Assert.AreEqual(InChIReturnCode.Error, genAromaticity1.ReturnStatus, "return status was not in error"); Assert.AreEqual(InChIReturnCode.Error, genAromaticity2.ReturnStatus, "return status was not in error"); // excluding the aromatic bonds gives the normal InChI Assert.AreEqual(InChIReturnCode.Ok, genNoAromaticity.ReturnStatus, "return status was not okay"); Assert.AreEqual("InChI=1S/CH2N4/c1-2-4-5-3-1/h1H,(H,2,3,4,5)", genNoAromaticity.InChI, "InChIs did not match"); } finally { InChIGeneratorFactory.Instance.IgnoreAromaticBonds = true; } }
public void TestGetInChIFromChlorineAtom() { var ac = builder.NewAtomContainer(); ac.Atoms.Add(builder.NewAtom("ClH")); var gen = factory.GetInChIGenerator(ac, "FixedH"); Assert.AreEqual(gen.ReturnStatus, InChIReturnCode.Ok); Assert.AreEqual("InChI=1/ClH/h1H", gen.InChI); }