public void LoadMolecule() { string filestring = Manager.GetComponent <OpenFileButton>().filestring; // TODO: display an error if filestring is null // First we will get the frames using Regex.Split GetFrames(filestring); // Then we get information about each individual atom with each frame. Most important: Atom#, Element, X, Y, Z GetAtoms(filestring); GetAtomInfo(); // fill out top.NATOM with the total number of atoms and pass it to Load Manager.GetComponent <Load>().top.NATOM = top.NATOM; // Fill our molecule struct and pass to Load Manager.GetComponent <Load>().molecule = molecule; // Fill out number of frames and pass to Load Manager.GetComponent <Load>().framenum = framenum; // Delete everything here molecule = null; filestring = null; framenum = 0; Models.Clear(); }
/* * * Group 1: Element * Group 2: X * Group 3: Y * Group 4: Z * Group 5: * */ void GetAtomInfo() { framenum = Models.Count(); Manager.GetComponent <Load>().molecule = new atominfo[framenum, top.NATOM]; molecule = new atominfo[framenum, top.NATOM]; foreach (string model in Models) { // This is to get the Atom#, Element, and X,Y,Z coord string reg = @"\r?\n?([A-Z]+)\s+(\S+)\s+(\S+)\s+(\S+)\r?\n?"; Regex r = new Regex(reg); Match m = r.Match(model); for (int a = 0; a < top.NATOM; a++) { Vector3 original = new Vector3(float.Parse(m.Groups[2].ToString()) / 25, float.Parse(m.Groups[3].ToString()) / 25, float.Parse(m.Groups[4].ToString()) / 25); //original = Fitbox.GetComponent<Fitbox>().toQuat*original; // Need this line because the HologramCollection is moved by the Fitbox when loading the app so we are correcting the X,Y,Z for that original = original + HologramCollection.transform.position; molecule[Models.IndexOf(model), a].x = original.x; molecule[Models.IndexOf(model), a].y = original.y; molecule[Models.IndexOf(model), a].z = original.z; molecule[0, a].element = m.Groups[1].ToString(); m = m.NextMatch(); } } }
public void CreateLines(atominfo[,] molecule) { foreach (Bonds k in GetComponent <ThisFileInfo>().Bonds[0]) { GameObject myLine = new GameObject(); myLine.tag = "Sticks"; myLine.AddComponent <LineRenderer>(); myLine.name = string.Format("Line{0}.{1}", k.a1, k.a2); lr = myLine.GetComponent <LineRenderer>(); lr.SetWidth(0.003f, 0.003f); lr.material = mat; lr.useWorldSpace = false; lr.startColor = Colors(molecule[0, k.a1].element); lr.endColor = Colors(molecule[0, k.a2].element); float x1, y1, z1, x2, y2, z2; x1 = molecule[0, k.a1].x; y1 = molecule[0, k.a1].y; z1 = molecule[0, k.a1].z; x2 = molecule[0, k.a2].x; y2 = molecule[0, k.a2].y; z2 = molecule[0, k.a2].z; Vector3 firstatom = new Vector3(x1, y1, z1) * 0.5f; Vector3 secondatom = new Vector3(x2, y2, z2) * 0.5f; offset = new Vector3(0, 0, 0f + MoleculeCollection.transform.position.z); lr.SetPosition(0, firstatom + offset); lr.SetPosition(1, secondatom + offset); lr.transform.parent = transform.GetChild(1).gameObject.transform; } }
/* * * Group 1: Element * Group 2: Atomic number * Group 3: X * Group 4: Y * Group 5: Z * */ void GetAtomInfo() { top.NATOM = Regex.Matches(Models[0], @"\r?\n?\s*([A-Z][A-Z]?)\s*([0-9]+)\s*(\S*)\s*(\S*)\s*(\S*)").Count; framenum = Models.Count(); Manager.GetComponent <Load>().molecule = new atominfo[framenum, top.NATOM]; molecule = new atominfo[framenum, top.NATOM]; foreach (string model in Models) { string reg = @"\r?\n?\s*([A-Z][A-Z]?)\s*([0-9]+)\s*(\S*)\s*(\S*)\s*(\S*)"; Regex r = new Regex(reg); Match m = r.Match(model); for (int a = 0; a < top.NATOM; a++) { Vector3 original = new Vector3(float.Parse(m.Groups[3].Value) / 25, float.Parse(m.Groups[4].Value) / 25, float.Parse(m.Groups[5].Value) / 25); //original = Fitbox.GetComponent<Fitbox>().toQuat*original; original = original + HologramCollection.transform.position; molecule[Models.IndexOf(model), a].x = original.x; molecule[Models.IndexOf(model), a].y = original.y; molecule[Models.IndexOf(model), a].z = original.z; molecule[0, a].element = m.Groups[1].ToString(); m = m.NextMatch(); } } }
public void LoadMolecule() { if (Manager.GetComponent <Dropdowns>().filetypeSelected == "AMBER Parm") { topfilestring = Manager.GetComponent <OpenFileButton>().filestring; LoadTopology(); } if (Manager.GetComponent <Dropdowns>().filetypeSelected == "AMBER Coord") { xfilestring = Manager.GetComponent <OpenFileButton>().filestring; GetFrameNum(); GetCrds(); GetAtomInfo(); Manager.GetComponent <Load>().molecule = molecule; Manager.GetComponent <Load>().top = top; Manager.GetComponent <Load>().framenum = framenum; molecule = null; topfilestring = null; xfilestring = null; framenum = 0; Models.Clear(); } }
/* * * Group 1: Element * Group 2: X * Group 3: Y * Group 4: Z * * */ void GetAtomInfo() { framenum = Models.Count(); GetComponent <Load>().molecule = new atominfo[framenum, top.NATOM]; molecule = new atominfo[framenum, top.NATOM]; int thisframe = 0; foreach (string model in Models) { // This is to get the Atom#, Element, and X,Y,Z coord string reg = @"([A-Z][A-Z]?)\s*(\S*)\s*(\S*)\s*(\S*)"; Regex r = new Regex(reg); Match m = r.Match(model); for (int a = 0; a < top.NATOM; a++) { Vector3 original = new Vector3(float.Parse(m.Groups[2].ToString()), float.Parse(m.Groups[3].ToString()), float.Parse(m.Groups[4].ToString())); molecule[Models.IndexOf(model), a].x = original.x; molecule[Models.IndexOf(model), a].y = original.y; molecule[Models.IndexOf(model), a].z = original.z; molecule[Models.IndexOf(model), a].element = m.Groups[1].ToString(); m = m.NextMatch(); } thisframe += 1; } }
public void LoadMolecule() { #if !UNITY_EDITOR filestring = Manager.GetComponent<OpenFileButton>().filestring; #endif // First we will get all info from the frames using ANTLR4 // We start this on new threads and then join them at the end for a small processing speedup istream = new AntlrInputStream(filestring); lexer = new XYZLexer(istream); tokens = new CommonTokenStream(lexer); parser = new XYZParser(tokens); // takes 0.5 seconds to parse fileContext = parser.file(); // firstFrame = fileContext.frame()[0]; top.NATOM = Convert.ToInt32(firstFrame.header().GetText()); framenum = fileContext.frame().Length; molecule = new atominfo[framenum, top.NATOM]; //double st = Time.realtimeSinceStartup; atomX = 0; frameX = 0; atomY = 0; frameY = 0; atomZ = 0; frameZ = 0; atomE = 0; frameE = 0; var X = new Task(() => GetX()); var Y = new Task(() => GetY()); var Z = new Task(() => GetZ()); var E = new Task(() => GetE()); X.Start(); Y.Start(); Z.Start(); E.Start(); X.Wait(); Y.Wait(); Z.Wait(); E.Wait(); // Debug.Log($"0:{Time.realtimeSinceStartup - st}"); // fill out top.NATOM with the total number of atoms and pass it to Load Manager.GetComponent<Load>().top.NATOM = top.NATOM; // Fill our molecule struct and pass to Load Manager.GetComponent<Load>().molecule = molecule; // Fill out number of frames and pass to Load Manager.GetComponent<Load>().framenum = framenum; // Delete everything here molecule = null; filestring = null; framenum = 0; }
/* * * Group 1: Element * Group 2: Atomic number * Group 3: X * Group 4: Y * Group 5: Z * */ void GetAtomInfo() { top.NATOM = Regex.Matches(Models[0], @"\r?\n?\s*([0-9]+)\s*([0-9])\s*([0-9])\s*(\S*)\s*(\S*)\s*(\S*)\r?\n?").Count; framenum = Models.Count(); Manager.GetComponent <Load>().molecule = new atominfo[framenum, top.NATOM]; molecule = new atominfo[framenum, top.NATOM]; foreach (string model in Models) { string reg = @"\r?\n?\s*([0-9]+)\s*([0-9])\s*([0-9])\s*(\S*)\s*(\S*)\s*(\S*)\r?\n?"; Regex r = new Regex(reg); Match m = r.Match(model); for (int a = 0; a < top.NATOM; a++) { Vector3 original = new Vector3(float.Parse(m.Groups[4].Value) / 25f, float.Parse(m.Groups[5].Value) / 25f, float.Parse(m.Groups[6].Value) / 25f); original = original + HologramCollection.transform.position; molecule[Models.IndexOf(model), a].x = original.x; molecule[Models.IndexOf(model), a].y = original.y; molecule[Models.IndexOf(model), a].z = original.z; switch (m.Groups[2].ToString()) { case "1": molecule[0, a].element = "H"; break; case "6": molecule[0, a].element = "C"; break; case "7": molecule[0, a].element = "N"; break; case "8": molecule[0, a].element = "O"; break; default: molecule[0, a].element = "S"; break; // TODO: Add more elements here // There is a switch case like this in LoadAMBER as well so copy paste there } m = m.NextMatch(); } //Debug.Log(molecule[Models.IndexOf(model), 1].x); } }
public void LoadMolecule() { // display an error if filestring is null GetFrames(Manager.GetComponent <OpenFileButton>().filestring); GetAtomInfo(); Manager.GetComponent <Load>().top.NATOM = top.NATOM; Manager.GetComponent <Load>().molecule = molecule; Manager.GetComponent <Load>().framenum = framenum; molecule = null; //filestring = null; framenum = 0; Models.Clear(); }
public async Task LoadMoleculeAsync() { // Check if any file was loaded in if (GetComponent <OpenFileButton>().filestring == null) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Cube); sphere.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); sphere.transform.position = new Vector3(0, 0, 1); goto NoFile; // Skips to the end of this function } // delete anything else in molecule collection (just one file at a time) // Create a new FileObject ThisFile = (GameObject)Instantiate(FilePrefab); ThisFile.transform.localScale = Vector3.one; ThisFile.SetActive(true); ThisFile.transform.parent = MoleculeCollection.transform; ThisFile.transform.name = String.Format("File {0}", FileNumber); // Get the AtomCollection object NewLineCollection = ThisFile.transform.GetChild(1).gameObject; //await loadDel[Manager.GetComponent<Dropdowns>().filetypes.IndexOf(Manager.GetComponent<Dropdowns>().filetypeSelected) - 1](ThisFile); await LoadXYZ(ThisFile); // maybe do this w moleculecolleciton instead ThisFile.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); // Can we put this data directly in the right place instead of moving it around and then deleting it? GetComponent <OpenFileButton>().filestring = null; molecule = null; AtomNumber = 0; FileNumber++; NoFile: Resources.UnloadUnusedAssets(); GC.Collect(); }
public void LoadMolecule() { filestring = Manager.GetComponent <OpenFileButton>().filestring; // display an error if filestring is null GetFrames(); //GetTotalAtoms(); GetAtomInfo(); Manager.GetComponent <Load>().top.NATOM = top.NATOM; Manager.GetComponent <Load>().molecule = molecule; Manager.GetComponent <Load>().framenum = framenum - 1; //txt.GetComponent<ChangeText>().totalFrames = framenum - 1; molecule = null; filestring = null; framenum = 0; Models.Clear(); }
// (......)(.....)(.....)(.)(...).(.)(....)(.)...(........)(........)(........)(......)(......)......(....)(..) /// <summary> /// (1-6) : "ATOM"/"HETATM"/"TER" : CHAR : Group 1 /// (7-11) : Atom serial number : INT : Group 2 /// 12 : BLANK /// (13-16) : Atom name : CHAR : Group 3 /// (17) : Alternate location indicator : CHAR : Group 4 /// (18-20) : Residue name : CHAR : Group 5 /// 21 : BLANK /// (22) : Chain identifier : CHAR : Group 6 /// (23-26) : Residue sequence number : INT : Group 7 /// (27) : Code for insertions of residues: CHAR : Group 8 /// 28-30 : BLANK /// (31-38) : X orthogonal A coordinate : FLOAT : Group 9 /// (39-46) : Y orthogonal A coordinate : FLOAT : Group 10 /// (47-54) : Z orthogonal A coordinate : FLOAT : Group 11 /// (55-60) : Occupancy : FLOAT : Group 12 /// (61-66) : Temperature factor : FLOAT : Group 13 /// (73-76) : Segment identifier : CHAR : Group 14 /// (77-78) : Element symbol : CHAR : Group 15 /// </summary> /// void GetAtomInfo() { Manager.GetComponent <Load>().molecule = new atominfo[framenum, top.NATOM]; molecule = new atominfo[framenum, top.NATOM]; Vector3 hc = HologramCollection.transform.position; double starttime = Time.realtimeSinceStartup; foreach (string model in Models) { string reg = "(......)(.....)(.....)(.)(...).(.)(....)(.)...(........)(........)(........)(......)(......)......(....)(..)"; Regex r = new Regex(reg); Match m = r.Match(model); for (int a = 0; a < top.NATOM; a++) { // original should be unmodified, not divided by 25 here. this is not the place for rescaling. localposition is used in movespheres() already Vector3 original = new Vector3(float.Parse(m.Groups[9].ToString().Trim()), float.Parse(m.Groups[10].ToString().Trim()), float.Parse(m.Groups[11].ToString().Trim())); //original = Fitbox.GetComponent<Fitbox>().toQuat*original; // Need this line because the HologramCollection is moved by the Fitbox when loading the app so we are correcting the X,Y,Z for that original = original + hc; molecule[Models.IndexOf(model), a].x = original.x; molecule[Models.IndexOf(model), a].y = original.y; molecule[Models.IndexOf(model), a].z = original.z; molecule[0, a].atomsym = m.Groups[3].ToString().Trim(); molecule[0, a].element = m.Groups[15].ToString().Trim(); molecule[0, a].resnum = Convert.ToInt32(m.Groups[7].ToString().Trim()); molecule[0, a].resid = m.Groups[5].ToString().Trim(); m = m.NextMatch(); } } Debug.Log($"time to load: {Time.realtimeSinceStartup - starttime}"); }
atominfo[,] GetCrds() { molecule = new atominfo[framenum, top.NATOM]; //Models = new string[framenum]; GetFrames(); rescale = 25; for (int i = 0; i < framenum; i++) { temp = Models[i]; string pattern = @"\s+(\S+)"; /// (x) (y) (z) {top.NATOM} Regex r = new Regex(pattern); m = r.Match(temp); for (int a = 0; a < top.NATOM; a++) { // molecule[i, a].atomnum = a+1;// Convert.ToInt32(m.Groups[1].ToString()); //molecule[i, a].atomsym = m.Groups[2].ToString(); //molecule[i, a].resid = m.Groups[3].ToString(); //molecule[i, a].resnum = Convert.ToInt32(m.Groups[5].ToString()); //var fmt = new NumberFormatInfo(); //fmt.NegativeSign = "-"; molecule[i, a].x = float.Parse(m.Groups[1].ToString()) / rescale; m = m.NextMatch(); molecule[i, a].y = float.Parse(m.Groups[1].ToString()) / rescale; m = m.NextMatch(); molecule[i, a].z = float.Parse(m.Groups[1].ToString()) / rescale; //molecule[i, a].element = m.Groups[11].ToString(); m = m.NextMatch(); } } return(molecule); }
public void LoadMolecule() { filestring = Manager.GetComponent <OpenFileButton>().filestring; // TODO: display an error if filestring is null if (filestring == null) { // Console text += " filetring is null" // `goto` somewhere at end of this LoadMolecule() function } // First we will get the frames using Regex.Split double starttime = Time.realtimeSinceStartup; GetFrames(); txt.text += $"\n GetFrames time : {Time.realtimeSinceStartup - starttime}"; starttime = Time.realtimeSinceStartup; // Then we get information about each individual atom with each frame. Most important: Atom#, Element, X, Y, Z GetAtomInfo(); txt.text += $"\n GetAtomInfo time : {Time.realtimeSinceStartup - starttime}"; starttime = Time.realtimeSinceStartup; // fill out top.NATOM with the total number of atoms and pass it to Load Manager.GetComponent <Load>().top.NATOM = top.NATOM; // Fill our molecule struct and pass to Load Manager.GetComponent <Load>().molecule = molecule; // Fill out number of frames and pass to Load Manager.GetComponent <Load>().framenum = framenum; // Delete everything here molecule = null; filestring = null; framenum = 0; Models.Clear(); }
public void MoveLine(int frame, atominfo[,] molecule) { int atom1, atom2; GameObject sphereone, spheretwo; if (GetComponent <ThisFileInfo>().dynamicBonds == true) { // Check for bonds which exist for the frame but were not constructed in a previous frame foreach (Bonds k in GetComponent <ThisFileInfo>().Bonds[frame]) { Transform[] children = transform.GetChild(1).transform.GetComponentsInChildren <Transform>(); string[] childrenNames = new string[children.Length]; foreach (Transform c in children) { childrenNames[Array.IndexOf(children, c)] = c.name; } if (!childrenNames.Contains($"Line{k.a1}.{k.a2}")) { GameObject myLine = new GameObject(); myLine.tag = "Sticks"; myLine.AddComponent <LineRenderer>(); myLine.name = string.Format("Line{0}.{1}", k.a1, k.a2); lr = myLine.GetComponent <LineRenderer>(); lr.SetWidth(0.003f, 0.003f); lr.material = mat; lr.useWorldSpace = false; lr.startColor = Colors(molecule[frame, k.a1].element); lr.endColor = Colors(molecule[frame, k.a2].element); float x1, y1, z1, x2, y2, z2; x1 = molecule[frame, k.a1].x; y1 = molecule[frame, k.a1].y; z1 = molecule[frame, k.a1].z; x2 = molecule[frame, k.a2].x; y2 = molecule[frame, k.a2].y; z2 = molecule[frame, k.a2].z; Vector3 firstatom = new Vector3(x1, y1, z1) * 0.5f; Vector3 secondatom = new Vector3(x2, y2, z2) * 0.5f; offset = new Vector3(0, 0, 0f + MoleculeCollection.transform.position.z); lr.transform.parent = transform.GetChild(1).gameObject.transform; lr.SetPosition(0, firstatom + offset); lr.SetPosition(1, secondatom + offset); myLine.transform.localPosition = new Vector3(0, 0, 0); myLine.transform.localRotation = new Quaternion(0, 0, 0, 1); myLine.transform.localScale = Vector3.one; } } } // Check for bonds which are extra for this frame and delete them, then update the lines' positions for the frame foreach (Transform k in transform.GetChild(1).GetComponentInChildren <Transform>()) { atom1 = Convert.ToInt32(Regex.Match(k.name, $"Line([0-9]+).([0-9]+)").Groups[1].ToString()); atom2 = Convert.ToInt32(Regex.Match(k.name, $"Line([0-9]+).([0-9]+)").Groups[2].ToString()); if (GetComponent <ThisFileInfo>().dynamicBonds == true) { string[] bondNames = new string[GetComponent <ThisFileInfo>().Bonds[frame].Count]; foreach (Bonds m in GetComponent <ThisFileInfo>().Bonds[frame]) { bondNames[GetComponent <ThisFileInfo>().Bonds[frame].IndexOf(m)] = $"Line{m.a1}.{m.a2}"; } if (!bondNames.Contains(k.name)) { Destroy(k.gameObject); goto SkipMove; // line 167 } } sphereone = AtomCollection.transform.GetChild(atom1).gameObject; spheretwo = AtomCollection.transform.GetChild(atom2).gameObject; float x1, y1, z1, x2, y2, z2; x1 = sphereone.transform.localPosition.x; y1 = sphereone.transform.localPosition.y; z1 = sphereone.transform.localPosition.z + 1; x2 = spheretwo.transform.localPosition.x; y2 = spheretwo.transform.localPosition.y; z2 = spheretwo.transform.localPosition.z + 1; Vector3 firstatom = new Vector3(x1, y1, z1); Vector3 secondatom = new Vector3(x2, y2, z2); GameObject myLine = k.gameObject; lr = myLine.GetComponent <LineRenderer>(); lr.SetPosition(0, firstatom); lr.SetPosition(1, secondatom); SkipMove: lr.useWorldSpace = false; } //Debug.Log($"Move Time: {Time.realtimeSinceStartup - sttime}"); }