public static List <Atom> GetAtoms(Ingredient ingredient) { Debug.Log("CellPackLoader: GetAtoms"); 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); }
//public void AddProteinInstance(string path, Vector3 position, Quaternion rotation) //{ // if (!ProteinIngredientNames.Contains(path)) // { // throw new Exception("Ingredient path do not exists"); // } // var ingredientId = ProteinIngredientNames.IndexOf(path); // CPUBuffers.Get.ProteinInstanceInfos.Add(new Vector4(ingredientId, (int) InstanceState.Normal, 0)); // CPUBuffers.Get.ProteinInstancePositions.Add(position); // CPUBuffers.Get.ProteinInstanceRotations.Add(MyUtility.QuanternionToVector4(rotation)); // TotalNumProteinAtoms += CPUBuffers.Get.ProteinAtomCount[ingredientId]; //} //*** Curve Ingredients ****// public void AddCurveIngredient(string path, string pdbName) { if (SceneHierarchy.Contains(path)) { throw new Exception("Invalid curve ingredient path: " + path); } if (CurveIngredientNames.Contains(path)) { throw new Exception("Invalid curve ingredient path: " + path); } AddIngredientToHierarchy(path); CurveIngredientNames.Add(path); var numSteps = 1; var twistAngle = 0.0f; var segmentLength = 34.0f; var color = new Color(1, 1, 1, 1); if (path.Contains("DNA")) { numSteps = 12; twistAngle = 34.3f; segmentLength = 34.0f; color = Color.yellow; var atomSpheres = PdbLoader.LoadAtomSpheres(pdbName); CPUBuffers.Get.CurveIngredientsAtomStart.Add(CPUBuffers.Get.CurveIngredientsAtoms.Count); CPUBuffers.Get.CurveIngredientsAtomCount.Add(atomSpheres.Count); CPUBuffers.Get.CurveIngredientsAtoms.AddRange(atomSpheres); } //else if (path.Contains("mRNA")) else if (path.Contains("RNA")) { numSteps = 12; twistAngle = 34.3f; segmentLength = 34.0f; color = Color.red; var atomSpheres = PdbLoader.LoadAtomSpheres(pdbName); CPUBuffers.Get.CurveIngredientsAtomStart.Add(CPUBuffers.Get.CurveIngredientsAtoms.Count); CPUBuffers.Get.CurveIngredientsAtomCount.Add(atomSpheres.Count); CPUBuffers.Get.CurveIngredientsAtoms.AddRange(atomSpheres); } else if (path.Contains("peptide")) { numSteps = 10; twistAngle = 0; segmentLength = 20.0f; color = Color.magenta; var atomSphere = new Vector4(0, 0, 0, 3); CPUBuffers.Get.CurveIngredientsAtomStart.Add(CPUBuffers.Get.CurveIngredientsAtoms.Count); CPUBuffers.Get.CurveIngredientsAtomCount.Add(1); CPUBuffers.Get.CurveIngredientsAtoms.Add(atomSphere); } else if (path.Contains("lypoglycane")) { numSteps = 10; twistAngle = 0; segmentLength = 20; color = Color.green; var atomSphere = new Vector4(0, 0, 0, 8); CPUBuffers.Get.CurveIngredientsAtomStart.Add(CPUBuffers.Get.CurveIngredientsAtoms.Count); CPUBuffers.Get.CurveIngredientsAtomCount.Add(1); CPUBuffers.Get.CurveIngredientsAtoms.Add(atomSphere); } else { throw new Exception("Curve ingredient unknown"); } CPUBuffers.Get.CurveIngredientsColors.Add(color); CPUBuffers.Get.CurveIngredientToggleFlags.Add(1); CPUBuffers.Get.CurveIngredientsInfos.Add(new Vector4(numSteps, twistAngle, segmentLength, 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"); }
public void AddCurveIngredient(string name, string pdbName) { if (ProteinNames.Contains(name)) { return; } int numSteps = 1; float twistAngle = 0; float segmentLength = 34.0f; var color = Helper.GetRandomColor(); if (name.Contains("DNA")) { numSteps = 12; twistAngle = 34.3f; segmentLength = 34.0f; color = Color.yellow; var atomSpheres = PdbLoader.LoadAtomSpheres(pdbName); CurveIngredientsAtomCount.Add(atomSpheres.Count); CurveIngredientsAtomStart.Add(CurveIngredientsAtoms.Count); CurveIngredientsAtoms.AddRange(atomSpheres); } else if (name.Contains("mRNA")) { numSteps = 12; twistAngle = 34.3f; segmentLength = 34.0f; color = Color.red; var atomSpheres = PdbLoader.LoadAtomSpheres(pdbName); CurveIngredientsAtomCount.Add(atomSpheres.Count); CurveIngredientsAtomStart.Add(CurveIngredientsAtoms.Count); CurveIngredientsAtoms.AddRange(atomSpheres); } else if (name.Contains("peptide")) { numSteps = 10; twistAngle = 0; segmentLength = 20.0f; color = Color.magenta; var atomSphere = new Vector4(0, 0, 0, 3); CurveIngredientsAtomCount.Add(1); CurveIngredientsAtomStart.Add(CurveIngredientsAtoms.Count); CurveIngredientsAtoms.Add(atomSphere); } else if (name.Contains("lypoglycane")) { numSteps = 10; twistAngle = 0; segmentLength = 20; color = Color.green; var atomSphere = new Vector4(0, 0, 0, 8); CurveIngredientsAtomCount.Add(1); CurveIngredientsAtomStart.Add(CurveIngredientsAtoms.Count); CurveIngredientsAtoms.Add(atomSphere); } else { throw new Exception("Curve ingredient unknown"); } CurveIngredientsNames.Add(name); CurveIngredientsColors.Add(color); CurveIngredientToggleFlags.Add(1); CurveIngredientsInfos.Add(new Vector4(numSteps, twistAngle, segmentLength)); }
public static void AddProteinIngredient(JSONNode ingredientDictionary, string prefix) { var name = prefix + "_" + ingredientDictionary["name"]; var biomt = (bool)ingredientDictionary["source"]["biomt"].AsBool; var center = (bool)ingredientDictionary["source"]["transform"]["center"].AsBool; var pdbName = ingredientDictionary["source"]["pdb"].Value.Replace(".pdb", ""); if (pdbName == "") { return; } if (pdbName == "null") { return; } if (pdbName == "None") { return; } if (pdbName.StartsWith("EMDB")) { return; } if (pdbName.Contains("1PI7_1vpu_biounit")) { return; } // Disable biomts until loading problem is resolved if (biomt) { return; } // Load atom set from pdb file var atomSet = PdbLoader.LoadAtomSet(pdbName); // If the set is empty return if (atomSet.Count == 0) { return; } var atomSpheres = AtomHelper.GetAtomSpheres(atomSet); var centerPosition = AtomHelper.ComputeBounds(atomSpheres).center; var biomtTransforms = biomt ? PdbLoader.LoadBiomtTransforms(pdbName) : new List <Matrix4x4>(); var biomtCenter = AtomHelper.GetBiomtCenter(biomtTransforms); var containsACarbonOnly = AtomHelper.ContainsACarbonOnly(atomSet); // Center atoms AtomHelper.OffsetSpheres(ref atomSpheres, centerPosition); // Compute bounds var bounds = AtomHelper.ComputeBounds(atomSpheres); // Get ingredient color // TODO: Move color palette code into dedicated function var cid = ColorPaletteGenerator.GetRandomUniqFromSample(current_color, usedColors[current_color]); usedColors[current_color].Add(cid); var sample = ColorPaletteGenerator.colorSamples[cid]; var c = ColorPaletteGenerator.lab2rgb(sample) / 255.0f; var color = new Color(c[0], c[1], c[2]); // Define cluster decimation levels var clusterLevels = (containsACarbonOnly) ? new List <float>() { 0.85f, 0.25f, 0.1f } : new List <float>() { 0.10f, 0.05f, 0.01f }; // Add ingredient type //SceneManager.Instance.AddIngredient(name, bounds, atomSpheres, color); SceneManager.Instance.AddIngredient(name, bounds, atomSpheres, color, clusterLevels); int instanceCount = 0; for (int k = 0; k < ingredientDictionary["results"].Count; k++) { var p = ingredientDictionary["results"][k][0]; var r = ingredientDictionary["results"][k][1]; var position = new Vector3(-p[0].AsFloat, p[1].AsFloat, p[2].AsFloat); var rotation = new Quaternion(r[0].AsFloat, r[1].AsFloat, r[2].AsFloat, r[3].AsFloat); var mat = Helper.quaternion_matrix(rotation); var euler = Helper.euler_from_matrix(mat); rotation = Helper.MayaRotationToUnity(euler); if (!biomt) { // Find centered position if (!center) { position += Helper.QuaternionTransform(rotation, centerPosition); } SceneManager.Instance.AddIngredientInstance(name, position, rotation); instanceCount++; } else { foreach (var transform in biomtTransforms) { var biomtOffset = Helper.RotationMatrixToQuaternion(transform) * centerPosition; var biomtInstanceRot = rotation * Helper.RotationMatrixToQuaternion(transform); var biomtInstancePos = rotation * (new Vector3(transform.m03, transform.m13, transform.m23) + biomtOffset) + position - biomtCenter; SceneManager.Instance.AddIngredientInstance(name, biomtInstancePos, biomtInstanceRot); instanceCount++; } } } Debug.Log("*****"); Debug.Log("Added ingredient: " + name); if (containsACarbonOnly) { Debug.Log("Alpha-carbons only"); } Debug.Log("Pdb name: " + pdbName + " *** " + "Num atoms: " + atomSpheres.Count + " *** " + "Num instances: " + instanceCount + " *** " + "Total atom count: " + atomSpheres.Count * instanceCount); }
public static void AddProteinIngredient(JSONNode ingredientDictionary, params string[] pathElements) { var name = ingredientDictionary["name"]; var path = MyUtility.GetUrlPath(pathElements.ToList(), name); var biomt = (bool)ingredientDictionary["source"]["biomt"].AsBool; var center = (bool)ingredientDictionary["source"]["transform"]["center"].AsBool; var pdbName = ingredientDictionary["source"]["pdb"].Value.Replace(".pdb", ""); List <Vector4> atomSpheres; List <Matrix4x4> biomtTransforms = new List <Matrix4x4>(); Vector3 biomtCenter = Vector3.zero; bool containsACarbonOnly = false; bool oneLOD = false; if ((pdbName == "") || (pdbName == "null") || (pdbName == "None") || pdbName.StartsWith("EMDB")) { return; ////check for sphere file//information in the file. if not in file is it on disk ? on repo ? ////possibly read the actuall recipe definition ? ////check if bin exist //var filePath = PdbLoader.DefaultPdbDirectory + ingredientDictionary["name"] + ".bin"; //if (File.Exists(filePath)){ // atomSpheres = new List<Vector4>(); // var points = MyUtility.ReadBytesAsFloats(filePath); // for (var i = 0; i < points.Length; i += 4) { // var currentAtom = new Vector4 (points [i], points [i + 1], points [i + 2], points [i + 3]); // atomSpheres.Add (currentAtom); // } // containsACarbonOnly = true; // oneLOD = true; //} //else if (ingredientDictionary ["radii"] != null) { // atomSpheres = MyUtility.gatherSphereTree(ingredientDictionary)[0]; // Debug.Log ("nbprim "+atomSpheres.Count.ToString());//one sphere // oneLOD = true; //} else { // float radius = 30.0f; // if (name.Contains("dLDL")) // radius = 108.08f;//or use the mesh? or make sphere from the mesh ? // if (name.Contains("iLDL")) // radius = 105.41f;//or use the mesh? or make sphere from the mesh ? // atomSpheres = new List<Vector4>(); // atomSpheres.Add (new Vector4(0,0,0,radius)); // //No LOD since only one sphere // oneLOD = true; //} } else { //if (pdbName.StartsWith("EMDB")) return; //if (pdbName.Contains("1PI7_1vpu_biounit")) return;//?? // Load atom set from pdb file var atomSet = PdbLoader.LoadAtomSet(pdbName); // If the set is empty return if (atomSet.Count == 0) { return; } atomSpheres = AtomHelper.GetAtomSpheres(atomSet); containsACarbonOnly = AtomHelper.ContainsCarbonAlphaOnly(atomSet); } var centerPosition = AtomHelper.ComputeBounds(atomSpheres).center; // Center atoms AtomHelper.OffsetSpheres(ref atomSpheres, centerPosition); // Compute bounds var bounds = AtomHelper.ComputeBounds(atomSpheres); biomtTransforms = biomt ? PdbLoader.LoadBiomtTransforms(pdbName) : new List <Matrix4x4>(); biomtCenter = AtomHelper.GetBiomtCenter(biomtTransforms, centerPosition); //if (!pdbName.Contains("1TWT_1TWV")) return; // Disable biomts until loading problem is resolved //if (!biomt) return; // Get ingredient color // TODO: Move color palette code into dedicated function var cid = ColorPaletteGenerator.GetRandomUniqFromSample(current_color, usedColors[current_color]); usedColors[current_color].Add(cid); var sample = ColorPaletteGenerator.colorSamples[cid]; var c = ColorPaletteGenerator.lab2rgb(sample) / 255.0f; var color = new Color(c[0], c[1], c[2]); // Define cluster decimation levels var clusterLevels = (containsACarbonOnly) ? new List <float>() { 0.85f, 0.25f, 0.1f } : new List <float>() { 0.15f, 0.10f, 0.05f }; if (oneLOD) { clusterLevels = new List <float> () { 1, 1, 1 } } ; // Add ingredient type //SceneManager.Instance.AddIngredient(name, bounds, atomSpheres, color); SceneManager.Get.AddProteinIngredient(path, bounds, atomSpheres, color, clusterLevels, oneLOD); int instanceCount = 0; for (int k = 0; k < ingredientDictionary["results"].Count; k++) { var p = ingredientDictionary["results"][k][0]; var r = ingredientDictionary["results"][k][1]; var position = new Vector3(-p[0].AsFloat, p[1].AsFloat, p[2].AsFloat); var rotation = new Quaternion(r[0].AsFloat, r[1].AsFloat, r[2].AsFloat, r[3].AsFloat); var mat = MyUtility.quaternion_matrix(rotation); var euler = MyUtility.euler_from_matrix(mat); rotation = MyUtility.MayaRotationToUnity(euler); if (!biomt) { // Find centered position if (!center) { position += MyUtility.QuaternionTransform(rotation, centerPosition); } SceneManager.Get.AddProteinInstance(path, position, rotation); instanceCount++; } else { foreach (var transform in biomtTransforms) { var biomteuler = MyUtility.euler_from_matrix(transform); var rotBiomt = MyUtility.MayaRotationToUnity(biomteuler); var offset = MyUtility.QuaternionTransform(rotBiomt, centerPosition); //Helper.RotationMatrixToQuaternion(matBiomt), GetCenter()); var posBiomt = new Vector3(-transform.m03, transform.m13, transform.m23) + offset - biomtCenter; var biomtOffset = MyUtility.RotationMatrixToQuaternion(transform) * centerPosition; var biomtInstanceRot = rotation * rotBiomt; //Helper.RotationMatrixToQuaternion(transform); var biomtInstancePos = rotation * posBiomt + position; SceneManager.Get.AddProteinInstance(path, biomtInstancePos, biomtInstanceRot); instanceCount++; } } } SceneManager.Get.AddIngredientProperties(atomSpheres.Count, instanceCount); Debug.Log("*****"); Debug.Log("Added ingredient: " + path); //if (isCarbonAlphaOnly) Debug.Log("Alpha-carbons only"); //Debug.Log("Pdb name: " + pdbName + " *** " + "Num atoms: " + atomSet.Count + " *** " + "Num instances: " + instanceCount + " *** " + "Total atom count: " + atomSet.Count * instanceCount); }