+ * 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);
+ }
+
+ /**