public void Constructor_PopulatesProperties() { // Act var torsion = new Torsion(4); // Assert Assert.Equal(4, torsion.Value); }
//Find index of type equivalent torsion //Return -1 if no type equivalent torsions are in this parameters set public int IndexTorsion(Torsion otherTorsion) { for (int index = 0; index < torsions.Count; index++) { if (torsions[index].TypeEquivalent(otherTorsion)) { return(index); } } return(-1); }
public bool ContainsTorsion(Torsion otherTorsion) { foreach (Torsion thisTorsion in torsions) { if (thisTorsion.TypeEquivalent(otherTorsion)) { return(true); } } return(false); }
public void AddTorsion(Torsion newTorsion) { foreach (Torsion torsion in torsions) { if (torsion.TypeEquivalent(newTorsion)) { throw new System.Exception("Torsion already exists in Parameters set"); } } torsions.Add(newTorsion); }
public void ToString_ReturnsExpectedString() { // Arrange var torsion = new Torsion(4); // Act var result = torsion.ToString(); // Assert Assert.Equal("4", result); }
public bool TypeEquivalent(Torsion 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 void Equals_WhenTorsionsDiffer_ReturnsFalse() { // Arrange var torsion1 = new Torsion(-5); var torsion2 = new Torsion(5); // Act var result = torsion1.Equals(torsion2); // Assert Assert.False(result); }
public void Equals_WhenTorsionsAreEqual_ReturnsTrue() { // Arrange var torsion1 = new Torsion(-5); var torsion2 = new Torsion(-5); // Act var result = torsion1.Equals(torsion2); // Assert Assert.True(result); }
public void SubtractOperator_WithTorsion_ReturnsNewTorsion() { // Arrange var torsion1 = new Torsion(4); var torsion2 = new Torsion(5); // Act var result = torsion1 - torsion2; // Assert Assert.Equal(-1, result.Value); }
public void AddOperator_WithTorsion_ReturnsSumOfTorsions() { // Arrange var torsion1 = new Torsion(4); var torsion2 = new Torsion(5); // Act var result = torsion1 + torsion2; // Assert Assert.Equal(9, result.Value); }
public void GetHashCode_WithDifferentTorsions_ReturnsDifferentValue() { // Arrange var torsion1 = new Torsion(-5); var torsion2 = new Torsion(5); // Act var hashCode1 = torsion1.GetHashCode(); var hashCode2 = torsion2.GetHashCode(); // Assert Assert.NotEqual(hashCode1, hashCode2); }
public void GetHashCode_WithSameTorsions_ReturnsSameValue() { // Arrange var torsion1 = new Torsion(-5); var torsion2 = new Torsion(-5); // Act var hashCode1 = torsion1.GetHashCode(); var hashCode2 = torsion2.GetHashCode(); // Assert Assert.Equal(hashCode1, hashCode2); }
//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(Torsion other) { return(this.types == other.types || this.types == other.reverseTypes); }
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); }
public static Direction Turn(this Direction direction, Torsion torsion) { return(new Direction((direction.Value + torsion.Value + Direction.Modulus) % Direction.Modulus)); }
public float ETorsion(int order, bool suppress = false) { Torsion param = GetTorsionParameter(); if (param == null) { if (!suppress) { Debug.LogError(string.Format("No parameter for 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) { if (param.v0 != 0) { e += 0.5f * param.v0 * (1f + Mathf.Cos(dihedral - param.gamma0)); } if (param.v1 != 0) { e += 0.5f * param.v1 * (1f + Mathf.Cos(2f * dihedral - param.gamma1)); } if (param.v2 != 0) { e += 0.5f * param.v2 * (1f + Mathf.Cos(3f * dihedral - param.gamma2)); } if (param.v3 != 0) { e += 0.5f * param.v3 * (1f + Mathf.Cos(4f * dihedral - param.gamma3)); } } else if (order == 1) { if (param.v0 != 0) { e -= 0.5f * param.v0 * (Mathf.Sin(dihedral - param.gamma0)); } if (param.v1 != 0) { e -= 0.5f * param.v1 * 2f * (Mathf.Sin(2f * dihedral - param.gamma1)); } if (param.v2 != 0) { e -= 0.5f * param.v2 * 3f * (Mathf.Sin(3f * dihedral - param.gamma2)); } if (param.v3 != 0) { e -= 0.5f * param.v3 * 4f * (Mathf.Sin(4f * dihedral - param.gamma3)); } } else if (order == 2) { if (param.v0 != 0) { e -= 0.5f * param.v0 * (Mathf.Cos(dihedral - param.gamma0)); } if (param.v1 != 0) { e -= 0.5f * param.v1 * 4f * (Mathf.Cos(2f * dihedral - param.gamma1)); } if (param.v2 != 0) { e -= 0.5f * param.v2 * 9f * (Mathf.Cos(3f * dihedral - param.gamma2)); } if (param.v3 != 0) { e -= 0.5f * param.v3 * 16f * (Mathf.Cos(4f * dihedral - param.gamma3)); } } return(e / param.npaths); }