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 * @throw IllegalArgumentException if the spec cannot be parsed, or represents
49 * more than one residue
51 public static AtomSpec fromChimeraAtomspec(String spec)
53 int colonPos = spec.indexOf(":");
56 throw new IllegalArgumentException(spec);
59 int hashPos = spec.indexOf("#");
60 if (hashPos == -1 && colonPos != 0)
62 // # is missing but something precedes : - reject
63 throw new IllegalArgumentException(spec);
66 String modelSubmodel = spec.substring(hashPos + 1, colonPos);
67 int dotPos = modelSubmodel.indexOf(".");
71 modelId = Integer.valueOf(dotPos == -1 ? modelSubmodel
72 : modelSubmodel.substring(0, dotPos));
73 } catch (NumberFormatException e)
75 // ignore, default to model 0
78 String residueChain = spec.substring(colonPos + 1);
79 dotPos = residueChain.indexOf(".");
83 resNum = Integer.parseInt(dotPos == -1 ? residueChain
84 : residueChain.substring(0, dotPos));
85 } catch (NumberFormatException e)
87 // could be a range e.g. #1:4-7.B
88 throw new IllegalArgumentException(spec);
91 String chainId = dotPos == -1 ? "" : residueChain.substring(dotPos + 1);
93 return new AtomSpec(modelId, chainId, resNum, 0);
104 public AtomSpec(String pdbFile, String chain, int resNo, int atomNo)
106 this.pdbFile = pdbFile;
108 this.pdbResNum = resNo;
109 this.atomIndex = atomNo;
120 public AtomSpec(int modelId, String chainId, int resNo, int atomNo)
122 this.modelNo = modelId;
123 this.chain = chainId;
124 this.pdbResNum = resNo;
125 this.atomIndex = atomNo;
128 public String getPdbFile()
133 public String getChain()
138 public int getPdbResNum()
143 public int getAtomIndex()
148 public int getModelNumber()
153 public void setPdbFile(String file)
159 public String toString()
161 return "pdbFile: " + pdbFile + ", chain: " + chain + ", res: "
162 + pdbResNum + ", atom: " + atomIndex;