Esempio n. 1
0
        /// <summary>
        /// <para>Converts an InChI into an InChI for validation purposes (the same as the -InChI2InChI option).</para>
        /// <para>This method may also be used to filter out specific layers. For instance, /Snon would remove the
        /// stereochemical layer; Omitting /FixedH and/or /RecMet would remove Fixed-H or Reconnected layers.
        /// In order to keep all InChI layers use options string "/FixedH /RecMet"; option /InChI2InChI is not needed.</para>
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static NInchiOutput GetInchiFromInchi(NInchiInputInchi input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input), "Null input");
            }

            var native_input = new Inchi_InputINCHI();

            var szInChI   = Marshal.StringToHGlobalAnsi(input.Inchi);
            var szOptions = Marshal.StringToHGlobalAnsi(input.Options);

            try
            {
                native_input.szInChI   = szInChI;
                native_input.szOptions = szOptions;

                var native_output = new Inchi_Output();

                var ret = GetINCHIfromINCHI(ref native_input, out native_output);

                NInchiOutput oo = ToInchiOutput(ret, native_output);
                FreeStdINCHI(ref native_output);
                return(oo);
            }
            finally
            {
                Marshal.FreeHGlobal(szOptions);
                Marshal.FreeHGlobal(szInChI);
            }
        }
Esempio n. 2
0
        public void TestGetOptions()
        {
            NInchiInputInchi input = new NInchiInputInchi("InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H");

            input.Options = NInchiWrapper.FlagChar + "compress";
            Assert.AreEqual(NInchiWrapper.FlagChar + "compress", input.Options);
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor. Generates CMLMolecule from InChI.
 /// </summary>
 /// <param name="inchi"></param>
 /// <param name="builder"></param>
 /// <param name="options"></param>
 internal InChIToStructure(string inchi, IChemObjectBuilder builder, string options)
 {
     try
     {
         input = new NInchiInputInchi(inchi, options);
     }
     catch (NInchiException jie)
     {
         throw new CDKException("Failed to convert InChI to molecule: " + jie.Message, jie);
     }
     GenerateAtomContainerFromInChI(builder);
 }
Esempio n. 4
0
 public void TestInchi2Structure()
 {
     // START SNIPPET: inchi2structure
     NInchiInputInchi      input  = new NInchiInputInchi("InChI=1/C2H6/c1-2/h1-2H3");
     NInchiOutputStructure output = NInchiWrapper.GetStructureFromInchi(input);
     //
     InChIReturnCode retStatus = output.ReturnStatus;
     int             nat       = output.Atoms.Count;
     int             nbo       = output.Bonds.Count;
     int             nst       = output.Stereos.Count;
     //
     NInchiAtom at0 = output.Atoms[0];
     // END SNIPPET: inchi2structure
 }
Esempio n. 5
0
        /// <summary>
        /// Constructor. Generates CMLMolecule from InChI.
        /// </summary>
        /// <param name="inchi"></param>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        internal InChIToStructure(string inchi, IChemObjectBuilder builder, IEnumerable <string> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            try
            {
                input = new NInchiInputInchi(inchi, options.Select(n => InChIOption.ValueOfIgnoreCase(n)));
            }
            catch (NInchiException jie)
            {
                throw new CDKException("Failed to convert InChI to molecule: " + jie.Message);
            }
            GenerateAtomContainerFromInChI(builder);
        }
Esempio n. 6
0
        /// <summary>
        /// Generated 0D structure from an InChI string.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static NInchiOutputStructure GetStructureFromInchi(NInchiInputInchi input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input), "Null input");
            }

            var native_input = new Inchi_InputINCHI();

            var szInChI   = Marshal.StringToHGlobalAnsi(input.Inchi);
            var szOptions = Marshal.StringToHGlobalAnsi(input.Options);

            try
            {
                native_input.szInChI   = szInChI;
                native_input.szOptions = szOptions;

                var native_output = new Inchi_OutputStruct();

                var ret = GetStructFromINCHI(ref native_input, out native_output);

                NInchiOutputStructure output = new NInchiOutputStructure(ret,
                                                                         Marshal.PtrToStringAnsi(native_output.szMessage),
                                                                         Marshal.PtrToStringAnsi(native_output.szLog),
                                                                         native_output.WarningFlags[0], native_output.WarningFlags[1],
                                                                         native_output.WarningFlags[2], native_output.WarningFlags[3]);

                CreateAtoms(output, native_output.num_atoms, native_output.atom);
                CreateBonds(output, native_output.num_atoms, native_output.atom);
                CreateStereos(output, native_output.num_stereo0D, native_output.stereo0D);

                FreeStructFromINCHI(ref native_output);
                return(output);
            }
            finally
            {
                Marshal.FreeHGlobal(szOptions);
                Marshal.FreeHGlobal(szInChI);
            }
        }
Esempio n. 7
0
        public void TestGetInchi()
        {
            NInchiInputInchi input = new NInchiInputInchi("InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H");

            Assert.AreEqual("InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H", input.Inchi);
        }