drawableSequence removed
[jalview.git] / src / MCview / PDBChain.java
1 /* Copyright (C) 1998  Michele Clamp\r
2  *\r
3  * This program is free software; you can redistribute it and/or\r
4  * modify it under the terms of the GNU General Public License\r
5  * as published by the Free Software Foundation; either version 2\r
6  * of the License, or (at your option) any later version.\r
7  *\r
8  * This program is distributed in the hope that it will be useful,\r
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
11  * GNU General Public License for more details.\r
12  *\r
13  * You should have received a copy of the GNU General Public License\r
14  * along with this program; if not, write to the Free Software\r
15  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
16  */\r
17 package MCview;\r
18 \r
19 import jalview.datamodel.*;\r
20 import jalview.schemes.ResidueProperties;\r
21 \r
22 import java.awt.*;\r
23 import java.util.*;\r
24 \r
25 \r
26 public class PDBChain {\r
27 \r
28   public String id;\r
29   public Vector bonds = new Vector();\r
30   public Vector atoms = new Vector();\r
31   public Vector residues = new Vector();\r
32   public int offset;\r
33 \r
34   public Sequence sequence;\r
35   public boolean isVisible = false;\r
36 \r
37   //public DrawableSequence ds;\r
38 \r
39   public PDBChain(String id) {\r
40     this.id = id;\r
41   }\r
42 \r
43 \r
44   public String print() {\r
45     String tmp = "";\r
46     for (int i=0; i < bonds.size() ;i++) {\r
47       tmp = tmp + ((Bond)bonds.elementAt(i)).at1.resName + " " + ((Bond)bonds.elementAt(i)).at1.resNumber +" " + offset+ "\n";\r
48     }\r
49     return tmp;\r
50   }\r
51   public void makeCaBondList() {\r
52     for (int i = 0; i < (residues.size() - 1) ; i++) {\r
53       Residue tmpres = (Residue)residues.elementAt(i);\r
54       Residue tmpres2 = (Residue)residues.elementAt(i+1);\r
55       myAtom at1 = tmpres.findAtom("CA");\r
56       myAtom at2 = tmpres2.findAtom("CA");\r
57       if ((at1 != null) && (at2 != null)) {\r
58         if (at1.chain.equals(at2.chain)) {\r
59           makeBond(at1,at2);\r
60         }\r
61       }\r
62     }\r
63   }\r
64 \r
65   public void makeBond(myAtom at1, myAtom at2) {\r
66     float[] start = new float[3];\r
67     float[] end = new float[3];\r
68 \r
69     start[0] = at1.x;\r
70     start[1] = at1.y;\r
71     start[2] = at1.z;\r
72 \r
73     end[0] = at2.x;\r
74     end[1] = at2.y;\r
75     end[2] = at2.z;\r
76 \r
77     bonds.addElement(new Bond(start, end, at1,at2));\r
78   }\r
79 \r
80   public void makeResidueList() {\r
81     int count = 0;\r
82     String seq = "";\r
83     for (int i = 0; i < atoms.size(); i++) {\r
84 \r
85       myAtom tmp = (myAtom)atoms.elementAt(i);\r
86       String resName = tmp.resName;\r
87       int resNumber = tmp.resNumber;\r
88       int res = resNumber;\r
89 \r
90       if (i ==0) {\r
91         offset = resNumber;\r
92       }\r
93       Vector resAtoms = new Vector();\r
94 \r
95       resAtoms.addElement((myAtom)atoms.elementAt(i));\r
96       i++;\r
97       resNumber = ((myAtom)atoms.elementAt(i)).resNumber;\r
98 \r
99       //Add atoms to a vector while the residue number\r
100       //remains the same\r
101       while ((resNumber == res) && (i < atoms.size())) {\r
102 \r
103         resAtoms.addElement((myAtom)atoms.elementAt(i));\r
104         i++;\r
105         if (i < atoms.size()) {\r
106           resNumber = ((myAtom)atoms.elementAt(i)).resNumber;\r
107         } else {\r
108           resNumber++;\r
109         }\r
110       }\r
111 \r
112       //We need this to keep in step with the outer for i = loop\r
113       i--;\r
114 \r
115       //Make a new Residue object with the new atoms vector\r
116       residues.addElement(new Residue(resAtoms, resNumber - 1,count));\r
117       count++;\r
118       Residue tmpres = (Residue)residues.lastElement();\r
119       myAtom tmpat = (myAtom)tmpres.atoms.elementAt(0);\r
120 \r
121       // Keep totting up the sequence\r
122       if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null) {\r
123         System.out.println("Null aa3Hash for " + tmpat.resName);\r
124       } else {\r
125         String tmpres2 =\r
126           ResidueProperties.aa[((Integer)ResidueProperties.getAA3Hash().get(tmpat.resName)).intValue()];\r
127         seq = seq + tmpres2;\r
128       }\r
129       //      System.out.println(tmpat.resName + " " + tmpres2);\r
130     }\r
131     sequence = new Sequence("PDB_seq",seq,1,seq.length());\r
132     System.out.println("Sequence = " + seq);\r
133     System.out.println("No of residues = " +residues.size());\r
134   }\r
135 \r
136   public void setChargeColours() {\r
137     for (int i = 0; i < bonds.size(); i++) {\r
138       try {\r
139         Bond b = (Bond)bonds.elementAt(i);\r
140 \r
141         if (b.at1.resName.toUpperCase().equals("ASP") || b.at1.resName.toUpperCase().equals("GLU")) {\r
142           b.startCol = Color.red;\r
143         } else if (b.at1.resName.toUpperCase().equals("LYS") || b.at1.resName.toUpperCase().equals("ARG")) {\r
144           b.startCol = Color.blue;\r
145         } else if (b.at1.resName.toUpperCase().equals("CYS")) {\r
146           b.startCol = Color.yellow;\r
147         } else {\r
148           int atno = ((Integer)ResidueProperties.getAA3Hash().get(b.at1.resName.toUpperCase())).intValue();\r
149           b.startCol = Color.lightGray;\r
150         }\r
151         if (b.at2.resName.toUpperCase().equals("ASP") || b.at2.resName.toUpperCase().equals("GLU")) {\r
152           b.endCol = Color.red;\r
153         } else if (b.at2.resName.toUpperCase().equals("LYS") || b.at2.resName.toUpperCase().equals("ARG")) {\r
154           b.endCol = Color.blue;\r
155         } else if (b.at2.resName.toUpperCase().equals("CYS")) {\r
156           b.endCol = Color.yellow;\r
157         } else {\r
158           int atno = ((Integer)ResidueProperties.getAA3Hash().get(b.at2.resName.toUpperCase())).intValue();\r
159           b.endCol = Color.lightGray;\r
160         }\r
161       } catch (Exception e) {\r
162         Bond b = (Bond)bonds.elementAt(i);\r
163         b.startCol = Color.gray;\r
164         b.endCol = Color.gray;\r
165       }\r
166     }\r
167   }\r
168 \r
169   public void setHydrophobicityColours() {\r
170     float hydmin = (float)ResidueProperties.getHydmin();\r
171     float hydmax = (float)ResidueProperties.getHydmax();\r
172     double[] hyd  = ResidueProperties.getHyd();\r
173 \r
174     Hashtable AA3Hash = ResidueProperties.getAA3Hash();\r
175 \r
176     for (int i = 0; i < bonds.size(); i++) {\r
177       try {\r
178         Bond b = (Bond)bonds.elementAt(i);\r
179 \r
180         int   atno = ((Integer)AA3Hash.get(b.at1.resName.toUpperCase())).intValue();\r
181         float red  = ((float)hyd[atno] - hydmin)/(hydmax - hydmin);\r
182 \r
183         if (red > (float)1.0) {\r
184           red = (float)1.0;\r
185         }\r
186         if (red < (float)0.0) {\r
187           red = (float)0.0;\r
188         }\r
189 \r
190         b.startCol = new Color(red,(float)0.0,(float)1.0-red);\r
191         atno = ((Integer)AA3Hash.get(b.at2.resName.toUpperCase())).intValue();\r
192 \r
193         red = ((float)hyd[atno] - hydmin)/(hydmax - hydmin);\r
194 \r
195         if (red > (float)1.0) {\r
196           red = (float)1.0;\r
197         }\r
198         if (red < (float)0.0) {\r
199           red = (float)0.0;\r
200         }\r
201 \r
202         b.endCol = new Color(red,(float)0.2,(float)1.0-red);\r
203       } catch (Exception e) {\r
204         Bond b = (Bond)bonds.elementAt(i);\r
205         b.startCol = Color.gray;\r
206         b.endCol = Color.gray;\r
207       }\r
208     }\r
209   }\r
210 \r
211 \r
212   public void colourBySequence(Sequence seq) {\r
213 \r
214 //    for (int i = 0; i < bonds.size(); i++) {\r
215 //      Bond tmp = (Bond)bonds.elementAt(i);\r
216 //      try {\r
217 //\r
218 //        if (tmp.at1.resNumber >= (offset + seq.pdbstart - 1) && tmp.at1.resNumber <= (offset + seq.pdbend - 1)) {\r
219 //\r
220 //          int pos   = seq.seqtart() + (tmp.at1.resNumber - seq.pdbstart - offset) ;\r
221 //          int index = seq.findIndex(pos);\r
222 //\r
223 //          tmp.startCol = (Color)seq.getResidueBoxColour(index);\r
224 //\r
225 //        } else {\r
226 //          tmp.startCol = Color.gray;\r
227 //        }\r
228 //\r
229 //        if (tmp.at2.resNumber >= (offset + seq.pdbstart -1) && tmp.at2.resNumber <= (seq.pdbend+offset-1)) {\r
230 //\r
231 //          int pos    = seq.seqstart + (tmp.at2.resNumber - seq.pdbstart-offset);\r
232 //          int index  = seq.findIndex(pos);\r
233 //\r
234 //          tmp.endCol = (Color)seq.getResidueBoxColour(index);\r
235 //\r
236 //        } else {\r
237 //          tmp.endCol = Color.gray;\r
238 //        }\r
239 //      } catch (Exception e) {\r
240 //        tmp.startCol = Color.lightGray;\r
241 //        tmp.endCol = Color.lightGray;\r
242 //      }\r
243 //    }\r
244   }\r
245 \r
246   public void setChainColours() {\r
247     for (int i = 0; i < bonds.size(); i++) {\r
248       Bond tmp = (Bond)bonds.elementAt(i);\r
249       try {\r
250         tmp.startCol = (Color) ResidueProperties.getChainColours().get(id);\r
251         tmp.endCol   = (Color) ResidueProperties.getChainColours().get(id);\r
252       } catch (Exception e) {\r
253         tmp.startCol = Color.lightGray;\r
254         tmp.endCol   = Color.lightGray;\r
255       }\r
256     }\r
257   }\r
258 }\r
259 \r
260 \r