Example #1
0
        public static SBarrel runSolBarrel(string pdb, ref Dictionary <string, AminoAcid> _aaDict, ref Dictionary <Tuple <string, string>, double> partialChargesDict)
        {
            Directory.SetCurrentDirectory(Global.SOL_DB_DIR);

            string fileName2 = pdb + ".pdb";

            Console.WriteLine("opened {0}", fileName2);
            AtomParser.AtomCategory myAtomCat = new AtomParser.AtomCategory();
            myAtomCat = readPdbFile(fileName2, ref partialChargesDict);

            string pdbName = pdb.Substring(0, 4).ToUpper();

            int chainNum = 0;
            //if (pdbName == "3RFZ" || pdbName == "3KVN") chainNum = 1;

            int stop = myAtomCat.ChainAtomList.Count();

            Console.Write("Protein Class {0}", chainNum);

            Protein newProt = new MonoProtein(ref myAtomCat, chainNum, pdbName);

            //Console.WriteLine("ChainNum {0}", chainNum);

            Console.Write("creating barrel class..");

            SBarrel myBarrel = new SBarrel(newProt.Chains[0], newProt);

            return(myBarrel);
        }
Example #2
0
        public static Barrel runBetaBarrel(string pdb, ref Dictionary <string, AminoAcid> _aaDict, ref Dictionary <Tuple <string, string>, double> partialChargesDict)
        {
            Directory.SetCurrentDirectory(Global.MONO_DB_DIR);

            string PDB         = pdb.Substring(0, 4).ToUpper();
            string pdbFileName = PDB + ".pdb";

            AtomParser.AtomCategory myAtomCat = new AtomParser.AtomCategory();

            if (File.Exists(pdbFileName))
            {
                Console.WriteLine("opened {0}", pdbFileName);
                myAtomCat = readPdbFile(pdbFileName, ref Global.partialChargesDict);
            }

            int chainNum = 0;

            int stop = myAtomCat.ChainAtomList.Count();

            Console.Write("Protein Class {0}", chainNum);

            Protein newProt = new MonoProtein(ref myAtomCat, chainNum, PDB);

            Console.Write("creating barrel class..");

            Barrel myBarrel = new MonoBarrel(newProt.Chains[0], newProt);

            return(myBarrel);
        }
Example #3
0
/// <summary>
/// added this function myself .... so that atomCat can be referenced elsewhere
/// </summary>
/// <param name="thisXmlFile"></param>
/// <param name="atomType"></param>
/// <param name="PassedAtomCat"></param>
        public void ParseXmlFileAndPassStorage(string thisXmlFile, string atomType, ref AtomCategory PassedAtomCat)
        {
            int xmlIndex = thisXmlFile.LastIndexOf("\\");
            // 4 character for Pdb entry ID
            string pdbId = thisXmlFile.Substring(xmlIndex + 1, 4);

            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(thisXmlFile);
                // Create an XmlNamespaceManager for resolving namespaces.
                XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable);

                string xmlNameSpace = xmlDoc.DocumentElement.Attributes["xmlns:PDBx"].InnerText;

                nsManager.AddNamespace("PDBx", xmlNameSpace);

                Hashtable entityPolyTypeHash = new Hashtable();

                // Parse atom
                //ParseAtoms(ref xmlDoc, ref entryCrystal.atomCat, ref nsManager, entityPolyTypeHash, atomType);
                ParseAtoms(ref xmlDoc, ref PassedAtomCat, ref nsManager, entityPolyTypeHash, atomType);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Parse {0} Errors: {1}", pdbId, ex.Message));
            }
        }
Example #4
0
        public string WriteFromAtomCategory(string _pdbId, string _chainId, AtomCategory _atomCategoryToPrint, string _pathToOutput)
        {
            ChainAtoms[] myChainAtomsArray = _atomCategoryToPrint.ChainAtomList;

            string emptyString = "dakj";

            return(emptyString);
        }
Example #5
0
        public AllProtein(ref AtomParser.AtomCategory _myAtomCat, string PdbName)
        {
            this.Chains      = new List <BarrelStructures.Chain>();
            this.ChainCount  = 0;
            this.totalResNum = 0;
            this.PdbName     = PdbName;

            AtomParser.AtomCategory myAtomCat = new AtomParser.AtomCategory();
            myAtomCat = _myAtomCat;

            var chainNumList = new Dictionary <int, int>();

            for (int chainNum = 0; chainNum < myAtomCat.chainAtomsList.Count; chainNum++)
            {
                bool IsItProtein = false;
                for (int atomNum = 0; atomNum < myAtomCat.ChainAtomList[chainNum].cartnAtoms.Count; atomNum++)
                {
                    if (myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomNum].atomName == "CA")
                    {
                        IsItProtein = true;
                    }
                }
                if (IsItProtein == true)
                {
                    BarrelStructures.Chain myChain = new BarrelStructures.Chain(ref myAtomCat, chainNum, PdbName, false, Global.DB_DIR, true);
                    this.Chains.Add(myChain);
                    chainNumList.Add(ChainCount, chainNum);
                    this.ChainCount++;
                }
            }

            this.Chains.Sort((x, y) => x.ChainName.CompareTo(y.ChainName)); //This sorts chains by letter
            for (int i = 0; i < this.ChainCount; i++)
            {
                this.Chains[i].ChainNum = i;
                foreach (Res res in this.Chains[i].Residues)
                {
                    res.ChainNum = i;
                }
            }
        }
Example #6
0
        public static PolyBarrel runPBetaBarrel(string pdb, ref Dictionary <string, AminoAcid> _aaDict)
        {
            Directory.SetCurrentDirectory(Global.POLY_DB_DIR);

            string pdbFileName = pdb + ".pdb";

            AtomParser.AtomCategory myAtomCat = new AtomParser.AtomCategory();

            if (File.Exists(pdbFileName))
            {
                Console.WriteLine("opened {0}", pdbFileName);
                myAtomCat = readPdbFile(pdbFileName, ref Global.partialChargesDict);
            }

            PolyProtein newProt = new PolyProtein(ref myAtomCat, pdb); //For considering all chains

            Console.WriteLine("creating barrel class..");

            PolyBarrel myBarrel = new PolyBarrel(newProt, Global.POLY_OUTPUT_DIR, Global.POLY_DB_DIR);

            return(myBarrel);
        }
Example #7
0
        public static void run()
        {
            /*string head = Global.DB_DIR;
             * head = "U:\\v5\\pdb_files";
             * string tail = ".pdb";
             * Console.WriteLine("head: " + head);
             * Console.WriteLine("tail: " + tail);
             * String[] files = Directory.GetFiles(head);
             */
            string fileOfPDBs = "U:/v4/MonoDBList_v4_85.txt";

            string[]      pdb_files;
            List <String> files = new List <String>();

            if (File.Exists(fileOfPDBs))
            {
                using (StreamReader sr = new StreamReader(fileOfPDBs))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        files.Add(line);
                    }
                }
            }
            foreach (String f in files)
            {
                //Console.Write(f);


                Protein m_Protein = null;
                Barrel  m_Barrel  = null;
                AtomParser.AtomCategory myAtomCat = new AtomParser.AtomCategory();
                ////Console.WriteLine("opened {0}", pdbFileName);
                try
                {
                    string head    = Global.DB_DIR;
                    string pattern = f + "*";
                    pdb_files = Directory.GetFiles(head, pattern);
                    //Console.WriteLine(pdb_files);
                    string pdb_file = pdb_files[0];

                    string pdb = f;

                    myAtomCat = Program.readPdbFile(pdb_file, ref Global.partialChargesDict);
                    int chainNum = 0;

                    int stop = myAtomCat.ChainAtomList.Count();
                    ////Console.Write("Protein Class {0}", chainNum);


                    Console.WriteLine(pdb_file);
                    m_Protein = new MonoProtein(ref myAtomCat, chainNum, pdb);

                    ////Console.Write("creating barrel class..");

                    m_Barrel = new MonoBarrel(m_Protein.Chains[0], m_Protein);



                    SharedFunctions.writePymolScriptForStrands(m_Barrel.Strands, Global.OUTPUT_DIR, Global.DB_DIR, pdb);
                }

                catch (Exception e)
                {
                }
            }
        }
Example #8
0
        public static void runThisBetaBarrel(string pdb, string method, ref Barrel ThisBarrel, ref Protein newProt)
        {
            string PDB         = pdb.Substring(0, 4).ToUpper();
            string pdbFileName = Global.DB_DIR + pdb + ".pdb";

            if (File.Exists(pdbFileName))
            {
                AtomParser.AtomCategory myAtomCat = new AtomParser.AtomCategory();
                //Console.WriteLine("opened {0}", pdbFileName);
                myAtomCat = Program.ReadPdbFile(pdbFileName, ref Global.partialChargesDict);
                Console.WriteLine("\nAttempting {0}", pdb);
                // use poly method
                if ("poly" == method)
                {
                    try
                    {
                        Console.WriteLine("Generating poly protein");
                        Poly.PolyProtein newPolyProt = new Poly.PolyProtein(ref myAtomCat, pdb);
                        Console.WriteLine("Generating poly barrel");
                        ThisBarrel = new Poly.PolyBarrel(ref newPolyProt);
                        newProt    = newPolyProt;
                    }
                    catch
                    {
                        Console.WriteLine("Failed to run {0} using the poly methods\n", pdb);
                    }
                }
                // use all method
                else if ("all" == method)
                {
                    try //if (File.Exists(pdbFileName))
                    {
                        Console.WriteLine("all method for protein...");
                        newProt = new AllProtein(ref myAtomCat, PDB);
                        Console.WriteLine("all method for barrel...");
                        ThisBarrel = new AllBarrel(ref newProt);
                    }
                    catch
                    {
                        Console.WriteLine("Failed to run {0} using the all methods\n", pdb);
                    }
                }
                // default to mono method
                else //if ("mono" == method)
                {
                    try
                    {
                        Console.WriteLine("Generating mono protein");
                        newProt = new MonoProtein(ref myAtomCat, 0, PDB);
                        Console.WriteLine("Generating mono barrel");
                        ThisBarrel = new MonoBarrel(newProt.Chains[0], newProt);
                    }
                    catch
                    {
                        Console.WriteLine("Failed to run {0} using the mono methods\n", pdb);
                    }
                }
            }
            else
            {
                Console.WriteLine("could not find {0}", pdbFileName);
            }
        }
Example #9
0
        //constructor
        public Res(ref AtomParser.AtomCategory _myAtomCat, int chainNum, int resNum, int FirstAtomNum)
        {
            this.Neighbors          = new List <int>();
            this.Atoms              = new List <Atom>();
            this.SideChainNeighbors = new List <Res>();
            this.BackboneNeighbors  = new List <Res>();
            // the coordinates of this carbon alpha -coordinates of the previous carbon alpha
            this.Direction = new Vector3();
            // N C CA
            this.BackboneCoords = new Dictionary <string, Vector3>();


            this.SideChainDir = new Vector3();
            this.Z            = 999;
            this.ResNum       = resNum; //count of residues - residue index
            this.ChainNum     = chainNum;
            this.ChainName    = _myAtomCat.ChainAtomList[chainNum].AuthAsymChain;
            this.Twist_next   = 999;
            this.Twist_prev   = 999;
            this.Coil2        = 999;
            this.Coil1        = 999;
            this.Coil3        = 999;
            this.Tilt         = 999;
            this.Radius       = 999;
            this.SSType       = "X";
            this.StrandNum    = 99;
            this.ThreeLetCode = _myAtomCat.ChainAtomList[chainNum].CartnAtoms[FirstAtomNum].residue;
            if (this.ThreeLetCode == "MSE")
            {
                this.ThreeLetCode = "MET";
            }
            this.OneLetCode = threeToOne(ThreeLetCode);
            this.SeqID      = Convert.ToInt32(_myAtomCat.ChainAtomList[chainNum].CartnAtoms[FirstAtomNum].authSeqId); //formerly authSeqID; resnum in the PDB

            int atomctr = FirstAtomNum;

            while (_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].seqId == _myAtomCat.ChainAtomList[chainNum].CartnAtoms[FirstAtomNum].seqId)
            {
                Vector3 coords = new Vector3((float)_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].xyz.X, (float)_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].xyz.Y, (float)_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].xyz.Z);
                Atom    myAtom = new Atom(this.ThreeLetCode, coords, atomctr, _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName, _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomType);
                Atoms.Add(myAtom); //collect info from myAtomCat

                if (_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName == "CA" || _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName == "C" || _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName == "N" || _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName == "O")
                {
                    if (BackboneCoords.ContainsKey(_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName) != true)
                    {
                        this.BackboneCoords.Add(_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName, myAtom.Coords);
                    }
                    else
                    {
                        Console.WriteLine("IMPORTANT!!!!! Residue {0} atom {1} has multiple ocupancy", this.SeqID, _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName);
                    }
                }
                //Added 6-2-17 for loop purposes
                if (_myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].atomName == "CA")
                {
                    this.BFacCA = _myAtomCat.ChainAtomList[chainNum].CartnAtoms[atomctr].bFac;
                }

                atomctr++;
                if (atomctr >= _myAtomCat.ChainAtomList[chainNum].cartnAtoms.Count)
                {
                    break;
                }
            }

            //Added 5-9-16 to determine which direction sidechain is pointing from barrel; also sets the ResSeqID for using with neighbor functions
            foreach (Atom atom1 in this.Atoms)
            {
                atom1.ResSeqID = this.SeqID;
                if (atom1.AtomName == "CB" && this.ThreeLetCode != "Gly")
                {
                    this.SideChainDir = atom1.Coords - this.Atoms[1].Coords;
                    //Console.WriteLine("{0}\t{1}", this.ThreeLetCode, this.SideChainDir);
                }
                else if (this.ThreeLetCode == "Gly")
                {
                    this.SideChainDir = this.Atoms[2].Coords - this.Atoms[0].Coords;
                    //Console.WriteLine("{0}\t{1}", this.ThreeLetCode, this.SideChainDir);
                }
            }
            //Added 10-8-2020 to warn about reading in partially resolved residues
            if (this.Atoms.Count < 4)
            {
                Console.WriteLine("IMPORTANT!???! Residue {0} is partially resolved (missing at least C, O, N, or CA)", this.SeqID);
            }
        }
Example #10
0
        //parse one XML file
        public void ParseXmlFile(string thisXmlFile, string atomType)
        {
            int xmlIndex = thisXmlFile.LastIndexOf("\\");
            // 4 character for Pdb entry ID
            string pdbId = thisXmlFile.Substring(xmlIndex + 1, 4);

            // <PDBx:struct_biol_genCategory>
            // the category to generate the biological units
            // BuGenCategory buGenCat = new BuGenCategory ();

            // <PDBx:atom_siteCategory>
            // the coordinates of atoms,
            AtomCategory atomCat = new AtomCategory();

            // <PDBx:cellCategory>
            // the cystal1 record
            // CrystalInfo crystalInfo = new CrystalInfo ();

            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(thisXmlFile);
                // Create an XmlNamespaceManager for resolving namespaces.
                XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable);
                nsManager.AddNamespace("PDBx", "http://deposit.pdb.org/pdbML/pdbx.xsd");

                Hashtable entityPolyTypeHash = new Hashtable();

                // if there are protein chains, no, return
                ///// parse polymer type of an entity

                /*
                 *              bool hasProtein = false;
                 *              ParseEntityPolyCategory(ref xmlDoc, entityPolyTypeHash, ref nsManager, out hasProtein);
                 *              if (! hasProtein)
                 *              {
                 *                      entryCrystal = null;
                 *                      return ;
                 *              }
                 */

                ///////////////
                // parse atom_sitescategory <PDBx:fract_transf_matrix11>
                //ParseFractTransfMatrix(ref xmlDoc, ref entryCrystal.scaleCat, ref nsManager);

                //////////////
                // Parse Cryst1 record
                //ParseCryst1 (ref xmlDoc, ref entryCrystal.crystal1, ref nsManager);

                ///////////////
                // Parse PDBx:struct_biol_genCategory
                //ParseBuGenCategory(ref xmlDoc, ref entryCrystal.buGenCat, ref nsManager);

                ///////////////
                // Parse atom
                //ParseAtoms(ref xmlDoc, ref entryCrystal.atomCat, ref nsManager, entityPolyTypeHash, atomType);
                ParseAtoms(ref xmlDoc, ref atomCat, ref nsManager, entityPolyTypeHash, atomType);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Parse {0} Errors: {1}", pdbId, ex.Message));
            }
        }
Example #11
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);
            }
        }