Example #1
0
        /// <summary>
        /// write the interactive chains into a pdb formated text file
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="interChains"></param>
        public string WriteBiolUnitFile(string pdbId, string buId, Dictionary <string, AtomInfo[]> buChains, string destDir, DataTable asuInfoTable, string type)
        {
            string       fileName   = Path.Combine(destDir, pdbId + "_" + buId + "." + type);
            FileStream   fileStream = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);
            string       header     = "HEADER    " + pdbId + "                    " + DateTime.Today;

            fileWriter.WriteLine(header);

            List <string> chainSymOpList = new List <string> (buChains.Keys);

            chainSymOpList.Sort();
            string[] chainSymOpStrs = new string[chainSymOpList.Count];
            chainSymOpList.CopyTo(chainSymOpStrs);
            //       string[] chainSymOpStrs = SortChainSymOpList(chainSymOpList);

            Dictionary <string, string> asymPolymerTypeHash = GetAsymChainPolymerTypeHash(asuInfoTable);
            string chainRemarkString = GetChainComponentRemarkString(chainSymOpStrs, asuInfoTable, type);

            fileWriter.WriteLine(chainRemarkString);

            bool isChainLigand = false;
            int  atomId        = 0;
            int  count         = 0;

            try
            {
                string preSymOpNum = "0";
                foreach (string chain in chainSymOpStrs)
                {
                    string[] fields   = chain.Split('_');
                    string   symOpNum = fields[1];
                    if (preSymOpNum != symOpNum)
                    {
                        atomId = 0;
                    }
                    isChainLigand = IsChainLigand(fields[0], asymPolymerTypeHash);
                    ChainAtoms buChain = new ChainAtoms();
                    buChain.CartnAtoms = (AtomInfo[])buChains[chain];
                    buChain.SortByAtomId();
                    string chainId = letters[count % letters.Length].ToString();
                    WriteOneChain(buChain.CartnAtoms, chainId, ref atomId, isChainLigand, fileWriter);
                    count++;
                    preSymOpNum = symOpNum;
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
            return(fileName);
        }
Example #2
0
        /// <summary>
        /// write the interactive chains into a pdb formated text file
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="interChains"></param>
        public string WriteBiolUnitFile(string pdbId, string buId, Dictionary <string, AtomInfo[]> buChains, string destDir, string remark, string type)
        {
            string       fileName   = Path.Combine(destDir, pdbId + "_" + buId + "." + type);
            FileStream   fileStream = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);
            string       header     = "HEADER    " + pdbId + "                    " + DateTime.Today;

            fileWriter.WriteLine(header);
            fileWriter.WriteLine(remark);

            List <string> chainSymOpList = new List <string> (buChains.Keys);

            string[] chainSymOpStrs = SortChainSymOpList(chainSymOpList);

            int atomId = 0;
            int count  = 0;

            try
            {
                string preSymOpNum = "0";
                foreach (string chain in chainSymOpStrs)
                {
                    string[] fields   = chain.Split('_');
                    string   symOpNum = fields[1];
                    if (preSymOpNum != symOpNum)
                    {
                        atomId = 0;
                    }
                    ChainAtoms buChain = new ChainAtoms();
                    buChain.CartnAtoms = (AtomInfo[])buChains[chain];
                    buChain.SortByAtomId();
                    string chainId = letters[count % letters.Length].ToString();
                    WriteOneChain(buChain.CartnAtoms, chainId, ref atomId, fileWriter);
                    count++;
                    preSymOpNum = symOpNum;
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
            return(fileName);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="asuChains"></param>
        /// <param name="destDir"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public string WriteAsymUnitFile(string pdbId, Dictionary <string, AtomInfo[]> asuChainsHash, string[] asymChainsInOrder,
                                        string[] fileChainsInOrder, string[] nonpolymerAsymChains, string destDir, string remark)
        {
            string       fileName   = Path.Combine(destDir, pdbId + ".ent");
            FileStream   fileStream = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);
            string       header     = "HEADER    " + pdbId + "                    " + DateTime.Today;

            fileWriter.WriteLine(header);
            fileWriter.WriteLine(remark);

            int    atomId          = 0;
            int    chainCount      = 0;
            string fileChain       = "";
            bool   nonpolymerChain = false;

            try
            {
                foreach (string asymChain in asymChainsInOrder)
                {
                    nonpolymerChain = false;
                    ChainAtoms asuChain = new ChainAtoms();
                    asuChain.CartnAtoms = asuChainsHash[asymChain];
                    asuChain.SortByAtomId();
                    fileChain = fileChainsInOrder[chainCount];
                    if (Array.IndexOf(nonpolymerAsymChains, asymChain) > -1)
                    {
                        nonpolymerChain = true;
                    }
                    WriteOneChain(asuChain.CartnAtoms, fileChain, ref atomId, nonpolymerChain, fileWriter);
                    chainCount++;
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
            return(fileName);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="asuChains"></param>
        /// <param name="destDir"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public void WriteAsymUnitFile(string coordFileName, Dictionary <string, AtomInfo[]> asuChainsHash, string[] asymChainsInOrder, string[] fileChainsInOrder, string[] hetChains, string remark)
        {
            FileStream   fileStream = new FileStream(coordFileName, FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);

            fileWriter.WriteLine(remark);

            int    atomId        = 0;
            int    chainCount    = 0;
            string fileChain     = "";
            bool   isHetatmChain = false;

            try
            {
                foreach (string asymChain in asymChainsInOrder)
                {
                    isHetatmChain = false;
                    if (asuChainsHash.ContainsKey(asymChain))
                    {
                        ChainAtoms asuChain = new ChainAtoms();
                        asuChain.CartnAtoms = asuChainsHash[asymChain];
                        asuChain.SortByAtomId();
                        fileChain = fileChainsInOrder[chainCount];
                        if (Array.IndexOf(hetChains, asymChain) > -1)
                        {
                            isHetatmChain = true;
                        }
                        WriteOneChain(asuChain.CartnAtoms, fileChain, ref atomId, isHetatmChain, fileWriter);
                        chainCount++;
                    }
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="asuChains"></param>
        /// <param name="destDir"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public string WriteAsymUnitFile(string pdbId, Dictionary <string, AtomInfo[]> asuChainsHash, string destDir, string remark)
        {
            string       fileName   = Path.Combine(destDir, pdbId + ".ent");
            FileStream   fileStream = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);
            string       header     = "HEADER    " + pdbId + "                    " + DateTime.Today;

            fileWriter.WriteLine(header);
            fileWriter.WriteLine(remark);

            List <string> asymChainList = new List <string>(asuChainsHash.Keys);

            asymChainList.Sort();
            int atomId = 0;

            try
            {
                foreach (string asymChain in asymChainList)
                {
                    ChainAtoms asuChain = new ChainAtoms();
                    asuChain.CartnAtoms = asuChainsHash[asymChain];
                    asuChain.SortByAtomId();
                    WriteOneChain(asuChain.CartnAtoms, asymChain, ref atomId, fileWriter);
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
            return(fileName);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="pdbId"></param>
        /// <param name="chainAtomsHash"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public string WriteAtoms(string fileName, string pdbId, Dictionary <string, AtomInfo[]> chainAtomsHash, string remark)
        {
            FileStream   fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);
            string       header     = "Header    " + pdbId.ToString() + "      " + DateTime.Today.ToShortDateString();

            fileWriter.WriteLine(header);
            fileWriter.WriteLine(remark);

            List <string> asymChainList = new List <string> (chainAtomsHash.Keys);

            asymChainList.Sort();
            int atomId = 0;

            try
            {
                foreach (string asymChain in asymChainList)
                {
                    ChainAtoms asuChain = new ChainAtoms();
                    asuChain.CartnAtoms = (AtomInfo[])chainAtomsHash[asymChain];
                    asuChain.SortByAtomId();
                    WriteOneChain(asuChain.CartnAtoms, asymChain, ref atomId, fileWriter);
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
            return(fileName);
        }
Example #7
0
        /// <summary>
        /// write the interactive chains into a pdb formated text file
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="interChains"></param>
        public string WriteBiolUnitFile(string pdbId, string buId, Dictionary <string, AtomInfo[]> buChains, string destDir,
                                        CrystalInfo cryst1, Matrix fractMatrix)
        {
            string       fileName   = Path.Combine(destDir, pdbId + "_" + buId.ToString() + ".pdb");
            FileStream   fileStream = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write);
            StreamWriter fileWriter = new StreamWriter(fileStream);
            string       header     = "HEADER    " + pdbId + "                    " + DateTime.Today;

            fileWriter.WriteLine(header);
            string        remark         = "REMARK 290 ";
            int           count          = 0;
            List <string> chainSymOpList = new List <string> (buChains.Keys);

            string[] chainSymOpStrs = SortChainSymOpList(chainSymOpList);
            foreach (string chainAndSymOpStr in chainSymOpStrs)
            {
                string thisRemark = remark + letters[count].ToString() + ": ";
                // format of chainAndSymOpStr: chain_symOpNum_fullsymString
                string[] fields = chainAndSymOpStr.Split('_');
                thisRemark += fields[0].PadRight(3, ' ');
                thisRemark += fields[1].PadRight(3, ' ');
                thisRemark += fields[2].PadRight(30, ' ');
                fileWriter.WriteLine(thisRemark);
                count++;
            }
            string crystString = FormatCrystString(cryst1);
            string fractString = FormatFractString(fractMatrix);

            fileWriter.WriteLine(crystString);
            fileWriter.WriteLine(fractString);


            int atomId = 0;

            count = 0;
            try
            {
                string preSymOpNum = "0";
                foreach (string chain in chainSymOpStrs)
                {
                    string[] fields   = chain.Split('_');
                    string   symOpNum = fields[1];
                    if (preSymOpNum != symOpNum)
                    {
                        atomId = 0;
                    }
                    ChainAtoms buChain = new ChainAtoms();
                    buChain.CartnAtoms = (AtomInfo[])buChains[chain];
                    buChain.SortByAtomId();
                    string chainId = letters[count % letters.Length].ToString();
                    WriteOneChain(buChain.CartnAtoms, chainId, ref atomId, fileWriter);
                    count++;
                    preSymOpNum = symOpNum;
                }
                fileWriter.WriteLine("END");
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message;
                throw ex;
            }
            finally
            {
                fileWriter.Close();
            }
            return(fileName);
        }