Пример #1
0
        public static List <MolData> ConvertToMolData(List <double[]> data, bool withBonds, List <int[]> bonds)
        {
            var system = new List <MolData>();

            for (int i = 0; i < data.Count; i++)
            {
                var newAtom = new MolData(data[i][3], i + 1, Convert.ToInt32(data[i][4]), data[i][0], data[i][1], data[i][2]);
                system.Add(newAtom);
            }

            if (withBonds)
            {
                foreach (var c in system)
                {
                    var beadBonds = new List <int>();
                    foreach (var p in bonds)
                    {
                        if (p[0] == c.Index)
                        {
                            beadBonds.Add(p[1]);
                        }
                        if (p[1] == c.Index)
                        {
                            beadBonds.Add(p[0]);
                        }
                    }

                    c.Bonds = beadBonds;
                }
            }

            return(system);
        }
Пример #2
0
        public static List <MolData> ShiftAll(bool hasWalls, int wallsType, bool onlyPolymer, double density, double[] sizes, double[] shifts, double[] centerPoint, List <double[]> data)
        {
            var system = new List <MolData>();

            foreach (var c in data)
            {
                for (int i = 0; i <= 2; i++)
                {
                    if (c[3] != 1.08 && c[3] != 1.09)
                    {
                        c[i] += shifts[i];
                        if (c[i] <= centerPoint[i] - sizes[i] / 2.0)
                        {
                            c[i] += sizes[i];
                        }
                        if (c[i] >= centerPoint[i] + sizes[i] / 2.0)
                        {
                            c[i] -= sizes[i];
                        }
                    }
                }
            }
            double maxNum = sizes[0] * sizes[1] * sizes[2] * density;

            if (data.Count < Math.Abs(maxNum))
            {
                maxNum = data.Count;
            }
            for (int i = 0; (double)i < maxNum; i++)
            {
                var newAtom = new MolData(data[i][3], i + 1, Convert.ToInt32(data[i][4]), data[i][0], data[i][1], data[i][2]);
                system.Add(newAtom);
            }
            if (onlyPolymer)
            {
                system = system.Where(x => x.AtomType.Equals(1.00) ||
                                      x.AtomType.Equals(1.01) ||
                                      x.AtomType.Equals(1.04) ||
                                      x.AtomType.Equals(1.09)).ToList();
            }

            if (hasWalls)
            {
                StructFormer fFormer = new StructFormer(hasWalls, wallsType, sizes[0], sizes[1], sizes[2], density, centerPoint, data);
                if (wallsType == 1 && system.Where(x => x.AtomType.Equals(1.09)).ToList().Count == 0)
                {
                    fFormer.AddWalls(system);
                }
            }
            return(system);
        }
Пример #3
0
        private void btnChooseInitFile_Click(object sender, EventArgs e)
        {
            InputCut         = LoadFile_Edit(InputCut, true, tbInitPath_Page1, tbX_Page1, tbY_Page1, tbZ_Page1, btnChooseInitBonds, InitCutBonds, InitCutAngles);
            CenterPoint_Edit = MolData.GetCenterPoint(new double[] { replaceValue(tbX_Page1.Text),
                                                                     replaceValue(tbY_Page1.Text),
                                                                     replaceValue(tbZ_Page1.Text) }, InputCut);
            if (InputCut.Count == 0)
            {
                return;
            }
            else
            {
                label10.Visible                   = (InitCutBonds.Count == 0);
                tbBondsPath_Page1.Visible         = (InitCutBonds.Count == 0);
                btnChooseInitAngles_Page1.Visible = (InitCutAngles.Count == 0);
                label106.Visible                  = (InitCutAngles.Count == 0);
                tbAnglesPath_Page1.Visible        = (InitCutAngles.Count == 0);
            }

            gbShift.Enabled = true;
        }
Пример #4
0
        public static void AddNonLinMol_Recurcion(int molIndex, string direction, List <double[]> borders, Random rnd, List <int> placedBeads, MolData currBead, List <MolData> mol, List <MolData> system)
        {
            currBead.XCoord = system[system.Count - 1].XCoord;
            currBead.YCoord = system[system.Count - 1].YCoord;
            currBead.ZCoord = system[system.Count - 1].ZCoord;

            placedBeads.Add(currBead.Index);

            if (currBead.Bonds.Count == 1 && placedBeads.Contains(currBead.Bonds[0]))
            {
                return;
            }
            else
            {
                foreach (var c in currBead.Bonds)
                {
                    if (!placedBeads.Contains(c))
                    {
                        double xCoord = rnd.Next(-600, 600) / 1000.0 + currBead.XCoord;
                        double yCoord = rnd.Next(-600, 600) / 1000.0 + currBead.YCoord;
                        double zCoord = rnd.Next(-600, 600) / 1000.0 + currBead.ZCoord;

                        if (direction == "X")
                        {
                            xCoord = rnd.Next(0, 500) / 1000.0 + currBead.XCoord;
                        }
                        if (direction == "Y")
                        {
                            yCoord = rnd.Next(0, 500) / 1000.0 + currBead.YCoord;
                        }
                        if (direction == "Z")
                        {
                            zCoord = rnd.Next(0, 500) / 1000.0 + currBead.ZCoord;
                        }

                        if (borders.Count != 0)
                        {
                            if (borders[0][0] != borders[0][1])
                            {
                                if (xCoord < borders[0][0])
                                {
                                    xCoord = borders[0][0];
                                }

                                if (xCoord > borders[0][1])
                                {
                                    xCoord = borders[0][1];
                                }
                            }

                            if (borders[1][0] != borders[1][1])
                            {
                                if (yCoord < borders[1][0])
                                {
                                    yCoord = borders[1][0];
                                }

                                if (yCoord > borders[1][1])
                                {
                                    yCoord = borders[1][1];
                                }
                            }

                            if (borders[2][0] != borders[2][1])
                            {
                                if (zCoord < borders[2][0])
                                {
                                    zCoord = borders[2][0];
                                }

                                if (zCoord > borders[2][1])
                                {
                                    zCoord = borders[2][1];
                                }
                            }
                        }

                        system.Add(new MolData(mol.First(x => x.Index == c).AtomType, system.Count + 1, molIndex, xCoord, yCoord, zCoord));


                        placedBeads.Add(c);

                        currBead = mol.First(x => x.Index == placedBeads[placedBeads.Count - 1]);

                        AddNonLinMol_Recurcion(molIndex, direction, rnd, placedBeads, currBead, mol, system);
                    }
                }
            }
        }
Пример #5
0
 // Add nonlinear molecule into the simulation box bead by bead (polymers) by recurcion
 public static void AddNonLinMol_Recurcion(int molIndex, string direction, Random rnd, List <int> placedBeads, MolData currBead, List <MolData> mol, List <MolData> system)
 {
     AddNonLinMol_Recurcion(molIndex, direction, new List <double[]>(), rnd, placedBeads, currBead, mol, system);
 }
Пример #6
0
        public static void GetOneAggregate_Recursion(bool hasBonds, double beadType, double radius, double[] sizes, double[] centerPoint,
                                                     MolData currBead, List <MolData> core, List <MolData> initCoreBeads)
        {
            if (initCoreBeads.Contains(currBead))
            {
                core.Add(currBead);
                initCoreBeads.Remove(currBead);
            }

            var newBeads = new List <MolData>();

            foreach (var c in initCoreBeads)
            {
                if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord, currBead.XCoord, currBead.YCoord, currBead.ZCoord) <= radius)
                {
                    newBeads.Add(c);
                }

                if (currBead.XCoord > (sizes[0] / 2.0 + centerPoint[0]) - radius)
                {
                    if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord,
                                      currBead.XCoord - (sizes[0] / 2.0 + centerPoint[0]), currBead.YCoord, currBead.ZCoord) <= radius)
                    {
                        newBeads.Add(c);
                    }
                }

                if (currBead.XCoord < (sizes[0] / 2.0 - centerPoint[0]) + radius)
                {
                    if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord,
                                      currBead.XCoord + (sizes[0] / 2.0 + centerPoint[0]), currBead.YCoord, currBead.ZCoord) <= radius)
                    {
                        newBeads.Add(c);
                    }
                }

                if (currBead.YCoord > (sizes[1] / 2.0 + centerPoint[1]) - radius)
                {
                    if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord,
                                      currBead.XCoord, currBead.YCoord - (sizes[1] / 2.0 + centerPoint[1]), currBead.ZCoord) <= radius)
                    {
                        newBeads.Add(c);
                    }
                }

                if (currBead.YCoord < (sizes[1] / 2.0 - centerPoint[1]) + radius)
                {
                    if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord,
                                      currBead.XCoord, currBead.YCoord + (sizes[1] / 2.0 + centerPoint[1]), currBead.ZCoord) <= radius)
                    {
                        newBeads.Add(c);
                    }
                }

                if (currBead.ZCoord > (sizes[2] / 2.0 + centerPoint[2]) - radius)
                {
                    if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord,
                                      currBead.XCoord, currBead.YCoord, currBead.ZCoord - (sizes[2] / 2.0 + centerPoint[2])) <= radius)
                    {
                        newBeads.Add(c);
                    }
                }

                if (currBead.ZCoord < (sizes[2] / 2.0 - centerPoint[2]) + radius)
                {
                    if (GetDistance3D(c.XCoord, c.YCoord, c.ZCoord,
                                      currBead.XCoord, currBead.YCoord, currBead.ZCoord + (sizes[2] / 2.0 + centerPoint[2])) <= radius)
                    {
                        newBeads.Add(c);
                    }
                }
            }
            foreach (var c in newBeads)
            {
                core.Add(c);
                initCoreBeads.Remove(c);
            }

            // Accounting bonds
            if (hasBonds)
            {
                var nbCount = newBeads.Count;
                for (int p = 0; p < nbCount; p++)
                {
                    foreach (var c in newBeads[p].Bonds)
                    {
                        var bondBead = initCoreBeads.Find(x => x.Index == c);

                        if (bondBead != null && !newBeads.Contains(bondBead))
                        {
                            newBeads.Add(bondBead);
                        }
                    }
                }
            }

            //newBeads = newBeads.Distinct().ToList();

            if (newBeads.Count != 0)
            {
                foreach (var c in newBeads)
                {
                    //if (!core.Contains(c))
                    //{
                    currBead = c;
                    GetOneAggregate_Recursion(hasBonds, beadType, radius, sizes, centerPoint, currBead, core, initCoreBeads);
                    //}
                }
            }
            else
            {
                return;
            }
        }
Пример #7
0
        private void SaveStruct(List <MolData> system, List <int[]> bonds, List <int[]> angles,
                                TextBox tbX, TextBox tbY, TextBox tbZ, TextBox tbDenstiy,
                                int molCount, bool hasWalls, bool addBonds)
        {
            saveFileDialog.Filter = "Файлы RasMol (*.ent)|*.ent|Lammps-файлы траекторные (*.lammpstrj)|*.lammpstrj|Конфиг. файлы Lammps (*.txt)|*.txt|Restart-файлы (*.dat)|*.dat|Текстовые файлы XYZR (*.xyzr)|*.xyzr";
            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            int boundaryCond = 3;

            if (hasWalls)
            {
                boundaryCond = 6;
            }
            double density = replaceValue(tbDenstiy.Text);

            double[] sizes = new double[] { replaceValue(tbX.Text),
                                            replaceValue(tbY.Text),
                                            replaceValue(tbZ.Text) };

            switch (saveFileDialog.FilterIndex)
            {
            case 1:
                FileWorker.Save_MOL(saveFileDialog.FileName, bonds, system);
                break;

            case 2:
                FileWorker.SaveLammpstrj(false, saveFileDialog.FileName, 0, sizes, density, system);
                break;

            case 3:
                int atomTypes = MolData.CalcTypes(system);
                int bondTypes = MolData.CalcBonds(bonds, system);
                if (addBonds)
                {
                    bondTypes++;
                }
                int angleTypes = 0;
                //if ((uint)angles.Count > 0U)
                //{
                //    var anglesTwo = MolData.CreateAngles(1.04, system, bonds);
                //    foreach (var c in anglesTwo)
                //    {
                //        angles.Add(c);
                //    }

                //    angles = angles.Distinct().ToList();

                //    angleTypes = MolData.CalcAngles(angles, system);
                //}
                //else
                //{
                //    angles = MolData.CreateAngles(1.04, system, bonds);
                //    angleTypes = MolData.CalcAngles(angles, system);
                //}
                FileWorker.Save_Conf(saveFileDialog.FileName, sizes, density, atomTypes, bondTypes, angleTypes, bonds, angles, system);
                break;

            case 4:
                FileWorker.Save_DAT(saveFileDialog.FileName, boundaryCond, 0, 1, sizes, bonds, angles, system);
                break;

            case 5:
                FileWorker.Save_XYZ(saveFileDialog.FileName, false, sizes, system);
                break;
            }
            StartProcces(saveFileDialog.FileName);
        }
Пример #8
0
        private void btnShiftStructure_Click(object sender, EventArgs e)
        {
            EditedComposition = MolData.ShiftAll((chbHasWalls_Page1.Checked ? 1 : 0) != 0, cmbWallsType_Page1.SelectedIndex,
                                                 (chbShiftOnlyPolymer.Checked ? 1 : 0) != 0, replaceValue(tbDensity_Page1.Text),
                                                 new double[] { replaceValue(tbX_Page1.Text),
                                                                replaceValue(tbY_Page1.Text),
                                                                replaceValue(tbZ_Page1.Text) },
                                                 new double[3] {
                replaceValue(tbShiftX_Page1.Text),
                replaceValue(tbShiftY_Page1.Text),
                replaceValue(tbShiftZ_Page1.Text)
            },
                                                 CenterPoint_Edit, InputCut);



            //for (int i = 0; i < EditedComposition.Count; i++)
            //{
            //    if (i >= 1700)
            //    {
            //        if (EditedComposition[i].AtomType == 1.00)
            //        {
            //            EditedComposition[i].AtomType = 1.01;
            //        }
            //    }
            //}

            // For Robin
            //    {
            //        double xSize = replaceValue(tbX_Page1.Text);
            //        double ySize = replaceValue(tbY_Page1.Text);
            //        double zSize = replaceValue(tbZ_Page1.Text);

            //        int maxNum = (int)xSize * (int)ySize * (int)zSize * 3;

            //        int watercount = (maxNum-EditedComposition.Count)/ 2;
            //        int molInd = EditedComposition.Max(x => x.MolIndex);

            //        Random rnd = new Random();
            //        Random rndDec = new Random();
            //        int counter = 0;
            //        do
            //        {

            //            double xCoord = (double)rnd.Next(0, (int)xSize - 1) + rndDec.NextDouble();
            //            double yCoord = (double)rnd.Next(0, (int)ySize - 1) + rndDec.NextDouble();
            //            double zCoord = (double)rnd.Next(0, 75) + rndDec.NextDouble();

            //                molInd++;
            //                counter++;
            //                EditedComposition.Add(new MolData(1.03, EditedComposition.Count + 1, molInd, xCoord, yCoord, zCoord));

            //        }
            //        while (counter < watercount);


            //    counter = 0;
            //    do
            //    {
            //            double xCoord = (double)rnd.Next(1, (int)xSize - 1) + rndDec.NextDouble();
            //            double yCoord = (double)rnd.Next(1, (int)ySize - 1) + rndDec.NextDouble();
            //            double zCoord = (double)rnd.Next(105, 179) + rndDec.NextDouble();


            //            if (true)
            //        {
            //            molInd++;
            //            counter++;
            //            EditedComposition.Add(new MolData(1.02, EditedComposition.Count + 1, molInd, xCoord , yCoord , zCoord ));
            //        }

            //    }
            //    while (counter < watercount);
            //}

            //Gavrilov-Rudyak
            // 1,4- regular monomers, 3 - initiator, the rest are the crosslinkers
            //foreach (var c in EditedComposition)
            //{
            //    if (c.AtomType == 1.02)
            //    {
            //        c.AtomType = 1.00;
            //    }
            //    if (c.AtomType == 1.03)
            //    {
            //        c.AtomType = 1.00;
            //    }
            //    if (c.AtomType == 1.04)
            //    {
            //        c.AtomType = 1.01;
            //    }
            //    if (c.AtomType == 1.06)
            //    {
            //        c.AtomType = 1.01;
            //    }
            //}

            if (chbHighlightCrossLinks.Checked)
            {
                var type = FileWorker.AtomTypes[Convert.ToInt32(tbHighlightType.Text)];

                foreach (var c in EditedComposition)
                {
                    var beadBonds = new List <int>();
                    foreach (var p in InitCutBonds)
                    {
                        if (p[0] == c.Index)
                        {
                            beadBonds.Add(p[1]);
                        }
                        if (p[1] == c.Index)
                        {
                            beadBonds.Add(p[0]);
                        }
                    }

                    c.Bonds = beadBonds;
                }

                foreach (var c in EditedComposition)
                {
                    //if (c.Bonds.Count == 2 && c.Index <= 833)
                    //{
                    //c.AtomType = 1.00;
                    //}

                    if (c.Bonds.Count > 2)
                    {
                        c.AtomType = type;
                    }
                }

                //Random rand = new Random();

                //int frac = (int)(EditedComposition.Count * 0.2);

                //int counter = 0;

                //do
                //{
                //    int ind = rand.Next(0, EditedComposition.Count-1);

                //    if (EditedComposition[ind].AtomType == 1.00 && EditedComposition[ind].Bonds.Count == 2)
                //    {
                //        var indTwo = EditedComposition[ind].Bonds[0] - 1;
                //        var indThree = EditedComposition[ind].Bonds[1] - 1;
                //        if (EditedComposition[indTwo].AtomType == 1.00)
                //        {
                //            if (EditedComposition[indTwo].Bonds.Count == 2)
                //            {
                //               if (EditedComposition[EditedComposition[indTwo].Bonds[0]].AtomType == 1.01)
                //                {
                //                    EditedComposition[indTwo].AtomType = 1.01;
                //                }
                //               else
                //                {
                //                    EditedComposition[indThree].AtomType = 1.01;
                //                }
                //            }
                //            else
                //            {
                //                continue;
                //            }
                //        }
                //        else
                //        {
                //            if (EditedComposition[indThree].AtomType == 1.00)
                //            {
                //                EditedComposition[indThree].AtomType = 1.01;
                //            }
                //            else
                //            {
                //                continue;
                //            }
                //        }

                //        EditedComposition[ind].AtomType = 1.01;

                //        counter += 2;
                //    }
                //} while (counter < frac);
            }
            if (chbCreateAngles.Checked)
            {
                var type = FileWorker.AtomTypes[Convert.ToInt32(tbAngleType.Text)];
                InitCutAngles = MolData.CreateAngles(type, EditedComposition, InitCutBonds);
            }

            if (chbMur.Checked)
            {
                foreach (MolData molData in EditedComposition)
                {
                    if (molData.AtomType.Equals(1.03) && molData.ZCoord > 40.0)
                    {
                        molData.AtomType = 1.02;
                    }
                    if (molData.AtomType.Equals(1.02) && molData.ZCoord <= 40.0)
                    {
                        molData.AtomType = 1.03;
                    }
                }
            }
            if (!btnSaveStruct_Page1.Enabled)
            {
                btnSaveStruct_Page1.Enabled = true;
            }
            if (!chbShrink.Checked)
            {
                return;
            }
            double num = replaceValue(tbShrinkRate.Text);

            foreach (MolData molData in EditedComposition)
            {
                molData.XCoord /= num;
                molData.YCoord /= num;
                molData.ZCoord /= num;
            }
        }