2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
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 - try using data source name.
58 id = safeName(getDataName());
60 chains = new Vector();
64 boolean modelFlag = false;
65 boolean terFlag = false;
69 String atomnam = null;
72 while ((line = nextLine()) != null)
74 if (line.indexOf("HEADER") == 0)
76 if (line.length() > 62)
79 if (line.length() > 67)
81 tid = line.substring(62, 67).trim();
85 tid = line.substring(62).trim();
94 // Were we to do anything with SEQRES - we start it here
95 if (line.indexOf("SEQRES") == 0)
99 if (line.indexOf("MODEL") == 0)
104 if (line.indexOf("TER") == 0)
109 if (modelFlag && line.indexOf("ENDMDL") == 0)
113 if (line.indexOf("ATOM") == 0
114 || (line.indexOf("HETATM") == 0 && !terFlag))
118 // Jalview is only interested in CA bonds????
119 atomnam = line.substring(12, 15).trim();
120 if (!atomnam.equals("CA") && !atomnam.equals("P"))
125 Atom tmpatom = new Atom(line);
126 tmpchain = findChain(tmpatom.chain);
127 if (tmpchain != null)
129 if (tmpatom.resNumIns.trim().equals(lastID))
131 // phosphorylated protein - seen both CA and P..
134 tmpchain.atoms.addElement(tmpatom);
138 tmpchain = new PDBChain(id, tmpatom.chain);
139 chains.addElement(tmpchain);
140 tmpchain.atoms.addElement(tmpatom);
142 lastID = tmpatom.resNumIns.trim();
152 id = inFile.getName();
154 for (int i = 0; i < chains.size(); i++)
156 SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
157 dataset.setName(id + "|" + dataset.getName());
158 PDBEntry entry = new PDBEntry();
162 entry.setFile(inFile.getAbsolutePath());
166 // TODO: decide if we should dump the datasource to disk
167 entry.setFile(getDataName());
169 dataset.addPDBId(entry);
170 SequenceI chainseq = dataset.deriveSequence(); // PDBChain objects
171 // maintain reference to
173 seqs.addElement(chainseq);
174 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
175 if (chainannot != null)
177 for (int ai = 0; ai < chainannot.length; ai++)
179 chainannot[ai].visible = VisibleChainAnnotation;
180 annotations.addElement(chainannot[ai]);
184 } catch (OutOfMemoryError er)
186 System.out.println("OUT OF MEMORY LOADING PDB FILE");
187 throw new IOException("Out of memory loading PDB File");
188 } catch (NumberFormatException ex)
192 System.err.println("Couldn't read number from line:");
193 System.err.println(line);
199 * make a friendly ID string.
202 * @return truncated dataName to after last '/'
204 private String safeName(String dataName)
207 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
209 dataName = dataName.substring(p + 1);
214 public void makeResidueList()
216 for (int i = 0; i < chains.size(); i++)
218 ((PDBChain) chains.elementAt(i)).makeResidueList();
222 public void makeCaBondList()
224 for (int i = 0; i < chains.size(); i++)
226 ((PDBChain) chains.elementAt(i)).makeCaBondList();
230 public PDBChain findChain(String id)
232 for (int i = 0; i < chains.size(); i++)
234 if (((PDBChain) chains.elementAt(i)).id.equals(id))
236 return (PDBChain) chains.elementAt(i);
243 public void setChargeColours()
245 for (int i = 0; i < chains.size(); i++)
247 ((PDBChain) chains.elementAt(i)).setChargeColours();
251 public void setColours(jalview.schemes.ColourSchemeI cs)
253 for (int i = 0; i < chains.size(); i++)
255 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
259 public void setChainColours()
261 for (int i = 0; i < chains.size(); i++)
263 ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
264 1.0f / (float) i, .4f, 1.0f));