/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ext.rbvi.chimera; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; /** * A class to model a Chimera or Jmol residue set, as * {@code Map>>}. This can then be * traversed to generate the required display command in Chimera or Jmol syntax. */ public class AtomSpecModel { private Map>> atomSpec; /** * Constructor */ public AtomSpecModel() { atomSpec = new TreeMap<>(); } public Map>> getMap() { return atomSpec; } /** * Adds one contiguous range to this atom spec * * @param model * @param startPos * @param endPos * @param chain */ public void addRange(int model, int startPos, int endPos, String chain) { /* * Get/initialize map of data for the colour and model */ Map> modelData = atomSpec.get(model); if (modelData == null) { atomSpec.put(model, modelData = new TreeMap<>()); } /* * Get/initialize map of data for colour, model and chain */ List chainData = modelData.get(chain); if (chainData == null) { chainData = new ArrayList<>(); modelData.put(chain, chainData); } /* * Add the start/end positions */ chainData.add(new int[] { startPos, endPos }); // TODO add intelligently, using a RangeList class } /** * Answers an iterable set of the structure models in this model * * @return */ public Iterable getModels() { return atomSpec.keySet(); } /** * Answers an iterable set of the chains in this model for the given structure * model, or an empty set if none * * @param model * @return */ public Iterable getChains(Integer model) { if (atomSpec.containsKey(model)) { return atomSpec.get(model).keySet(); } return Collections.emptySet(); } public List getRanges(Integer model, String chain) { Map> modelData = atomSpec.get(model); if (modelData != null) { List chainData = modelData.get(chain); if (chainData != null) { return chainData; } } return Collections.EMPTY_LIST; } }