2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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) ? "PDBFILE" : inFile.getName();
61 chains = new Vector();
65 boolean modelFlag = false;
66 boolean terFlag = false;
69 while ((line = nextLine()) != null)
71 if (line.indexOf("HEADER") == 0)
73 id = line.substring(62, 67).trim();
76 // Were we to do anything with SEQRES - we start it here
77 if (line.indexOf("SEQRES") == 0)
81 if (line.indexOf("MODEL") == 0)
86 if (line.indexOf("TER") == 0)
91 if (modelFlag && line.indexOf("ENDMDL") == 0)
95 if (line.indexOf("ATOM") == 0
96 || (line.indexOf("HETATM") == 0 && !terFlag))
100 // Jalview is only interested in CA bonds????
101 if (!line.substring(12, 15).trim().equals("CA"))
106 Atom tmpatom = new Atom(line);
107 tmpchain = findChain(tmpatom.chain);
108 if (tmpchain != null)
110 tmpchain.atoms.addElement(tmpatom);
114 tmpchain = new PDBChain(id, tmpatom.chain);
115 chains.addElement(tmpchain);
116 tmpchain.atoms.addElement(tmpatom);
127 id = inFile.getName();
129 for (int i = 0; i < chains.size(); i++)
131 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
132 dataset.setName(id + "|" + dataset.getName());
133 PDBEntry entry = new PDBEntry();
137 entry.setFile(inFile.getAbsolutePath());
139 dataset.addPDBId(entry);
140 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
141 // maintain reference to
143 seqs.addElement(chainseq);
144 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
145 if (chainannot != null)
147 for (int ai = 0; ai < chainannot.length; ai++)
149 chainannot[ai].visible = VisibleChainAnnotation;
150 annotations.addElement(chainannot[ai]);
154 } catch (OutOfMemoryError er)
156 System.out.println("OUT OF MEMORY LOADING PDB FILE");
157 throw new IOException("Out of memory loading PDB File");
161 public void makeResidueList()
163 for (int i = 0; i < chains.size(); i++)
165 ((PDBChain) chains.elementAt(i)).makeResidueList();
169 public void makeCaBondList()
171 for (int i = 0; i < chains.size(); i++)
173 ((PDBChain) chains.elementAt(i)).makeCaBondList();
177 public PDBChain findChain(String id)
179 for (int i = 0; i < chains.size(); i++)
181 if (((PDBChain) chains.elementAt(i)).id.equals(id))
183 return (PDBChain) chains.elementAt(i);
190 public void setChargeColours()
192 for (int i = 0; i < chains.size(); i++)
194 ((PDBChain) chains.elementAt(i)).setChargeColours();
198 public void setColours(jalview.schemes.ColourSchemeI cs)
200 for (int i = 0; i < chains.size(); i++)
202 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
206 public void setChainColours()
208 for (int i = 0; i < chains.size(); i++)
210 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
211 1.0f / (float) i, .4f, 1.0f));