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);
54 chains = new Vector();
58 boolean modelFlag = false;
59 boolean terFlag = false;
62 while ( (line = nextLine()) != null)
64 if (line.indexOf("HEADER") == 0)
66 id = line.substring(62, 67).trim();
69 // Were we to do anything with SEQRES - we start it here
70 if (line.indexOf("SEQRES") == 0)
74 if (line.indexOf("MODEL") == 0)
79 if (line.indexOf("TER") == 0)
84 if (modelFlag && line.indexOf("ENDMDL") == 0)
88 if (line.indexOf("ATOM") == 0
89 || (line.indexOf("HETATM") == 0 && !terFlag)
94 //Jalview is only interested in CA bonds????
95 if (!line.substring(12, 15).trim().equals("CA"))
100 Atom tmpatom = new Atom(line);
101 tmpchain = findChain(tmpatom.chain);
102 if (tmpchain != null)
104 tmpchain.atoms.addElement(tmpatom);
108 tmpchain = new PDBChain(id, tmpatom.chain);
109 chains.addElement(tmpchain);
110 tmpchain.atoms.addElement(tmpatom);
121 id = inFile.getName();
123 for (int i = 0; i < chains.size(); i++)
125 SequenceI dataset = ( (PDBChain) chains.elementAt(i)).
127 dataset.setName(id + "|" + dataset.getName());
128 PDBEntry entry = new PDBEntry();
132 entry.setFile(inFile.getAbsolutePath());
134 dataset.addPDBId(entry);
135 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects maintain reference to dataset
136 seqs.addElement(chainseq);
137 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
138 if (chainannot!=null)
140 for (int ai=0; ai<chainannot.length; ai++)
142 chainannot[ai].visible=VisibleChainAnnotation;
143 annotations.addElement(chainannot[ai]);
148 catch (OutOfMemoryError er)
150 System.out.println("OUT OF MEMORY LOADING PDB FILE");
151 throw new IOException("Out of memory loading PDB File");
155 public void makeResidueList()
157 for (int i = 0; i < chains.size(); i++)
159 ( (PDBChain) chains.elementAt(i)).makeResidueList();
163 public void makeCaBondList()
165 for (int i = 0; i < chains.size(); i++)
167 ( (PDBChain) chains.elementAt(i)).makeCaBondList();
171 public PDBChain findChain(String id)
173 for (int i = 0; i < chains.size(); i++)
175 if ( ( (PDBChain) chains.elementAt(i)).id.equals(id))
177 return (PDBChain) chains.elementAt(i);
184 public void setChargeColours()
186 for (int i = 0; i < chains.size(); i++)
188 ( (PDBChain) chains.elementAt(i)).setChargeColours();
192 public void setColours(jalview.schemes.ColourSchemeI cs)
194 for (int i = 0; i < chains.size(); i++)
196 ( (PDBChain) chains.elementAt(i)).setChainColours(cs);
200 public void setChainColours()
202 for (int i = 0; i < chains.size(); i++)
204 ( (PDBChain) chains.elementAt(i)).setChainColours(
205 Color.getHSBColor(1.0f / (float) i, .4f, 1.0f)