Repository navigation
Expand file tree
/
Copy pathTestBond.java
More file actions
345 lines (285 loc) · 9.64 KB
/
Copy pathTestBond.java
File metadata and controls
345 lines (285 loc) · 9.64 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
* 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/
*
*/
package org.biojava.nbio.structure;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.biojava.nbio.structure.io.FileParsingParameters;
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.*;
public class TestBond {
private static final Logger logger = LoggerFactory.getLogger(TestBond.class);
private static AtomCache cache;
@BeforeClass
public static void setUp() {
// important: without this the tests can fail when running in maven (but not in IDE)
// that's because it depends on the order on how tests were run - JD 2018-03-10
ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());
cache = new AtomCache();
cache.setUseMmCif(true);
FileParsingParameters params = cache.getFileParsingParams();
params.setAlignSeqRes(true);
params.setCreateAtomBonds(true);
StructureIO.setAtomCache(cache);
}
@Test
public void testStructConnModels() throws IOException, StructureException {
Structure s = StructureIO.getStructure("1cdr");
Group groupOne = s.getPolyChain("A",1).getGroupByPDB(new ResidueNumber("A", 18, ' '));
Group groupTwo = s.getNonPolyChain("B",1).getGroupByPDB(new ResidueNumber("A", 78, ' '));
Atom atomOne = groupOne.getAtom("ND2");
Atom atomTwo = groupTwo.getAtom("C1");
assertTrue(areBonded(atomOne, atomTwo));
}
@Test
public void testIntraResidueBonds() throws StructureException, IOException {
Structure s = StructureIO.getStructure("1kh9");
Group g = s.getPolyChainByPDB("A").getSeqResGroup(274);
Atom cg = g.getAtom("CG");
Atom cb = g.getAtom("CB");
Atom cd1 = g.getAtom("CD1");
Atom cd2 = g.getAtom("CD2");
assertEquals(3, cg.getBonds().size());
for (Bond bond : cg.getBonds()) {
if (bond.getOther(cg) == cb) {
assertEquals(1, bond.getBondOrder());
} else if (bond.getOther(cg) == cd1) {
assertEquals(2, bond.getBondOrder());
} else if (bond.getOther(cg) == cd2) {
assertEquals(1, bond.getBondOrder());
}
}
}
@Test
public void testPeptideBonds() throws StructureException, IOException {
Structure s = StructureIO.getStructure("1kh9");
AminoAcidImpl residue1 = (AminoAcidImpl) s.getPolyChainByPDB("A").getSeqResGroup(273);
AminoAcidImpl residue2 = (AminoAcidImpl) s.getPolyChainByPDB("A").getSeqResGroup(274);
Atom carboxylC = residue1.getC();
Atom aminoN = residue2.getN();
assertTrue(areBonded(carboxylC, aminoN));
}
@Test
public void testDisulfideBonds() throws StructureException, IOException {
Structure s = StructureIO.getStructure("1kh9");
Atom atom1 = s.getPolyChainByPDB("A").getSeqResGroup(177).getAtom("SG");
Atom atom2 = s.getPolyChainByPDB("A").getSeqResGroup(167).getAtom("SG");
assertTrue(areBonded(atom1, atom2));
}
@Test
public void testLigandBonds() throws StructureException, IOException {
Structure s = StructureIO.getStructure("1kh9");
Atom phosphateP = s.getChain("I").getAtomGroup(0).getAtom("P");
Atom phosphateO = s.getChain("I").getAtomGroup(0).getAtom("O1");
assertTrue(areBonded(phosphateP, phosphateO));
}
/**
* Test whether nucleotide bonds are being generated
* @throws IOException
* @throws StructureException
*/
@Test
public void testNucleotideBonds() throws IOException, StructureException {
Structure bio = StructureIO.getStructure("4y60");
for( Chain c : bio.getChains()) {
int groupCounter = 0;
List<Group> currentGroups = c.getAtomGroups();
for ( Group g : currentGroups) {
if(groupCounter!=0 && groupCounter<currentGroups.size()) {
List<Atom> atoms = g.getAtoms();
for ( Atom a : atoms) {
if ( a.getName().equals("P")){
// Check to see if one of the phosphate atoms has bonding to something
// outside of the group.
List<Integer> indexList = new ArrayList<>();
for (Bond b : a.getBonds()){
indexList.add(atoms.indexOf(b.getOther(a)));
}
assertTrue(indexList.contains(-1));
}
}
}
groupCounter++;
}
}
}
/**
* Test whether these partial occupancy hydrogens are bonded to the residue.
* @throws StructureException
* @throws IOException
*/
@Test
public void testHeavyAtomBondMissing() throws IOException, StructureException {
assertEquals(0, countAtomsWithoutBonds("3jtm"));
assertEquals(0, countAtomsWithoutBonds("3jq8"));
assertEquals(0, countAtomsWithoutBonds("3jq9"));
assertEquals(0, countAtomsWithoutBonds("3i06"));
assertEquals(0, countAtomsWithoutBonds("3nu3"));
assertEquals(0, countAtomsWithoutBonds("3nu4"));
assertEquals(0, countAtomsWithoutBonds("3nvd"));
}
/**
* Test whether these partial occupancy hydrogens are bonded to the residue.
* @throws StructureException
* @throws IOException
*/
@Test
public void testHydrogenToProteinBondMissing() throws IOException, StructureException {
assertEquals(0, countAtomsWithoutBonds("4txr"));
assertEquals(0, countAtomsWithoutBonds("3nvd"));
}
/**
* Test whether these partial occupancy hydrogens are bonded to the residue.
* @throws StructureException
* @throws IOException
*/
@Test
public void testAltLocBondMissing() throws IOException, StructureException {
assertEquals(0, countAtomsWithoutBonds("4cup"));
}
/**
* Loops through whole structure counting all atoms (in groups larger than 1 atom)
* that have no bonds.
* @throws IOException
* @throws StructureException
*/
private int countAtomsWithoutBonds(String pdbId) throws IOException, StructureException {
Structure inputStructure = StructureIO.getStructure(pdbId);
// Loop through the structure
int nonBondedCounter = 0;
for(int i=0;i<inputStructure.nrModels();i++){
for(Chain c: inputStructure.getChains(i)){
for(Group g: c.getAtomGroups()){
// Skip single atom groups
if(g.size()<=1){
continue;
}
// Get all the atoms
List<Atom> atomsList = new ArrayList<>(g.getAtoms());
for(Group altLocOne: g.getAltLocs()){
atomsList.addAll(altLocOne.getAtoms());
}
// Check they all have bonds
for(Atom a: atomsList){
if(a.getBonds()==null){
logger.debug("Atom {}-{} has no bonds", a.getPDBserial(), a.getName());
nonBondedCounter++;
}
}
}
}
}
return nonBondedCounter;
}
private int countBondedToSelf(String pdbId) throws IOException, StructureException {
Structure inputStructure = StructureIO.getStructure(pdbId);
int bondedToSelf =0;
for(int i=0;i<inputStructure.nrModels();i++){
for(Chain c: inputStructure.getChains(i)){
for(Group g: c.getAtomGroups()){
// Skip single atom groups
if(g.size()<=1){
continue;
}
// Get all the atoms
List<Atom> atomsList = new ArrayList<>(g.getAtoms());
for(Group altLocOne: g.getAltLocs()){
atomsList.addAll(altLocOne.getAtoms());
}
// Check they all have bonds
for(Atom a: atomsList){
if(a.getBonds()!=null){
for(Bond b: a.getBonds()){
if(b.getAtomA().equals(b.getAtomB())){
bondedToSelf+=1;
}
}
}
}
}
}
}
return bondedToSelf;
}
private boolean areBonded(Atom a, Atom b) {
for (Bond bond : a.getBonds()) {
if (bond.getOther(a) == b) {
return true;
}
}
return false;
}
/*
* Each of the following PDB IDs used to make formBonds() crash.
*/
@Test
public void test145D() throws IOException, StructureException {
StructureIO.getStructure("145D");
}
@Test
public void test1APJ() throws IOException, StructureException {
StructureIO.getStructure("1APJ");
}
@Test
public void test1BDX() throws IOException, StructureException {
StructureIO.getStructure("1BDX");
}
/**
* Test that all the atoms in deuterated structures are bonded.
* @throws IOException an error getting the required file
* @throws StructureException an error parsing the required file
*/
@Test
public void testDeuterated() throws IOException, StructureException {
// The terminal Hydrogen D3 - is missing (from the CCD)
assertEquals(2, countAtomsWithoutBonds("1GKT"));
assertEquals(2, countAtomsWithoutBonds("1IO5"));
// All H/D2,H/D3 errors
assertEquals(13, countAtomsWithoutBonds("5E5J"));
}
/**
* Test this weird case - with missing Oxygen atoms, alternate locations on Deuterium
* and terminal hydrogens.
* @throws IOException an error getting the required file
* @throws StructureException an error parsing the required file
*/
@Test
public void testWeirdCase() throws IOException, StructureException {
assertEquals(6, countAtomsWithoutBonds("1IU6"));
}
/**
* Test that Sulphur atoms are not found to be bonded to themselves
* @throws IOException an error getting the required file
* @throws StructureException an error parsing the required file
*/
@Test
public void testSSBonds() throws IOException, StructureException {
for(String pdbCode : new String[]{"3ZXW","1NTY", "4H2I", "2K6D", "2MLM"}){
assertEquals(0, countBondedToSelf(pdbCode));
}
}
}