2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
26 import java.awt.Color;
29 public class PDBfile extends jalview.io.AlignFile {
33 public PDBfile(String inFile, String inType) throws IOException
35 super(inFile, inType);
43 public void parse() throws IOException
46 chains = new Vector();
50 boolean modelFlag = false;
51 boolean terFlag = false;
54 while ( (line = nextLine()) != null)
56 if (line.indexOf("HEADER") == 0)
58 id = line.substring(62, 67).trim();
61 // Were we to do anything with SEQRES - we start it here
62 if (line.indexOf("SEQRES") == 0) {
65 if (line.indexOf("MODEL") == 0)
68 if (line.indexOf("TER") == 0)
71 if (modelFlag && line.indexOf("ENDMDL") == 0)
73 if (line.indexOf("ATOM") == 0
74 || (line.indexOf("HETATM") == 0 && !terFlag)
79 //Jalview is only interested in CA bonds????
80 if (!line.substring(12, 15).trim().equals("CA"))
85 Atom tmpatom = new Atom(line);
86 tmpchain = findChain(tmpatom.chain);
89 tmpchain.atoms.addElement(tmpatom);
93 tmpchain = new PDBChain(id,tmpatom.chain);
94 chains.addElement(tmpchain);
95 tmpchain.atoms.addElement(tmpatom);
106 id = inFile.getName();
108 for (int i = 0; i < chains.size(); i++)
110 SequenceI dataset = ( (PDBChain) chains.elementAt(i)).
112 dataset.setName(id + "|" + dataset.getName());
113 PDBEntry entry = new PDBEntry();
116 entry.setFile(inFile.getAbsolutePath());
117 dataset.addPDBId(entry);
118 getSeqs().addElement(dataset.deriveSequence()); // PDBChain objects maintain reference to dataset
120 }catch(OutOfMemoryError er)
122 System.out.println("OUT OF MEMORY LOADING PDB FILE");
123 throw new IOException("Out of memory loading PDB File");
127 public void makeResidueList() {
128 for (int i = 0; i < chains.size(); i++) {
129 ((PDBChain) chains.elementAt(i)).makeResidueList();
133 public void makeCaBondList() {
134 for (int i = 0; i < chains.size(); i++) {
135 ((PDBChain) chains.elementAt(i)).makeCaBondList();
139 public PDBChain findChain(String id) {
140 for (int i = 0; i < chains.size(); i++) {
141 if (((PDBChain) chains.elementAt(i)).id.equals(id)) {
142 return (PDBChain) chains.elementAt(i);
149 public void setChargeColours() {
150 for (int i = 0; i < chains.size(); i++) {
151 ((PDBChain) chains.elementAt(i)).setChargeColours();
155 public void setColours(jalview.schemes.ColourSchemeI cs) {
156 for (int i = 0; i < chains.size(); i++) {
157 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
161 public void setChainColours()
163 for (int i = 0; i < chains.size(); i++)
165 ((PDBChain) chains.elementAt(i)).setChainColours(
166 Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)