Ejemplo n.º 1
0
        // public static string CTabToCharExpression = // expression to convert a ctab into a Oracle char type. Returns 'Large Structure' if too big & handle at retrieve time
        //  "case when length(chime(ctab)) <= 4000 then to_char(chime(ctab)) else 'Large Structure' end";
        // public static string LargeStructureString = "Large Structure"; // string that indicates that chime for structure is > 4000 chars
        // Examples: 3203030, 3020939, 3020943, 3046095, 2240877, 2312187, 2836746

        /// <summary>
        /// Convert an objectinto a ChemicalStructure object
        /// </summary>
        /// <param name="fieldValue"></param>
        /// <returns></returns>

        public static MoleculeMx ConvertObjectToChemicalStructure(
            object fieldValue)
        {
            MoleculeMx     cs;
            MoleculeFormat structureFormat;
            string         txt;

            if (fieldValue == null)
            {
                cs = null;
            }

            else if (fieldValue is MoleculeMx)
            {
                cs = (MoleculeMx)fieldValue;
            }

            else if (fieldValue is string || fieldValue is CompoundId || fieldValue is QualifiedNumber)
            {
                if (fieldValue is string)
                {
                    txt = (string)fieldValue;
                }

                else if (fieldValue is CompoundId)
                {
                    txt = ((CompoundId)fieldValue).Value;
                }

                else
                {
                    txt = ((QualifiedNumber)fieldValue).TextValue;
                }

                structureFormat = MoleculeMx.GetMoleculeFormatType(txt);
                if (structureFormat != MoleculeFormat.Unknown)                 // just convert is known format
                {
                    cs = MoleculeMx.MolStringToMoleculeMx(txt);
                }

                else                 // see if unqualified compound id
                {
                    cs = MoleculeUtil.SelectMoleculeForCid(txt);
                }
            }

            else
            {
                throw new Exception("Object is not a recognized structure format");
            }

            return(cs);
        }