コード例 #1
0
ファイル: MinEnsembleRMSD.cs プロジェクト: htna/explsolv
            public static void Align(List <Vector>[] ensemble)
            {
                List <Vector> meanconf = ensemble[0].HClone();
                int           iter     = 0;

                while (true)
                {
                    iter++;

                    List <Vector> meanconf0 = meanconf.HClone();
                    for (int i = 0; i < ensemble.Length; i++)
                    {
                        MinRMSD.Align(meanconf, ref ensemble[i]);
                    }
                    for (int i = 0; i < meanconf.Count; i++)
                    {
                        meanconf[i] = new double[3];
                        foreach (List <Vector> conf in ensemble)
                        {
                            meanconf[i] += conf[i];
                        }
                        meanconf[i] /= ensemble.Length;
                    }
                    double maxmove = VectorBlock.PwSub(meanconf0, meanconf).ToVector().ToArray().HAbs().Max();
                    if (maxmove < 0.001)
                    {
                        break;
                    }
                    if (iter >= 100)
                    {
                        break;
                    }
                }
            }
コード例 #2
0
ファイル: Tinker.FromNamd.cs プロジェクト: htna/explsolv
            public static void SelfTest(string pdbname, string psfname, string prmname, string xyzname)
            {
                using (var temp = new HTempDirectory(@"C:\temp\", null))
                {
                    temp.EnterTemp();
                    {
                        string resbase = "HTLib2.Bioinfo.HTLib2.Bioinfo.External.Tinker.Resources.selftest.";
                        HResource.CopyResourceTo <Tinker>(resbase + pdbname, pdbname);
                        HResource.CopyResourceTo <Tinker>(resbase + psfname, psfname);
                        HResource.CopyResourceTo <Tinker>(resbase + "par_all27_prot_lipid.inp", prmname);
                        if (xyzname != null)
                        {
                            HResource.CopyResourceTo <Tinker>(resbase + xyzname, xyzname);
                        }
                        HResource.CopyResourceTo <Tinker>(resbase + "charmm22.prm", "charmm22.prm");

                        {
                            var pdb = Pdb.FromFile(pdbname);
                            var psf = Namd.Psf.FromFile(psfname);
                            var prm = Namd.Prm.FromFile(prmname);

                            var xyz_prm = BuildFromNamd(pdb, psf, prm);
                            xyz_prm.Item1.ToFile("TinkFromNamd.xyz", false);
                            xyz_prm.Item2.ToFile("TinkFromNamd.prm");
                        }

                        if (xyzname != null)
                        {
                            var xyz0  = Xyz.FromFile("TinkFromNamd.xyz", false);
                            var prm0  = Prm.FromFile("TinkFromNamd.prm");
                            var grad0 = Run.Testgrad(xyz0, prm0, @"C:\temp\"
                                                     //, "VDWTERM     NONE"
                                                     //, "CHARGETERM  NONE"
                                                     //, "BONDTERM    NONE"
                                                     //, "ANGLETERM   NONE"
                                                     //, "UREYTERM    NONE"
                                                     //, "IMPROPTERM  NONE"
                                                     //, "TORSIONTERM NONE"
                                                     );
                            var forc0 = grad0.anlyts.GetForces(xyz0.atoms);

                            var xyz1  = Xyz.FromFile(xyzname, false);
                            var prm1  = Prm.FromFile("charmm22.prm");
                            var grad1 = Run.Testgrad(xyz1, prm1, @"C:\temp\"
                                                     //, "VDWTERM     NONE"
                                                     //, "CHARGETERM  NONE"
                                                     //, "BONDTERM    NONE"
                                                     //, "ANGLETERM   NONE"
                                                     //, "UREYTERM    NONE"
                                                     //, "IMPROPTERM  NONE"
                                                     //, "TORSIONTERM NONE"
                                                     );
                            var forc1 = grad1.anlyts.GetForces(xyz1.atoms);
                            {
                                KDTree.KDTree <object> kdtree = new KDTree.KDTree <object>(3);
                                var atoms0 = xyz0.atoms;
                                for (int i = 0; i < atoms0.Length; i++)
                                {
                                    kdtree.insert(atoms0[i].Coord, i);
                                }
                                var   atoms1  = xyz1.atoms;
                                int[] idx1to0 = new int[atoms1.Length];
                                for (int i1 = 0; i1 < atoms1.Length; i1++)
                                {
                                    Vector coord1 = atoms1[i1].Coord;
                                    int    i0     = (int)kdtree.nearest(coord1);
                                    Vector coord0 = atoms0[i0].Coord;
                                    kdtree.delete(coord0);
                                    idx1to0[i0] = i1;
                                }
                                atoms1 = atoms1.HSelectByIndex(idx1to0);
                                forc1  = forc1.HSelectByIndex(idx1to0);
                            }

                            Vector[] dforc     = VectorBlock.PwSub(forc0, forc1).ToArray();
                            double[] dforcl    = dforc.Dist();
                            double   max_dforc = dforc.Dist().Max();
                            HDebug.Exception(max_dforc < 1);       // 0.72682794387667848

                            {
                                double EB   = Math.Abs(grad0.enrgCmpnt.EB - grad1.enrgCmpnt.EB);    HDebug.Exception(EB < 0.1);
                                double EA   = Math.Abs(grad0.enrgCmpnt.EA - grad1.enrgCmpnt.EA);    HDebug.Exception(EA < 0.1);
                                double EBA  = Math.Abs(grad0.enrgCmpnt.EBA - grad1.enrgCmpnt.EBA);    HDebug.Exception(EBA < 0.1);
                                double EUB  = Math.Abs(grad0.enrgCmpnt.EUB - grad1.enrgCmpnt.EUB);    HDebug.Exception(EUB < 0.1);
                                double EAA  = Math.Abs(grad0.enrgCmpnt.EAA - grad1.enrgCmpnt.EAA);    HDebug.Exception(EAA < 0.1);
                                double EOPB = Math.Abs(grad0.enrgCmpnt.EOPB - grad1.enrgCmpnt.EOPB);    HDebug.Exception(EOPB < 0.1);
                                double EOPD = Math.Abs(grad0.enrgCmpnt.EOPD - grad1.enrgCmpnt.EOPD);    HDebug.Exception(EOPD < 0.1);
                                double EID  = Math.Abs(grad0.enrgCmpnt.EID - grad1.enrgCmpnt.EID);    HDebug.Exception(EID < 0.1);          // 0.0019000000000000128 : N-terminus (and C-terminus) information is/are inconsistent betweeen namd-charmm and tink-charmm22
                                double EIT  = Math.Abs(grad0.enrgCmpnt.EIT - grad1.enrgCmpnt.EIT);    HDebug.Exception(EIT < 0.1);
                                double ET   = Math.Abs(grad0.enrgCmpnt.ET - grad1.enrgCmpnt.ET);    HDebug.Exception(ET < 0.5);             // 0.33029999999999404   : N-terminus (and C-terminus) information is/are inconsistent betweeen namd-charmm and tink-charmm22
                                double EPT  = Math.Abs(grad0.enrgCmpnt.EPT - grad1.enrgCmpnt.EPT);    HDebug.Exception(EPT < 0.1);
                                double EBT  = Math.Abs(grad0.enrgCmpnt.EBT - grad1.enrgCmpnt.EBT);    HDebug.Exception(EBT < 0.1);
                                double ETT  = Math.Abs(grad0.enrgCmpnt.ETT - grad1.enrgCmpnt.ETT);    HDebug.Exception(ETT < 0.1);
                                double EV   = Math.Abs(grad0.enrgCmpnt.EV - grad1.enrgCmpnt.EV);    HDebug.Exception(EV < 0.1);
                                double EC   = Math.Abs(grad0.enrgCmpnt.EC - grad1.enrgCmpnt.EC);    HDebug.Exception(EC < 0.5);             // 0.37830000000002428
                                double ECD  = Math.Abs(grad0.enrgCmpnt.ECD - grad1.enrgCmpnt.ECD);    HDebug.Exception(ECD < 0.1);
                                double ED   = Math.Abs(grad0.enrgCmpnt.ED - grad1.enrgCmpnt.ED);    HDebug.Exception(ED < 0.1);
                                double EM   = Math.Abs(grad0.enrgCmpnt.EM - grad1.enrgCmpnt.EM);    HDebug.Exception(EM < 0.1);
                                double EP   = Math.Abs(grad0.enrgCmpnt.EP - grad1.enrgCmpnt.EP);    HDebug.Exception(EP < 0.1);
                                double ER   = Math.Abs(grad0.enrgCmpnt.ER - grad1.enrgCmpnt.ER);    HDebug.Exception(ER < 0.1);
                                double ES   = Math.Abs(grad0.enrgCmpnt.ES - grad1.enrgCmpnt.ES);    HDebug.Exception(ES < 0.1);
                                double ELF  = Math.Abs(grad0.enrgCmpnt.ELF - grad1.enrgCmpnt.ELF);    HDebug.Exception(ELF < 0.1);
                                double EG   = Math.Abs(grad0.enrgCmpnt.EG - grad1.enrgCmpnt.EG);    HDebug.Exception(EG < 0.1);
                                double EX   = Math.Abs(grad0.enrgCmpnt.EX - grad1.enrgCmpnt.EX);    HDebug.Exception(EX < 0.1);
                            }
                        }
                    }
                    temp.QuitTemp();
                }

                //{
                //    //string pathbase = @"C:\Users\htna.IASTATE\svn\htnasvn_htna\Research.bioinfo.prog.NAMD\1A6G\New folder\";
                //    string pathbase = @"C:\Users\htna.IASTATE\svn\htnasvn_htna\Research.bioinfo.prog.NAMD\1A6G\";
                //    string toplbase = @"C:\Users\htna.IASTATE\svn\htnasvn_htna\Research.bioinfo.prog.NAMD\top_all27_prot_lipid\";
                //    var pdb = Pdb     .FromFile(pathbase+"1A6G.psfgen.pdb");
                //    var psf = Namd.Psf.FromFile(pathbase+"1A6G.psfgen.psf");
                //    var prm = Namd.Prm.FromFile(toplbase+"par_all27_prot_na.prm");
                //
                //        pdb = Pdb     .FromFile(@"K:\Tim-8TIM,1TPH,1M6J\Tim-1M6J\1M6J.psfgen.pdb");
                //        psf = Namd.Psf.FromFile(@"K:\Tim-8TIM,1TPH,1M6J\Tim-1M6J\1M6J.psfgen.psf");
                //        prm = Namd.Prm.FromFile(@"K:\Tim-8TIM,1TPH,1M6J\Tim-1M6J\par_all27_prot_lipid.inp");
                //    var xyz_prm = BuildFromNamd(pdb, psf, prm);
                //    xyz_prm.Item1.ToFile(@"C:\temp\TinkFromNamd.xyz", false);
                //    xyz_prm.Item2.ToFile(@"C:\temp\TinkFromNamd.prm");
                //}
            }