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) ? "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)
75 if (line.length()>67) {
76 id = line.substring(62, 67).trim();
78 id=line.substring(62).trim();
83 // Were we to do anything with SEQRES - we start it here
84 if (line.indexOf("SEQRES") == 0)
88 if (line.indexOf("MODEL") == 0)
93 if (line.indexOf("TER") == 0)
98 if (modelFlag && line.indexOf("ENDMDL") == 0)
102 if (line.indexOf("ATOM") == 0
103 || (line.indexOf("HETATM") == 0 && !terFlag))
107 // Jalview is only interested in CA bonds????
108 if (!line.substring(12, 15).trim().equals("CA"))
113 Atom tmpatom = new Atom(line);
114 tmpchain = findChain(tmpatom.chain);
115 if (tmpchain != null)
117 tmpchain.atoms.addElement(tmpatom);
121 tmpchain = new PDBChain(id, tmpatom.chain);
122 chains.addElement(tmpchain);
123 tmpchain.atoms.addElement(tmpatom);
134 id = inFile.getName();
136 for (int i = 0; i < chains.size(); i++)
138 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
139 dataset.setName(id + "|" + dataset.getName());
140 PDBEntry entry = new PDBEntry();
144 entry.setFile(inFile.getAbsolutePath());
146 dataset.addPDBId(entry);
147 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
148 // maintain reference to
150 seqs.addElement(chainseq);
151 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
152 if (chainannot != null)
154 for (int ai = 0; ai < chainannot.length; ai++)
156 chainannot[ai].visible = VisibleChainAnnotation;
157 annotations.addElement(chainannot[ai]);
161 } catch (OutOfMemoryError er)
163 System.out.println("OUT OF MEMORY LOADING PDB FILE");
164 throw new IOException("Out of memory loading PDB File");
168 public void makeResidueList()
170 for (int i = 0; i < chains.size(); i++)
172 ((PDBChain) chains.elementAt(i)).makeResidueList();
176 public void makeCaBondList()
178 for (int i = 0; i < chains.size(); i++)
180 ((PDBChain) chains.elementAt(i)).makeCaBondList();
184 public PDBChain findChain(String id)
186 for (int i = 0; i < chains.size(); i++)
188 if (((PDBChain) chains.elementAt(i)).id.equals(id))
190 return (PDBChain) chains.elementAt(i);
197 public void setChargeColours()
199 for (int i = 0; i < chains.size(); i++)
201 ((PDBChain) chains.elementAt(i)).setChargeColours();
205 public void setColours(jalview.schemes.ColourSchemeI cs)
207 for (int i = 0; i < chains.size(); i++)
209 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
213 public void setChainColours()
215 for (int i = 0; i < chains.size(); i++)
217 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
218 1.0f / (float) i, .4f, 1.0f));