3 * Copyright (c) 2006 The Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions, and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
15 * 3. Redistributions must acknowledge that this software was
16 * originally developed by the UCSF Computer Graphics Laboratory
17 * under support by the NIH National Center for Research Resources,
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package ext.edu.ucsf.rbvi.strucviz2;
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import java.util.List;
38 import java.util.TreeMap;
41 * This class provides the implementation for the ChimeraChain object
46 // TODO: [Optional] Implement toAttr() method
47 public class ChimeraChain implements ChimeraStructuralObject
51 * The model/subModel number this chain is a part of
53 private int modelNumber;
55 private int subModelNumber;
58 * A pointer to the model this chain is a part of
60 private ChimeraModel chimeraModel;
63 * The chainID (from the PDB record)
65 private String chainId;
68 * The residues that are part of this chain
70 private TreeMap<String, ChimeraResidue> residueMap;
73 * userData to associate with this chain
75 private Object userData;
78 * Flag to indicate the selection state
80 private boolean selected = false;
83 * Constructor to create a new ChimeraChain
86 * the model number this chain is part of
88 * the subModel number this chain is part of
90 * the chain ID for this chain
92 public ChimeraChain(int model, int subModel, String chainId)
94 this.modelNumber = model;
95 this.subModelNumber = subModel;
96 this.chainId = chainId;
97 residueMap = new TreeMap<String, ChimeraResidue>();
101 * set the selected state of this chain
104 * a boolean to set the selected state to
106 public void setSelected(boolean selected)
108 this.selected = selected;
112 * return the selected state of this chain
114 * @return the selected state
116 public boolean isSelected()
121 public boolean hasSelectedChildren()
129 for (ChimeraResidue residue : getResidues())
131 if (residue.isSelected())
139 * Return the list of selected residues
141 * @return all selected residues
143 public List<ChimeraResidue> getSelectedResidues()
145 List<ChimeraResidue> residueList = new ArrayList<ChimeraResidue>();
148 residueList.addAll(getResidues());
152 for (ChimeraResidue residue : getResidues())
154 if (residue.isSelected())
155 residueList.add(residue);
162 * Add a residue to the chain.
165 * the ChimeraResidue to add to the chain.
167 public void addResidue(ChimeraResidue residue)
169 String index = residue.getIndex();
170 // Put it in our map so that we can return it in order
171 residueMap.put(index, residue);
175 * Return the list of residues in this chain in pdb residue order
177 * @return a Collection of residues in residue order
179 public Collection<ChimeraResidue> getResidues()
181 return residueMap.values();
185 * Return the list of residues in this chain as a list
187 * @return List of residues
189 public List<ChimeraStructuralObject> getChildren()
191 return new ArrayList<ChimeraStructuralObject>(residueMap.values());
195 * Get a specific residue
197 * @param residueIndex
198 * String representation of the residue index
199 * @return the ChimeraResidue represented by the residueIndex
201 public ChimeraResidue getResidue(String index)
203 // Integer index = new Integer(residueIndex);
204 if (residueMap.containsKey(index))
205 return residueMap.get(index);
210 * Get a list of residues as a residue range
212 * @param residueRange
213 * String representation of the residue range
214 * @return the List of ChimeraResidues represented by the range
216 public List<ChimeraResidue> getResidueRange(String residueRange)
218 String[] range = residueRange.split("-", 2);
219 if (range[1] == null || range[1].length() == 0)
223 List<ChimeraResidue> resultRange = new ArrayList<ChimeraResidue>();
224 int start = Integer.parseInt(range[0]);
225 int end = Integer.parseInt(range[1]);
226 for (int i = start; i <= end; i++)
228 String index = String.valueOf(i);
229 if (residueMap.containsKey(index))
230 resultRange.add(residueMap.get(index));
236 * Get the ID for this chain
238 * @return String value of the chainId
240 public String getChainId()
246 * Get the model number for this chain
248 * @return the model number
250 public int getModelNumber()
256 * Get the sub-model number for this chain
258 * @return the sub-model number
260 public int getSubModelNumber()
262 return subModelNumber;
266 * Return a string representation of this chain as follows: Chain
267 * <i>chainId</i> (<i>residue_count</i> residues)
269 * @return String representation of chain
271 public String displayName()
273 if (chainId.equals("_"))
275 return ("Chain (no ID) (" + getResidueCount() + " residues)");
279 return ("Chain " + chainId + " (" + getResidueCount() + " residues)");
284 * Return a string representation of this chain as follows: Node xxx [Model
285 * yyyy Chain <i>chainId</i>]
287 * @return String representation of chain
289 public String toString()
291 String displayName = chimeraModel.getModelName();
292 if (displayName.length() > 14)
293 displayName = displayName.substring(0, 13) + "...";
294 if (chainId.equals("_"))
296 return (displayName + " Chain (no ID) (" + getResidueCount() + " residues)");
300 return (displayName + " Chain " + chainId + " (" + getResidueCount() + " residues)");
305 * Return the Chimera specification for this chain
307 * @return Chimera specification
309 public String toSpec()
311 if (chainId.equals("_"))
313 return ("#" + modelNumber + "." + subModelNumber + ":.");
317 return ("#" + modelNumber + "." + subModelNumber + ":." + chainId);
322 * Return the number of residues in this chain
324 * @return integer number of residues
326 public int getResidueCount()
328 return residueMap.size();
332 * Set the ChimeraModel for this chain
335 * ChimeraModel to associate with this chain
337 public void setChimeraModel(ChimeraModel model)
339 this.chimeraModel = model;
343 * Get the ChimeraModel for this chain
345 * @return ChimeraModel associated with this chain
347 public ChimeraModel getChimeraModel()
353 * Get the user data for this Chain
357 public Object getUserData()
363 * Set the user data for this Chain
366 * the user data to associate with this chain
368 public void setUserData(Object data)
370 this.userData = data;