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
21 import jalview.datamodel.*;
\r
23 import jalview.schemes.ResidueProperties;
\r
28 import jalview.analysis.AlignSeq;
\r
31 public class PDBChain {
\r
33 public Vector bonds = new Vector();
\r
34 public Vector atoms = new Vector();
\r
35 public Vector residues = new Vector();
\r
37 public Sequence sequence;
\r
38 public boolean isVisible = true;
\r
39 public int pdbstart = 0;
\r
40 public int pdbend = 0;
\r
41 public int seqstart = 0;
\r
42 public int seqend = 0;
\r
44 //public DrawableSequence ds;
\r
45 public PDBChain(String id) {
\r
49 public String print() {
\r
52 for (int i = 0; i < bonds.size(); i++) {
\r
53 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " " +
\r
54 ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
\r
61 void makeExactMapping(AlignSeq as, Sequence s1)
\r
63 int pdbpos = as.getSeq2Start()-2;
\r
64 int alignpos = s1.getStart() + as.getSeq1Start()-3;
\r
66 for(int i=0; i<as.astr1.length(); i++)
\r
68 if (as.astr1.charAt(i) != '-')
\r
73 if (as.astr2.charAt(i) != '-')
\r
78 if (as.astr1.charAt(i) == as.astr2.charAt(i))
\r
80 Residue res = (Residue) residues.elementAt(pdbpos);
\r
81 Enumeration en = res.atoms.elements();
\r
82 while (en.hasMoreElements())
\r
84 Atom atom = (Atom) en.nextElement();
\r
85 atom.alignmentMapping = alignpos;
\r
93 public void makeCaBondList()
\r
95 for (int i = 0; i < (residues.size() - 1); i++)
\r
97 Residue tmpres = (Residue) residues.elementAt(i);
\r
98 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
\r
99 Atom at1 = tmpres.findAtom("CA");
\r
100 Atom at2 = tmpres2.findAtom("CA");
\r
102 if ((at1 != null) && (at2 != null))
\r
104 if (at1.chain.equals(at2.chain))
\r
106 makeBond(at1, at2);
\r
112 public void makeBond(Atom at1, Atom at2) {
\r
113 float[] start = new float[3];
\r
114 float[] end = new float[3];
\r
124 bonds.addElement(new Bond(start, end, at1, at2));
\r
127 public void makeResidueList() {
\r
129 StringBuffer seq = new StringBuffer();
\r
131 int i, iSize = atoms.size()-1;
\r
132 for (i = 0; i < iSize; i++)
\r
134 Atom tmp = (Atom) atoms.elementAt(i);
\r
135 int resNumber = tmp.resNumber;
\r
136 int res = resNumber;
\r
139 offset = resNumber;
\r
142 Vector resAtoms = new Vector();
\r
144 resAtoms.addElement((Atom) atoms.elementAt(i));
\r
146 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
\r
148 //Add atoms to a vector while the residue number
\r
150 while ((resNumber == res) && (i < atoms.size())) {
\r
151 resAtoms.addElement((Atom) atoms.elementAt(i));
\r
154 if (i < atoms.size()) {
\r
155 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
\r
161 //We need this to keep in step with the outer for i = loop
\r
164 //Make a new Residue object with the new atoms vector
\r
165 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
\r
168 Residue tmpres = (Residue) residues.lastElement();
\r
169 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
\r
171 // Keep totting up the sequence
\r
172 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
\r
175 // System.err.println("PDBReader:Null aa3Hash for " +
\r
179 seq.append(ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()
\r
180 .get(tmpat.resName)).intValue()]);
\r
184 if(id.length()<1 || id.equals(" "))
\r
187 sequence = new Sequence(id, seq.toString(), 1, seq.length());
\r
188 // System.out.println("PDB Sequence is :\nSequence = " + seq);
\r
189 // System.out.println("No of residues = " + residues.size());
\r
192 public void setChargeColours() {
\r
193 for (int i = 0; i < bonds.size(); i++) {
\r
195 Bond b = (Bond) bonds.elementAt(i);
\r
197 if (b.at1.resName.toUpperCase().equals("ASP") ||
\r
198 b.at1.resName.toUpperCase().equals("GLU")) {
\r
199 b.startCol = Color.red;
\r
200 } else if (b.at1.resName.toUpperCase().equals("LYS") ||
\r
201 b.at1.resName.toUpperCase().equals("ARG")) {
\r
202 b.startCol = Color.blue;
\r
203 } else if (b.at1.resName.toUpperCase().equals("CYS")) {
\r
204 b.startCol = Color.yellow;
\r
206 //int atno = ((Integer) ResidueProperties.getAA3Hash().get(b.at1.resName.toUpperCase())).intValue();
\r
207 b.startCol = Color.lightGray;
\r
210 if (b.at2.resName.toUpperCase().equals("ASP") ||
\r
211 b.at2.resName.toUpperCase().equals("GLU")) {
\r
212 b.endCol = Color.red;
\r
213 } else if (b.at2.resName.toUpperCase().equals("LYS") ||
\r
214 b.at2.resName.toUpperCase().equals("ARG")) {
\r
215 b.endCol = Color.blue;
\r
216 } else if (b.at2.resName.toUpperCase().equals("CYS")) {
\r
217 b.endCol = Color.yellow;
\r
219 //int atno = ((Integer) ResidueProperties.getAA3Hash().get(b.at2.resName.toUpperCase())).intValue();
\r
220 b.endCol = Color.lightGray;
\r
222 } catch (Exception e) {
\r
223 Bond b = (Bond) bonds.elementAt(i);
\r
224 b.startCol = Color.gray;
\r
225 b.endCol = Color.gray;
\r
230 public void setHydrophobicityColours() {
\r
231 float hydmin = (float) ResidueProperties.getHydmin();
\r
232 float hydmax = (float) ResidueProperties.getHydmax();
\r
233 double[] hyd = ResidueProperties.getHyd();
\r
235 Hashtable AA3Hash = ResidueProperties.getAA3Hash();
\r
237 for (int i = 0; i < bonds.size(); i++) {
\r
239 Bond b = (Bond) bonds.elementAt(i);
\r
241 int atno = ((Integer) AA3Hash.get(b.at1.resName.toUpperCase())).intValue();
\r
242 float red = ((float) hyd[atno] - hydmin) / (hydmax - hydmin);
\r
244 if (red > (float) 1.0) {
\r
248 if (red < (float) 0.0) {
\r
252 b.startCol = new Color(red, (float) 0.0, (float) 1.0 - red);
\r
253 atno = ((Integer) AA3Hash.get(b.at2.resName.toUpperCase())).intValue();
\r
255 red = ((float) hyd[atno] - hydmin) / (hydmax - hydmin);
\r
257 if (red > (float) 1.0) {
\r
261 if (red < (float) 0.0) {
\r
265 b.endCol = new Color(red, (float) 0.2, (float) 1.0 - red);
\r
266 } catch (Exception e) {
\r
267 Bond b = (Bond) bonds.elementAt(i);
\r
268 b.startCol = Color.gray;
\r
269 b.endCol = Color.gray;
\r
276 public void setChainColours(Color col)
\r
278 for (int i = 0; i < bonds.size(); i++)
\r
280 Bond tmp = (Bond) bonds.elementAt(i);
\r
281 tmp.startCol = col;
\r