Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.structure

File AtomSpec.java

 

Coverage histogram

../../img/srcFileCovDistChart2.png
51% of files have more coverage

Code metrics

10
34
10
1
164
89
18
0.53
3.4
10
1.8

Classes

Class Line # Actions
AtomSpec 30 34 18 43
0.203703720.4%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.structure;
22   
23    /**
24    * Java bean representing an atom in a PDB (or similar) structure model or
25    * viewer
26    *
27    * @author gmcarstairs
28    *
29    */
 
30    public class AtomSpec
31    {
32    int modelNo;
33   
34    private String pdbFile;
35   
36    private String chain;
37   
38    private int pdbResNum;
39   
40    private int atomIndex;
41   
42    /**
43    * Parses a Chimera atomspec e.g. #1:12.A to construct an AtomSpec model (with
44    * null pdb file name)
45    *
46    * @param spec
47    * @return
48    * @throw IllegalArgumentException if the spec cannot be parsed, or represents
49    * more than one residue
50    */
 
51  0 toggle public static AtomSpec fromChimeraAtomspec(String spec)
52    {
53  0 int colonPos = spec.indexOf(":");
54  0 if (colonPos == -1)
55    {
56  0 throw new IllegalArgumentException(spec);
57    }
58   
59  0 int hashPos = spec.indexOf("#");
60  0 if (hashPos == -1 && colonPos != 0)
61    {
62    // # is missing but something precedes : - reject
63  0 throw new IllegalArgumentException(spec);
64    }
65   
66  0 String modelSubmodel = spec.substring(hashPos + 1, colonPos);
67  0 int dotPos = modelSubmodel.indexOf(".");
68  0 int modelId = 0;
69  0 try
70    {
71  0 modelId = Integer.valueOf(dotPos == -1 ? modelSubmodel
72    : modelSubmodel.substring(0, dotPos));
73    } catch (NumberFormatException e)
74    {
75    // ignore, default to model 0
76    }
77   
78  0 String residueChain = spec.substring(colonPos + 1);
79  0 dotPos = residueChain.indexOf(".");
80  0 int resNum = 0;
81  0 try
82    {
83  0 resNum = Integer.parseInt(dotPos == -1 ? residueChain
84    : residueChain.substring(0, dotPos));
85    } catch (NumberFormatException e)
86    {
87    // could be a range e.g. #1:4-7.B
88  0 throw new IllegalArgumentException(spec);
89    }
90   
91  0 String chainId = dotPos == -1 ? "" : residueChain.substring(dotPos + 1);
92   
93  0 return new AtomSpec(modelId, chainId, resNum, 0);
94    }
95   
96    /**
97    * Constructor
98    *
99    * @param pdbFile
100    * @param chain
101    * @param resNo
102    * @param atomNo
103    */
 
104  1 toggle public AtomSpec(String pdbFile, String chain, int resNo, int atomNo)
105    {
106  1 this.pdbFile = pdbFile;
107  1 this.chain = chain;
108  1 this.pdbResNum = resNo;
109  1 this.atomIndex = atomNo;
110    }
111   
112    /**
113    * Constructor
114    *
115    * @param modelId
116    * @param chainId
117    * @param resNo
118    * @param atomNo
119    */
 
120  0 toggle public AtomSpec(int modelId, String chainId, int resNo, int atomNo)
121    {
122  0 this.modelNo = modelId;
123  0 this.chain = chainId;
124  0 this.pdbResNum = resNo;
125  0 this.atomIndex = atomNo;
126    }
127   
 
128  2 toggle public String getPdbFile()
129    {
130  2 return pdbFile;
131    }
132   
 
133  1 toggle public String getChain()
134    {
135  1 return chain;
136    }
137   
 
138  1 toggle public int getPdbResNum()
139    {
140  1 return pdbResNum;
141    }
142   
 
143  0 toggle public int getAtomIndex()
144    {
145  0 return atomIndex;
146    }
147   
 
148  0 toggle public int getModelNumber()
149    {
150  0 return modelNo;
151    }
152   
 
153  0 toggle public void setPdbFile(String file)
154    {
155  0 pdbFile = file;
156    }
157   
 
158  0 toggle @Override
159    public String toString()
160    {
161  0 return "pdbFile: " + pdbFile + ", chain: " + chain + ", res: "
162    + pdbResNum + ", atom: " + atomIndex;
163    }
164    }