Exemplo n.º 1
0
        public static void AddProteinIngredient(ref Ingredient ingredient)
        {
            Debug.Log("CellPackLoader: AddProteinIngredient");
            var path    = ingredient.path;
            var biomt   = ingredient.source.biomt;
            var pdbName = ingredient.source.pdb.Replace(".pdb", "");

            Debug.Log("*****");
            Debug.Log("Ingredient: " + ingredient.ingredient_id);
            Debug.Log("Name: " + ingredient.path);
            Debug.Log("Pdb id: " + ingredient.source.pdb);


            // ***** Load atoms *****//

            var atoms = GetAtoms(ingredient);

            var numChains = AtomHelper.GetNumChains(atoms);

            Debug.Log("Num chains: " + numChains);

            ingredient.nbChains = numChains;

            var isFromCustomStructureFile = AtomHelper.IsFromCustomStructureFile(atoms);

            if (isFromCustomStructureFile)
            {
                Debug.Log("From custom structure file");
            }

            var alphaCarbonsOnly = AtomHelper.ContainsCarbonAlphaOnly(atoms);

            if (alphaCarbonsOnly)
            {
                AtomHelper.OverwriteRadii(ref atoms, 3);
            }
            if (alphaCarbonsOnly)
            {
                Debug.Log("Alpha carbons only");
            }


            // ***** Compute lod proxies *****//

            var lodProxies = new List <List <Vector4> >();

            // Define cluster decimation levels
            var clusterLevelFactors = new List <float>()
            {
                0.15f, 0.10f, 0.05f
            };

            if (alphaCarbonsOnly || isFromCustomStructureFile)
            {
                clusterLevelFactors = new List <float>()
                {
                    1, 1, 1
                }
            }
            ;

            if (!biomt)
            {
                // Center atoms before computing the lod proxies
                AtomHelper.CenterAtoms(ref atoms);

                var atomSpheres = AtomHelper.GetAtomSpheres(atoms);
                lodProxies = AtomHelper.ComputeLodProxies(atomSpheres, clusterLevelFactors);
            }
            else
            {
                var atomSpheres     = AtomHelper.GetAtomSpheres(atoms);
                var biomtTransforms = PdbLoader.LoadBiomtTransforms(pdbName);

                // Compute centered lod proxies
                lodProxies = AtomHelper.ComputeLodProxiesBiomt(atomSpheres, biomtTransforms, clusterLevelFactors);

                // Assemble the atom set from biomt transforms and center
                atoms = AtomHelper.BuildBiomt(atoms, biomtTransforms);

                var centerPosition = AtomHelper.ComputeBounds(atoms).center;

                // Center atoms
                AtomHelper.OffsetAtoms(ref atoms, centerPosition);

                // Center proxies
                for (int i = 0; i < lodProxies.Count; i++)
                {
                    var t = lodProxies[i];
                    AtomHelper.OffsetSpheres(ref t, centerPosition);
                }
            }

            SceneManager.Get.AddProteinIngredientToCPUBuffer(ingredient, atoms, lodProxies);
            Debug.Log("Ingredient added succesfully");
        }