private LabelingPositionList RedoAV() { LabelingPositionList lps_local = new LabelingPositionList(this.LabelingPositions.Count); lps_local.AddRange(this.LabelingPositions); AVEngine av = new AVEngine(mt, this.ProjectDataCopy.AVGlobalParameters); LabelingPosition l; Vector3 rmp; int natom, nmol; for (Int32 i = 0; i < lps_local.Count; i++) { l = lps_local[i]; if (l.AVData.AVType == AVSimlationType.None) { continue; } nmol = sr.Molecules.FindIndex(l.Molecule); natom = Array.BinarySearch <Int32>(mt.OriginalAtomID, molstart[nmol], molnatoms[nmol], l.AVData.AtomID); if (l.AVData.AVType == AVSimlationType.SingleDyeR) { av.Calculate1R(l.AVData.L, l.AVData.W, l.AVData.R, natom); } else if (l.AVData.AVType == AVSimlationType.ThreeDyeR) { av.Calculate3R(l.AVData.L, l.AVData.W, l.AVData.R1, l.AVData.R2, l.AVData.R3, natom); } rmp = Matrix3.Transpose(sr.Rotation[nmol]) * (av.Rmp - sr.Translation[nmol] + sr.Molecules[0].CM - sr.Molecules[nmol].CM) + sr.Molecules[nmol].CM; l.X = rmp.X; l.Y = rmp.Y; l.Z = rmp.Z; lps_local[i] = l; } return(lps_local); }
private void PrepareSimulation() { // molecules Nmolecules = _molecules.Count; int maxatomsincluster = 0; for (int i = 0; i < Nmolecules; i++) { minmass = Math.Min(minmass, _molecules[i].Mass); maxatomsincluster = Math.Max(maxatomsincluster, _molecules[i].MaxAtomsInCluster); } // labeling positions int im; labelingpos_cm = new LabelingPositionList(); labelingpos_cm.AddRange(this._labelingpositions); lpossim = new Vector3[labelingpos_cm.Count]; LtoM = new int[labelingpos_cm.Count]; // convert to local coordinates for (int i = 0; i < labelingpos_cm.Count; i++) { im = _molecules.FindIndex(labelingpos_cm[i].Molecule); LtoM[i] = im; labelingpos_cm[i] -= _molecules[im].CM; lpossim[i] = labelingpos_cm[i]; } // distances Distance dist_i; DtoL1 = new int[_distances.Count]; DtoM1 = new int[_distances.Count]; DtoL2 = new int[_distances.Count]; DtoM2 = new int[_distances.Count]; kplus = new double[_distances.Count]; kminus = new double[_distances.Count]; drmaxplus = new double[_distances.Count]; drmaxminus = new double[_distances.Count]; double minerror = double.MaxValue; for (int i = 0; i < _distances.Count; i++) { DtoL1[i] = labelingpos_cm.FindIndex(_distances[i].Position1); DtoM1[i] = _molecules.FindIndex(labelingpos_cm.Find(_distances[i].Position1).Molecule); DtoL2[i] = labelingpos_cm.FindIndex(_distances[i].Position2); DtoM2[i] = _molecules.FindIndex(labelingpos_cm.Find(_distances[i].Position2).Molecule); // check if bond dist_i = _distances[i]; dist_i.IsBond = (labelingpos_cm[DtoL1[i]].Dye == DyeType.Unknown && labelingpos_cm[DtoL1[i]].AVData.AtomID > 0 && labelingpos_cm[DtoL1[i]].AVData.AVType == AVSimlationType.None && labelingpos_cm[DtoL2[i]].Dye == DyeType.Unknown && labelingpos_cm[DtoL2[i]].AVData.AtomID > 0 && labelingpos_cm[DtoL2[i]].AVData.AVType == AVSimlationType.None); _distances[i] = dist_i; // if bond, set small vdW radii to "exclude" from clashing if (dist_i.IsBond) { foreach (var lp in new[] { labelingpos_cm[DtoL1[i]], labelingpos_cm[DtoL2[i]] }) { int m = _molecules.FindIndex(lp.Molecule); int natom = Array.BinarySearch <int>(_molecules[m].OriginalAtomID, lp.AVData.AtomID); _molecules[m].vdWR[natom] = AtomData.vdWRNoClash; int natom_cluster = Array.FindIndex <int>(_molecules[m].ClusteredAtomOriginalIndex, n => n == natom); if (natom_cluster >= 0) { _molecules[m].ClusteredAtomvdwR[natom_cluster] = AtomData.vdWRNoClash; System.Runtime.InteropServices.Marshal.Copy(new[] { (float)AtomData.vdWRNoClash }, 0, FpsNativeWrapper.Aligned16(_molecules[m].XYZvdwRVectorArray) + (4 * natom_cluster + 3) * sizeof(float), 1); } } } // "spring constants" kplus[i] = 2.0 / _distances[i].ErrPlus / _distances[i].ErrPlus; kminus[i] = 2.0 / _distances[i].ErrMinus / _distances[i].ErrMinus; //Console.Out.WriteLine("distance#" + i + " k+= " + kplus[i] + " k-= " + kminus[i] + " err+ " + _distances[i].ErrPlus + " err- " + _distances[i].ErrMinus); drmaxplus[i] = SimulationParameters.MaxForce / kplus[i]; drmaxminus[i] = -SimulationParameters.MaxForce / kminus[i]; minerror = Math.Min(minerror, Math.Min(_distances[i].ErrPlus, _distances[i].ErrMinus)); } // simulation parameters kclash = 2.0 / SimulationParameters.ClashTolerance / SimulationParameters.ClashTolerance; drmaxclash = -SimulationParameters.MaxForce / kclash; dr4dt = Math.Min(SimulationParameters.ClashTolerance * 0.5, minerror); }