Repository navigation
Expand file tree
/
Copy pathAtomImpl.java
More file actions
329 lines (278 loc) · 6.02 KB
/
Copy pathAtomImpl.java
File metadata and controls
329 lines (278 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
* Created on 28.04.2004
* @author Andreas Prlic
*
*/
package org.biojava.nbio.structure;
import org.biojava.nbio.structure.io.FileConvert;
import java.util.ArrayList;
import java.util.List;
import javax.vecmath.Point3d;
/**
* Implementation of an Atom of a PDB file.
* currently the coordinates of an atom are represented by a double[3] array.
* @author Andreas Prlic
* @since 1.4
* @version %I% %G%
*/
public class AtomImpl implements Atom {
private static final long serialVersionUID = -2258364127420562883L;
/**
* The inital capacity of the bonds list.
* Most atoms have a maximum of 3 heavy atom neighbors.
*/
public static final int BONDS_INITIAL_CAPACITY = 3;
private String name;
private Element element;
private Point3d coords;
private int pdbserial;
private short charge;
private float occupancy ;
private float tempfactor;
private char altLoc ;
private Group parent;
private List<Bond> bonds;
public AtomImpl () {
name = null;
element = Element.R;
coords = new Point3d();
occupancy = 0.0f;
tempfactor = 0.0f;
altLoc = 0;
parent = null;
bonds = null; // let's save some memory and let's not initialise this until it's needed - JD 2016-03-02
charge = 0;
}
/**
* {@inheritDoc}
*/
@Override
public void setName(String s) { name = s ;}
/**
* {@inheritDoc}
*/
@Override
public String getName() { return name ;}
/**
* {@inheritDoc}
*/
@Override
public void setPDBserial(int i) { pdbserial = i ; }
/**
* {@inheritDoc}
*/
@Override
public int getPDBserial() { return pdbserial ; }
/**
* {@inheritDoc}
*/
@Override
public void setCoords( double[] c ) {
coords = new Point3d(c);
}
/**
* {@inheritDoc}
*/
@Override
public double[] getCoords() {
double[] c = new double[3];
coords.get(c);
return c;
}
/**
* {@inheritDoc}
*/
@Override
public Point3d getCoordsAsPoint3d() {
return coords;
}
@Override
public void setX(double x) {
coords.x = x ;
}
@Override
public void setY(double y) {
coords.y = y ;
}
@Override
public void setZ(double z) {
coords.z = z ;
}
/**
* {@inheritDoc}
*/
@Override
public double getX() { return coords.x; }
/**
* {@inheritDoc}
*/
@Override
public double getY() { return coords.y; }
/**
* {@inheritDoc}
*/
@Override
public double getZ() { return coords.z; }
/**
* Set alternate Location.
* @see #getAltLoc
*/
@Override
public void setAltLoc(Character c) {
// after changing altLoc from Character to char, we do this to keep the interface the same as it used to be - JD 2016-01-27
if (c==null)
altLoc = 0;
else
altLoc = c ;
}
/**
* Get alternate Location.
* @return a Character object representing the alt loc value
* @see #setAltLoc
*/
@Override
public Character getAltLoc() {
// after changing altLoc from Character to char, we do this to keep the interface the same as it used to be - JD 2016-01-27
if (altLoc==0 ) return null;
return altLoc ;
}
@Override
public String toString() {
return name + " " + element + " " + pdbserial + " " + coords.x + " " + coords.y + " " + coords.z;
}
@Override
public void setOccupancy(float occu){
occupancy = occu ;
}
@Override
public float getOccupancy(){
return occupancy;
}
@Override
public void setTempFactor(float temp) {
tempfactor = temp ;
}
@Override
public float getTempFactor() {
return tempfactor;
}
/** returns and identical copy of this object .
* @return and identical copy of this object
*/
@Override
public Object clone() {
AtomImpl n = new AtomImpl();
n.setOccupancy(getOccupancy());
n.setTempFactor(getTempFactor());
n.altLoc = altLoc; // since char is a primitive we can do this (to avoid going through getter/setter that check for nulls)
n.setCharge(getCharge());
double[] coords = getCoords();
n.setX(coords[0]);
n.setY(coords[1]);
n.setZ(coords[2]);
n.setPDBserial(getPDBserial());
n.setName(getName());
n.setElement(getElement());
// NOTE bonds can't be cloned here, they would need to be cloned at the
// chain or group level (depending if they are intra or inter group bonds) -- JD 2016-03-02
return n ;
}
/**
* {@inheritDoc}
*/
@Override
public void setGroup(Group parent){
this.parent = parent;
}
/**
* {@inheritDoc}
*/
@Override
public Group getGroup(){
return parent;
}
/**
* {@inheritDoc}
*/
@Override
public Element getElement() {
return element;
}
/**
* {@inheritDoc}
*/
@Override
public void setElement(Element e) {
this.element = e;
}
@Override
public String toPDB() {
return FileConvert.toPDB(this);
}
@Override
public void toPDB(StringBuffer buf) {
FileConvert.toPDB(this,buf);
}
/**
* {@inheritDoc}
*/
@Override
public List<Bond> getBonds() {
return bonds;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasBond(Atom other){
if ( bonds == null)
return false;
for (Bond b : bonds){
if ( b.getAtomA().equals(other) || b.getAtomB().equals(other))
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
@Override
public void setBonds(List<Bond> bonds) {
this.bonds = bonds;
}
@Override
public void addBond(Bond bond) {
if (bonds==null) {
bonds = new ArrayList<Bond>(BONDS_INITIAL_CAPACITY);
}
bonds.add(bond);
}
@Override
public short getCharge() {
// Get the charge
return charge;
}
@Override
public void setCharge(short inputCharge) {
// Set the charge
charge = inputCharge;
}
}