Beispiel #1
0
        private Counts ReadCtabHeader(StreamReader reader)
        {
            Counts result = new Counts();

            // Title
            string title = SdFileConverter.GetNextLine(reader); //reader.ReadLine();

            if (!string.IsNullOrEmpty(title))
            {
                if (title.StartsWith("$MDL"))
                {
                    _molecule.Errors.Add("RGFiles are currently not supported");
                    throw new Exception("RGFiles are currently not supported");
                }
                if (title.StartsWith("$RXN"))
                {
                    _molecule.Errors.Add("RXNFiles are currently not supported");
                    throw new Exception("RXNFiles are currently not supported");
                }
                if (title.StartsWith("$RDFILE"))
                {
                    _molecule.Errors.Add("RDFiles are currently not supported");
                    throw new Exception("RDFiles are currently not supported");
                }
                if (title.StartsWith("<XDfile>"))
                {
                    _molecule.Errors.Add("XDFiles are currently not supported");
                    throw new Exception("XDFiles are currently not supported");
                }
            }

            // Header
            string header = SdFileConverter.GetNextLine(reader); //reader.ReadLine();

            // Comment
            string comment = SdFileConverter.GetNextLine(reader); //reader.ReadLine();

            // Counts
            string counts = SdFileConverter.GetNextLine(reader); //reader.ReadLine();

            try
            {
                result.Atoms   = ParseInteger(counts, 0, 3);
                result.Bonds   = ParseInteger(counts, 3, 3);
                result.Version = GetSubString(counts, 34, 5).ToUpper();
            }
            catch (Exception ex)
            {
                result.Message = $"Exception {ex.Message}";
                Debug.WriteLine(ex.Message);
            }

            return(result);
        }
Beispiel #2
0
        public override SdfState ImportFromStream(StreamReader reader, Molecule molecule, out string message)
        {
            _molecule    = molecule;
            atomByNumber = new Dictionary <int, Atom>();
            bondByNumber = new Dictionary <int, Bond>();
            numberByAtom = new Dictionary <Atom, int>();

            message = null;
            SdfState result = SdfState.Null;

            try
            {
                while (!reader.EndOfStream)
                {
                    Counts counts = ReadCtabHeader(reader);
                    if (!string.IsNullOrEmpty(counts.Message) && counts.Message.Contains("Unsupported"))
                    {
                        result  = SdfState.Unsupported;
                        message = counts.Message;
                        break;
                    }
                    else
                    {
                        ReadAtoms(reader, counts.Atoms);
                        ReadBonds(reader, counts.Bonds);
                        result = ReadCtabFooter(reader);
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message);
                message = ex.Message;
                result  = SdfState.Error;
            }

            return(result);
        }