Example #1
0
        private void SaveDistances(String rfilename)
        {
            LabelingPosition l1, l2;

            LabelingPosition[] l1index = new LabelingPosition[dist.Count];
            LabelingPosition[] l2index = new LabelingPosition[dist.Count];
            Double             R;

            using (StreamWriter sw = new StreamWriter(rfilename + "_Rmp.txt", false))
            {
                sw.Write("Structure\tNumber");
                for (Int32 i = 0; i < dist.Count; i++)
                {
                    l1         = labelingpos.Find(dist[i].Position1);
                    l2         = labelingpos.Find(dist[i].Position2);
                    l1index[i] = l1;
                    l2index[i] = l2;
                    sw.Write('\t' + l1.Name + '_' + l2.Name);
                }
                sw.WriteLine();
                for (Int32 j = 0; j < _dataToSave.Length; j++)
                {
                    sw.Write(filenametextBox.Text + _dataToSave[j].InternalNumber.ToString() + '\t' + _dataToSave[j].InternalNumber.ToString());
                    for (Int32 i = 0; i < dist.Count; i++)
                    {
                        sw.Write('\t' + _dataToSave[j].ModelDistance(l1index[i], l2index[i]).ToString("F3"));
                    }
                    sw.WriteLine();
                }
                sw.Close();
            }

            // saving converted distances if requested
            if (dist.DataType != DistanceDataType.Rmp)
            {
                using (StreamWriter sw = new StreamWriter(rfilename + '_' + dist.DataType.ToString() + ".txt", false))
                {
                    sw.Write("Structure\tNumber");
                    for (Int32 i = 0; i < dist.Count; i++)
                    {
                        l1 = labelingpos.Find(dist[i].Position1);
                        l2 = labelingpos.Find(dist[i].Position2);
                        sw.Write('\t' + l1.Name + '_' + l2.Name);
                    }
                    sw.WriteLine();
                    for (Int32 j = 0; j < _dataToSave.Length; j++)
                    {
                        sw.Write(filenametextBox.Text + _dataToSave[j].InternalNumber.ToString() + '\t' + _dataToSave[j].InternalNumber.ToString());
                        for (Int32 i = 0; i < dist.Count; i++)
                        {
                            R = (l1index[i].Dye != DyeType.Unknown && l2index[i].Dye != DyeType.Unknown) ?
                                Distance.Convert(_dataToSave[j].ModelDistance(l1index[i], l2index[i]), _globalcf) : _dataToSave[j].ModelDistance(l1index[i], l2index[i]);
                            sw.Write('\t' + R.ToString("F3"));
                        }
                        sw.WriteLine();
                    }
                    sw.Close();
                }
            }
        }
Example #2
0
        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);
        }