Highlight doesnt use offset
[jalview.git] / src / MCview / PDBfile.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\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
9 *\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
14 *\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
18 */\r
19 package MCview;\r
20 \r
21 import java.io.*;\r
22 \r
23 import java.net.*;\r
24 \r
25 import java.util.*;\r
26 import java.awt.Color;\r
27 \r
28 \r
29 public class PDBfile extends jalview.io.FileParse {\r
30     public Vector chains = new Vector();\r
31     Vector lineArray = new Vector();\r
32 \r
33     public PDBfile(String[] lines) {\r
34         for (int i = 0; i < lines.length; i++)\r
35             lineArray.addElement(lines[i]);\r
36 \r
37         noLines = lineArray.size();\r
38         parse();\r
39     }\r
40 \r
41     public PDBfile(String inFile, String inType) throws IOException {\r
42         super(inFile, inType);\r
43 \r
44         String line;\r
45         this.lineArray = new Vector();\r
46 \r
47         BufferedReader dataIn;\r
48 \r
49         if (inType.equals("File")) {\r
50             dataIn = new BufferedReader(new FileReader(inFile));\r
51         }\r
52         else if(inType.equals("Paste"))\r
53         {\r
54             dataIn = new BufferedReader(new StringReader(inFile));\r
55         }\r
56         else {\r
57             URL url = new URL(inFile);\r
58             this.fileSize = 0;\r
59             dataIn = new BufferedReader(new InputStreamReader(url.openStream()));\r
60         }\r
61 \r
62         while ((line = dataIn.readLine()) != null) {\r
63             lineArray.addElement(line);\r
64         }\r
65 \r
66         noLines = lineArray.size();\r
67 \r
68         parse();\r
69     }\r
70 \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
74                                                                .toString());\r
75 \r
76             if (str.hasMoreTokens()) {\r
77                 String inStr = str.nextToken();\r
78 \r
79                 if (inStr.indexOf("ATOM") != -1) {\r
80                     try {\r
81                         Atom tmpatom = new Atom(str);\r
82 \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
86                         } else {\r
87                             PDBChain tmpchain = new PDBChain(tmpatom.chain);\r
88                             chains.addElement(tmpchain);\r
89                             tmpchain.atoms.addElement(tmpatom);\r
90                         }\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
95                     }\r
96                 }\r
97             }\r
98         }\r
99 \r
100         makeResidueList();\r
101         makeCaBondList();\r
102     }\r
103 \r
104     public void makeResidueList() {\r
105         for (int i = 0; i < chains.size(); i++) {\r
106             ((PDBChain) chains.elementAt(i)).makeResidueList();\r
107         }\r
108     }\r
109 \r
110     public void makeCaBondList() {\r
111         for (int i = 0; i < chains.size(); i++) {\r
112             ((PDBChain) chains.elementAt(i)).makeCaBondList();\r
113         }\r
114     }\r
115 \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
120             }\r
121         }\r
122 \r
123         return null;\r
124     }\r
125 \r
126     public void setChargeColours() {\r
127         for (int i = 0; i < chains.size(); i++) {\r
128             ((PDBChain) chains.elementAt(i)).setChargeColours();\r
129         }\r
130     }\r
131 \r
132     public void setHydrophobicityColours() {\r
133         for (int i = 0; i < chains.size(); i++) {\r
134             ((PDBChain) chains.elementAt(i)).setHydrophobicityColours();\r
135         }\r
136     }\r
137 \r
138     public void setChainColours()\r
139     {\r
140        for (int i = 0; i < chains.size(); i++)\r
141        {\r
142             ((PDBChain) chains.elementAt(i)).setChainColours(\r
143                      Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)\r
144                 );\r
145         }\r
146     }\r
147 }\r