public void MoleculeLoaded(int id, string name, PrimaryStructure primaryStructure)
 {
     moleculeSettingsPanel.MoleculeLoaded(id, name, primaryStructure.Title, primaryStructure.AtomCount(), primaryStructure.ResidueCount());
     elementsSettingsPanel.SetModelElements(id, primaryStructure.ElementNames);
     residuesSettingsPanel.SetPrimaryStructure(id, primaryStructure);
 }
        // Loads a molecule trajectory. Will only work if molecule is already loaded
        public IEnumerator LoadMoleculeTrajectory(int moleculeID, string filePath)
        {
            if (!molecules.ContainsKey(moleculeID))
            {
                MoleculeEvents.RaiseShowMessage("Can't load molecule trajectory. No molecule found.", true);
                yield break;
            }

            if (loadingTrajectory)
            {
                MoleculeEvents.RaiseShowMessage("Can't Load Trajectory: another trajectory currently loading", true);
                yield break;
            }

            PrimaryStructure primaryStructure = molecules[moleculeID].PrimaryStructure;
            int atomCount = loadTrajectoryAtomCount(filePath);

            if (atomCount != primaryStructure.AtomCount())
            {
                MoleculeEvents.RaiseShowMessage("Trajectory atom count [" + atomCount + " doesn't match loaded structure atom count [" + primaryStructure.AtomCount() + "]", true);
                yield break;
            }

            MoleculeEvents.RaiseShowMessage("Loading trajectory. Please wait", false);

            loadingTrajectory = true;

            PrimaryStructureTrajectory trajectory = null;
            string loadException = null;

            Thread thread = new Thread(() => {
                try {
                    int startFrame     = 0;
                    int frameFrequency = 1;
                    int frameCount     = Settings.MaxTrajectoryFrames;

                    if (filePath.EndsWith(".xtc"))
                    {
                        trajectory = XTCTrajectoryParser.GetTrajectory(filePath, startFrame, frameCount, frameFrequency);
                    }
                    else if (filePath.EndsWith(".dcd"))
                    {
                        trajectory = DCDTrajectoryParser.GetTrajectory(filePath, startFrame, frameCount, frameFrequency);
                    }
                    else if (filePath.EndsWith(".gro"))
                    {
                        trajectory = GROTrajectoryParser.GetTrajectory(filePath, startFrame, frameCount, frameFrequency);
                    }
                }
                catch (FileParseException ex) {
                    loadException = ex.Message;
                }
            });

            thread.Start();

            while (thread.IsAlive)
            {
                yield return(null);
            }

            if (loadException != null)
            {
                MoleculeEvents.RaiseShowMessage("Error Loading Trajectory File: " + loadException, true);
                loadingTrajectory = false;
                yield break;
            }

            if (trajectory != null)
            {
                molecules[moleculeID].SetTrajectory(trajectory);
                MoleculeEvents.RaiseTrajectoryLoaded(moleculeID, filePath, trajectory.FrameCount());
            }

            loadingTrajectory = false;
        }