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
92 .substring(dotPos + 1);
93 if (chainId.length() == 0)
97 return new AtomSpec(modelId, chainId, resNum, 0);
108 public AtomSpec(String pdbFile, String chain, int resNo, int atomNo)
110 this.pdbFile = pdbFile;
112 this.pdbResNum = resNo;
113 this.atomIndex = atomNo;
124 public AtomSpec(int modelId, String chainId, int resNo, int atomNo)
126 this.modelNo = modelId;
127 this.chain = chainId;
128 this.pdbResNum = resNo;
129 this.atomIndex = atomNo;
132 public String getPdbFile()
137 public String getChain()
142 public int getPdbResNum()
147 public int getAtomIndex()
152 public int getModelNumber()
157 public void setPdbFile(String file)
163 public String toString()
165 return "pdbFile: " + pdbFile + ", chain: " + chain + ", res: "
166 + pdbResNum + ", atom: " + atomIndex;