2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 import jalview.datamodel.*;
29 extends jalview.io.AlignFile
34 public PDBfile(String inFile, String inType)
37 super(inFile, inType);
50 chains = new Vector();
54 boolean modelFlag = false;
55 boolean terFlag = false;
58 while ( (line = nextLine()) != null)
60 if (line.indexOf("HEADER") == 0)
62 id = line.substring(62, 67).trim();
65 // Were we to do anything with SEQRES - we start it here
66 if (line.indexOf("SEQRES") == 0)
70 if (line.indexOf("MODEL") == 0)
75 if (line.indexOf("TER") == 0)
80 if (modelFlag && line.indexOf("ENDMDL") == 0)
84 if (line.indexOf("ATOM") == 0
85 || (line.indexOf("HETATM") == 0 && !terFlag)
90 //Jalview is only interested in CA bonds????
91 if (!line.substring(12, 15).trim().equals("CA"))
96 Atom tmpatom = new Atom(line);
97 tmpchain = findChain(tmpatom.chain);
100 tmpchain.atoms.addElement(tmpatom);
104 tmpchain = new PDBChain(id, tmpatom.chain);
105 chains.addElement(tmpchain);
106 tmpchain.atoms.addElement(tmpatom);
117 id = inFile.getName();
119 for (int i = 0; i < chains.size(); i++)
121 SequenceI dataset = ( (PDBChain) chains.elementAt(i)).
123 dataset.setName(id + "|" + dataset.getName());
124 PDBEntry entry = new PDBEntry();
128 entry.setFile(inFile.getAbsolutePath());
130 dataset.addPDBId(entry);
131 getSeqs().addElement(dataset.deriveSequence()); // PDBChain objects maintain reference to dataset
134 catch (OutOfMemoryError er)
136 System.out.println("OUT OF MEMORY LOADING PDB FILE");
137 throw new IOException("Out of memory loading PDB File");
141 public void makeResidueList()
143 for (int i = 0; i < chains.size(); i++)
145 ( (PDBChain) chains.elementAt(i)).makeResidueList();
149 public void makeCaBondList()
151 for (int i = 0; i < chains.size(); i++)
153 ( (PDBChain) chains.elementAt(i)).makeCaBondList();
157 public PDBChain findChain(String id)
159 for (int i = 0; i < chains.size(); i++)
161 if ( ( (PDBChain) chains.elementAt(i)).id.equals(id))
163 return (PDBChain) chains.elementAt(i);
170 public void setChargeColours()
172 for (int i = 0; i < chains.size(); i++)
174 ( (PDBChain) chains.elementAt(i)).setChargeColours();
178 public void setColours(jalview.schemes.ColourSchemeI cs)
180 for (int i = 0; i < chains.size(); i++)
182 ( (PDBChain) chains.elementAt(i)).setChainColours(cs);
186 public void setChainColours()
188 for (int i = 0; i < chains.size(); i++)
190 ( (PDBChain) chains.elementAt(i)).setChainColours(
191 Color.getHSBColor(1.0f / (float) i, .4f, 1.0f)