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.structure;
24 * Java bean representing an atom in a PDB (or similar) structure model or
34 private String pdbFile;
38 private int pdbResNum;
40 private int atomIndex;
43 * Parses a Chimera atomspec e.g. #1:12.A to construct an AtomSpec model (with
48 * #1.2:12-20.A model 1, submodel 2, chain A, atoms 12-20
56 * @throw IllegalArgumentException if the spec cannot be parsed, or represents
57 * more than one residue
58 * @see https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/frameatom_spec.html
59 * @see http://rbvi.ucsf.edu/chimerax/docs/user/commands/atomspec.html
61 public static AtomSpec fromChimeraAtomspec(String spec, boolean chimeraX)
63 int modelSeparatorPos = spec.indexOf(chimeraX ? "/" : ":");
64 if (modelSeparatorPos == -1)
66 throw new IllegalArgumentException(spec);
69 int hashPos = spec.indexOf("#");
70 if (hashPos == -1 && modelSeparatorPos != 0)
72 // # is missing but something precedes : - reject
73 throw new IllegalArgumentException(spec);
76 String modelSubmodel = spec.substring(hashPos + 1, modelSeparatorPos);
80 int subModelPos = modelSubmodel.indexOf(".");
81 modelId = Integer.valueOf(
82 subModelPos > 0 ? modelSubmodel.substring(0, subModelPos)
84 } catch (NumberFormatException e)
86 // ignore, default to model 0
90 * now process what follows the model, either
91 * Chimera: atoms.chain
92 * ChimeraX: chain:atoms
94 String atomsAndChain = spec.substring(modelSeparatorPos + 1);
95 String[] tokens = atomsAndChain.split(chimeraX ? "\\:" : "\\.");
96 String atoms = tokens.length == 1 ? atomsAndChain
97 : (chimeraX ? tokens[1] : tokens[0]);
101 resNum = Integer.parseInt(atoms);
102 } catch (NumberFormatException e)
104 // could be a range e.g. #1:4-7.B
105 throw new IllegalArgumentException(spec);
108 String chainId = tokens.length == 1 ? ""
109 : (chimeraX ? tokens[0] : tokens[1]);
111 return new AtomSpec(modelId, chainId, resNum, 0);
122 public AtomSpec(String pdbFile, String chain, int resNo, int atomNo)
124 this.pdbFile = pdbFile;
126 this.pdbResNum = resNo;
127 this.atomIndex = atomNo;
138 public AtomSpec(int modelId, String chainId, int resNo, int atomNo)
140 this.modelNo = modelId;
141 this.chain = chainId;
142 this.pdbResNum = resNo;
143 this.atomIndex = atomNo;
146 public String getPdbFile()
151 public String getChain()
156 public int getPdbResNum()
161 public int getAtomIndex()
166 public int getModelNumber()
171 public void setPdbFile(String file)
177 public String toString()
179 return "pdbFile: " + pdbFile + ", chain: " + chain + ", res: "
180 + pdbResNum + ", atom: " + atomIndex;