Esempio n. 1
0
        public static ProteinStructure GetInstance(string pdbFilename)
        {
            List <Dictionary <int, Residue> > residues = new List <Dictionary <int, Residue> >();

            string line;
            int    currentModel = -1;
            bool   onlyOneModel = false;

            using (TextReader reader = Bio.Util.FileUtils.OpenTextStripComments(pdbFilename))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("MODEL"))
                    {
                        Helper.CheckCondition(!onlyOneModel, "Thought we wouldn't see any of these for this particular file.");
                        currentModel = int.Parse(line.Substring(10, 4).Trim());
                        residues.Add(new Dictionary <int, Residue>());
                    }
                    if (line.StartsWith("ATOM"))
                    {
                        if (currentModel < 0)
                        {
                            currentModel = 1;
                            residues.Add(new Dictionary <int, Residue>());
                            onlyOneModel = true;
                        }
                        Atom atom = Atom.GetInstance(line);

                        if (!residues[currentModel - 1].ContainsKey(atom.Position))
                        {
                            residues[currentModel - 1].Add(atom.Position, Residue.GetInstance(atom.Position, atom.ResidueName));
                        }
                        residues[currentModel - 1][atom.Position].AddAtom(atom);
                    }
                }
            }

            return(new ProteinStructure(residues));
        }