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
35 * set to true to add chain alignment annotation as visible annotation.
37 boolean VisibleChainAnnotation=false;
38 public PDBfile(String inFile, String inType)
41 super(inFile, inType);
52 // TODO set the filename sensibly
53 id = (inFile==null) ? "PDBFILE" : inFile.getName();
56 chains = new Vector();
60 boolean modelFlag = false;
61 boolean terFlag = false;
64 while ( (line = nextLine()) != null)
66 if (line.indexOf("HEADER") == 0)
68 id = line.substring(62, 67).trim();
71 // Were we to do anything with SEQRES - we start it here
72 if (line.indexOf("SEQRES") == 0)
76 if (line.indexOf("MODEL") == 0)
81 if (line.indexOf("TER") == 0)
86 if (modelFlag && line.indexOf("ENDMDL") == 0)
90 if (line.indexOf("ATOM") == 0
91 || (line.indexOf("HETATM") == 0 && !terFlag)
96 //Jalview is only interested in CA bonds????
97 if (!line.substring(12, 15).trim().equals("CA"))
102 Atom tmpatom = new Atom(line);
103 tmpchain = findChain(tmpatom.chain);
104 if (tmpchain != null)
106 tmpchain.atoms.addElement(tmpatom);
110 tmpchain = new PDBChain(id, tmpatom.chain);
111 chains.addElement(tmpchain);
112 tmpchain.atoms.addElement(tmpatom);
123 id = inFile.getName();
125 for (int i = 0; i < chains.size(); i++)
127 SequenceI dataset = ( (PDBChain) chains.elementAt(i)).
129 dataset.setName(id + "|" + dataset.getName());
130 PDBEntry entry = new PDBEntry();
134 entry.setFile(inFile.getAbsolutePath());
136 dataset.addPDBId(entry);
137 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects maintain reference to dataset
138 seqs.addElement(chainseq);
139 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
140 if (chainannot!=null)
142 for (int ai=0; ai<chainannot.length; ai++)
144 chainannot[ai].visible=VisibleChainAnnotation;
145 annotations.addElement(chainannot[ai]);
150 catch (OutOfMemoryError er)
152 System.out.println("OUT OF MEMORY LOADING PDB FILE");
153 throw new IOException("Out of memory loading PDB File");
157 public void makeResidueList()
159 for (int i = 0; i < chains.size(); i++)
161 ( (PDBChain) chains.elementAt(i)).makeResidueList();
165 public void makeCaBondList()
167 for (int i = 0; i < chains.size(); i++)
169 ( (PDBChain) chains.elementAt(i)).makeCaBondList();
173 public PDBChain findChain(String id)
175 for (int i = 0; i < chains.size(); i++)
177 if ( ( (PDBChain) chains.elementAt(i)).id.equals(id))
179 return (PDBChain) chains.elementAt(i);
186 public void setChargeColours()
188 for (int i = 0; i < chains.size(); i++)
190 ( (PDBChain) chains.elementAt(i)).setChargeColours();
194 public void setColours(jalview.schemes.ColourSchemeI cs)
196 for (int i = 0; i < chains.size(); i++)
198 ( (PDBChain) chains.elementAt(i)).setChainColours(cs);
202 public void setChainColours()
204 for (int i = 0; i < chains.size(); i++)
206 ( (PDBChain) chains.elementAt(i)).setChainColours(
207 Color.getHSBColor(1.0f / (float) i, .4f, 1.0f)