2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.rbvi.chimera;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
27 import java.util.TreeMap;
30 * A class to model a Chimera or Jmol residue set, as
31 * {@code Map<modelNumber, Map<chainId, List<residueRange>>>}. This can then be
32 * traversed to generate the required display command in Chimera or Jmol syntax.
34 public class AtomSpecModel
36 private Map<Integer, Map<String, List<int[]>>> atomSpec;
41 public AtomSpecModel()
43 atomSpec = new TreeMap<>();
46 public Map<Integer, Map<String, List<int[]>>> getMap()
52 * Adds one contiguous range to this atom spec
59 public void addRange(int model, int startPos, int endPos, String chain)
62 * Get/initialize map of data for the colour and model
64 Map<String, List<int[]>> modelData = atomSpec.get(model);
65 if (modelData == null)
67 atomSpec.put(model, modelData = new TreeMap<>());
71 * Get/initialize map of data for colour, model and chain
73 List<int[]> chainData = modelData.get(chain);
74 if (chainData == null)
76 chainData = new ArrayList<>();
77 modelData.put(chain, chainData);
81 * Add the start/end positions
83 chainData.add(new int[] { startPos, endPos });
84 // TODO add intelligently, using a RangeList class
88 * Answers an iterable set of the structure models in this model
92 public Iterable<Integer> getModels()
94 return atomSpec.keySet();
98 * Answers an iterable set of the chains in this model for the given structure
99 * model, or an empty set if none
104 public Iterable<String> getChains(Integer model)
106 if (atomSpec.containsKey(model))
108 return atomSpec.get(model).keySet();
110 return Collections.emptySet();
113 public List<int[]> getRanges(Integer model, String chain)
115 Map<String, List<int[]>> modelData = atomSpec.get(model);
116 if (modelData != null)
118 List<int[]> chainData = modelData.get(chain);
119 if (chainData != null)
124 return Collections.EMPTY_LIST;