X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FAtomSpec.java;fp=src%2Fjalview%2Fstructure%2FAtomSpec.java;h=f20cd31e4b44c6a4d1a98500724eaa43ad8ce139;hb=3d2b5edf9ea33c6ebbde4717ccc14f03554fb6f0;hp=a19acef74c85b4b4150c5f55dfcd5dcd9a4f5ce7;hpb=734d0e761fda32cebaae59c370c5d64e1e8c99e8;p=jalview.git diff --git a/src/jalview/structure/AtomSpec.java b/src/jalview/structure/AtomSpec.java index a19acef..f20cd31 100644 --- a/src/jalview/structure/AtomSpec.java +++ b/src/jalview/structure/AtomSpec.java @@ -29,9 +29,8 @@ package jalview.structure; */ public class AtomSpec { - // TODO clarify do we want pdbFile here, or pdbId? - // compare highlightAtom in 2.8.2 for JalviewJmolBinding and - // javascript.MouseOverStructureListener + int modelNo; + private String pdbFile; private String chain; @@ -41,6 +40,60 @@ public class AtomSpec private int atomIndex; /** + * Parses a Chimera atomspec e.g. #1:12.A to construct an AtomSpec model (with + * null pdb file name) + * + * @param spec + * @return + * @throw IllegalArgumentException if the spec cannot be parsed, or represents + * more than one residue + */ + public static AtomSpec fromChimeraAtomspec(String spec) + { + int colonPos = spec.indexOf(":"); + if (colonPos == -1) + { + throw new IllegalArgumentException(spec); + } + + int hashPos = spec.indexOf("#"); + if (hashPos == -1 && colonPos != 0) + { + // # is missing but something precedes : - reject + throw new IllegalArgumentException(spec); + } + + String modelSubmodel = spec.substring(hashPos + 1, colonPos); + int dotPos = modelSubmodel.indexOf("."); + int modelId = 0; + try + { + modelId = Integer.valueOf(dotPos == -1 ? modelSubmodel + : modelSubmodel.substring(0, dotPos)); + } catch (NumberFormatException e) + { + // ignore, default to model 0 + } + + String residueChain = spec.substring(colonPos + 1); + dotPos = residueChain.indexOf("."); + int resNum = 0; + try + { + resNum = Integer.parseInt(dotPos == -1 ? residueChain + : residueChain.substring(0, dotPos)); + } catch (NumberFormatException e) + { + // could be a range e.g. #1:4-7.B + throw new IllegalArgumentException(spec); + } + + String chainId = dotPos == -1 ? "" : residueChain.substring(dotPos + 1); + + return new AtomSpec(modelId, chainId, resNum, 0); + } + + /** * Constructor * * @param pdbFile @@ -56,6 +109,22 @@ public class AtomSpec this.atomIndex = atomNo; } + /** + * Constructor + * + * @param modelId + * @param chainId + * @param resNo + * @param atomNo + */ + public AtomSpec(int modelId, String chainId, int resNo, int atomNo) + { + this.modelNo = modelId; + this.chain = chainId; + this.pdbResNum = resNo; + this.atomIndex = atomNo; + } + public String getPdbFile() { return pdbFile; @@ -76,6 +145,16 @@ public class AtomSpec return atomIndex; } + public int getModelNumber() + { + return modelNo; + } + + public void setPdbFile(String file) + { + pdbFile = file; + } + @Override public String toString() {