Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        static NInchiOutput ToInchiOutput(int ret, Inchi_Output output)
        {
            var inchi = Marshal.PtrToStringAnsi(output.szInChI);
            var aux   = Marshal.PtrToStringAnsi(output.szAuxInfo);
            var mes   = Marshal.PtrToStringAnsi(output.szMessage);
            var log   = Marshal.PtrToStringAnsi(output.szLog);

            return(new NInchiOutput(ret, inchi, aux, mes, log));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>Calculates the Standard InChI string for a chemical structure.</para>
        /// <para>The only valid structure perception options are NEWPSOFF/DoNotAddH/SNon. In any other structural
        /// perception options are specified then the calculation will fail.</para>
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static NInchiOutput GetStdInchi(NInchiInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input), "Null input");
            }

            var prep = InitInchiInput(input);

            fixed(Inchi_Atom *atoms = prep.atoms)
            fixed(Inchi_Stereo0D * stereos = prep.stereos)
            {
                Inchi_Input  native_input  = new Inchi_Input();
                Inchi_Output native_output = new Inchi_Output();

                native_input.atom         = new IntPtr(atoms);
                native_input.num_atoms    = (Int16)input.Atoms.Count;
                native_input.stereo0D     = new IntPtr(stereos);
                native_input.num_stereo0D = (Int16)input.Stereos.Count;

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

                try
                {
                    native_input.szOptions = szOptions;

                    var          ret = GetStdINCHI(ref native_input, out native_output);
                    NInchiOutput oo  = ToInchiOutput(ret, native_output);
                    FreeStdINCHI(ref native_output);

                    return(oo);
                }
                finally
                {
                    Marshal.FreeHGlobal(szOptions);
                }
            }
        }
Ejemplo n.º 4
0
 internal static extern int GetINCHIfromINCHI([In] ref Inchi_InputINCHI pinpInChI, [Out] out Inchi_Output pOut);
Ejemplo n.º 5
0
 internal static extern void FreeStdINCHI([In] ref Inchi_Output pOut);
Ejemplo n.º 6
0
 internal static extern int GetStdINCHI([In] ref Inchi_Input pIn, [Out] out Inchi_Output pOut);
Ejemplo n.º 7
0
 internal static extern int GetINCHI([In] ref Inchi_Input inp, [Out] out Inchi_Output outp);