Пример #1
0
        private static void ProcessChemFile(IChemFile chemFile, ISettings settings, FileUsage usage,
                                            MoleculeLoadingResults results, LoadingProgress progress)
        {
            MoleculeProcessingProgress molProcessing = new MoleculeProcessingProgress(progress);

            progress.MoveToNextProcess(molProcessing);

            // calc size
            int numModels = 0;

            for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++)
            {
                IChemSequence chemSeq = chemFile.getChemSequence(seq);
                numModels += chemSeq.ChemModelCount;
            }
            float modelSz = 1.0f / (float)numModels;

            results.NumSequences = chemFile.ChemSequenceCount;
            for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++)
            {
                IChemSequence chemSeq = chemFile.getChemSequence(seq);
                results.NumModels += chemSeq.ChemModelCount;
                for (int model = 0; model < chemSeq.ChemModelCount; model++)
                {
                    ProcessChemModel(chemSeq.getChemModel(model), settings, usage, results, molProcessing, modelSz);
                }
                molProcessing.Log("Processed Sequence", LogItem.ItemLevel.Success);
            }
            molProcessing.Log("Processed File", LogItem.ItemLevel.Success);
        }
Пример #2
0
        internal static IChemFile LoadFromFile(string filename, ISettings settings, FileUsage usage,
                                               LoadingProgress progress, out MoleculeLoadingResults results)
        {
            IChemObjectReader reader;

            results          = new MoleculeLoadingResults();
            results.Filename = filename;

            MoleculeLoadingProgress molLoading = new MoleculeLoadingProgress(Path.GetFileName(filename), progress);

            progress.MoveToNextProcess(molLoading);

            try
            {
                molLoading.Log("Reading file", LogItem.ItemLevel.StageInfo);

                StreamReader  file          = new StreamReader(filename, System.Text.Encoding.Default);
                ReaderFactory readerFactory = new ReaderFactory();

                molLoading.Log("Creating Reader", LogItem.ItemLevel.DebugInfo);

                reader = readerFactory.createReader(filename, file);
                file.Close();

                if (reader != null)
                {
                    reader.setReader(new StreamReader(filename, System.Text.Encoding.Default));
                }
                else
                {
                    throw new UserLevelException("Format not recognised", UserLevelException.ExceptionType.FileLoading,
                                                 typeof(MoleculeLoader), null);
                }
                results.FileFormat = (IChemFormat)reader.Format;

                molLoading.Log("Found File Format: " + reader.Format.FormatName, LogItem.ItemLevel.UserInfo);
            }
            catch (FileNotFoundException fnfe)
            {
                throw new UserLevelException("Target file no found", UserLevelException.ExceptionType.FileLoading,
                                             typeof(MoleculeLoader), fnfe);
            }
            molLoading.Log("Loaded Molecule File", LogItem.ItemLevel.Success);

            //catch (IOException ioe)
            //{
            //    throw new UserLevelException("Problem reading from file", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), ioe);
            //}
            //catch (UserLevelException ule)
            //{
            //    results.Result = MoleculeLoadingResults.Results.Problems;
            //    throw ule;
            //}
            //catch (Exception e)
            //{
            //    results.Result = MoleculeLoadingResults.Results.Errors;
            //    throw new UserLevelException("Problem loading file", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), e);
            //}

            IChemFile chemFile;
            ChemModel chemModel;

            if (reader.accepts(typeof(IChemFile)))
            {
                // try to read a ChemFile
                //try
                //{
                chemFile = (IChemFile)reader.read((IChemObject) new ChemFile());
                molLoading.UpdateProgress(1);
                if (chemFile != null)
                {
                    ProcessChemFile(chemFile, settings, usage, results, progress);
                }
                return(chemFile);
                //}
                //catch (UserLevelException ule)
                //{
                //    throw ule;
                //}
                //catch (Exception e)
                //{
                //    results.Result = MoleculeLoadingResults.Results.Errors;

                //    throw new UserLevelException("Problem reading/processing file", UserLevelException.ExceptionType.FileLoading,
                //                                 typeof(MoleculeLoader), e);
                //}
            }
            if (reader.accepts(typeof(ChemModel)))
            {
                // try to read a ChemModel
                //try
                //{
                chemModel = (ChemModel)reader.read((IChemObject) new ChemModel());
                molLoading.UpdateProgress(1);
                if (chemModel != null)
                {
                    MoleculeProcessingProgress molProcessing = new MoleculeProcessingProgress(progress);
                    progress.MoveToNextProcess(molProcessing);
                    ProcessChemModel(chemModel, settings, usage, results, molProcessing, 1);
                }
                //}
                //catch (UserLevelException ule)
                //{
                //    throw ule;
                //}
                //catch (Exception e)
                //{
                //    throw new UserLevelException("Problem reading/processing file", UserLevelException.ExceptionType.FileLoading,
                //                                 typeof(MoleculeLoader), e);
                //}
            }
            else
            {
                throw new UserLevelException("Unable to process reading", UserLevelException.ExceptionType.FileLoading,
                                             typeof(MoleculeLoader), null);
            }
            return(null);
        }