示例#1
0
        /// <summary>
        /// sort chains by atom ID
        /// </summary>
        public void SortByAtomId()
        {
            if (cartnAtoms == null)
            {
                return;
            }
            AtomInfo[] chain   = this.CartnAtoms;
            Hashtable  seqHash = new Hashtable();

            foreach (AtomInfo atom in chain)
            {
                // sould have unique atom id
                seqHash.Add(atom.atomId, atom);
            }
            ArrayList atomIdList = new ArrayList(seqHash.Keys);

            atomIdList.Sort();
            AtomInfo[] sortedChain = new AtomInfo [chain.Length];
            int        count       = 0;

            foreach (object atomId in atomIdList)
            {
                sortedChain[count] = (AtomInfo)seqHash[atomId];
                count++;
            }
            this.CartnAtoms = sortedChain;
        }
示例#2
0
        /// <summary>
        /// c-beta and C-alpha atoms
        /// </summary>
        public AtomInfo[] CalphaCbetaAtoms()
        {
            ArrayList calphaCbetaList = new ArrayList();

            foreach (AtomInfo atom in cartnAtoms)
            {
                if (atom.atomName.ToUpper() == "CB" || atom.atomName.ToUpper() == "CA")
                {
                    calphaCbetaList.Add(new AtomInfo(atom));
                }
            }
            // for some PDB entries, there is only Calpha

            /*	if (calphaCbetaList.Count == 0)
             *      {
             *              foreach (AtomInfo atom in cartnAtoms)
             *              {
             *                      if (atom.atomName.ToUpper () == "CA")
             *                      {
             *                              calphaCbetaList.Add (new AtomInfo(atom));
             *                      }
             *              }
             *      }*/
            AtomInfo[] calphaCbetaArray = new AtomInfo [calphaCbetaList.Count];
            calphaCbetaList.CopyTo(calphaCbetaArray);
            return(calphaCbetaArray);
        }
示例#3
0
        /// <summary>
        /// deep copy every fields
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            // showdow copy
            AtomInfo clonedAtomInfo = (AtomInfo)this.MemberwiseClone();

            // deep copy fields with reference type
            clonedAtomInfo.xyz = new Coordinate(xyz.X, xyz.Y, xyz.Z);

            return(clonedAtomInfo);
        }
示例#4
0
        /// <summary>
        /// Writes a pdbline given an atom as input (for use for those residues with insertion codes)
        /// </summary>
        /// <param name="_inputAtom"></param>
        /// <param name="_atomCounter"></param>
        /// <param name="_newResi"></param>
        /// <param name="_newChain"></param>
        /// <param name="_insertionCode"></param>
        /// <returns></returns>
        public string WriteSingleLine(AtomInfo _inputAtom, int _atomCounter, string _newResi, string _newChain, string _insertionCode)
        {
            string line = "";

            line = "ATOM  ";
            string atomIdStr = _atomCounter.ToString();

            line += atomIdStr.PadLeft(5, ' ');
            line += " ";
            string atomName = _inputAtom.atomName;

            if (atomName != "" && _inputAtom.atomType != "H" && atomName.Length < 4)
            {
                atomName = " " + atomName;
            }
            line += atomName.PadRight(4, ' ');
            // next line was: line += " ";
            // replace by:
            if (_inputAtom.altConfID == "")
            {
                line += " ";
            }
            else
            {
                line += _inputAtom.altConfID;
            }
            // end of replace block
            line += _inputAtom.residue;
            line += " ";
            line += _newChain;
            //line += _inputAtom.seqId.PadLeft(4, ' ');
            line += _newResi.PadLeft(4, ' '); // replaces this line: line += _inputAtom.seqId.PadLeft(4, ' ');
            line += _insertionCode;
            line += "   ";
            line += FormatDoubleString(_inputAtom.xyz.X, 4, 3);
            line += FormatDoubleString(_inputAtom.xyz.Y, 4, 3);
            line += FormatDoubleString(_inputAtom.xyz.Z, 4, 3);
            // next line was: line += "  1.00"; (for dummy occupancy)
            // replace with:
            line += _inputAtom.occupancy.ToString("##0.00").PadLeft(6);
            // end of occupancy replace block

            // next line was: line += "  0.00"; (for dummy bfactor)
            // replace with:
            //string bFacString = _inputAtom.bFac.ToString("##0.00");
            line += _inputAtom.bFac.ToString("##0.00").PadLeft(6);
            // end of bfactor replace block
            line += "    "; // old version from QiFang
            //line += "           "; // version consistent with pdb
            line += _inputAtom.atomType;
            return(line);
        }
示例#5
0
        /// <summary>
        /// c-beta atoms
        /// </summary>
        public AtomInfo[] CbetaAtoms()
        {
            ArrayList cbetaList = new ArrayList();

            foreach (AtomInfo atom in cartnAtoms)
            {
                if (atom.atomName.ToUpper() == "CB")
                {
                    cbetaList.Add(new AtomInfo(atom));
                }
            }
            AtomInfo[] cbetaArray = new AtomInfo [cbetaList.Count];
            cbetaList.CopyTo(cbetaArray);
            return(cbetaArray);
        }
示例#6
0
 /// <summary>
 /// deep copy of external atom information
 /// </summary>
 /// <param name="extAtomInfo"></param>
 public AtomInfo(AtomInfo extAtomInfo)
 {
     this.residue       = extAtomInfo.residue;
     this.seqId         = extAtomInfo.seqId;     // FASTA id
     this.authSeqId     = extAtomInfo.authSeqId; // residue number by author
     this.atomId        = extAtomInfo.atomId;
     this.authResidue   = extAtomInfo.authResidue;
     this.xyz           = new Coordinate(extAtomInfo.xyz.X, extAtomInfo.xyz.Y, extAtomInfo.xyz.Z);
     this.atomName      = extAtomInfo.atomName;
     this.atomType      = extAtomInfo.atomType;
     this.bFac          = extAtomInfo.bFac;
     this.altConfID     = extAtomInfo.altConfID;
     this.occupancy     = extAtomInfo.occupancy;
     this.AuthAsymChain = extAtomInfo.AuthAsymChain;
     this.asymChain     = extAtomInfo.asymChain;
 }
示例#7
0
        public string WriteSingleLine(AtomInfo _inputAtom, int _atomCounter, string _chainId)
        {
            string line = "";

            line = "ATOM  ";
            string atomIdStr = _atomCounter.ToString();

            line += atomIdStr.PadLeft(5, ' ');
            line += " ";
            string atomName = _inputAtom.atomName;

            if (atomName != "" && _inputAtom.atomType != "H" && atomName.Length < 4)
            {
                atomName = " " + atomName;
            }
            line += atomName.PadRight(4, ' ');
            if (_inputAtom.altConfID == "")
            {
                line += " ";
            }
            else
            {
                line += _inputAtom.altConfID;
            }
            line += _inputAtom.residue;
            line += " ";
            line += _chainId;
            line += _inputAtom.seqId.PadLeft(4, ' ');
            line += "    ";
            line += FormatDoubleString(_inputAtom.xyz.X, 4, 3);
            line += FormatDoubleString(_inputAtom.xyz.Y, 4, 3);
            line += FormatDoubleString(_inputAtom.xyz.Z, 4, 3);
            // next line was: line += "  1.00"; (for dummy occupancy)
            // replace with:
            line += _inputAtom.occupancy.ToString("##0.00").PadLeft(6);
            // end of occupancy replace block

            // next line was: line += "  0.00"; (for dummy bfactor)
            // replace with:
            //string bFacString = _inputAtom.bFac.ToString("##0.00");
            line += _inputAtom.bFac.ToString("##0.00").PadLeft(6);
            // end of bfactor replace block
            line += "    ";
            line += _inputAtom.atomType;
            return(line);
        }
示例#8
0
        /// <summary>
        /// get backbone atoms
        /// </summary>
        public AtomInfo[] BackboneAtoms()
        {
            ArrayList backboneList = new ArrayList();

            foreach (AtomInfo atom in cartnAtoms)
            {
                if (atom.atomName == "CA" || atom.atomName == "N" ||
                    atom.atomName == "C" || atom.atomName == "O" || atom.atomName == "OXT")
                {
                    backboneList.Add(new AtomInfo(atom));
                }
            }

            AtomInfo[] backboneArray = new AtomInfo [backboneList.Count];
            backboneList.CopyTo(backboneArray);
            return(backboneArray);
        }
示例#9
0
 /// <summary>
 /// add an atom to the list
 /// </summary>
 /// <param name="atom"></param>
 /// <returns></returns>
 public int AddAtom(AtomInfo atom)
 {
     return(cartnAtoms.Add(atom));
 }
示例#10
0
        /// <summary>

        /// parse the coordinate of C alphas

        /// </summary>

        /// <param name="xmlDoc"></param>

        /// <param name="calphaInfoHash"></param>

        /// <param name="nsManager"></param>
        //private void ParseAtomsOld(ref XmlDocument xmlDoc, ref AtomCategory atomCat, ref XmlNamespaceManager nsManager,
        //     string retrievingAtomType)

        private void ParseAtoms(ref XmlDocument xmlDoc, ref AtomCategory atomCat, ref XmlNamespaceManager nsManager,
                                Hashtable entityPolyTypeHash, string retrievingAtomType)
        {
            XmlNodeList atomNodeList = xmlDoc.DocumentElement.SelectNodes("descendant::PDBx:atom_siteCategory/PDBx:atom_site", nsManager);

            int    atomId          = 0;
            string asymId          = "";
            string preAsymId       = "";
            string preAuthAsymId   = "";
            string authAsymId      = "";
            string preEntityId     = "";
            string preResidue      = "";
            string entityId        = "";
            string residue         = "";
            string authResidue     = "";
            string seqId           = "";
            string authSeqId       = "";
            double cartnX          = 0.0;
            double cartnY          = 0.0;
            double cartnZ          = 0.0;
            string atomType        = "-";
            string atomName        = "-";
            int    modelNum        = 1;
            int    heterResidueNum = 0;

            double Bfac = 0.0; // added this value here (BN)
            double res  = -1;  // added this value here (BN)
            double occ  = 0.0; // added this value here (BN) for occupancy

            // string polymerType = "";

            // find the resolution here-- added (BN)
            XmlNodeList resolutionNodes = xmlDoc.DocumentElement.SelectNodes("descendant::PDBx:refineCategory/PDBx:refine", nsManager);

            foreach (XmlNode resNode in resolutionNodes)             // this should only run once
            {
                XmlNodeList childNodes = resNode.ChildNodes;
                foreach (XmlNode refineNode in childNodes)
                {
                    if (refineNode.Name.ToLower().IndexOf("pdbx:ls_d_res_high") > -1)
                    {
                        if (refineNode.InnerText.ToString() != "")
                        {
                            string resString = refineNode.InnerText.ToString();
                            res = Convert.ToDouble(resString);
                            atomCat.Resolution = res;
                        }
                        break;
                    }
                }
            }
            string altConfID = ""; // added this value
            // xml tag called "B_iso_or_equiv"

            ChainAtoms chainAtoms   = new ChainAtoms();
            ArrayList  atomList     = new ArrayList();
            bool       isAtomNeeded = false;

            //Run through each atom
            foreach (XmlNode atomNode in atomNodeList)
            {
                isAtomNeeded = false;
                atomId       = System.Convert.ToInt32(atomNode.Attributes[0].InnerText.ToString());
                XmlNodeList atomInfoNodeList = atomNode.ChildNodes;

                //Go through each "child node" and define all properties for a single atom
                foreach (XmlNode atomInfoNode in atomInfoNodeList)
                {
                    if (atomInfoNode.Name.ToLower() == "pdbx:type_symbol")
                    {
                        atomType = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:label_atom_id")
                    {
                        atomName = atomInfoNode.InnerText;
                        //I think the if/elif sections will just pull out residues depending on the input of retrieving atom type, which is currently set to null
                        //This means that it always returns true
                        if (retrievingAtomType == "CA" || retrievingAtomType == "CB")
                        {
                            if (atomInfoNode.InnerText.ToUpper() != retrievingAtomType)
                            {
                                isAtomNeeded = false;
                                break;
                            }
                            else
                            {
                                isAtomNeeded = true;
                                continue;
                            }
                        }

                        else if (retrievingAtomType == "CA_CB")
                        {
                            if (atomInfoNode.InnerText.ToUpper() != "CA" &&
                                atomInfoNode.InnerText.ToUpper() != "CB")
                            {
                                isAtomNeeded = false;
                                break;
                            }
                            else
                            {
                                isAtomNeeded = true;
                                continue;
                            }
                        }
                        else
                        {
                            isAtomNeeded = true;
                        }
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:pdbx_pdb_model_num")
                    {
                        modelNum = Convert.ToInt16(atomInfoNode.InnerText);
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:label_comp_id")
                    {
                        residue = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:auth_comp_id")
                    {
                        authResidue = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:label_asym_id")
                    {
                        asymId = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower().IndexOf("pdbx:auth_asym_id") > -1)
                    {
                        authAsymId = atomInfoNode.InnerText.ToString();
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:label_entity_id")
                    {
                        entityId = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:label_seq_id")
                    {
                        seqId = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:auth_seq_id")
                    {
                        authSeqId = atomInfoNode.InnerText;
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:cartn_x")
                    {
                        cartnX = System.Convert.ToDouble(atomInfoNode.InnerText);
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:cartn_y")
                    {
                        cartnY = System.Convert.ToDouble(atomInfoNode.InnerText);
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:cartn_z")
                    {
                        cartnZ = System.Convert.ToDouble(atomInfoNode.InnerText);
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:b_iso_or_equiv")
                    {
                        Bfac = System.Convert.ToDouble(atomInfoNode.InnerText.ToString());
                        continue; //added: check
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:label_alt_id")
                    {
                        altConfID = atomInfoNode.InnerText.ToString();
                        continue;
                    }
                    if (atomInfoNode.Name.ToLower() == "pdbx:occupancy")
                    {
                        occ = System.Convert.ToDouble(atomInfoNode.InnerText.ToString());
                        continue;
                    }
                }

                //If this has crossed into the next chain, write previous residues to chain and start chain list over
                if (preAsymId != asymId && preAsymId != "" && atomList.Count > 0)
                {
                    chainAtoms.AsymChain     = preAsymId;
                    chainAtoms.AuthAsymChain = preAuthAsymId;
                    chainAtoms.EntityID      = preEntityId; // problem with int to string in new version
                    if (entityPolyTypeHash.ContainsKey(preEntityId))
                    {
                        chainAtoms.PolymerType = entityPolyTypeHash[preEntityId].ToString();
                    }
                    else
                    {
                        chainAtoms.PolymerType = "-";
                    }
                    AtomInfo[] atomArray = new AtomInfo[atomList.Count];
                    atomList.CopyTo(atomArray);
                    chainAtoms.CartnAtoms = atomArray;
                    atomCat.AddChainAtoms(chainAtoms);
                    atomList        = new ArrayList();
                    chainAtoms      = new ChainAtoms();
                    heterResidueNum = 0;
                    preResidue      = "";
                }

                if (modelNum > 1) // only pick up the model with model number 1
                {
                    break;
                }
                if (isAtomNeeded && residue.ToUpper() != "HOH")
                {
                    if (seqId == "")
                    {
                        if (preResidue != residue)
                        {
                            heterResidueNum++;
                        }
                        seqId = heterResidueNum.ToString();
                    }
                    AtomInfo atomInfo = new AtomInfo();
                    atomInfo.atomId      = atomId;
                    atomInfo.atomType    = atomType;
                    atomInfo.atomName    = atomName;
                    atomInfo.seqId       = seqId;
                    atomInfo.authSeqId   = authSeqId;
                    atomInfo.residue     = residue;
                    atomInfo.authResidue = authResidue;
                    atomInfo.xyz.X       = cartnX;
                    atomInfo.xyz.Y       = cartnY;
                    atomInfo.xyz.Z       = cartnZ;
                    atomInfo.bFac        = Bfac;
                    atomInfo.altConfID   = altConfID;
                    atomInfo.occupancy   = occ;

                    /* if (entityPolyTypeHash.ContainsKey(entityId))
                     * {
                     * polymerType = entityPolyTypeHash[entityId].ToString();
                     * }
                     * else
                     * {
                     * polymerType = "-";
                     * }
                     * atomCat.AddAtom(entityId, asymId, polymerType, atomInfo);*/
                    atomList.Add(atomInfo);
                }
                preAsymId     = asymId;
                preAuthAsymId = authAsymId;
                preEntityId   = entityId;
                preResidue    = residue;
            }
            // add the last one
            if (atomList.Count > 0)
            {
                chainAtoms.AsymChain     = asymId;
                chainAtoms.AuthAsymChain = authAsymId;
                chainAtoms.EntityID      = entityId;
                if (entityPolyTypeHash.ContainsKey(entityId))
                {
                    chainAtoms.PolymerType = entityPolyTypeHash[entityId].ToString();
                }
                else
                {
                    chainAtoms.PolymerType = "-";
                }
                AtomInfo[] atomArray = new AtomInfo[atomList.Count];
                atomList.CopyTo(atomArray);
                chainAtoms.CartnAtoms = atomArray;
                atomCat.AddChainAtoms(chainAtoms);
            }
        }