2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
26 import java.awt.Color;
\r
27 import jalview.io.AppletFormatAdapter;
\r
30 public class PDBfile extends jalview.io.FileParse {
\r
31 public Vector chains = new Vector();
\r
32 Vector lineArray = new Vector();
\r
35 public PDBfile(String[] lines) {
\r
36 for (int i = 0; i < lines.length; i++)
\r
37 lineArray.addElement(lines[i]);
\r
42 public PDBfile(String inFile, String inType) throws IOException {
\r
43 super(inFile, inType);
\r
46 this.lineArray = new Vector();
\r
48 BufferedReader dataIn;
\r
51 if (inType.equals(AppletFormatAdapter.FILE)) {
\r
52 dataIn = new BufferedReader(new FileReader(inFile));
\r
54 else if(inType.equals(AppletFormatAdapter.PASTE))
\r
56 dataIn = new BufferedReader(new StringReader(inFile));
\r
58 else if (inType.equalsIgnoreCase(AppletFormatAdapter.CLASSLOADER))
\r
60 java.io.InputStream is = getClass().getResourceAsStream("/" +
\r
63 dataIn = new BufferedReader(new java.io.InputStreamReader(is));
\r
67 URL url = new URL(inFile);
\r
68 dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
\r
71 while ((line = dataIn.readLine()) != null) {
\r
72 lineArray.addElement(line);
\r
84 boolean modelFlag = false;
\r
85 boolean terFlag = false;
\r
88 for (int i = 0; i < lineArray.size(); i++)
\r
91 line = lineArray.elementAt(i).toString();
\r
94 if (line.indexOf("HEADER") == 0)
\r
96 id = line.substring(62, 67).trim();
\r
100 if(line.indexOf("MODEL")==0)
\r
103 if(line.indexOf("TER")==0)
\r
106 if(modelFlag && line.indexOf("ENDMDL")==0)
\r
109 if ( line.indexOf("ATOM")==0
\r
110 || (line.indexOf("HETATM")==0 && !terFlag)
\r
116 //Jalview is only interested in CA bonds????
\r
117 if (!line.substring(12, 15).trim().equals("CA"))
\r
122 Atom tmpatom = new Atom(line);
\r
124 tmpchain = findChain(tmpatom.chain);
\r
125 if (tmpchain != null)
\r
127 tmpchain.atoms.addElement(tmpatom);
\r
131 tmpchain = new PDBChain(tmpatom.chain);
\r
132 chains.addElement(tmpchain);
\r
133 tmpchain.atoms.addElement(tmpatom);
\r
143 public void makeResidueList() {
\r
144 for (int i = 0; i < chains.size(); i++) {
\r
145 ((PDBChain) chains.elementAt(i)).makeResidueList();
\r
149 public void makeCaBondList() {
\r
150 for (int i = 0; i < chains.size(); i++) {
\r
151 ((PDBChain) chains.elementAt(i)).makeCaBondList();
\r
155 public PDBChain findChain(String id) {
\r
156 for (int i = 0; i < chains.size(); i++) {
\r
157 if (((PDBChain) chains.elementAt(i)).id.equals(id)) {
\r
158 return (PDBChain) chains.elementAt(i);
\r
165 public void setChargeColours() {
\r
166 for (int i = 0; i < chains.size(); i++) {
\r
167 ((PDBChain) chains.elementAt(i)).setChargeColours();
\r
171 public void setColours(jalview.schemes.ColourSchemeI cs) {
\r
172 for (int i = 0; i < chains.size(); i++) {
\r
173 ((PDBChain) chains.elementAt(i)).setChainColours(cs);
\r
177 public void setChainColours()
\r
179 for (int i = 0; i < chains.size(); i++)
\r
181 ((PDBChain) chains.elementAt(i)).setChainColours(
\r
182 Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)
\r