public static Matrix3 RepairRotation(Matrix3 R) { Vector3 u; Double theta = Matrix3.AngleAndAxis(R, out u); Double absu = Vector3.Abs(u); u = u * (1.0 / absu); return(Matrix3.Rotation(u, theta)); }
private void SaveOverlayStates(String ofilename) { String fullfname = ofilename + ".pml"; Vector3 u; Double theta; using (StreamWriter sw = new StreamWriter(fullfname, false)) { sw.Write("# Overlay of structures "); for (Int32 j = 0; j < _dataToSave.Length - 1; j++) { sw.Write(_dataToSave[j].InternalNumber.ToString() + ", "); } sw.WriteLine(_dataToSave[_dataToSave.Length - 1].InternalNumber.ToString()); for (Int32 i = 0; i < molecules.Count; i++) { sw.WriteLine("load " + molecules[i].FullFileName); } SimulationResult sr; for (Int32 j = 0; j < _dataToSave.Length; j++) { sr = _dataToSave[j]; for (Int32 i = 0; i < molecules.Count; i++) { theta = Matrix3.AngleAndAxis(sr.Rotation[i], out u) * 180.0 / Math.PI; sw.WriteLine("copy _tmp" + i.ToString() + ", " + molecules[i].Name); sw.WriteLine("rotate [" + u.ToString() + "], " + theta.ToString("F3") + ", _tmp" + i.ToString() + ", origin=[" + molecules[i].CM.ToString() + "]"); sw.WriteLine("translate [" + sr.Translation[i].ToString() + "], _tmp" + i.ToString()); } sw.WriteLine("select object _tmp*"); if (_bestfit) { sw.WriteLine("translate [" + sr.BestFitTranslation.ToString() + "], sele"); theta = Matrix3.AngleAndAxis(sr.BestFitRotation, out u) * 180.0 / Math.PI; sw.WriteLine("rotate [" + u.ToString() + "], " + theta.ToString("F3") + ", sele, origin=[0, 0, 0]"); } sw.WriteLine("save _tmp.pdb, sele"); sw.WriteLine("load _tmp.pdb, " + filenametextBox.Text); sw.WriteLine("delete _tmp*"); } for (Int32 i = 0; i < molecules.Count; i++) { sw.WriteLine("delete " + molecules[i].Name); } sw.Close(); } }
/// <summary> /// Do one iteration /// </summary> /// <param name="normF">Sum of F*F</param> /// <param name="normT">Sum of T*T</param> /// <param name="K">Kinetic energy</param> /// <returns>Potential energy (before the iteration)</returns> private double Iterate(out double normF, out double normT, out double K) { double E, theta, thetaw, abst, absw; Molecule m; Vector3 force_i, torque_i, tmpt, v, w; Matrix3 tmpr; E = ForceAndTorque(); CheckForClashes(true); E += Eclash; normF = 0; normT = 0.0; K = 0.0; for (int i = 0; i < Nmolecules; i++) { m = _molecules[i]; tmpt = translationm1[i]; tmpr = rotation[i] * Matrix3.Transpose(rotationm1[i]); translationm1[i] = translation[i]; rotationm1[i] = rotation[i]; force_i = force[i]; normF += force_i * force_i; torque_i = torque[i]; normT += torque_i * torque_i; translation[i] = translation[i] * (2.0 - viscosity) - tmpt * (1.0 - viscosity) + force_i * (dt * dt / m.Mass); v = (translation[i] - tmpt) * 0.5 * rdt; K += 0.5 * m.Mass * (v * v); abst = torque_i.Normalize(); theta = dt * dt * abst / m.SimpleI; thetaw = Matrix3.AngleAndAxis(tmpr, out w); rotation[i] = Matrix3.Rotation(torque_i, theta) * Matrix3.Rotation(w, -thetaw * viscosity) * tmpr * rotation[i]; absw = thetaw * rdt; K += 0.5 * m.SimpleI * absw * absw; } return(E); }
private void SaveSimulationResult(SimulationResult sr, String fname, Boolean addpdbsave) { String converged = sr.Converged ? " (converged)" : " (not converged)"; String fullfname = fname + ".pml"; Vector3 u; Double theta; using (StreamWriter sw = new StreamWriter(fullfname, false)) { sw.WriteLine("# Energy = " + sr.E.ToString("F8") + converged); for (Int32 i = 0; i < molecules.Count; i++) { sw.WriteLine("load " + molecules[i].FullFileName); } for (Int32 i = 1; i < molecules.Count; i++) { theta = Matrix3.AngleAndAxis(sr.Rotation[i], out u) * 180.0 / Math.PI; sw.WriteLine("rotate [" + u.ToString() + "], " + theta.ToString("F3") + ", " + molecules[i].Name + ", origin=[" + molecules[i].CM.ToString() + "]"); sw.WriteLine("translate [" + sr.Translation[i].ToString() + "], " + molecules[i].Name); } if (_bestfit) { sw.WriteLine("select all"); sw.WriteLine("translate [" + sr.BestFitTranslation.ToString() + "], sele"); theta = Matrix3.AngleAndAxis(sr.BestFitRotation, out u) * 180.0 / Math.PI; sw.WriteLine("rotate [" + u.ToString() + "], " + theta.ToString("F3") + ", sele, origin=[0, 0, 0]"); } if (addpdbsave) { sw.WriteLine("select all"); sw.WriteLine("save " + fname + ".pdb, sele"); } String lpnames = ""; if (lpcheckBox.Checked) { Int32 im; Vector3 r; LabelingPosition lpref; foreach (LabelingPosition l in labelingpos) { im = molecules.FindIndex(l.Molecule); if ((sr.SimulationMethod & SimulationMethods.Refinement) != 0) { lpref = sr.RefinedLabelingPositions.Find(l.Name); } else { lpref = l; } r = sr.Rotation[im] * (lpref - molecules[im].CM) + molecules[im].CM + sr.Translation[im]; sw.WriteLine("pseudoatom " + l.Name + ", pos=[" + r.ToString() + "]"); sw.WriteLine("label " + l.Name + ", \"" + l.Name + "\""); sw.WriteLine("show spheres, " + l.Name); if (l.Dye == DyeType.Donor) { sw.WriteLine("color green, " + l.Name); } if (l.Dye == DyeType.Acceptor) { sw.WriteLine("color red, " + l.Name); } lpnames += " + " + l.Name; } } if (_bestfit && lpnames != String.Empty) { sw.WriteLine("deselect"); sw.WriteLine("select " + lpnames.Substring(3)); sw.WriteLine("translate [" + sr.BestFitTranslation.ToString() + "], sele"); theta = Matrix3.AngleAndAxis(sr.BestFitRotation, out u) * 180.0 / Math.PI; sw.WriteLine("rotate [" + u.ToString() + "], " + theta.ToString("F3") + ", sele, origin=[0, 0, 0]"); } sw.WriteLine("deselect"); sw.Close(); } }