2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import jalview.datamodel.*;
23 import jalview.schemes.ResidueProperties;
28 import jalview.analysis.AlignSeq;
31 public class PDBChain {
33 public Vector bonds = new Vector();
34 public Vector atoms = new Vector();
35 public Vector residues = new Vector();
37 public Sequence sequence;
38 public boolean isVisible = true;
39 public int pdbstart = 0;
40 public int pdbend = 0;
41 public int seqstart = 0;
42 public int seqend = 0;
44 public PDBChain(String id) {
48 public String print() {
51 for (int i = 0; i < bonds.size(); i++) {
52 tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " " +
53 ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
60 void makeExactMapping(AlignSeq as, Sequence s1)
62 int pdbpos = as.getSeq2Start()-2;
63 int alignpos = s1.getStart() + as.getSeq1Start()-3;
65 for(int i=0; i<as.astr1.length(); i++)
67 if (as.astr1.charAt(i) != '-')
72 if (as.astr2.charAt(i) != '-')
77 if (as.astr1.charAt(i) == as.astr2.charAt(i))
79 Residue res = (Residue) residues.elementAt(pdbpos);
80 Enumeration en = res.atoms.elements();
81 while (en.hasMoreElements())
83 Atom atom = (Atom) en.nextElement();
84 atom.alignmentMapping = alignpos;
92 public void makeCaBondList()
94 for (int i = 0; i < (residues.size() - 1); i++)
96 Residue tmpres = (Residue) residues.elementAt(i);
97 Residue tmpres2 = (Residue) residues.elementAt(i + 1);
98 Atom at1 = tmpres.findAtom("CA");
99 Atom at2 = tmpres2.findAtom("CA");
101 if ((at1 != null) && (at2 != null))
103 if (at1.chain.equals(at2.chain))
109 System.out.println("not found "+i);
113 public void makeBond(Atom at1, Atom at2) {
114 float[] start = new float[3];
115 float[] end = new float[3];
125 bonds.addElement(new Bond(start, end, at1, at2));
128 public void makeResidueList() {
130 StringBuffer seq = new StringBuffer();
132 int i, iSize = atoms.size()-1;
133 for (i = 0; i < iSize; i++)
135 Atom tmp = (Atom) atoms.elementAt(i);
136 int resNumber = tmp.resNumber;
143 Vector resAtoms = new Vector();
145 resAtoms.addElement((Atom) atoms.elementAt(i));
147 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
149 //Add atoms to a vector while the residue number
151 while ((resNumber == res) && (i < atoms.size())) {
152 resAtoms.addElement((Atom) atoms.elementAt(i));
155 if (i < atoms.size()) {
156 resNumber = ((Atom) atoms.elementAt(i)).resNumber;
162 //We need this to keep in step with the outer for i = loop
165 //Make a new Residue object with the new atoms vector
166 residues.addElement(new Residue(resAtoms, resNumber - 1, count));
169 Residue tmpres = (Residue) residues.lastElement();
170 Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
172 // Keep totting up the sequence
173 if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
176 // System.err.println("PDBReader:Null aa3Hash for " +
180 seq.append(ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()
181 .get(tmpat.resName)).intValue()]);
185 if(id.length()<1 || id.equals(" "))
188 sequence = new Sequence(id, seq.toString(), 1, seq.length());
189 // System.out.println("PDB Sequence is :\nSequence = " + seq);
190 // System.out.println("No of residues = " + residues.size());
193 public void setChargeColours() {
194 for (int i = 0; i < bonds.size(); i++) {
196 Bond b = (Bond) bonds.elementAt(i);
198 if (b.at1.resName.equalsIgnoreCase("ASP") ||
199 b.at1.resName.equalsIgnoreCase("GLU")) {
200 b.startCol = Color.red;
201 } else if (b.at1.resName.equalsIgnoreCase("LYS") ||
202 b.at1.resName.equalsIgnoreCase("ARG")) {
203 b.startCol = Color.blue;
204 } else if (b.at1.resName.equalsIgnoreCase("CYS")) {
205 b.startCol = Color.yellow;
207 //int atno = ((Integer) ResidueProperties.getAA3Hash().get(b.at1.resName.toUpperCase())).intValue();
208 b.startCol = Color.lightGray;
211 if (b.at2.resName.equalsIgnoreCase("ASP") ||
212 b.at2.resName.equalsIgnoreCase("GLU")) {
213 b.endCol = Color.red;
214 } else if (b.at2.resName.equalsIgnoreCase("LYS") ||
215 b.at2.resName.equalsIgnoreCase("ARG")) {
216 b.endCol = Color.blue;
217 } else if (b.at2.resName.equalsIgnoreCase("CYS")) {
218 b.endCol = Color.yellow;
220 //int atno = ((Integer) ResidueProperties.getAA3Hash().get(b.at2.resName.toUpperCase())).intValue();
221 b.endCol = Color.lightGray;
223 } catch (Exception e) {
224 Bond b = (Bond) bonds.elementAt(i);
225 b.startCol = Color.gray;
226 b.endCol = Color.gray;
232 public void setChainColours(jalview.schemes.ColourSchemeI cs)
235 for (int i = 0; i < bonds.size(); i++) {
237 b = (Bond) bonds.elementAt(i);
239 ( (Bond) bonds.elementAt(i)).startCol = cs.findColour(
240 ResidueProperties.aa[ ( (Integer) ResidueProperties.aa3Hash.
241 get(b.at1.resName)).intValue()]
244 b.endCol = cs.findColour(
245 ResidueProperties.aa[ ( (Integer) ResidueProperties.aa3Hash.
246 get(b.at2.resName)).intValue()]
249 } catch (Exception e)
251 b = (Bond) bonds.elementAt(i);
252 b.startCol = Color.gray;
253 b.endCol = Color.gray;
260 public void setChainColours(Color col)
262 for (int i = 0; i < bonds.size(); i++)
264 Bond tmp = (Bond) bonds.elementAt(i);