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
29 public class PDBfile extends jalview.io.FileParse {
\r
30 public Vector chains = new Vector();
\r
31 Vector lineArray = new Vector();
\r
33 public PDBfile(String[] lines) {
\r
34 for (int i = 0; i < lines.length; i++)
\r
35 lineArray.addElement(lines[i]);
\r
37 noLines = lineArray.size();
\r
41 public PDBfile(String inFile, String inType) throws IOException {
\r
42 super(inFile, inType);
\r
45 this.lineArray = new Vector();
\r
47 BufferedReader dataIn;
\r
49 if (inType.equals("File")) {
\r
50 dataIn = new BufferedReader(new FileReader(inFile));
\r
52 else if(inType.equals("Paste"))
\r
54 dataIn = new BufferedReader(new StringReader(inFile));
\r
57 URL url = new URL(inFile);
\r
59 dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
\r
62 while ((line = dataIn.readLine()) != null) {
\r
63 lineArray.addElement(line);
\r
66 noLines = lineArray.size();
\r
71 public void parse() {
\r
72 for (int i = 0; i < lineArray.size(); i++) {
\r
73 StringTokenizer str = new StringTokenizer(lineArray.elementAt(i)
\r
76 if (str.hasMoreTokens()) {
\r
77 String inStr = str.nextToken();
\r
79 if (inStr.indexOf("ATOM") != -1) {
\r
81 Atom tmpatom = new Atom(str);
\r
83 if (findChain(tmpatom.chain) != null) {
\r
84 // System.out.println("Adding to chain " + tmpatom.chain);
\r
85 findChain(tmpatom.chain).atoms.addElement(tmpatom);
\r
87 PDBChain tmpchain = new PDBChain(tmpatom.chain);
\r
88 chains.addElement(tmpchain);
\r
89 tmpchain.atoms.addElement(tmpatom);
\r
91 } catch (NumberFormatException e) {
\r
92 System.err.println("Caught" + e);
\r
93 System.err.println("Record not added to PDB model:" +
\r
94 lineArray.elementAt(i).toString());
\r
104 public void makeResidueList() {
\r
105 for (int i = 0; i < chains.size(); i++) {
\r
106 ((PDBChain) chains.elementAt(i)).makeResidueList();
\r
110 public void makeCaBondList() {
\r
111 for (int i = 0; i < chains.size(); i++) {
\r
112 ((PDBChain) chains.elementAt(i)).makeCaBondList();
\r
116 public PDBChain findChain(String id) {
\r
117 for (int i = 0; i < chains.size(); i++) {
\r
118 if (((PDBChain) chains.elementAt(i)).id.equals(id)) {
\r
119 return (PDBChain) chains.elementAt(i);
\r
126 public void setChargeColours() {
\r
127 for (int i = 0; i < chains.size(); i++) {
\r
128 ((PDBChain) chains.elementAt(i)).setChargeColours();
\r
132 public void setHydrophobicityColours() {
\r
133 for (int i = 0; i < chains.size(); i++) {
\r
134 ((PDBChain) chains.elementAt(i)).setHydrophobicityColours();
\r
138 public void setChainColours()
\r
140 for (int i = 0; i < chains.size(); i++)
\r
142 ((PDBChain) chains.elementAt(i)).setChainColours(
\r
143 Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)
\r