public float EVdW(int order, bool suppress) { VdW vdw0 = GetVdWParameter(0); VdW vdw1 = GetVdWParameter(1); float r = atoms.getDistance(this.a0, this.a1); float r0 = (vdw0.r + vdw1.r) * 0.5f; float v = Mathf.Sqrt(vdw0.v * vdw1.v); //Amber type VdW if (atoms.parameters.nonbonding.vType == 3) { if (order == 0) { return(v * (Mathf.Pow(r0 / r, 12f) - 2f * Mathf.Pow(r0 / r, 6f))); } else if (order == 1) { return(12f * v * (Mathf.Pow(r0 / r, 7f) * -Mathf.Pow(r0 / r, 13f)) / r0); } else if (order == 2) { return(12f * v * (13f * Mathf.Pow(r0 / r, 14f) - 7f * Mathf.Pow(r0 / r, 8f)) / (r0 * r0)); } } else { Debug.LogError(string.Format("VdW Nonbonding type {0} not available", atoms.parameters.nonbonding.vType)); } return(0f); }
//Find index of type equivalent VdW //Return -1 if no type equivalent VdWs are in this parameters set public int IndexVdW(VdW otherVdW) { for (int index = 0; index < vdws.Count; index++) { if (vdws[index].TypeEquivalent(otherVdW)) { return(index); } } return(-1); }
public bool ContainsVdW(VdW otherVdW) { foreach (VdW thisVdW in vdws) { if (thisVdW.TypeEquivalent(otherVdW)) { return(true); } } return(false); }
public void AddVdW(VdW newVdw) { foreach (VdW vdw in vdws) { if (vdw.TypeEquivalent(newVdw)) { throw new System.Exception("VdW already exists in Parameters set"); } } vdws.Add(newVdw); }
public Parameters ParametersFromFRCMODFile(string filename) { Parameters parameters = Instantiate <Parameters>(parametersPrefab); string[] lines = FileIO.Readlines(filename); int maxLines = lines.Length; List <string> sections = new List <string> { "MASS", "BOND", "ANGL", "DIHE", "IMPR", "NONB", "IPOL", "CMAP", "%" }; string sectionName; int sectionNum = 0; int numSections = sections.Count; string section = ""; lineNumber = 0; string restOfLine; string[] splitLine; Stretch newStretchParam; Bend newBendParam; Torsion newTorsionParam; ImproperTorsion newImproperTorsionParam; VdW newVdWParam; Torsion existingTorsionParam; int existingTorsionNum; bool torsionModified; int offset; while (lineNumber < maxLines) { line = lines [lineNumber]; if (line == "") { continue; } for (sectionNum = 0; sectionNum < numSections; sectionNum++) { sectionName = sections [sectionNum]; if (line.StartsWith(sectionName)) { section = sectionName; goto SKIP; } } //Ignore MASS section //Parse Bond if (section == "BOND") { t0 = GetAmberFromString(line, 0); t1 = GetAmberFromString(line, 3); restOfLine = line.Substring(5, line.Length - 6); splitLine = restOfLine.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); keq = float.Parse(splitLine [0]); req = float.Parse(splitLine [1]); newStretchParam = new Stretch(t0, t1, req, keq); parameters.stretches.Add(newStretchParam); } else if (section == "ANGL") { t0 = GetAmberFromString(line, 0); t1 = GetAmberFromString(line, 3); t2 = GetAmberFromString(line, 6); restOfLine = line.Substring(8, line.Length - 9); splitLine = restOfLine.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); keq = float.Parse(splitLine [0]); req = float.Parse(splitLine [1]); newBendParam = new Bend(t0, t1, t2, req, keq); parameters.bends.Add(newBendParam); } else if (section == "DIHE") { t0 = GetAmberFromString(line, 0); t1 = GetAmberFromString(line, 3); t2 = GetAmberFromString(line, 6); t3 = GetAmberFromString(line, 9); newTorsionParam = new Torsion(t0, t1, t2, t3); restOfLine = line.Substring(11, line.Length - 12); splitLine = restOfLine.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); npaths = int.Parse(splitLine [0]); v = float.Parse(splitLine [1]); gamma = float.Parse(splitLine [2]); periodicity = (int)Mathf.Abs(float.Parse(splitLine [3])); //The same param can be defined on multiple lines torsionModified = false; for (existingTorsionNum = 0; existingTorsionNum < parameters.torsions.Count; existingTorsionNum++) { existingTorsionParam = parameters.torsions [existingTorsionNum]; if (existingTorsionParam.TypeEquivalent(newTorsionParam)) { existingTorsionParam.Modify(periodicity, v, gamma); torsionModified = true; } } if (!torsionModified) { newTorsionParam.npaths = npaths; if (periodicity == 1) { newTorsionParam.v0 = v; newTorsionParam.gamma0 = gamma; } else if (periodicity == 2) { newTorsionParam.v1 = v; newTorsionParam.gamma1 = gamma; } else if (periodicity == 3) { newTorsionParam.v2 = v; newTorsionParam.gamma2 = gamma; } else if (periodicity == 4) { newTorsionParam.v3 = v; newTorsionParam.gamma3 = gamma; } parameters.torsions.Add(newTorsionParam); } } else if (section == "IMPR") { t0 = GetAmberFromString(line, 0); t1 = GetAmberFromString(line, 3); t2 = GetAmberFromString(line, 6); t3 = GetAmberFromString(line, 9); restOfLine = line.Substring(11, line.Length - 12); splitLine = restOfLine.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); offset = 1; //Sometimes npaths is included here, even though ignored. Sometimes it's not. if (splitLine [0].Contains(".")) { offset = 0; } v = float.Parse(splitLine [offset]); gamma = float.Parse(splitLine [offset + 1]); periodicity = (int)Mathf.Abs(float.Parse(splitLine [offset + 2])); newImproperTorsionParam = new ImproperTorsion(t0, t1, t2, t3, v, gamma, periodicity); parameters.improperTorsions.Add(newImproperTorsionParam); } else if (section == "NONB") { splitLine = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); t = splitLine [0]; radius = float.Parse(splitLine [1]); v = float.Parse(splitLine [2]); newVdWParam = new VdW(t, radius, v); parameters.vdws.Add(newVdWParam); } SKIP: ; } return(parameters); }
//This can be used to read parameters from gaussian input files as well public IEnumerator ParametersFromPRMLines(string[] lines, Parameters parameters) { int vType; int cType; int vCutoff; int cCutoff; float vScale1; float vScale2; float vScale3; float cScale1; float cScale2; float cScale3; string t0; string t1; string t2; string t3; float req; float keq; float v; float v0; float v1; float v2; float v3; float gamma; float gamma0; float gamma1; float gamma2; float gamma3; int npaths; int periodicity; foreach (string line in lines) { string[] splitLine = line.Split(new [] { " " }, System.StringSplitOptions.RemoveEmptyEntries); if (splitLine.Length == 0) { continue; } if (splitLine [0].ToUpper() == "NONBON") { vType = int.Parse(splitLine [1]); cType = int.Parse(splitLine [2]); vCutoff = int.Parse(splitLine [3]); cCutoff = int.Parse(splitLine [4]); vScale1 = float.Parse(splitLine [5]); vScale2 = float.Parse(splitLine [6]); vScale3 = float.Parse(splitLine [7]); cScale1 = float.Parse(splitLine [8]); cScale2 = float.Parse(splitLine [9]); cScale3 = float.Parse(splitLine [10]); parameters.SetNonBonding(vType, cType, vCutoff, cCutoff, vScale1, vScale2, vScale3, cScale1, cScale2, cScale3); } else if (splitLine [0].ToUpper().StartsWith("VDW")) { t0 = splitLine [1]; req = float.Parse(splitLine [2]); v = float.Parse(splitLine [3]); VdW stretch = new VdW(t0, req, v); parameters.AddVdW(stretch); } else if (splitLine [0].ToUpper().StartsWith("HRMSTR")) { t0 = splitLine [1]; t1 = splitLine [2]; keq = float.Parse(splitLine [3]); req = float.Parse(splitLine [4]); Stretch stretch = new Stretch(t0, t1, req, keq); parameters.AddStretch(stretch); } else if (splitLine [0].ToUpper().StartsWith("HRMBND")) { t0 = splitLine [1]; t1 = splitLine [2]; t2 = splitLine [3]; keq = float.Parse(splitLine [4]); req = float.Parse(splitLine [5]); Bend bend = new Bend(t0, t1, t2, req, keq); parameters.AddBend(bend); } else if (splitLine [0].ToUpper().StartsWith("AMBTRS")) { t0 = splitLine [1]; t1 = splitLine [2]; t2 = splitLine [3]; t3 = splitLine [4]; gamma0 = float.Parse(splitLine [5]); gamma1 = float.Parse(splitLine [6]); gamma2 = float.Parse(splitLine [7]); gamma3 = float.Parse(splitLine [8]); v0 = float.Parse(splitLine [9]); v1 = float.Parse(splitLine [10]); v2 = float.Parse(splitLine [11]); v3 = float.Parse(splitLine [12]); npaths = (int)float.Parse(splitLine [13]); Torsion torsion = new Torsion(t0, t1, t2, t3, v0, v1, v2, v3, gamma0, gamma1, gamma2, gamma3, npaths); parameters.AddTorsion(torsion); } else if (splitLine [0].ToUpper().StartsWith("IMPTRS")) { t0 = splitLine [1]; t1 = splitLine [2]; t2 = splitLine [3]; t3 = splitLine [4]; v = float.Parse(splitLine [5]);; gamma = float.Parse(splitLine [6]); periodicity = (int)float.Parse(splitLine [7]); ImproperTorsion improperTorsion = new ImproperTorsion(t0, t1, t2, t3, v, gamma, periodicity); parameters.AddImproperTorsion(improperTorsion); } } yield return(null); }
public bool TypeEquivalent(VdW other) { return(this.t == other.t); }