public void Initialise(AtomRenderSettings settings, ResidueCustomColourSelect colourSelectPanel, AtomButtonClickDelegate onClick) { this.AtomSettings = settings; this.colourSelectPanel = colourSelectPanel; this.onClick = onClick; updateAtomSettingsDisplay(); }
public AtomRenderSettings Clone() { AtomRenderSettings clone = new AtomRenderSettings(AtomName, defaultColour); clone.Representation = Representation; clone.CustomColour = CustomColour; clone.AtomColour = AtomColour; return(clone); }
public bool Equals(AtomRenderSettings other) { if (other.AtomName == AtomName && other.Representation == Representation && other.CustomColour == CustomColour && other.AtomColour.Equals(AtomColour)) { return(true); } return(false); }
private float getAtomRadius(Atom atom) { MolecularRepresentation?customRepresentation = null; if (renderSettings.CustomResidueRenderSettings != null && renderSettings.CustomResidueRenderSettings.ContainsKey(atom.ResidueID)) { ResidueRenderSettings residueSettings = renderSettings.CustomResidueRenderSettings[atom.ResidueID]; if (residueSettings != null) { // use the atom specific settings if available. if (residueSettings.AtomSettings.ContainsKey(atom.Name)) { AtomRenderSettings atomSettings = residueSettings.AtomSettings[atom.Name]; if (atomSettings.Representation != MolecularRepresentation.None) { customRepresentation = atomSettings.Representation; } } // if we didn't get from atom specific settings then try residue settings if (customRepresentation == null) { if (residueSettings.AtomRepresentation != MolecularRepresentation.None) { customRepresentation = residueSettings.AtomRepresentation; } } } } float atomRadius; if (!renderSettings.ShowAtoms) { atomRadius = 0.001f; } else if (customRepresentation != null && customRepresentation != MolecularRepresentation.None) { atomRadius = (MolecularRepresentation)customRepresentation == MolecularRepresentation.VDW ? atom.VDWRadius : atom.AtomicRadius / 2f; atomRadius *= renderSettings.AtomScale; } else { atomRadius = renderSettings.Representation == MolecularRepresentation.VDW ? atom.VDWRadius : atom.AtomicRadius / 2f; atomRadius *= renderSettings.AtomScale; } return(atomRadius); }
private IEnumerator createModelAtomsByElement(MoleculeRenderSettings renderSettings, PrimaryStructureFrame frame, int meshQuality) { Quaternion atomOrientation = Quaternion.Euler(45, 45, 45); // generate combined meshes (i.e single GameObject) for atoms with same element/colour Dictionary <Color, List <Matrix4x4> > mergeTransforms = new Dictionary <Color, List <Matrix4x4> >(); Dictionary <int, Atom> atoms = primaryStructure.GetAtoms(renderSettings.ShowStandardResidues, renderSettings.ShowNonStandardResidues, renderSettings.EnabledElements, renderSettings.EnabledResidueNames, renderSettings.EnabledResidueIDs); foreach (KeyValuePair <int, Atom> item in atoms) { Atom atom = item.Value; Vector3 position; // if no frame use the base structure coordinates. if (frame == null) { position = new Vector3(atom.Position.x, atom.Position.y, atom.Position.z); } else { if (atom.Index >= frame.AtomCount) { MoleculeEvents.RaiseShowMessage("Atoms not found in frame record. Aborting frame render.", true); yield break; } position = new Vector3(frame.Coords[atom.Index * 3], frame.Coords[(atom.Index * 3) + 1], frame.Coords[(atom.Index * 3) + 2]); } // flip coord system for Unity position.z *= -1; Color32?customColour = null; MolecularRepresentation?customRepresentation = null; if (renderSettings.CustomResidueRenderSettings != null && renderSettings.CustomResidueRenderSettings.ContainsKey(atom.ResidueID)) { ResidueRenderSettings residueSettings = renderSettings.CustomResidueRenderSettings[atom.ResidueID]; if (residueSettings != null) { // use the atom specific settings if available. if (residueSettings.AtomSettings.ContainsKey(atom.Name)) { AtomRenderSettings atomSettings = residueSettings.AtomSettings[atom.Name]; if (atomSettings.CustomColour) { customColour = atomSettings.AtomColour; } if (atomSettings.Representation != MolecularRepresentation.None) { customRepresentation = atomSettings.Representation; } } // if we didn't get from atom specific settings then get from residue settings if (customColour == null && residueSettings.ColourAtoms) { customColour = residueSettings.ResidueColour; } if (customRepresentation == null) { if (residueSettings.AtomRepresentation != MolecularRepresentation.None) { customRepresentation = residueSettings.AtomRepresentation; } } } } Color32 atomColour = Color.white; if (customColour != null) { atomColour = (Color)customColour; } else { if (!MolecularConstants.CPKColors.TryGetValue(atom.Element.ToString(), out atomColour)) { MolecularConstants.CPKColors.TryGetValue("Other", out atomColour); } } float atomDiameter = getAtomRadius(atom, renderSettings, customRepresentation) * 2; Vector3 scale = new Vector3(atomDiameter, atomDiameter, atomDiameter); Matrix4x4 atomTransform = Matrix4x4.TRS(position, atomOrientation, scale); if (!mergeTransforms.ContainsKey(atomColour)) { mergeTransforms.Add(atomColour, new List <Matrix4x4>()); } mergeTransforms[atomColour].Add(atomTransform); } // create the meshes by colour GameObject prefab = AtomPrefabs[meshQuality]; GameObject parent = new GameObject("CombinedMeshParent"); parent.SetActive(false); foreach (KeyValuePair <Color, List <Matrix4x4> > item in mergeTransforms) { yield return(StartCoroutine(meshBuilder.CombinedMesh(prefab, item.Value.ToArray(), item.Key, parent))); } parent.transform.SetParent(AtomParent.transform, false); yield break; }
public void loadSettings() { if (residueUpdateType == ResidueUpdateType.ID) { if (residueIDs != null && residueIDs.Count > 0) { panelTitle.text = "Residue " + residueIDs[0] + " - Custom Settings"; } else { panelTitle.text = "Residue - Custom Settings"; } } else if (residueUpdateType == ResidueUpdateType.Name) { panelTitle.text = "Residue " + residueName + " - Custom Settings"; } else { panelTitle.text = "Custom Residue Settings"; } colourAtomsToggle.isOn = renderSettings.ColourAtoms; cpkToggle.isOn = false; vdwToggle.isOn = false; if (renderSettings.AtomRepresentation == MolecularRepresentation.CPK) { cpkToggle.isOn = true; } else if (renderSettings.AtomRepresentation == MolecularRepresentation.VDW) { vdwToggle.isOn = true; } colourBondsToggle.isOn = renderSettings.ColourBonds; largeBondsToggle.isOn = renderSettings.LargeBonds; colourSecondaryStructureToggle.isOn = renderSettings.ColourSecondaryStructure; setResidueColourButtonColour(renderSettings.ResidueColour); // create atom option buttons atomButtons = new Dictionary <string, ResidueAtomNameButton>(); UnityCleanup.DestroyGameObjects(atomListContentPanel); if (atomNames != null) { foreach (string atomName in atomNames) { GameObject atomOptionsButton = GameObject.Instantiate(atomNameButtonPrefab); atomOptionsButton.transform.SetParent(atomListContentPanel.transform, false); ResidueAtomNameButton buttonScript = atomOptionsButton.GetComponent <ResidueAtomNameButton>(); AtomRenderSettings atomSettingsCopy = new AtomRenderSettings(atomName, Settings.ResidueColourDefault); if (renderSettings.AtomSettings.ContainsKey(atomName)) { atomSettingsCopy = renderSettings.AtomSettings[atomName].Clone(); } buttonScript.Initialise(atomSettingsCopy, colourSelectPanel, AutoSaveSettings); if (!atomButtons.ContainsKey(atomName)) { atomButtons.Add(atomName, buttonScript); } else { Debug.Log("Duplicate atom name in custom residue settings"); } } } }