private void getResult() { LinEquationResult = GaussianCalculator.Calculate(MG, Fources); for (int i = 0; i < mExperementalObject.AKT.Count; i++) { Node prev = mExperementalObject.AKT[i]; double[] point = LinEquationResult.Skip(i * 3).Take(3).ToArray(); DefformatedObject.Add(new KeyValuePair <Node, double>(new Node(Math.Round(prev.X + point[0], 4), Math.Round(prev.Y + point[1], 4), Math.Round(prev.Z + point[2], 4), prev.IsIntermediate), 0)); } }
public IEnumerator AtomsFromPQRFile(string path, Atoms atoms, Atom atomPrefab) { atoms.globalSettings = globalSettings; atoms.setSourceFile(path); atoms.name = Path.GetFileName(path); gc = Instantiate <GaussianCalculator> (gaussianCalculatorPrefab, atoms.transform); atoms.gaussianCalculator = gc; int index = 0; int residueNumber; int offset; Vector3 position; string[] splitLine; List <int> highAtoms = new List <int>(); List <int> lowAtoms = new List <int>(); string[] lines = FileIO.Readlines(path, "#"); for (lineNumber = 0; lineNumber < lines.Length; lineNumber++) { line = lines [lineNumber]; if ((line.StartsWith("ATOM") || line.StartsWith("HETATM"))) { Atom atom = Instantiate(atomPrefab, atoms.atomsHolder.transform); splitLine = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); //PDB atom.pdbName = line.Substring(12, 4).Trim(); //Element if (data.pdbToElementDict.ContainsKey(atom.pdbName.ToUpper())) { atom.element = data.pdbToElementDict [atom.pdbName]; } else { atom.element = atom.pdbName.Substring(0, 1); } //Residue atom.residueName = splitLine[3]; if (line.StartsWith("HETATM") && !(atom.residueName == "WAT" || atom.residueName == "HOH")) { highAtoms.Add(index); } else { lowAtoms.Add(index); } //Chain ID is optional in PQR, but can also merge with residue number residueNumber = 0; offset = 0; if (!int.TryParse(splitLine [4], out residueNumber)) { if (splitLine [4].Length == 1) { offset = 1; atom.chainID = splitLine [4]; residueNumber = int.Parse(splitLine [5]); } else { atom.chainID = splitLine [4].Substring(0, 1); residueNumber = int.Parse(splitLine [4].Substring(1)); } } atom.residueNumber = residueNumber; //Position position = new Vector3(); position.x = float.Parse(splitLine[5 + offset]); position.y = float.Parse(splitLine[6 + offset]); position.z = float.Parse(splitLine[7 + offset]); atom.transform.position = position; atom.partialCharge = float.Parse(splitLine[8 + offset]); atom.vdwRadius = float.Parse(splitLine[9 + offset]); atom.index = index; atoms.AddAtom(atom); //atom.resolution = globalSettings.ballResolution; //atom.transform.SetParent(atoms.atomsHolder.transform); //atoms.atomList.Add (atom); index++; } if (lineNumber % globalSettings.maxLinesToYield == 0) { yield return(new WaitForSeconds(0.1f)); } } atoms.graph.SetAtoms(atoms); gc.layers.SetSize(atoms.size); gc.layers.SetLowAtoms(lowAtoms); gc.layers.SetHighAtoms(highAtoms); yield return(null); }
public IEnumerator AtomsFromMol2File(string path, Atoms atoms, Atom atomPrefab) { atoms.globalSettings = globalSettings; atoms.setSourceFile(path); atoms.name = Path.GetFileName(path); gc = Instantiate <GaussianCalculator> (GameObject.FindObjectOfType <PrefabManager>().gaussianCalculatorPrefab, atoms.transform); atoms.gaussianCalculator = gc; int index = 0; Vector3 position = new Vector3(); List <Data.AmberToElement> amberToElementList = data.amberToElementData; Data.AmberToElement amberToElement; int amberToElementNum; List <int[]> connectionList = new List <int[]> (); int a0; int a1; int bondOrder; bool readAtoms = false; bool readConnectivity = false; string[] lines = FileIO.Readlines(path); string[] splitLine; int lineNumber; string line; for (lineNumber = 0; lineNumber < lines.Length; lineNumber++) { line = lines [lineNumber]; if (line.StartsWith("@<TRIPOS>")) { readAtoms = line.Contains("ATOM"); //readConnectivity = line.Contains("BOND"); } else if (readAtoms) { splitLine = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); Atom atom = Instantiate <Atom> (atomPrefab); //Atom types atom.pdbName = splitLine [1]; atom.amberName = splitLine [5]; for (amberToElementNum = 0; amberToElementNum < amberToElementList.Count; amberToElementNum++) { amberToElement = amberToElementList [amberToElementNum]; if (amberToElement.amberName == atom.amberName) { atom.element = amberToElement.element; atom.formalCharge = amberToElement.formalCharge; } } //Position position.x = float.Parse(splitLine [2]); position.y = float.Parse(splitLine [3]); position.z = float.Parse(splitLine [4]); atom.transform.position = position; //Residue atom.residueNumber = int.Parse(splitLine [6]); atom.residueName = splitLine [7]; if (splitLine.Length > 8) { atom.partialCharge = float.Parse(splitLine [8]); } atom.index = index; atoms.AddAtom(atom); //atom.resolution = globalSettings.ballResolution; //atom.transform.SetParent(atoms.atomsHolder.transform); //atoms.atomList.Add (atom); index++; } else if (readConnectivity) { splitLine = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); a0 = int.Parse(splitLine [1]) - 1; a1 = int.Parse(splitLine [2]) - 1; bondOrder = int.Parse(splitLine [3]); connectionList.Add(new int[3] { a0, a1, bondOrder }); } if (lineNumber % globalSettings.maxLinesToYield == 0) { yield return(new WaitForSeconds(0.1f)); } } atoms.graph.SetAtoms(atoms); gc.SetAtoms(atoms); foreach (int[] connectionPair in connectionList) { atoms.graph.Connect(connectionPair [0], connectionPair [1], (double)connectionPair [2]); } }
public IEnumerator AtomsFromGaussianInput(string path, Atoms atoms, Atom atomPrefab) { atoms.globalSettings = globalSettings; atoms.setSourceFile(path); atoms.name = Path.GetFileName(path); gc = Instantiate <GaussianCalculator> (gaussianCalculatorPrefab, atoms.transform); atoms.gaussianCalculator = gc; int index = 0; int lineNumber = 0; string line; string[] lines = FileIO.Readlines(path, "!"); string[] stringArray; int stringArrayIndex; int maxLines = lines.Length; //Link 0 commands while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); if (line.StartsWith("#")) { break; } else if (line.ToUpper().StartsWith("%CHK")) { gc.checkpointPath = GetValueFromPair(line); } else if (line.ToUpper().StartsWith("%OLDCHK")) { gc.oldCheckpointPath = GetValueFromPair(line); } else if (line.ToUpper().StartsWith("%MEM")) { gc.jobMemoryMB = GetMemoryMB(GetValueFromPair(line)); } else if (line.ToUpper().StartsWith("%NPROC")) { gc.nProcessors = int.Parse(GetValueFromPair(line)); } else if (line.ToUpper().StartsWith("%KJOB")) { stringArray = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); gc.killJobLink = stringArray [1]; if (stringArray.Length > 2) { gc.killJobAfter = int.Parse(stringArray [2]); } else { gc.killJobAfter = 1; } } lineNumber++; } List <string> keywordsList = new List <string> (); string keywordItem; //Keywords while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); if (line == "") { break; } stringArray = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); for (stringArrayIndex = 0; stringArrayIndex < stringArray.Length; stringArrayIndex++) { keywordsList.Add(stringArray [stringArrayIndex].ToLower()); } lineNumber++; } //Parse keywords - only one line so don't need to worry about optimisation for (stringArrayIndex = 0; stringArrayIndex < keywordsList.Count; stringArrayIndex++) { keywordItem = keywordsList [stringArrayIndex]; //Print level if (keywordItem.StartsWith("#")) { gc.gaussianPrintLevel = keywordItem.Replace("#", ""); //Method } else if (keywordItem.StartsWith("oniom")) { string oniomMethodsStr = GetStringInParentheses(keywordItem); string oniomOptionsStr = GetStringInParentheses(GetValueFromPair(keywordItem, checkEnclosed: true)); string[] oniomOptions = oniomOptionsStr.Split(new [] { "," }, System.StringSplitOptions.RemoveEmptyEntries); foreach (string oniomOption in oniomOptions) { gc.oniomOptions.Add(oniomOption); } string[] methods = oniomMethodsStr.Split(new [] { ":" }, System.StringSplitOptions.RemoveEmptyEntries); string[] highMBO = GetMethodFromString(methods [0]); gc.layers.AddLayer(highMBO [0], highMBO [1], highMBO [2], 'H'); if (methods.Length == 2) { string[] lowMBO = GetMethodFromString(methods [1]); gc.layers.AddLayer(lowMBO [0], lowMBO [1], lowMBO [2], 'L'); } else if (methods.Length == 3) { string[] mediumMBO = GetMethodFromString(methods [1]); gc.layers.AddLayer(mediumMBO [0], mediumMBO [1], mediumMBO [2], 'M'); string[] lowMBO = GetMethodFromString(methods [2]); gc.layers.AddLayer(lowMBO [0], lowMBO [1], lowMBO [2], 'L'); } } else if (keywordItem.StartsWith("guess")) { string guessOptionsStr = GetStringInParentheses(GetValueFromPair(keywordItem, checkEnclosed: true)); string[] guessOptions = guessOptionsStr.Split(new [] { "," }, System.StringSplitOptions.RemoveEmptyEntries); foreach (string guessOption in guessOptions) { gc.guessOptions.Add(guessOption); } } else if (keywordItem.StartsWith("geom")) { string geomOptionsStr = GetStringInParentheses(GetValueFromPair(keywordItem, checkEnclosed: true)); string[] geomOptions = geomOptionsStr.Split(new [] { "," }, System.StringSplitOptions.RemoveEmptyEntries); foreach (string geomOption in geomOptions) { gc.geomOptions.Add(geomOption); } } else { foreach (string methodName in data.gaussianMethods) { if (keywordItem.StartsWith(methodName)) { string[] highMBO = GetMethodFromString(keywordItem); gc.layers.AddLayer(highMBO [0], highMBO [1], highMBO [2], 'H'); break; } } } } //Title List <string> titleLines = new List <string>(); if (!gc.geomOptions.Contains("allcheck")) { while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); if (line != "") { titleLines.Add(line); } else if (titleLines.Count != 0) { break; } lineNumber++; } } gc.title = string.Join("\n", titleLines.ToArray()); //Layer Charge/Multiplicity if (!gc.geomOptions.Contains("allcheck")) { while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); if (line != "") { string[] cmStr = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); int numLayersSpecified = cmStr.Length / 2; for (int layerIndex = 0; layerIndex < numLayersSpecified; layerIndex++) { gc.layers.SetLayerCharge(gc.layers.layerNames[layerIndex], int.Parse(cmStr [2 * layerIndex])); gc.layers.SetLayerMultiplicity(gc.layers.layerNames[layerIndex], int.Parse(cmStr [2 * layerIndex + 1])); } lineNumber++; break; } lineNumber++; } } System.Text.StringBuilder sb = new System.Text.StringBuilder(); int charNum = 0; int phase = 0; char lineChar; int pdbOption = 0; string linkType = ""; int linkIndex = 0; Vector3 position = new Vector3(); List <int> highAtoms = new List <int>(); List <int> mediumAtoms = new List <int>(); List <int> lowAtoms = new List <int>(); //Atoms - AtomFromGaussianInputLine should be optimised if (!(gc.geomOptions.Contains("allcheck") && gc.geomOptions.Contains("check") && gc.geomOptions.Contains("checkpoint"))) { while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); if (line == "") { lineNumber++; break; } Atom atom = Instantiate <Atom> (atomPrefab); atom.index = index; charNum = 0; phase = (int)atomPhase.ELEMENT; sb.Length = 0; while (charNum <= line.Length) { if (charNum == line.Length) { lineChar = ' '; } else { lineChar = line [charNum]; } //Read element if (phase == (int)atomPhase.ELEMENT) { if (lineChar == '-') { phase = (int)atomPhase.AMBER_NAME; } else if (lineChar == '(') { phase = (int)atomPhase.PDB; } else if (lineChar == ' ') { phase = (int)atomPhase.FROZEN; } else { sb.Append(lineChar); charNum++; continue; } atom.element = sb.ToString(); sb.Length = 0; } else if (phase == (int)atomPhase.AMBER_NAME) { if (lineChar == '-') { phase = (int)atomPhase.PARTIAL_CHARGE; } else if (lineChar == '(') { phase = (int)atomPhase.PDB; } else if (lineChar == ' ') { phase = (int)atomPhase.FROZEN; } else { sb.Append(lineChar); charNum++; continue; } atom.amberName = sb.ToString(); sb.Length = 0; } else if (phase == (int)atomPhase.PARTIAL_CHARGE) { if (lineChar == '(') { phase = (int)atomPhase.PDB; } else if (lineChar == ' ') { phase = (int)atomPhase.FROZEN; } else { sb.Append(lineChar); charNum++; continue; } if (sb.Length > 0) { atom.partialCharge = float.Parse(sb.ToString()); } sb.Length = 0; } else if (phase == (int)atomPhase.PDB) { if (lineChar == '=') { phase = (int)atomPhase.PDB_VALUE; } else if (lineChar == ')') { phase = (int)atomPhase.FROZEN; } else if (sb.Length == 5) { if (sb.ToString().ToUpper() == "PDBNA") { pdbOption = (int)pdbOptions.PDBNAME; } if (sb.ToString().ToUpper() == "RESNA") { pdbOption = (int)pdbOptions.RESNAME; } if (sb.ToString().ToUpper() == "RESNU") { pdbOption = (int)pdbOptions.RESNUM; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; } else if (phase == (int)atomPhase.PDB_VALUE) { if (lineChar == ',') { if (pdbOption == (int)pdbOptions.PDBNAME) { atom.pdbName = sb.ToString(); } else if (pdbOption == (int)pdbOptions.RESNAME) { atom.residueName = sb.ToString(); } else if (pdbOption == (int)pdbOptions.RESNUM) { atom.residueNumber = int.Parse(ToNumber(sb.ToString())); } phase = (int)atomPhase.PDB; } else if (lineChar == ')') { if (pdbOption == (int)pdbOptions.PDBNAME) { atom.pdbName = sb.ToString(); } else if (pdbOption == (int)pdbOptions.RESNAME) { atom.residueName = sb.ToString(); } else if (pdbOption == (int)pdbOptions.RESNUM) { atom.residueNumber = int.Parse(ToNumber(sb.ToString())); } phase = (int)atomPhase.FROZEN; } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; //Frozen is optional, so this could be the X coordinate } else if (phase == (int)atomPhase.FROZEN) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else if (sb.Length == 1) { atom.frozen = int.Parse(sb.ToString()); phase = (int)atomPhase.X; } else { position.x = float.Parse(sb.ToString()); phase = (int)atomPhase.Y; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } else if (phase == (int)atomPhase.X) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else { position.x = float.Parse(sb.ToString()); phase = (int)atomPhase.Y; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } else if (phase == (int)atomPhase.Y) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else { position.y = float.Parse(sb.ToString()); phase = (int)atomPhase.Z; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } else if (phase == (int)atomPhase.Z) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else { position.z = float.Parse(sb.ToString()); atom.transform.position = position; phase = (int)atomPhase.LAYER_NAME; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } else if (phase == (int)atomPhase.LAYER_NAME) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else { if (sb[0] == 'H') { highAtoms.Add(index); } else if (sb[0] == 'M') { mediumAtoms.Add(index); } else if (sb[0] == 'L') { lowAtoms.Add(index); } phase = (int)atomPhase.LINK; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } else if (phase == (int)atomPhase.LINK) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else { linkType = sb.ToString(); phase = (int)atomPhase.LINK_INDEX; } } else if (lineChar == '-') { sb.Length = 0; } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } else if (phase == (int)atomPhase.LINK_INDEX) { if (lineChar == ' ') { if (sb.Length == 0) { ; } else { linkIndex = int.Parse(sb.ToString()); gc.layers.AddLink(index, linkIndex, linkType); charNum++; continue; } } else { sb.Append(lineChar); charNum++; continue; } sb.Length = 0; charNum++; continue; } charNum++; } atoms.AddAtom(atom); index++; lineNumber++; if (lineNumber % globalSettings.maxLinesToYield == 0) { yield return(null); } } } gc.layers.SetSize(atoms.size); gc.layers.SetHighAtoms(highAtoms); gc.layers.SetMediumAtoms(mediumAtoms); gc.layers.SetLowAtoms(lowAtoms); //Connectivity atoms.graph.SetAtoms(atoms); if (gc.geomOptions.Contains("connectivity")) { string[] splitConn; int connectionNum; int numConnections; int connectionIndex0; int connectionIndex1; double bondOrder; while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); if (line == "") { break; } splitConn = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); connectionIndex0 = int.Parse(splitConn [0]) - 1; numConnections = (splitConn.Length - 1) / 2; for (connectionNum = 0; connectionNum < numConnections; connectionNum++) { connectionIndex1 = int.Parse(splitConn [connectionNum * 2 + 1]) - 1; bondOrder = double.Parse(splitConn [connectionNum * 2 + 2]); atoms.graph.Connect(connectionIndex0, connectionIndex1, bondOrder); } lineNumber++; if (lineNumber % globalSettings.maxLinesToYield == 0) { yield return(new WaitForSeconds(0.1f)); } } } //Parameters List <string> parameterLines = new List <string>(); while (lineNumber < maxLines) { line = lines [lineNumber].Trim(); parameterLines.Add(line); lineNumber++; } atoms.parameters = prmReader.ParametersFromPRMLines(parameterLines.ToArray()); atoms.parameters.transform.parent = atoms.transform; }
private void TENSORCalculation() { // One for each finite element double[,,] dxyzabg = new double[3, 3, 20]; double[,,] dfixyz = new double[20, 20, 3]; double[,,] duxyz = new double[20, 3, 3]; double[][,] SUM = new double[mExperementalObject.AKT.Count][, ]; for (int i = 0; i < mExperementalObject.AKT.Count; i++) { SUM[i] = new double[3, 3]; } double[][] sigma = new double[mExperementalObject.AKT.Count][]; double[] amount = new double[mExperementalObject.AKT.Count]; List <int> coordinates = new List <int>(); // Get number of entries for each node for (int number = 0; number < mExperementalObject.nel; number++) { coordinates = mExperementalObject.NT[number]; for (int j = 0; j < 20; j++) { amount[coordinates[j]]++; } } // Fill sum matrix for (int number = 0; number < mExperementalObject.nel; number++) { coordinates = mExperementalObject.NT[number]; // Generating dxyzabg double globalCoordinate = 0; double diFi = 0; double sum = 0; for (int i = 0; i < 3; i++) // Global coords { for (int j = 0; j < 3; j++) // Local goords { for (int n = 0; n < 20; n++) // Gaussian Nodes { sum = 0; for (int f = 0; f < 20; f++) // Functions { switch (i) { case 0: globalCoordinate = mExperementalObject.AKT[coordinates[f]].X; break; case 1: globalCoordinate = mExperementalObject.AKT[coordinates[f]].Y; break; case 2: globalCoordinate = mExperementalObject.AKT[coordinates[f]].Z; break; } diFi = DFIABG_P[n, j, f]; sum += globalCoordinate * diFi; } dxyzabg[i, j, n] = sum; } } } // Get dfixyz // col is free column double[] col = new double[3]; for (int i = 0; i < 20; i++) // Gaussian Nodes { for (int phi = 0; phi < 20; phi++) // Functions { for (int k = 0; k < 3; k++) { col[k] = DFIABG_P[i, k, phi]; } double[,] matrix = new double[3, 3] { { dxyzabg[0, 0, i], dxyzabg[1, 0, i], dxyzabg[2, 0, i] }, { dxyzabg[0, 1, i], dxyzabg[1, 1, i], dxyzabg[2, 1, i] }, { dxyzabg[0, 2, i], dxyzabg[1, 2, i], dxyzabg[2, 2, i] } }; double[] gaussianSolve = GaussianCalculator.Calculate(matrix, col); for (int k = 0; k < 3; k++) { dfixyz[i, phi, k] = gaussianSolve[k]; } } } // Get duxyz for (int i = 0; i < 20; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { sum = 0; for (int l = 0; l < 20; l++) { sum += LinEquationResult[coordinates[l] * 3 + j] * dfixyz[i, l, k]; } duxyz[i, j, k] = sum; } } } // Get all sums: in each global point add all 9 values for (int i = 0; i < 20; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { SUM[coordinates[i]][j, k] += duxyz[i, j, k]; } } } } // Get the avarage for each point for (int i = 0; i < mExperementalObject.AKT.Count; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { SUM[i][j, k] /= amount[i]; } } } for (int i = 0; i < mExperementalObject.AKT.Count; i++) { sigma[i] = CalculateSigma(SUM[i]); } for (int i = 0; i < mExperementalObject.AKT.Count; i++) { DefformatedObject[i] = new KeyValuePair <Node, double>(DefformatedObject[i].Key, GetNodePreasure(sigma[i]).Sum()); } }
/* Private functionality */ /* * Generates one time for all elements */ private void GenMGMatrix() { double[,,] DXYZABG = new double[3, 3, 27]; double[] DJ = new double[27]; double[,,] DFIXYZ = new double[27, 20, 3]; for (int element = 0; element < mExperementalObject.nel; element++) { List <int> glblCoords = mExperementalObject.NT[element]; // Generatting DXYZABG double glbCoordinate = 0; double deFee = 0; double sum = 0; for (int gl = 0; gl < 3; gl++) // Global coordinates { for (int loc = 0; loc < 3; loc++) // Local coordinates { for (int n = 0; n < 27; n++) // Gausse nodes { sum = 0; for (int f = 0; f < 20; f++) // functions { switch (gl) { case 0: glbCoordinate = mExperementalObject.AKT[glblCoords[f]].X; break; case 1: glbCoordinate = mExperementalObject.AKT[glblCoords[f]].Y; break; case 2: glbCoordinate = mExperementalObject.AKT[glblCoords[f]].Z; break; } deFee = DFIABG[n, loc, f]; sum += glbCoordinate * deFee; } DXYZABG[gl, loc, n] = sum; } } } // Generatting DJ double[,] jak; for (int i = 0; i < 27; i++) { jak = new double[3, 3] { { DXYZABG[0, 0, i], DXYZABG[1, 0, i], DXYZABG[2, 0, i] }, { DXYZABG[0, 1, i], DXYZABG[1, 1, i], DXYZABG[2, 1, i] }, { DXYZABG[0, 2, i], DXYZABG[1, 2, i], DXYZABG[2, 2, i] } }; DJ[i] = ( jak[0, 0] * jak[1, 1] * jak[2, 2] + jak[0, 1] * jak[1, 2] * jak[2, 0] + jak[0, 2] * jak[1, 0] * jak[2, 1] ) - ( jak[0, 2] * jak[1, 1] * jak[2, 0] + jak[0, 1] * jak[1, 0] * jak[2, 2] + jak[0, 0] * jak[1, 2] * jak[2, 1] ); } // Generatting DFIXYZ double[] col = new double[3]; for (int n = 0; n < 27; n++) // Gaussian nodes { for (int fee = 0; fee < 20; fee++) // Functions { for (int k = 0; k < 3; k++) { col[k] = DFIABG[n, k, fee]; } double[,] matrix = new double[3, 3] { { DXYZABG[0, 0, n], DXYZABG[1, 0, n], DXYZABG[2, 0, n] }, { DXYZABG[0, 1, n], DXYZABG[1, 1, n], DXYZABG[2, 1, n] }, { DXYZABG[0, 2, n], DXYZABG[1, 2, n], DXYZABG[2, 2, n] } }; double[] gaussianResults = GaussianCalculator.Calculate(matrix, col); for (int k = 0; k < 3; k++) { DFIXYZ[n, fee, k] = gaussianResults[k]; } } } double[, ][,] lilMG = new double[3, 3][, ]; lilMG[0, 0] = x11(DFIXYZ, DJ); lilMG[1, 1] = x22(DFIXYZ, DJ); lilMG[2, 2] = x33(DFIXYZ, DJ); lilMG[0, 1] = x12(DFIXYZ, DJ); lilMG[0, 2] = x13(DFIXYZ, DJ); lilMG[1, 2] = x23(DFIXYZ, DJ); lilMG[1, 0] = matrixRot(lilMG[0, 1]); lilMG[2, 0] = matrixRot(lilMG[0, 2]); lilMG[2, 1] = matrixRot(lilMG[1, 2]); int x, y, localX, localY, globalX, globalY; for (int i = 0; i < 60; i++) { for (int j = 0; j < 60; j++) { x = i / 20; y = j / 20; localX = i % 20; localY = j % 20; globalX = (mExperementalObject.NT[element][localX]) * 3 + x; globalY = (mExperementalObject.NT[element][localY]) * 3 + y; MG[globalX, globalY] += lilMG[x, y][localX, localY]; } } } }
public IEnumerator AtomsFromPDBFile(string path, Atoms atoms, Atom atomPrefab, string alternateLocationID = "A") { atoms.globalSettings = globalSettings; atoms.setSourceFile(path); atoms.name = Path.GetFileName(path); gc = Instantiate <GaussianCalculator> (GameObject.FindObjectOfType <PrefabManager>().gaussianCalculatorPrefab, atoms.transform); atoms.gaussianCalculator = gc; string element; Vector3 position; string chargeStr; List <int> highAtoms = new List <int>(); List <int> lowAtoms = new List <int>(); int index = 0; string[] lines = FileIO.Readlines(path, "#"); for (lineNumber = 0; lineNumber < lines.Length; lineNumber++) { line = lines [lineNumber]; if ( ( line.StartsWith("ATOM") || line.StartsWith("HETATM") ) && ( line [16].ToString() == " " || line [16].ToString() == alternateLocationID )) { Atom atom = Instantiate(atomPrefab, atoms.atomsHolder.transform); element = line.Substring(76, 2).Trim(); //PDB atom.pdbName = line.Substring(12, 4).Trim(); //Use PDB to get Atom if (element == string.Empty) { //If 12th column is a letter, it is a metal if (char.IsLetter(line [12])) { element = line.Substring(12, 2).Trim(); atom.element = ToAlpha(element); } else { element = line.Substring(12, 4).Trim(); atom.element = ToAlpha(element) [0].ToString(); } } else { if (element.Length > 1) { atom.element = element.Substring(0, 1).ToUpper() + element.Substring(1).ToLower(); } else { atom.element = element; } } //Residue atom.residueName = line.Substring(17, 3).Trim(); atom.residueNumber = int.Parse(line.Substring(22, 4).Trim()); atom.chainID = line [21].ToString(); if (line.StartsWith("HETATM") && !(atom.residueName == "WAT" || atom.residueName == "HOH")) { highAtoms.Add(index); } else { lowAtoms.Add(index); } //Position position = new Vector3(); position.x = float.Parse(line.Substring(30, 8)); position.y = float.Parse(line.Substring(38, 8)); position.z = float.Parse(line.Substring(46, 8)); atom.transform.position = position; chargeStr = line [79].ToString(); if (chargeStr != " ") { if (line [78].ToString() == "-") { atom.formalCharge = -int.Parse(chargeStr); } else { atom.formalCharge = int.Parse(chargeStr); } } atom.index = index; atoms.AddAtom(atom); index++; } if (lineNumber % globalSettings.maxLinesToYield == 0) { yield return(new WaitForSeconds(0.1f)); } } atoms.graph.SetAtoms(atoms); gc.SetAtoms(atoms); gc.layers.SetLowAtoms(lowAtoms); gc.layers.SetHighAtoms(highAtoms); yield return(null); }
public IEnumerator AtomsFromPDBFile(string path, Atoms atoms, Atom atomPrefab, string alternateLocationID = "A") { atoms.globalSettings = globalSettings; atoms.setSourceFile(path); atoms.name = Path.GetFileName(path); gc = Instantiate <GaussianCalculator> (gaussianCalculatorPrefab, atoms.transform); atoms.gaussianCalculator = gc; string amber; string element; Vector3 position; string chargeStr; List <int> highAtoms = new List <int>(); List <int> lowAtoms = new List <int>(); List <Data.AmberToElement> amberToElementList = data.amberToElementData; Data.AmberToElement amberToElement; int amberToElementNum; int index = 0; bool amberUsed; string[] lines = FileIO.Readlines(path, "#"); for (lineNumber = 0; lineNumber < lines.Length; lineNumber++) { line = lines [lineNumber]; if ( ( line.StartsWith("ATOM") || line.StartsWith("HETATM") ) && ( line [16].ToString() == " " || line [16].ToString() == alternateLocationID )) { Atom atom = Instantiate(atomPrefab, atoms.atomsHolder.transform); //See if we can use the last columns to get Atom amberUsed = false; amber = line.Substring(76, 2).Trim(); if (amber != string.Empty) { atom.amberName = amber; for (amberToElementNum = 0; amberToElementNum < amberToElementList.Count; amberToElementNum++) { amberToElement = amberToElementList [amberToElementNum]; if (amberToElement.amberName == amber) { atom.element = amberToElement.element; atom.formalCharge = amberToElement.formalCharge; amberUsed = true; } } } //PDB atom.pdbName = line.Substring(12, 4).Trim(); //Use PDB to get Atom if (!amberUsed) { //If 12th column is a letter, it is a metal if (char.IsLetter(line [12])) { element = line.Substring(12, 2).Trim(); atom.element = ToAlpha(element); } else { element = line.Substring(12, 4).Trim(); atom.element = ToAlpha(element) [0].ToString(); } } //Residue atom.residueName = line.Substring(17, 3).Trim(); atom.residueNumber = int.Parse(line.Substring(22, 4).Trim()); atom.chainID = line [21].ToString(); if (line.StartsWith("HETATM") && !(atom.residueName == "WAT" || atom.residueName == "HOH")) { highAtoms.Add(index); } else { lowAtoms.Add(index); } //Position position = new Vector3(); position.x = float.Parse(line.Substring(30, 8)); position.y = float.Parse(line.Substring(38, 8)); position.z = float.Parse(line.Substring(46, 8)); atom.transform.position = position; chargeStr = line [79].ToString(); if (chargeStr != " ") { if (line [78].ToString() == "-") { atom.formalCharge = -int.Parse(chargeStr); } else { atom.formalCharge = int.Parse(chargeStr); } } atom.index = index; atoms.AddAtom(atom); index++; } if (lineNumber % globalSettings.maxLinesToYield == 0) { yield return(new WaitForSeconds(0.1f)); } } atoms.graph.SetAtoms(atoms); gc.layers.SetSize(atoms.size); gc.layers.SetLowAtoms(lowAtoms); gc.layers.SetHighAtoms(highAtoms); yield return(null); }