private IEnumerator createSecondaryStructure(MoleculeRenderSettings settings, PrimaryStructureFrame frame, SecondaryStructure secondaryStructure)
        {
            for (int i = 0; i < primaryStructure.Chains().Count; i++)
            {
                Chain chain = primaryStructure.Chains()[i];

                if (chain.ResidueType != StandardResidue.AminoAcid)
                {
                    // UnityEngine.Debug.Log("Skipping secondary strucure. Non protein structures not currently supported.");
                    continue;
                }

                if (chain.MainChainResidues.Count < 2)
                {
                    // UnityEngine.Debug.Log("Skipping secondary strucure. Protein structure doesn't have enough residues for mesh.");
                    continue;
                }

                Mesh structureMesh = BuildStructureMesh(settings, chain, frame, secondaryStructure);

                GameObject structure = (GameObject)Instantiate(SecondaryStructurePrefab);
                structure.GetComponent <MeshFilter>().sharedMesh = structureMesh;

                structure.SetActive(false);
                structure.transform.SetParent(StructureParent.transform, false);

                yield return(null);
            }
        }
        private IEnumerator createMainChains(PrimaryStructureFrame frame)
        {
            int   interpolation = 5;
            int   resolution    = 5; // should be in config
            float radius        = 0.015f;
            int   currentIndex  = 0;

            foreach (Chain chain in primaryStructure.Chains())
            {
                if (chain.ResidueType != StandardResidue.AminoAcid)
                {
                    // UnityEngine.Debug.Log("Skipping main chain build. Non protein main chain not currently supported.");
                    continue;
                }

                List <Vector3> nodePositions = new List <Vector3>();

                foreach (Atom atom in chain.MainChainAtoms)
                {
                    // if no frame number use the base structure coordinates.
                    Vector3 position;
                    if (frame == null)
                    {
                        if (atom == null)
                        {
                            UnityEngine.Debug.Log("Main chain atom is null");
                        }

                        position = new Vector3(atom.Position.x, atom.Position.y, atom.Position.z);
                    }
                    else
                    {
                        position = new Vector3(frame.Coords[atom.Index * 3], frame.Coords[(atom.Index * 3) + 1], frame.Coords[(atom.Index * 3) + 2]);
                    }

                    // flip coord system for Unity
                    position.z *= -1;

                    nodePositions.Add(position);
                }

                List <DynamicMeshNode> nodes        = new List <DynamicMeshNode>();
                IEnumerable            splinePoints = Interpolate.NewCatmullRom(nodePositions.ToArray(), interpolation, false);
                Color32 chainColour = ChainColors[currentIndex % ChainColors.Length];

                foreach (Vector3 position in splinePoints)
                {
                    DynamicMeshNode node = new DynamicMeshNode();
                    node.Position    = position;
                    node.VertexColor = chainColour;
                    nodes.Add(node);
                }

                DynamicMesh mesh      = new DynamicMesh(nodes, radius, resolution, interpolation + 1);
                Mesh        chainMesh = mesh.Build(Settings.DebugFlag);

                GameObject chainStructure = (GameObject)Instantiate(ChainPrefab);
                chainStructure.GetComponent <MeshFilter>().sharedMesh = chainMesh;

                chainStructure.SetActive(false);
                chainStructure.transform.SetParent(ChainParent.transform, false);

                currentIndex++;
                yield return(null);
            }
        }