// called by JMolSelectionListener.java to set the selected Atoms list public void setSelectedAtoms(BS values) { // System.out.println("Selected: " + values); if (selectedAtoms == null) selectedAtoms = new ArrayList<Atom>(); else selectedAtoms.clear(); String[] valueGet = values.toString().split("[{ }]"); if (modelList != null) { Model currentModel = modelList.get(viewer.getDisplayModelIndex()); for (int i = 0; i < valueGet.length; i++) { if (valueGet[i].compareTo("") != 0) { // if its list of continuous atoms if (valueGet[i].contains(":")) { int start = Integer.parseInt(valueGet[i].split(":")[0]) + 1; int end = Integer.parseInt(valueGet[i].split(":")[1]) + 1; for (int j = start; j <= end; j++) { selectedAtoms.add(currentModel.getAtomHash().get(currentModel.getModelName() + j)); } } else { selectedAtoms.add( currentModel .getAtomHash() .get(currentModel.getModelName() + (Integer.parseInt(valueGet[i]) + 1))); } } } } }
// set the model's bonds using Jmol display. public void setModelBonds() { int currModel = 0, prevModel = 0; Atom atom1, atom2; Bond bond; String index1, index2; ArrayList<Bond> ownbonds = new ArrayList<Bond>(); org.jmol.modelset.Bond[] bonds = viewer.ms.bo; for (int i = 0; i < bonds.length; i++) { prevModel = currModel; currModel = bonds[i].getAtom1().getModelNumber(); Model model = modelList.get(currModel - 1); if (currModel != prevModel && i != 0) { modelList.get(prevModel - 1).setBonds(ownbonds); ownbonds.clear(); } index1 = model.getModelName() + bonds[i].getAtom1().atomSite; index2 = model.getModelName() + bonds[i].getAtom2().atomSite; atom1 = model.getAtomHash().get(index1); atom2 = model.getAtomHash().get(index2); if (atom1 == null || atom2 == null) continue; bond = new Bond(atom1, atom2); ownbonds.add(bond); atom1.setBond(bond); atom2.setBond(bond); if (i == bonds.length - 1) { modelList.get(currModel - 1).setBonds(ownbonds); } } }