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 {
50 * The model/subModel number this chain is a part of
52 private int modelNumber;
53 private int subModelNumber;
56 * A pointer to the model this chain is a part of
58 private ChimeraModel chimeraModel;
61 * The chainID (from the PDB record)
63 private String chainId;
66 * The residues that are part of this chain
68 private TreeMap<String, ChimeraResidue> residueMap;
71 * userData to associate with this chain
73 private Object userData;
76 * Flag to indicate the selection state
78 private boolean selected = false;
81 * Constructor to create a new ChimeraChain
84 * the model number this chain is part of
86 * the subModel number this chain is part of
88 * the chain ID for this chain
90 public ChimeraChain(int model, int subModel, String chainId) {
91 this.modelNumber = model;
92 this.subModelNumber = subModel;
93 this.chainId = chainId;
94 residueMap = new TreeMap<String, ChimeraResidue>();
98 * set the selected state of this chain
101 * a boolean to set the selected state to
103 public void setSelected(boolean selected) {
104 this.selected = selected;
108 * return the selected state of this chain
110 * @return the selected state
112 public boolean isSelected() {
116 public boolean hasSelectedChildren() {
120 for (ChimeraResidue residue : getResidues()) {
121 if (residue.isSelected())
129 * Return the list of selected residues
131 * @return all selected residues
133 public List<ChimeraResidue> getSelectedResidues() {
134 List<ChimeraResidue> residueList = new ArrayList<ChimeraResidue>();
136 residueList.addAll(getResidues());
138 for (ChimeraResidue residue : getResidues()) {
139 if (residue.isSelected())
140 residueList.add(residue);
147 * Add a residue to the chain.
150 * the ChimeraResidue to add to the chain.
152 public void addResidue(ChimeraResidue residue) {
153 String index = residue.getIndex();
154 // Put it in our map so that we can return it in order
155 residueMap.put(index, residue);
159 * Return the list of residues in this chain in pdb residue order
161 * @return a Collection of residues in residue order
163 public Collection<ChimeraResidue> getResidues() {
164 return residueMap.values();
168 * Return the list of residues in this chain as a list
170 * @return List of residues
172 public List<ChimeraStructuralObject> getChildren() {
173 return new ArrayList<ChimeraStructuralObject>(residueMap.values());
177 * Get a specific residue
179 * @param residueIndex
180 * String representation of the residue index
181 * @return the ChimeraResidue represented by the residueIndex
183 public ChimeraResidue getResidue(String index) {
184 // Integer index = new Integer(residueIndex);
185 if (residueMap.containsKey(index))
186 return residueMap.get(index);
191 * Get a list of residues as a residue range
193 * @param residueRange
194 * String representation of the residue range
195 * @return the List of ChimeraResidues represented by the range
197 public List<ChimeraResidue> getResidueRange(String residueRange) {
198 String[] range = residueRange.split("-", 2);
199 if (range[1] == null || range[1].length() == 0) {
202 List<ChimeraResidue> resultRange = new ArrayList<ChimeraResidue>();
203 int start = Integer.parseInt(range[0]);
204 int end = Integer.parseInt(range[1]);
205 for (int i = start; i <= end; i++) {
206 String index = String.valueOf(i);
207 if (residueMap.containsKey(index))
208 resultRange.add(residueMap.get(index));
214 * Get the ID for this chain
216 * @return String value of the chainId
218 public String getChainId() {
223 * Get the model number for this chain
225 * @return the model number
227 public int getModelNumber() {
232 * Get the sub-model number for this chain
234 * @return the sub-model number
236 public int getSubModelNumber() {
237 return subModelNumber;
241 * Return a string representation of this chain as follows: Chain <i>chainId</i>
242 * (<i>residue_count</i> residues)
244 * @return String representation of chain
246 public String displayName() {
247 if (chainId.equals("_")) {
248 return ("Chain (no ID) (" + getResidueCount() + " residues)");
250 return ("Chain " + chainId + " (" + getResidueCount() + " residues)");
255 * Return a string representation of this chain as follows: Node xxx [Model yyyy Chain
258 * @return String representation of chain
260 public String toString() {
261 String displayName = chimeraModel.getModelName();
262 if (displayName.length() > 14)
263 displayName = displayName.substring(0, 13) + "...";
264 if (chainId.equals("_")) {
265 return (displayName + " Chain (no ID) (" + getResidueCount() + " residues)");
267 return (displayName + " Chain " + chainId + " (" + getResidueCount() + " residues)");
272 * Return the Chimera specification for this chain
274 * @return Chimera specification
276 public String toSpec() {
277 if (chainId.equals("_")) {
278 return ("#" + modelNumber + "." + subModelNumber + ":.");
280 return ("#" + modelNumber + "." + subModelNumber + ":." + chainId);
285 * Return the number of residues in this chain
287 * @return integer number of residues
289 public int getResidueCount() {
290 return residueMap.size();
294 * Set the ChimeraModel for this chain
297 * ChimeraModel to associate with this chain
299 public void setChimeraModel(ChimeraModel model) {
300 this.chimeraModel = model;
304 * Get the ChimeraModel for this chain
306 * @return ChimeraModel associated with this chain
308 public ChimeraModel getChimeraModel() {
313 * Get the user data for this Chain
317 public Object getUserData() {
322 * Set the user data for this Chain
325 * the user data to associate with this chain
327 public void setUserData(Object data) {
328 this.userData = data;