2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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.*;
27 import jalview.io.FileParse;
29 public class PDBfile extends jalview.io.AlignFile
36 * set to true to add chain alignment annotation as visible annotation.
38 boolean VisibleChainAnnotation = false;
40 public PDBfile(String inFile, String inType) throws IOException
42 super(inFile, inType);
45 public PDBfile(FileParse source) throws IOException
55 public void parse() throws IOException
57 // TODO set the filename sensibly
58 id = (inFile == null || inFile.getName()==null || inFile.getName().length()==0) ? "PDBFILE" : inFile.getName();
61 chains = new Vector();
65 boolean modelFlag = false;
66 boolean terFlag = false;
71 while ((line = nextLine()) != null)
73 if (line.indexOf("HEADER") == 0)
78 if (line.length()>67) {
79 tid = line.substring(62, 67).trim();
81 tid=line.substring(62).trim();
90 // Were we to do anything with SEQRES - we start it here
91 if (line.indexOf("SEQRES") == 0)
95 if (line.indexOf("MODEL") == 0)
100 if (line.indexOf("TER") == 0)
105 if (modelFlag && line.indexOf("ENDMDL") == 0)
109 if (line.indexOf("ATOM") == 0
110 || (line.indexOf("HETATM") == 0 && !terFlag))
114 // Jalview is only interested in CA bonds????
115 atomnam = line.substring(12, 15).trim();
116 if (!atomnam.equals("CA") && !atomnam.equals("P"))
121 Atom tmpatom = new Atom(line);
122 tmpchain = findChain(tmpatom.chain);
123 if (tmpchain != null)
125 if (tmpatom.resNumIns.trim().equals(lastID))
127 // phosphorylated protein - seen both CA and P..
130 tmpchain.atoms.addElement(tmpatom);
134 tmpchain = new PDBChain(id, tmpatom.chain);
135 chains.addElement(tmpchain);
136 tmpchain.atoms.addElement(tmpatom);
138 lastID = tmpatom.resNumIns.trim();
148 id = inFile.getName();
150 for (int i = 0; i < chains.size(); i++)
152 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
153 dataset.setName(id + "|" + dataset.getName());
154 PDBEntry entry = new PDBEntry();
158 entry.setFile(inFile.getAbsolutePath());
160 dataset.addPDBId(entry);
161 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
162 // maintain reference to
164 seqs.addElement(chainseq);
165 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
166 if (chainannot != null)
168 for (int ai = 0; ai < chainannot.length; ai++)
170 chainannot[ai].visible = VisibleChainAnnotation;
171 annotations.addElement(chainannot[ai]);
175 } catch (OutOfMemoryError er)
177 System.out.println("OUT OF MEMORY LOADING PDB FILE");
178 throw new IOException("Out of memory loading PDB File");
182 public void makeResidueList()
184 for (int i = 0; i < chains.size(); i++)
186 ((PDBChain) chains.elementAt(i)).makeResidueList();
190 public void makeCaBondList()
192 for (int i = 0; i < chains.size(); i++)
194 ((PDBChain) chains.elementAt(i)).makeCaBondList();
198 public PDBChain findChain(String id)
200 for (int i = 0; i < chains.size(); i++)
202 if (((PDBChain) chains.elementAt(i)).id.equals(id))
204 return (PDBChain) chains.elementAt(i);
211 public void setChargeColours()
213 for (int i = 0; i < chains.size(); i++)
215 ((PDBChain) chains.elementAt(i)).setChargeColours();
219 public void setColours(jalview.schemes.ColourSchemeI cs)
221 for (int i = 0; i < chains.size(); i++)
223 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
227 public void setChainColours()
229 for (int i = 0; i < chains.size(); i++)
231 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
232 1.0f / (float) i, .4f, 1.0f));