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;
30 extends jalview.io.AlignFile
36 * set to true to add chain alignment annotation as visible annotation.
38 boolean VisibleChainAnnotation=false;
39 public PDBfile(String inFile, String inType)
42 super(inFile, inType);
45 public PDBfile(FileParse source) throws IOException
58 // TODO set the filename sensibly
59 id = (inFile==null) ? "PDBFILE" : inFile.getName();
62 chains = new Vector();
66 boolean modelFlag = false;
67 boolean terFlag = false;
70 while ( (line = nextLine()) != null)
72 if (line.indexOf("HEADER") == 0)
74 id = line.substring(62, 67).trim();
77 // Were we to do anything with SEQRES - we start it here
78 if (line.indexOf("SEQRES") == 0)
82 if (line.indexOf("MODEL") == 0)
87 if (line.indexOf("TER") == 0)
92 if (modelFlag && line.indexOf("ENDMDL") == 0)
96 if (line.indexOf("ATOM") == 0
97 || (line.indexOf("HETATM") == 0 && !terFlag)
102 //Jalview is only interested in CA bonds????
103 if (!line.substring(12, 15).trim().equals("CA"))
108 Atom tmpatom = new Atom(line);
109 tmpchain = findChain(tmpatom.chain);
110 if (tmpchain != null)
112 tmpchain.atoms.addElement(tmpatom);
116 tmpchain = new PDBChain(id, tmpatom.chain);
117 chains.addElement(tmpchain);
118 tmpchain.atoms.addElement(tmpatom);
129 id = inFile.getName();
131 for (int i = 0; i < chains.size(); i++)
133 SequenceI dataset = ( (PDBChain) chains.elementAt(i)).
135 dataset.setName(id + "|" + dataset.getName());
136 PDBEntry entry = new PDBEntry();
140 entry.setFile(inFile.getAbsolutePath());
142 dataset.addPDBId(entry);
143 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects maintain reference to dataset
144 seqs.addElement(chainseq);
145 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
146 if (chainannot!=null)
148 for (int ai=0; ai<chainannot.length; ai++)
150 chainannot[ai].visible=VisibleChainAnnotation;
151 annotations.addElement(chainannot[ai]);
156 catch (OutOfMemoryError er)
158 System.out.println("OUT OF MEMORY LOADING PDB FILE");
159 throw new IOException("Out of memory loading PDB File");
163 public void makeResidueList()
165 for (int i = 0; i < chains.size(); i++)
167 ( (PDBChain) chains.elementAt(i)).makeResidueList();
171 public void makeCaBondList()
173 for (int i = 0; i < chains.size(); i++)
175 ( (PDBChain) chains.elementAt(i)).makeCaBondList();
179 public PDBChain findChain(String id)
181 for (int i = 0; i < chains.size(); i++)
183 if ( ( (PDBChain) chains.elementAt(i)).id.equals(id))
185 return (PDBChain) chains.elementAt(i);
192 public void setChargeColours()
194 for (int i = 0; i < chains.size(); i++)
196 ( (PDBChain) chains.elementAt(i)).setChargeColours();
200 public void setColours(jalview.schemes.ColourSchemeI cs)
202 for (int i = 0; i < chains.size(); i++)
204 ( (PDBChain) chains.elementAt(i)).setChainColours(cs);
208 public void setChainColours()
210 for (int i = 0; i < chains.size(); i++)
212 ( (PDBChain) chains.elementAt(i)).setChainColours(
213 Color.getHSBColor(1.0f / (float) i, .4f, 1.0f)