Example #1
0
        /// <summary>
        /// Checks and canonicalises options.
        /// </summary>
        /// <param name="ops">Space delimited string of options to pass to InChI library.
        ///                     Each option may optionally be preceded by a command line
        ///                     switch (/ or -).</param>
        protected internal static string CheckOptions(string ops)
        {
            if (ops == null)
            {
                throw new ArgumentNullException(nameof(ops), "Null options");
            }

            var tok       = Strings.Tokenize(ops);
            var sbOptions = string.Join(" ", tok.Select(n =>
            {
                string op = n;
                if (op.StartsWithChar('-') || op.StartsWithChar('/'))
                {
                    op = op.Substring(1);
                }
                var option = InChIOption.ValueOfIgnoreCase(op);
                if (option != null)
                {
                    return(FlagChar + option.Name);
                }
                throw new NInchiException("Unrecognised InChI option");
            }));

            return(sbOptions);
        }
Example #2
0
        private static string CheckOptions(string ops)
        {
            if (ops == null)
            {
                throw new ArgumentNullException(nameof(ops));
            }
            var sbOptions = new StringBuilder();

            bool hasUserSpecifiedTimeout = false;

            var    tok     = Strings.Tokenize(ops);
            string options = string.Join(" ", tok.Select(n =>
            {
                string op = n;
                if (op.StartsWithChar('-') || op.StartsWithChar('/'))
                {
                    op = op.Substring(1);
                }

                InChIOption option = InChIOption.ValueOfIgnoreCase(op);
                if (option != null)
                {
                    return(FLAG_CHAR + option.Name);
                }
                else if (IsTimeoutOptions(op))
                {
                    hasUserSpecifiedTimeout = true;
                    return(FLAG_CHAR + op);
                }
                // 1,5 tautomer option
                else if (string.Equals("15T", op, StringComparison.Ordinal))
                {
                    return(FLAG_CHAR + "15T");
                }
                // keto-enol tautomer option
                else if (string.Equals("KET", op, StringComparison.Ordinal))
                {
                    return(FLAG_CHAR + "KET");
                }
                else
                {
                    throw new NInchiException("Unrecognised InChI option");
                }
            }));

            if (!hasUserSpecifiedTimeout)
            {
                if (options.Length > 0)
                {
                    options += " ";
                }
                options += FIVE_SECOND_TIMEOUT;
            }
            return(options);
        }
Example #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, 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);
        }
Example #4
0
        private static string CheckOptions(string ops)
        {
            if (ops == null)
            {
                throw new ArgumentNullException(nameof(ops));
            }
            var sbOptions = new StringBuilder();

            bool hasUserSpecifiedTimeout = false;

            var    tok     = Strings.Tokenize(ops);
            string options = string.Join(" ", tok.Select(n =>
            {
                string op = n;
                if (op.StartsWithChar('-') || op.StartsWithChar('/'))
                {
                    op = op.Substring(1);
                }

                var option = InChIOption.ValueOfIgnoreCase(op);
                if (option != null)
                {
                    return(FLAG_CHAR + option.Name);
                }
                else if (IsTimeoutOptions(op))
                {
                    hasUserSpecifiedTimeout = true;
                    // only reformat if we actually have a decimal
                    if (IsSubSecondTimeout(op))
                    {
                        // because the JNI-InChI library is expecting an platform number, format it as such
                        var time = double.Parse(op.Substring(1));
                        return($"{FLAG_CHAR}W{time.ToString("F2")}");
                    }
                    else
                    {
                        return($"{FLAG_CHAR}{op}");
                    }
                }
                // 1,5 tautomer option
                else if (string.Equals("15T", op, StringComparison.Ordinal))
                {
                    return(FLAG_CHAR + "15T");
                }
                // keto-enol tautomer option
                else if (string.Equals("KET", op, StringComparison.Ordinal))
                {
                    return(FLAG_CHAR + "KET");
                }
                else
                {
                    throw new NInchiException("Unrecognised InChI option");
                }
            }));

            if (!hasUserSpecifiedTimeout)
            {
                if (options.Length > 0)
                {
                    options += " ";
                }
                options += FIVE_SECOND_TIMEOUT;
            }
            return(options);
        }