示例#1
0
            public static Top FromPdb(string pdbpath
                                      , string ff    = "charmm27"
                                      , string water = "none"
                                      , HPack <Pdb> optout_confout = null
                                      )
            {
                Top top;

                FileInfo      pdbinfo  = new FileInfo(pdbpath);
                string        currdir  = HEnvironment.CurrentDirectory;
                DirectoryInfo temproot = HDirectory.CreateTempDirectory();

                HEnvironment.CurrentDirectory = temproot.FullName;
                {
                    HFile.Copy(pdbinfo.FullName, "protein.pdb");

                    RunPdb2gmx(f: "protein.pdb"
                               , o: "confout.pdb"
                               , p: "topol.top"
                               , q: "clean.pdb"
                               , ff: ff
                               , water: water
                               , merge: "all"
                               , lineStderr: null
                               , lineStdout: null
                               );

                    top = Top.FromFile("topol.top");
                    if (optout_confout != null)
                    {
                        optout_confout.value = Pdb.FromFile("confout.pdb");
                    }
                }
                HEnvironment.CurrentDirectory = currdir;
                Thread.Sleep(100);
                try{ temproot.Delete(true); } catch (Exception) {}

                return(top);
            }
示例#2
0
文件: Pymol.cs 项目: htna/explsolv
        public static void SavePse(string psepath
                                   , bool cartoon
                                   , bool line
                                   , string pngpath // null if not save png
                                   , params string[] pdbpaths)
        {
            string currpath = HEnvironment.CurrentDirectory;

            HEnvironment.CurrentDirectory = HFile.GetFileInfo(psepath).Directory.FullName;
            {
                Random rand    = new Random();
                string psename = HFile.GetFileInfo(psepath).Name;

                int      count     = pdbpaths.Length;
                string[] pdblnames = new string[count];
                string[] pdblpaths = new string[count];
                for (int i = 0; i < count; i++)
                {
                    var info = HFile.GetFileInfo(pdbpaths[i]);
                    pdblnames[i] = info.Name.Replace(".pdb", "").Replace(".PDB", "");
                    pdblpaths[i] = psepath + info.Name + rand.NextInt(99999).ToString(".rnd00000") + ".pdb";
                    HFile.Copy(pdbpaths[i], pdblpaths[i]);
                }

                string        pmlpath = psepath + rand.NextInt(99999).ToString(".rnd00000") + ".pml";
                List <string> pmltext = new List <string>();
                for (int i = 0; i < count; i++)
                {
                    pmltext.Add("load $$path$$, $$name$$;".Replace("$$path$$", pdblpaths[i]).Replace("$$name$$", pdblnames[i]));
                }
                if (cartoon)
                {
                    pmltext.Add("show cartoon;");
                }
                else
                {
                    pmltext.Add("hide cartoon");
                }
                if (line)
                {
                    pmltext.Add("show lines;");
                }
                else
                {
                    pmltext.Add("hide lines");
                }
                pmltext.Add("reset;");
                pmltext.Add("save $$psepath$$;".Replace("$$psepath$$", psepath));
                if (pngpath != null)
                {
                    pmltext.Add("png $$pngpath$$;".Replace("$$pngpath$$", pngpath));
                }
                pmltext.Add("quit;");

                HFile.WriteAllLines(pmlpath, pmltext);

                System.Diagnostics.Process pymol;
                pymol = System.Diagnostics.Process.Start(@"C:\Program Files (x86)\PyMOL\PyMOL\PymolWin.exe", pmlpath);
                pymol.WaitForExit();

                for (int i = 0; i < count; i++)
                {
                    HFile.Delete(pdblpaths[i]);
                }
                HFile.Delete(pmlpath);
            }
            HEnvironment.CurrentDirectory = currpath;
        }