Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private static void ProcessChemModel(IChemModel chemModel, ISettings settings, FileUsage usage,
                                             MoleculeLoadingResults results, MoleculeProcessingProgress progress,
                                             float sectionSz)
        {
            //if (ChemModelManipulator.getAllInOneContainer(chemModel).getBondCount() == 0)
            //{
            //    return;
            //}

            // check for coordinates
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))//
            {
                results.Num2DCoords++;
            }
            //    usage == FileUsage.TwoD)
            //{
            //    throw new UserLevelException("File has no 2D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))// &&
            {
                results.Num3DCoords++;
            }
            //    usage == FileUsage.ThreeD)
            //{
            //    throw new UserLevelException("File has no 3D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}

            ElementPTFactory elements = ElementPTFactory.Instance;

            // calc item sz
            int numItems = 0;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    numItems += chemModel.SetOfMolecules.Molecules[mol].Atoms.Length;
                    //numItems += chemModel.SetOfMolecules.Molecules[mol].Bonds.Length;
                }
            }
            float itemSz = sectionSz / (float)numItems;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    IMolecule molecule = chemModel.SetOfMolecules.Molecules[mol];
                    results.NumAtoms += molecule.Atoms.Length;
                    results.NumBonds += molecule.Bonds.Length;
                    foreach (IAtom atom in molecule.Atoms)
                    {
                        PeriodicTableElement pe = elements.getElement(atom.Symbol);
                        if (pe != null)
                        {
                            atom.AtomicNumber = pe.AtomicNumber;
                            atom.Properties["PeriodicTableElement"] = pe;
                            atom.Properties["Period"] = int.Parse(pe.Period);
                        }
                        else
                        {
                            progress.Log(string.Format("Failed to find periodic element: {0}", atom.Symbol), LogItem.ItemLevel.Failure);
                        }
                        progress.UpdateProgress(itemSz);
                    }
                    progress.Log(string.Format("Processed {0} atoms", molecule.Atoms.Length), LogItem.ItemLevel.Info);
                }
            }
            progress.Log("Processed Model", LogItem.ItemLevel.Success);
        }