public float EImproperTorsion(int order, bool suppress = false) { ImproperTorsion param = GetImproperTorsionParameter(); if (param == null) { if (!suppress) { Debug.LogError(string.Format("No parameter for Improper Torsion: {0}-{1}-{2}-{3}", this.atom0.amberName, this.atom1.amberName, this.atom2.amberName, this.atom3.amberName)); } return(0f); } float dihedral = this.atoms.getDihedral(this.a0, this.a1, this.a2, this.a3); float e = 0f; if (order == 0) { e += 0.5f * param.v * (1f + Mathf.Cos(param.periodicity * dihedral - param.gamma)); } else if (order == 1) { e -= 0.5f * param.v * param.periodicity * (Mathf.Sin(param.periodicity * dihedral - param.gamma)); } else if (order == 2) { e -= 0.5f * param.v * param.periodicity * param.periodicity * (Mathf.Cos(param.periodicity * dihedral - param.gamma)); } return(e); }
//Find index of type equivalent improper torsion //Return -1 if no type equivalent improper torsions are in this parameters set public int IndexImproperTorsion(ImproperTorsion otherImproperTorsion) { for (int index = 0; index < improperTorsions.Count; index++) { if (improperTorsions[index].TypeEquivalent(otherImproperTorsion)) { return(index); } } return(-1); }
public bool ContainsImproperTorsion(ImproperTorsion otherImproperTorsion) { foreach (ImproperTorsion thisImproperTorsion in improperTorsions) { if (thisImproperTorsion.TypeEquivalent(otherImproperTorsion)) { return(true); } } return(false); }
public void AddImproperTorsion(ImproperTorsion newImproperTorsion) { foreach (ImproperTorsion improperTorsion in improperTorsions) { if (improperTorsion.TypeEquivalent(newImproperTorsion)) { throw new System.Exception("ImproperTorsion already exists in Parameters set"); } } improperTorsions.Add(newImproperTorsion); }
public bool TypeEquivalent(ImproperTorsion other) { if (this.t0 == other.t0 && this.t1 == other.t1 && this.t2 == other.t2 && this.t3 == other.t3) { return(true); } if (this.t0 == other.t3 && this.t1 == other.t2 && this.t2 == other.t1 && this.t3 == other.t0) { return(true); } return(false); }
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(ImproperTorsion other) { return(this.types == other.types || this.types == other.reverseTypes); }