1 /* Copyright (C) 1998 Michele Clamp
\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
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
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
19 import jalview.datamodel.*;
\r
20 import jalview.schemes.ResidueProperties;
\r
21 import jalview.gui.*;
\r
27 public class PDBChain {
\r
30 public Vector bonds = new Vector();
\r
31 public Vector atoms = new Vector();
\r
32 public Vector residues = new Vector();
\r
35 public Sequence sequence;
\r
36 public boolean isVisible = false;
\r
38 //public DrawableSequence ds;
\r
40 public PDBChain(String id) {
\r
45 public String print() {
\r
47 for (int i=0; i < bonds.size() ;i++) {
\r
48 tmp = tmp + ((Bond)bonds.elementAt(i)).at1.resName + " " + ((Bond)bonds.elementAt(i)).at1.resNumber +" " + offset+ "\n";
\r
52 public void makeCaBondList() {
\r
53 for (int i = 0; i < (residues.size() - 1) ; i++) {
\r
54 Residue tmpres = (Residue)residues.elementAt(i);
\r
55 Residue tmpres2 = (Residue)residues.elementAt(i+1);
\r
56 myAtom at1 = tmpres.findAtom("CA");
\r
57 myAtom at2 = tmpres2.findAtom("CA");
\r
58 if ((at1 != null) && (at2 != null)) {
\r
59 if (at1.chain.equals(at2.chain)) {
\r
66 public void makeBond(myAtom at1, myAtom at2) {
\r
67 float[] start = new float[3];
\r
68 float[] end = new float[3];
\r
78 bonds.addElement(new Bond(start, end, at1,at2));
\r
81 public void makeResidueList() {
\r
84 for (int i = 0; i < atoms.size(); i++) {
\r
86 myAtom tmp = (myAtom)atoms.elementAt(i);
\r
87 String resName = tmp.resName;
\r
88 int resNumber = tmp.resNumber;
\r
89 int res = resNumber;
\r
94 Vector resAtoms = new Vector();
\r
96 resAtoms.addElement((myAtom)atoms.elementAt(i));
\r
98 resNumber = ((myAtom)atoms.elementAt(i)).resNumber;
\r
100 //Add atoms to a vector while the residue number
\r
102 while ((resNumber == res) && (i < atoms.size())) {
\r
104 resAtoms.addElement((myAtom)atoms.elementAt(i));
\r
106 if (i < atoms.size()) {
\r
107 resNumber = ((myAtom)atoms.elementAt(i)).resNumber;
\r
113 //We need this to keep in step with the outer for i = loop
\r
116 //Make a new Residue object with the new atoms vector
\r
117 residues.addElement(new Residue(resAtoms, resNumber - 1,count));
\r
119 Residue tmpres = (Residue)residues.lastElement();
\r
120 myAtom tmpat = (myAtom)tmpres.atoms.elementAt(0);
\r
122 // Keep totting up the sequence
\r
123 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null) {
\r
124 System.out.println("Null aa3Hash for " + tmpat.resName);
\r
127 ResidueProperties.aa[((Integer)ResidueProperties.getAA3Hash().get(tmpat.resName)).intValue()];
\r
128 seq = seq + tmpres2;
\r
130 // System.out.println(tmpat.resName + " " + tmpres2);
\r
132 sequence = new Sequence("PDB_seq",seq,1,seq.length());
\r
133 System.out.println("Sequence = " + seq);
\r
134 System.out.println("No of residues = " +residues.size());
\r
137 public void setChargeColours() {
\r
138 for (int i = 0; i < bonds.size(); i++) {
\r
140 Bond b = (Bond)bonds.elementAt(i);
\r
142 if (b.at1.resName.toUpperCase().equals("ASP") || b.at1.resName.toUpperCase().equals("GLU")) {
\r
143 b.startCol = Color.red;
\r
144 } else if (b.at1.resName.toUpperCase().equals("LYS") || b.at1.resName.toUpperCase().equals("ARG")) {
\r
145 b.startCol = Color.blue;
\r
146 } else if (b.at1.resName.toUpperCase().equals("CYS")) {
\r
147 b.startCol = Color.yellow;
\r
149 int atno = ((Integer)ResidueProperties.getAA3Hash().get(b.at1.resName.toUpperCase())).intValue();
\r
150 b.startCol = Color.lightGray;
\r
152 if (b.at2.resName.toUpperCase().equals("ASP") || b.at2.resName.toUpperCase().equals("GLU")) {
\r
153 b.endCol = Color.red;
\r
154 } else if (b.at2.resName.toUpperCase().equals("LYS") || b.at2.resName.toUpperCase().equals("ARG")) {
\r
155 b.endCol = Color.blue;
\r
156 } else if (b.at2.resName.toUpperCase().equals("CYS")) {
\r
157 b.endCol = Color.yellow;
\r
159 int atno = ((Integer)ResidueProperties.getAA3Hash().get(b.at2.resName.toUpperCase())).intValue();
\r
160 b.endCol = Color.lightGray;
\r
162 } catch (Exception e) {
\r
163 Bond b = (Bond)bonds.elementAt(i);
\r
164 b.startCol = Color.gray;
\r
165 b.endCol = Color.gray;
\r
170 public void setHydrophobicityColours() {
\r
171 float hydmin = (float)ResidueProperties.getHydmin();
\r
172 float hydmax = (float)ResidueProperties.getHydmax();
\r
173 double[] hyd = ResidueProperties.getHyd();
\r
175 Hashtable AA3Hash = ResidueProperties.getAA3Hash();
\r
177 for (int i = 0; i < bonds.size(); i++) {
\r
179 Bond b = (Bond)bonds.elementAt(i);
\r
181 int atno = ((Integer)AA3Hash.get(b.at1.resName.toUpperCase())).intValue();
\r
182 float red = ((float)hyd[atno] - hydmin)/(hydmax - hydmin);
\r
184 if (red > (float)1.0) {
\r
187 if (red < (float)0.0) {
\r
191 b.startCol = new Color(red,(float)0.0,(float)1.0-red);
\r
192 atno = ((Integer)AA3Hash.get(b.at2.resName.toUpperCase())).intValue();
\r
194 red = ((float)hyd[atno] - hydmin)/(hydmax - hydmin);
\r
196 if (red > (float)1.0) {
\r
199 if (red < (float)0.0) {
\r
203 b.endCol = new Color(red,(float)0.2,(float)1.0-red);
\r
204 } catch (Exception e) {
\r
205 Bond b = (Bond)bonds.elementAt(i);
\r
206 b.startCol = Color.gray;
\r
207 b.endCol = Color.gray;
\r
213 public void colourBySequence(DrawableSequence seq) {
\r
215 // for (int i = 0; i < bonds.size(); i++) {
\r
216 // Bond tmp = (Bond)bonds.elementAt(i);
\r
219 // if (tmp.at1.resNumber >= (offset + seq.pdbstart - 1) && tmp.at1.resNumber <= (offset + seq.pdbend - 1)) {
\r
221 // int pos = seq.seqtart() + (tmp.at1.resNumber - seq.pdbstart - offset) ;
\r
222 // int index = seq.findIndex(pos);
\r
224 // tmp.startCol = (Color)seq.getResidueBoxColour(index);
\r
227 // tmp.startCol = Color.gray;
\r
230 // if (tmp.at2.resNumber >= (offset + seq.pdbstart -1) && tmp.at2.resNumber <= (seq.pdbend+offset-1)) {
\r
232 // int pos = seq.seqstart + (tmp.at2.resNumber - seq.pdbstart-offset);
\r
233 // int index = seq.findIndex(pos);
\r
235 // tmp.endCol = (Color)seq.getResidueBoxColour(index);
\r
238 // tmp.endCol = Color.gray;
\r
240 // } catch (Exception e) {
\r
241 // tmp.startCol = Color.lightGray;
\r
242 // tmp.endCol = Color.lightGray;
\r
247 public void setChainColours() {
\r
248 for (int i = 0; i < bonds.size(); i++) {
\r
249 Bond tmp = (Bond)bonds.elementAt(i);
\r
251 tmp.startCol = (Color) ResidueProperties.getChainColours().get(id);
\r
252 tmp.endCol = (Color) ResidueProperties.getChainColours().get(id);
\r
253 } catch (Exception e) {
\r
254 tmp.startCol = Color.lightGray;
\r
255 tmp.endCol = Color.lightGray;
\r