//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 IEnumerator ParametersFromFRCMODFile(string filename, Parameters parameters) { 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 = ""; string restOfLine; string[] splitLine; Stretch newStretchParam; Bend newBendParam; Torsion newTorsionParam; ImproperTorsion newImproperTorsionParam; VdW newVdWParam; Torsion existingTorsionParam; int existingTorsionNum; bool torsionModified; int offset; foreach (string line in lines) { 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.AddStretch(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.AddBend(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; } yield return(null); parameters.AddTorsion(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.AddImproperTorsion(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.AddVdW(newVdWParam); } SKIP :; } }