Beispiel #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);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
 internal static extern int GetINCHIfromINCHI([In] ref Inchi_InputINCHI pinpInChI, [Out] out Inchi_Output pOut);
Beispiel #4
0
 internal static extern int GetStructFromStdINCHI([In] ref Inchi_InputINCHI pinpInChI, [Out] out Inchi_OutputStruct pOutStruct);