Esempio n. 1
0
        public static List<Atom> GetAtoms(Ingredient ingredient)
        {
            var name = ingredient.name;
            var pdbName = ingredient.source.pdb.Replace(".pdb", "");

            var atoms = new List<Atom>();

            if ((pdbName == "") || (pdbName == "null") || (pdbName == "None") || pdbName.StartsWith("EMDB"))
            {
                var filePath = PdbLoader.GetFile(PdbLoader.DefaultPdbDirectory, name, "bin");

                if (File.Exists(filePath))
                {
                    var points = MyUtility.ReadBytesAsFloats(filePath);
                    for (var i = 0; i < points.Length; i += 4)
                    {
                        var currentAtom = new Atom
                        {
                            position = new Vector3(points[i], points[i + 1], points[i + 2]),
                            radius = points[i + 3],
                            symbolId = -1,
                            chainId = 0
                        };
                        atoms.Add(currentAtom);
                    }
                }
            }
            else
            {
                // Load atom set from pdb file
                atoms = PdbLoader.LoadAtomDataFull(pdbName);
            }

            // If the set is empty return
            if (atoms.Count == 0)
                throw new Exception("Atom list empty: " + name);

            return atoms; 
        }
Esempio n. 2
0
        public static void AddProteinIngredient(ref Ingredient ingredient)
        {
            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");
        }