private void fillTransportOptions(string login, string password, HOptions options, JObject context) { try { this.transportOptions.Login = login; this.transportOptions.Password = password; this.transportOptions.Timeout = options.GetTimeout(); this.transportOptions.AuthCb = options.AuthCb; //for endpoints, pick one randomly and fill transport options if (options.GetEndpoints().Count() > 0) { int endpointIndex = HUtil.PickIndex(options.GetEndpoints()); string endpoint = options.GetEndpoints()[endpointIndex].ToString(); transportOptions.EndpointHost = HUtil.GetHost(endpoint); transportOptions.EndpointPort = HUtil.GetPort(endpoint); transportOptions.EndpointPath = HUtil.GetPath(endpoint); } else { transportOptions.EndpointHost = null; transportOptions.EndpointPort = 0; transportOptions.EndpointPath = null; } } catch (Exception e) { Debug.WriteLine("{0} : ", e); } }
public static Run.CPsfgen RunPsfgen (IList <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms , string tempbase //=null , string parameters //=null , string namdversion //="2.8" , IList <string> infiles , IList <string> outfiles , string topology , IList <string> psfgen_lines = null , string psfgen_workdir = null , HOptions options = null ) { return(Run.Psfgen (lstSegFileAtoms , tempbase //=null , parameters //=null , namdversion //="2.8" , infiles , outfiles , topology , psfgen_lines: psfgen_lines , psfgen_workdir: psfgen_workdir , options: options )); }
public static CPsfgenExt PsfgenExt (Pdb pdb , string[] toplines , string[] parlines , Pdb alignto , HOptions options ) { string[] psfgen_lines = null; List <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms = new List <Tuple <string, string, Pdb.IAtom[]> >(); var pdb_iatoms = pdb.iatoms; foreach (var ch_iatoms in pdb_iatoms.GroupChainID()) { lstSegFileAtoms.Add(new Tuple <string, string, Pdb.IAtom[]> (ch_iatoms.Key + "" , null , ch_iatoms.Value.ToArray() )); } return(PsfgenExt (lstSegFileAtoms, toplines, parlines, alignto, psfgen_lines , options: options )); }
public MainPage() { this.InitializeComponent(); client = new HClient(); options = new HOptions(); client.onMessage += client_onMessage; client.onStatus += client_onStatus; }
public static void UpdateMassReduced(this IList <Mode> modes, IList <double> masses, HOptions options = null) { if (options == null) { options = ""; } if (options.Contains("parallel")) { HDebug.Exception(new NotImplementedException("check")); int[] iter = new int[1] { 0 }; System.Threading.Tasks.Parallel.For(0, modes.Count, delegate(int i) { Mode modei = modes[i]; modes[i] = null; modes[i] = modei.GetMassReduced(masses); lock (iter) { iter[0]++; if (iter[0] % 1000 == 0) { System.GC.Collect(0); } } }); System.GC.Collect(); } else { for (int i = 0; i < modes.Count; i++) { Mode modei = modes[i]; modes[i] = null; modes[i] = modei.GetMassReduced(masses); if (i % 1000 == 0) { System.GC.Collect(0); } } System.GC.Collect(); } }
public static IList <Mode> GetMassReduced(this IList <Mode> modes, IList <double> masses, HOptions options = null) { Mode[] mrmodes = modes.ToArray().HClone(); mrmodes.UpdateMassReduced(masses, options); return(mrmodes); }
public static CPsfgen Psfgen (IList <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms // segname, filename, pdbatoms , string tempbase //=null , string parameters //=null , string namdversion //="2.8" , IList <string> infiles , IList <string> outfiles , string topology , IList <string> psfgen_lines = null , string psfgen_workdir = null , HOptions options = null ) { if (options == null) { options = new HOptions((string)null); } Dictionary <System.IO.FileInfo, string[]> infile_lines = new Dictionary <System.IO.FileInfo, string[]>(); foreach (string infile in infiles) { infile_lines.Add(HFile.GetFileInfo(infile), HFile.ReadAllLines(infile)); } string currpath = HEnvironment.CurrentDirectory; System.IO.DirectoryInfo tmpdir = null; if (psfgen_workdir != null) { HEnvironment.CurrentDirectory = psfgen_workdir; } else { tmpdir = HDirectory.CreateTempDirectory(tempbase); HEnvironment.CurrentDirectory = tmpdir.FullName; } string[] lines = null; if ((psfgen_lines != null) && (psfgen_lines.Count > 0)) { lines = psfgen_lines.ToArray(); } else { lines = GetPsfgenLines (custom_pdbalias: null , custom_patches: null ); } if (topology != null) { lines = lines.ToArray().HReplace("$topology$", topology); } List <string> psf_lines; List <string> pdb_lines; { { //foreach(var respath_filename in GetResourcePaths("2.8", "psfgen")) foreach (var respath_filename in GetResourcePaths(namdversion, "psfgen")) { string respath = respath_filename.Item1; string filename = respath_filename.Item2; HResource.CopyResourceTo <Tinker>(respath, filename); } } // Dictionary<string, Tuple<string, Pdb.IAtom[]>> segname_filename_pdbatoms = new Dictionary<string, Tuple<string, Pdb.IAtom[]>>(); // //if(pdbs.Length != 1) throw new ArgumentException(); // for(int i=0; i<lstSegFilePdb.Count; i++) // { // string segnameprefix = lstSegFilePdb[i].Item1; if( segnameprefix == null) segnameprefix = string.Format("{0:00}", i); // string filenameprefix = lstSegFilePdb[i].Item2; if(filenameprefix == null) filenameprefix = string.Format("{0:00}", i); // Pdb pdb = lstSegFilePdb[i].Item3; // List<Pdb.IAtom> pdb_atoms = new List<Pdb.IAtom>(); // pdb_atoms.AddRange(pdb.atoms); // pdb_atoms.AddRange(pdb.hetatms); // char[] chains = pdb_atoms.ListChainID().HToHashSet().ToArray(); // // HDebug.AssertIf(chains.Length> 1, segnameprefix.Length <= 5); // HDebug.AssertIf(chains.Length<=1, segnameprefix.Length <= 6); // foreach(char chain in chains) // { // Pdb.IAtom[] chain_atoms = pdb_atoms.SelectByChainID(chain).SelectByAltLoc().ToArray(); // string suffix = null; // if(('a' <= chain) && (chain <= 'z')) suffix = string.Format("L{0}", chain); // if(('A' <= chain) && (chain <= 'Z')) suffix = string.Format("U{0}", chain); // if(('0' <= chain) && (chain <= '9')) suffix = string.Format("N{0}", chain); // string segname = segnameprefix + ((chains.Length <= 1) ? "" : suffix); // string filename = filenameprefix + ((chains.Length <= 1) ? "" : suffix); // segname_filename_pdbatoms.Add(segname, new Tuple<string,Pdb.IAtom[]>(filename, chain_atoms)); // } // } foreach (var finfo_line in infile_lines) { string inname = finfo_line.Key.Name; string[] inlines = finfo_line.Value; HFile.WriteAllLines(inname, inlines); } HashSet <string> segnames = new HashSet <string>(); int segindex = 0; foreach (var seg_file_atoms in lstSegFileAtoms) { string segname = seg_file_atoms.Item1; string filename = seg_file_atoms.Item2; Pdb.IAtom[] chain_atoms = seg_file_atoms.Item3.SelectByAltLoc().ToArray(); HDebug.Exception(chain_atoms.ListChainID().HToHashSet().Count == 1); if (segname == null) { while (segindex <= 9999) { if (segnames.Contains(segindex.ToString()) == false) { segname = segindex.ToString(); segnames.Add(segname); break; } segindex++; } } if (filename == null) { filename = segname; } Pdb.ToFile (filename + ".pdb" , chain_atoms.HToType <Pdb.IAtom, Pdb.Element>() , false ); for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains("$segname$")) { string insert = lines[i]; insert = insert.Replace("$segname$", segname); insert = insert.Replace("$segfilename$", filename); lines = lines.HInsert(i, insert); i++; } } } lines = lines.HRemoveAllContains("$segname$"); HFile.WriteAllLines("prot.inp", lines); string command0 = string.Format("psfgen < prot.inp"); bool pause = options.Contains("psfgen pause"); HProcess.StartAsBatchInConsole(null, pause, command0); psf_lines = System.IO.File.ReadLines("prot.psf").ToList(); pdb_lines = System.IO.File.ReadLines("prot.pdb").ToList(); } HEnvironment.CurrentDirectory = currpath; if (tmpdir != null) { try{ tmpdir.Delete(true); } catch {} } return(new CPsfgen { psf_lines = psf_lines, pdb_lines = pdb_lines, }); }
/// <summary> /// Connect to server /// </summary> /// <param name="login"></param> /// <param name="password"></param> /// <param name="options"></param> public void Connect(string login, string password, HOptions options) { this.Connect(login, password, options, null); }
/// <summary> /// Connect to server /// </summary> /// <param name="login">user jid i.e.(my_user@domain/resource)</param> /// <param name="password"></param> /// <param name="options"></param> /// <param name="context"></param> public void Connect(string login, string password, HOptions options, JObject context) { bool shouldConnect = false; bool connInprogress = false; bool disconnInprogress = false; this.options = new HOptions(options); if (this.connectionStatus == ConnectionStatus.DISCONNECTED) { shouldConnect = true; connectionStatus = ConnectionStatus.CONNECTING; } if (this.connectionStatus == ConnectionStatus.CONNECTING) { connInprogress = true; } if (this.connectionStatus == ConnectionStatus.DISCONNECTING) { disconnInprogress = true; } if (shouldConnect) { fillTransportOptions(login, password, options, context); if (options.GetTransport() == "socketio") { if (transport == null || !(transport is HTransportSocketIO)) { this.transport = new HTransportSocketIO(); } if (transportManager == null) { this.transportManager = new HTransportManager(this.transport); } if (!isEventHandlerAdded) { this.transportManager.onStatus = transport_onStatus; this.transportManager.onData = transport_onData; isEventHandlerAdded = true; } notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.NO_ERROR, null); this.transportManager.Connect(this.transportOptions); } } else { if (connInprogress) { notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.CONN_PROGRESS, null); } else if (disconnInprogress) { notifyStatus(ConnectionStatus.DISCONNECTING, ConnectionErrors.ALREADY_CONNECTED, null); } else { notifyStatus(ConnectionStatus.CONNECTED, ConnectionErrors.ALREADY_CONNECTED, null); } } }
public static CPsfgenExt PsfgenExt (IList <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms , string[] toplines , string[] parlines , Pdb alignto , string[] psfgen_lines , IList <string> minimize_conf_lines = null , HOptions options = null ) { if (options == null) { options = new HOptions((string)null); } string tempbase = @"C:\temp\"; string psfgen_workdir = null; string topname = "prot.top"; string parname = "prot.par"; List <string> psf_lines = null; List <string> pdb_lines = null; using (var temp = new HTempDirectory(tempbase, null)) { temp.EnterTemp(); HFile.WriteAllLines(topname, toplines); HFile.WriteAllLines(parname, parlines); if ((HFile.Exists("prot.pdb") == false) || (HFile.Exists("prot.psf") == false)) { var psfgen = Namd.RunPsfgen (lstSegFileAtoms, tempbase, null, "2.10" , new string[] { topname } , new string[] {} , topname , psfgen_lines: psfgen_lines , psfgen_workdir: psfgen_workdir , options: options ); psf_lines = psfgen.psf_lines; pdb_lines = psfgen.pdb_lines; if (alignto != null) { HDebug.Exception("check!!!"); //////////////////////////// Pdb prot = Pdb.FromLines(pdb_lines); prot = PsfgenExt_AlignTo(prot, alignto); pdb_lines = prot.ToLines().ToList(); } HFile.WriteAllLines("prot.pdb", pdb_lines); HFile.WriteAllLines("prot.psf", psf_lines); } if (options.Contains("nomin") == false) { if ((HFile.Exists("protmin.coor") == false) || (HFile.Exists("protmin.pdb") == false)) { List <string> psfgen_pdb_lines = System.IO.File.ReadLines("prot.pdb").ToList(); List <string> psfgen_psf_lines = System.IO.File.ReadLines("prot.psf").ToList(); List <string> prm_lines = System.IO.File.ReadLines(parname).ToList(); string Namd2_opt = null; if (options.HSelectStartsWith("minimize option:").Length >= 1) { Namd2_opt = options.HSelectStartsWith("minimize option:").First().Replace("minimize option:", ""); } var minpdb = Namd.Run.Namd2 (psfgen_pdb_lines , psfgen_psf_lines , prm_lines , tempbase , "2.10" , ((Namd2_opt == null) ? "+p3" : Namd2_opt) , conf_lines: minimize_conf_lines ); HFile.WriteAllLines("protmin.coor", minpdb.coor_lines); Pdb prot0 = Pdb.FromLines(psfgen_pdb_lines); Pdb prot1 = Pdb.FromLines(minpdb.coor_lines); HDebug.Exception(prot0.atoms.Length == prot1.atoms.Length); HDebug.Exception(prot0.elements.Length == prot1.elements.Length); // update conformation to minimized conformation for (int i = 0; i < prot0.elements.Length; i++) { if (prot0.elements[i].GetType() != prot1.elements[i].GetType()) { throw new HException("prot0.elements[i].GetType() != prot1.elements[i].GetType()"); } if ((prot0.elements[i] is Pdb.IAtom) == false) { continue; } Pdb.IAtom iatom0 = prot0.elements[i] as Pdb.IAtom; Pdb.IAtom iatom1 = prot1.elements[i] as Pdb.IAtom; Vector coord0 = iatom0.coord; Vector coord1 = iatom1.coord; double dist = (coord0 - coord1).Dist; if (iatom0.occupancy != 0) { if (dist != 0) { throw new HException("iatom0.coord - iatom1.coord != 0"); } } if (dist != 0) { if (iatom0 is Pdb.Atom) { string nline0 = (iatom0 as Pdb.Atom).GetUpdatedLine(coord1); Pdb.Atom natom0 = Pdb.Atom.FromString(nline0); prot0.elements[i] = natom0; continue; } if (iatom0 is Pdb.Hetatm) { string nline0 = (iatom0 as Pdb.Hetatm).GetUpdatedLine(coord1); Pdb.Hetatm natom0 = Pdb.Hetatm.FromString(nline0); prot0.elements[i] = natom0; continue; } } } if ((prot0.elements[0] is Pdb.Remark) && (prot1.elements[0] is Pdb.Remark)) { prot0.elements[0] = Pdb.Remark.FromString(prot1.elements[0].line); } prot0.ToFile("protmin.pdb"); pdb_lines = System.IO.File.ReadLines("protmin.pdb").ToList(); } } //{ // Pdb confpdb = GetConfPdb(options); // var psf = Namd.Psf.FromFile("prot.psf"); // var prm = Namd.Prm.FromFile(parname); // List<string> log = new List<string>(); // Universe univ = Universe.BuilderNamd.Build(psf, prm, confpdb, true, new TextLogger(log)); // return univ; //} temp.QuitTemp(); } return(new CPsfgenExt { psflines = psf_lines, pdblines = pdb_lines, }); }