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); }