Esempio n. 1
0
    //*** Protein Ingredients ****//

    public void AddProteinIngredientToCPUBuffer(Ingredient ingredient, List <Atom> atoms, List <List <Vector4> > clusterLevels = null)
    {
        if (SceneHierarchy.Contains(ingredient.path))
        {
            throw new Exception("Invalid protein path: " + ingredient.path);
        }
        if (ProteinIngredientNames.Contains(ingredient.path))
        {
            throw new Exception("Invalid protein path: " + ingredient.path);
        }

        if (clusterLevels != null)
        {
            if (NumLodLevels != 0 && NumLodLevels != clusterLevels.Count)
            {
                throw new Exception("Uneven cluster levels number: " + ingredient.path);
            }
        }

        AddIngredientToHierarchy(ingredient.path);
        ProteinIngredientNames.Add(ingredient.path);

        CPUBuffers.Get.ProteinToggleFlags.Add(1);
        CPUBuffers.Get.ProteinIngredientsRadii.Add(AtomHelper.ComputeRadius(atoms));

        CPUBuffers.Get.ProteinAtomCount.Add(atoms.Count);
        CPUBuffers.Get.ProteinAtomStart.Add(CPUBuffers.Get.ProteinAtoms.Count);


        for (var i = 0; i < atoms.Count; i++)
        {
            var helix = atoms[i].helixIndex >= 0;
            var sheet = atoms[i].sheetIndex >= 0;
            //if (helix && sheet) throw new Exception("Da fuk just happened");

            var secondaryStructure = 0;
            secondaryStructure = (helix) ? atoms[i].helixIndex : secondaryStructure;
            secondaryStructure = (sheet) ? -atoms[i].sheetIndex : secondaryStructure;

            //if (sheet)
            //{
            //    int a = 0;
            //}

            CPUBuffers.Get.ProteinAtoms.Add(new Vector4(atoms[i].position.x, atoms[i].position.y, atoms[i].position.z, atoms[i].radius));
            CPUBuffers.Get.ProteinAtomInfo.Add(new Vector4(secondaryStructure, atoms[i].symbolId, atoms[i].residueId, atoms[i].chainId));
            CPUBuffers.Get.ProteinAtomInfo2.Add(new Vector4(atoms[i].helixIndex, atoms[i].nbHelicesPerChain, atoms[i].sheetIndex, atoms[i].nbSheetsPerChain));
        }

        if (clusterLevels != null)
        {
            NumLodLevels = clusterLevels.Count;
            foreach (var level in clusterLevels)
            {
                CPUBuffers.Get.ProteinAtomClusterCount.Add(level.Count);
                CPUBuffers.Get.ProteinAtomClusterStart.Add(CPUBuffers.Get.ProteinAtomClusters.Count);
                CPUBuffers.Get.ProteinAtomClusters.AddRange(level);
            }
        }
    }
Esempio n. 2
0
    public void AddProteinIngredient(string path, Bounds bounds, List <Vector4> atomSpheres, Color color,
                                     List <float> clusterLevels = null,
                                     bool nolod = false)
    {
        if (SceneHierarchy.Contains(path))
        {
            throw new Exception("Invalid protein path: " + path);
        }
        if (ProteinIngredientNames.Contains(path))
        {
            throw new Exception("Invalid protein path: " + path);
        }

        if (clusterLevels != null)
        {
            if (NumLodLevels != 0 && NumLodLevels != clusterLevels.Count)
            {
                throw new Exception("Uneven cluster levels number: " + path);
            }
        }
        if (color == null)
        {
            color = MyUtility.GetRandomColor();
        }


        AddIngredientToHierarchy(path);


        ProteinColors.Add(color);
        ProteinToggleFlags.Add(1);
        ProteinIngredientNames.Add(path);
        ProteinRadii.Add(AtomHelper.ComputeRadius(atomSpheres));

        ProteinAtomCount.Add(atomSpheres.Count);
        ProteinAtomStart.Add(ProteinAtoms.Count);
        ProteinAtoms.AddRange(atomSpheres);

        if (clusterLevels != null)
        {
            NumLodLevels = clusterLevels.Count;
            foreach (var level in clusterLevels)
            {
                var            numClusters = Math.Max(atomSpheres.Count * level, 5);
                List <Vector4> clusterSpheres;
                if (!nolod)
                {
                    clusterSpheres = KMeansClustering.GetClusters(atomSpheres, (int)numClusters);
                }
                else
                {
                    clusterSpheres = new List <Vector4>(atomSpheres);
                }
                ProteinAtomClusterCount.Add(clusterSpheres.Count);
                ProteinAtomClusterStart.Add(ProteinAtomClusters.Count);
                ProteinAtomClusters.AddRange(clusterSpheres);
            }
        }
    }