2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
25 import jalview.datamodel.*;
26 import jalview.io.FileParse;
28 public class PDBfile extends jalview.io.AlignFile
35 * set to true to add chain alignment annotation as visible annotation.
37 boolean VisibleChainAnnotation = false;
39 public PDBfile(String inFile, String inType) throws IOException
41 super(inFile, inType);
44 public PDBfile(FileParse source) throws IOException
54 public void parse() throws IOException
56 // TODO set the filename sensibly - try using data source name.
57 id = safeName(getDataName());
59 chains = new Vector();
63 boolean modelFlag = false;
64 boolean terFlag = false;
68 String atomnam = null;
71 while ((line = nextLine()) != null)
73 if (line.indexOf("HEADER") == 0)
75 if (line.length() > 62)
78 if (line.length() > 67)
80 tid = line.substring(62, 67).trim();
84 tid = line.substring(62).trim();
93 // Were we to do anything with SEQRES - we start it here
94 if (line.indexOf("SEQRES") == 0)
98 if (line.indexOf("MODEL") == 0)
103 if (line.indexOf("TER") == 0)
108 if (modelFlag && line.indexOf("ENDMDL") == 0)
112 if (line.indexOf("ATOM") == 0
113 || (line.indexOf("HETATM") == 0 && !terFlag))
117 // Jalview is only interested in CA bonds????
118 atomnam = line.substring(12, 15).trim();
119 if (!atomnam.equals("CA") && !atomnam.equals("P"))
124 Atom tmpatom = new Atom(line);
125 tmpchain = findChain(tmpatom.chain);
126 if (tmpchain != null)
128 if (tmpatom.resNumIns.trim().equals(lastID))
130 // phosphorylated protein - seen both CA and P..
133 tmpchain.atoms.addElement(tmpatom);
137 tmpchain = new PDBChain(id, tmpatom.chain);
138 chains.addElement(tmpchain);
139 tmpchain.atoms.addElement(tmpatom);
141 lastID = tmpatom.resNumIns.trim();
151 id = inFile.getName();
153 for (int i = 0; i < chains.size(); i++)
155 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
156 dataset.setName(id + "|" + dataset.getName());
157 PDBEntry entry = new PDBEntry();
161 entry.setFile(inFile.getAbsolutePath());
165 // TODO: decide if we should dump the datasource to disk
166 entry.setFile(getDataName());
168 dataset.addPDBId(entry);
169 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
170 // maintain reference to
172 seqs.addElement(chainseq);
173 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
174 if (chainannot != null)
176 for (int ai = 0; ai < chainannot.length; ai++)
178 chainannot[ai].visible = VisibleChainAnnotation;
179 annotations.addElement(chainannot[ai]);
183 } catch (OutOfMemoryError er)
185 System.out.println("OUT OF MEMORY LOADING PDB FILE");
186 throw new IOException("Out of memory loading PDB File");
187 } catch (NumberFormatException ex)
191 System.err.println("Couldn't read number from line:");
192 System.err.println(line);
198 * make a friendly ID string.
201 * @return truncated dataName to after last '/'
203 private String safeName(String dataName)
206 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
208 dataName = dataName.substring(p + 1);
213 public void makeResidueList()
215 for (int i = 0; i < chains.size(); i++)
217 ((PDBChain) chains.elementAt(i)).makeResidueList();
221 public void makeCaBondList()
223 for (int i = 0; i < chains.size(); i++)
225 ((PDBChain) chains.elementAt(i)).makeCaBondList();
229 public PDBChain findChain(String id)
231 for (int i = 0; i < chains.size(); i++)
233 if (((PDBChain) chains.elementAt(i)).id.equals(id))
235 return (PDBChain) chains.elementAt(i);
242 public void setChargeColours()
244 for (int i = 0; i < chains.size(); i++)
246 ((PDBChain) chains.elementAt(i)).setChargeColours();
250 public void setColours(jalview.schemes.ColourSchemeI cs)
252 for (int i = 0; i < chains.size(); i++)
254 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
258 public void setChainColours()
260 for (int i = 0; i < chains.size(); i++)
262 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
263 1.0f / (float) i, .4f, 1.0f));