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
22 import jalview.datamodel.*;
\r
28 public class PDBfile extends jalview.io.FileParse {
\r
30 public Vector chains = new Vector();
\r
32 Vector lineArray = new Vector();
\r
34 public PDBfile(String [] lines)
\r
36 for(int i=0; i<lines.length; i++)
\r
37 lineArray.addElement(lines[i]);
\r
39 noLines = lineArray.size();
\r
43 public PDBfile(String inFile, String inType) throws IOException {
\r
45 super(inFile,inType);
\r
48 this.lineArray = new Vector();
\r
49 BufferedReader dataIn;
\r
51 if (inType.equals("File"))
\r
52 dataIn = new BufferedReader(new FileReader( inFile ));
\r
56 URL url = new URL(inFile);
\r
58 dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
\r
61 while ((line = dataIn.readLine()) != null) {
\r
62 lineArray.addElement(line);
\r
64 noLines = lineArray.size();
\r
71 public void parse() {
\r
73 for (int i = 0; i < lineArray.size(); i++) {
\r
74 StringTokenizer str = new StringTokenizer(lineArray.elementAt(i).toString());
\r
75 if (str.hasMoreTokens()) {
\r
76 String inStr = str.nextToken();
\r
78 if (inStr.indexOf("ATOM") != -1) {
\r
80 myAtom tmpatom = new myAtom(str);
\r
81 if (findChain(tmpatom.chain) != null) {
\r
82 // System.out.println("Adding to chain " + tmpatom.chain);
\r
83 findChain(tmpatom.chain).atoms.addElement(tmpatom);
\r
85 // System.out.println("Making chain " + tmpatom.chain);
\r
86 PDBChain tmpchain = new PDBChain(tmpatom.chain);
\r
87 chains.addElement(tmpchain);
\r
88 tmpchain.atoms.addElement(tmpatom);
\r
90 } catch(NumberFormatException e) {
\r
91 System.err.println("Caught" + e);
\r
92 System.err.println("Record not added to PDB model:"+lineArray.elementAt(i).toString());
\r
99 // for (int i=0; i < chains.size() ; i++) {
\r
100 // String pog = ((PDBChain)chains.elementAt(i)).print();
\r
101 // System.out.println(pog);
\r
105 public void makeResidueList() {
\r
106 for (int i=0; i < chains.size() ; i++) {
\r
107 ((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 // System.out.println("ID = " + id + " " +((PDBChain)chains.elementAt(i)).id);
\r
119 if (((PDBChain)chains.elementAt(i)).id.equals(id)) {
\r
120 return (PDBChain)chains.elementAt(i);
\r
127 public void setChargeColours() {
\r
128 for (int i=0; i < chains.size(); i++) {
\r
129 ((PDBChain)chains.elementAt(i)).setChargeColours();
\r
133 public void setHydrophobicityColours() {
\r
134 for (int i=0; i < chains.size(); i++) {
\r
135 ((PDBChain)chains.elementAt(i)).setHydrophobicityColours();
\r
139 public void colourBySequence(Sequence seq) {
\r
141 // int max = seq.maxchain;
\r
142 // if (seq.maxchain != -1) {
\r
143 // ((PDBChain)chains.elementAt(max)).colourBySequence(seq);
\r
147 public void setChainColours() {
\r
148 for (int i=0; i < chains.size(); i++) {
\r
149 ((PDBChain)chains.elementAt(i)).setChainColours();
\r
152 public static void main(String[] args) {
\r
154 PDBfile pdb = new PDBfile("enkp1.pdb","File");
\r
155 } catch(IOException e) {
\r
156 System.out.println(e);
\r
157 e.printStackTrace();
\r