Skip to content

Commit df98f2e

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 7f1a7f3 + bd62ae2 commit df98f2e

24 files changed

Lines changed: 5556 additions & 151 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java

Lines changed: 81 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.biojava.nbio.structure.test;
2424

2525
import junit.framework.TestCase;
26+
2627
import org.biojava.nbio.structure.*;
2728
import org.biojava.nbio.structure.align.util.AtomCache;
2829
import org.biojava.nbio.structure.io.FileParsingParameters;
@@ -35,21 +36,15 @@
3536

3637
public class StructureToolsTest extends TestCase {
3738

38-
Structure structure, structure2, structure3;
39+
Structure structure, structure2, structure3, structure4;
3940

4041
@Override
4142
protected void setUp() throws IOException
4243
{
4344
InputStream inStream = this.getClass().getResourceAsStream("/5pti.pdb");
4445
assertNotNull(inStream);
4546

46-
4747
PDBFileParser pdbpars = new PDBFileParser();
48-
FileParsingParameters params = new FileParsingParameters();
49-
params.setAlignSeqRes(false);
50-
params.setLoadChemCompInfo(false);
51-
52-
pdbpars.setFileParsingParameters(params);
5348

5449
structure = pdbpars.parsePDBFile(inStream) ;
5550

@@ -59,7 +54,7 @@ protected void setUp() throws IOException
5954

6055
Chain chain = structure.getChain(0);
6156
assertEquals("Wrong number of residues.",123,chain.getAtomLength());
62-
57+
6358
inStream.close();
6459

6560
// Load structure2
@@ -93,11 +88,32 @@ public void testGetCAAtoms(){
9388
assertEquals("did not find the expected number of Atoms (58), but got " + cas.length,58,cas.length);
9489
}
9590

91+
public void testGetAtomsConsistency() throws IOException, StructureException{
92+
AtomCache cache = new AtomCache();
93+
FileParsingParameters params = new FileParsingParameters();
94+
params.setLoadChemCompInfo(true);
95+
cache.setFileParsingParams(params);
96+
97+
Structure hivA = cache.getStructure("1hiv.A");
98+
Atom[] caSa = StructureTools.getRepresentativeAtomArray(hivA);
99+
Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChain(0));
100+
assertEquals("did not find the same number of Atoms from structure and from chain..",
101+
caSa.length,caCa.length);
102+
Structure hivB = cache.getStructure("1hiv.B");
103+
Atom[] caSb = StructureTools.getRepresentativeAtomArray(hivB);
104+
Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChain(0));
105+
assertEquals("did not find the same number of Atoms from structure and from chain..",
106+
caSb.length,caCb.length);
107+
//Both chains have to be the same size (A and B)
108+
assertEquals(caSa.length,99);
109+
assertEquals("did not find the same number of Atoms in both chains...",
110+
caSa.length,caCb.length);
111+
assertEquals(caSa.length, 99);
112+
}
113+
96114
public void testGetNrAtoms(){
97115
int length = StructureTools.getNrAtoms(structure);
98116
assertEquals("did not find the expected number of Atoms (1087), but got " + length,1087,length);
99-
100-
101117
}
102118

103119
public void testGetSubRanges() throws StructureException {
@@ -188,18 +204,18 @@ public void testGetSubRanges() throws StructureException {
188204
range = "_:";
189205
substr = StructureTools.getSubRanges(structure2, range);
190206
assertEquals("Wrong number of chains in "+range, 1, substr.size());
191-
207+
192208
chain = substr.getChain(0);
193209
assertEquals("Chain _ not converted to chain A.","A",chain.getChainID());
194210
assertEquals("Did not find the expected number of residues in first chain of "+range, 411, chain.getAtomLength() );
195-
211+
196212
try {
197213
// Illegal chain name
198214
range = "X:";
199215
substr = StructureTools.getSubRanges(structure2, range);
200216
fail("Illegal chain name in '"+range+"'. Should throw StructureException");
201217
} catch(StructureException ex) {} //expected
202-
218+
203219
// some negative tests
204220
try {
205221
range = "7-10";
@@ -217,7 +233,7 @@ public void testRevisedConvention() throws IOException, StructureException{
217233

218234
AtomCache cache = new AtomCache();
219235

220-
236+
221237
String name11 = "4hhb.A";
222238
Structure s = cache.getStructure(name11);
223239
assertTrue(s.getChains().size() == 1);
@@ -230,7 +246,7 @@ public void testRevisedConvention() throws IOException, StructureException{
230246
String name13 = "4hhb.A_";
231247
s = cache.getStructure(name13);
232248
assertTrue(s.getChains().size() == 1);
233-
249+
234250
String name9 = "4hhb.C_1-83";
235251
String chainId = "C";
236252
s = cache.getStructure(name9);
@@ -247,47 +263,47 @@ public void testRevisedConvention() throws IOException, StructureException{
247263
ca = StructureTools.getRepresentativeAtomArray(s);
248264
assertEquals(93, ca.length);
249265

250-
266+
251267
}
252268

253269

254-
// this will get replaced by #81
255-
// public void testStructureToolsRegexp(){
256-
//
257-
//
258-
// Pattern p = ResidueRange.RANGE_REGEX;
259-
//
260-
// String t2 = "A_10-20";
261-
// Matcher m2 = p.matcher(t2);
262-
// assertNotNull(m2);
263-
// assertTrue(m2.find());
264-
// assertTrue(m2.matches());
265-
//
266-
// // for (int i=0;i< m2.groupCount();i++){
267-
// // String s = m2.group(i);
268-
// // System.out.println(s);
269-
// // }
270-
// assertEquals(3,m2.groupCount());
271-
//
272-
//
273-
// String t1 = "A:10-20";
274-
// Matcher m1 = p.matcher(t1);
275-
// assertNotNull(m1);
276-
// assertTrue(m1.find());
277-
// assertTrue(m1.matches());
278-
// assertEquals(3,m1.groupCount());
279-
//
280-
//
281-
// String t3 = "A";
282-
// Matcher m3 = p.matcher(t3);
283-
//
284-
// assertNotNull(m3);
285-
// assertTrue(m3.find());
286-
// assertTrue(m3.matches());
287-
// assertEquals(3,m3.groupCount());
288-
//
289-
//
290-
// }
270+
// this will get replaced by #81
271+
// public void testStructureToolsRegexp(){
272+
//
273+
//
274+
// Pattern p = ResidueRange.RANGE_REGEX;
275+
//
276+
// String t2 = "A_10-20";
277+
// Matcher m2 = p.matcher(t2);
278+
// assertNotNull(m2);
279+
// assertTrue(m2.find());
280+
// assertTrue(m2.matches());
281+
//
282+
// // for (int i=0;i< m2.groupCount();i++){
283+
// // String s = m2.group(i);
284+
// // System.out.println(s);
285+
// // }
286+
// assertEquals(3,m2.groupCount());
287+
//
288+
//
289+
// String t1 = "A:10-20";
290+
// Matcher m1 = p.matcher(t1);
291+
// assertNotNull(m1);
292+
// assertTrue(m1.find());
293+
// assertTrue(m1.matches());
294+
// assertEquals(3,m1.groupCount());
295+
//
296+
//
297+
// String t3 = "A";
298+
// Matcher m3 = p.matcher(t3);
299+
//
300+
// assertNotNull(m3);
301+
// assertTrue(m3.find());
302+
// assertTrue(m3.matches());
303+
// assertEquals(3,m3.groupCount());
304+
//
305+
//
306+
// }
291307

292308
/**
293309
* Test some subranges that we used to have problems with
@@ -408,27 +424,35 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
408424
public void testGroupsWithinShell() {
409425
//TODO
410426
}
411-
427+
412428
public void testCAmmCIF() throws StructureException {
413429
//mmCIF files left justify their atom names (eg "CA "), so can have different behavior
414430
AtomCache pdbCache = new AtomCache();
415431
pdbCache.setUseMmCif(false);
432+
FileParsingParameters params = new FileParsingParameters();
433+
params.setLoadChemCompInfo(true);
434+
pdbCache.setFileParsingParams(params);
435+
416436
AtomCache mmcifCache = new AtomCache();
417437
mmcifCache.setUseMmCif(true);
438+
FileParsingParameters params2 = new FileParsingParameters();
439+
params2.setLoadChemCompInfo(true);
440+
mmcifCache.setFileParsingParams(params2);
418441

442+
419443
Structure pdb=null, mmcif=null;
420-
444+
421445
String name = "3PIU";
422446
try {
423447
pdb = pdbCache.getStructure(name);
424448
mmcif = mmcifCache.getStructure(name);
425449
} catch (IOException e) {
426450
assumeNoException(e);
427451
}
428-
452+
429453
Atom[] pdbCA = StructureTools.getRepresentativeAtomArray(pdb);
430454
Atom[] mmcifCA = StructureTools.getRepresentativeAtomArray(mmcif);
431-
455+
432456
assertEquals("PDB has wrong length",409,pdbCA.length);
433457
assertEquals("PDB has wrong length",409,mmcifCA.length);
434458
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package demo;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import org.biojava.nbio.structure.Atom;
8+
import org.biojava.nbio.structure.Structure;
9+
import org.biojava.nbio.structure.StructureException;
10+
import org.biojava.nbio.structure.StructureTools;
11+
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
12+
import org.biojava.nbio.structure.align.util.AtomCache;
13+
import org.biojava.nbio.structure.symmetry.gui.SymmetryDisplay;
14+
import org.biojava.nbio.structure.symmetry.internal.CESymmParameters;
15+
import org.biojava.nbio.structure.symmetry.internal.CESymmParameters.RefineMethod;
16+
import org.biojava.nbio.structure.symmetry.internal.CESymmParameters.SymmetryType;
17+
import org.biojava.nbio.structure.symmetry.internal.CeSymm;
18+
19+
/**
20+
* Quick demo of how to call CE-Symm programmatically.
21+
* Some examples of different symmetry types are proposed.
22+
*
23+
* @author Spencer Bliven
24+
* @author Aleix Lafita
25+
*
26+
*/
27+
public class DemoCeSymm {
28+
29+
public static void main(String[] args)
30+
throws IOException, StructureException {
31+
32+
/*
33+
* Some examples:
34+
*
35+
* CLOSED
36+
* 2-fold: 1hiv.A,
37+
* 3-fold: 4i4q, 4dou
38+
* 5-fold: 2jaj.A
39+
* 6-fold: 1u6d
40+
* 7-fold: 1jof.A
41+
* 8-fold: 1vzw, d1i4na_
42+
*
43+
* OPEN
44+
* ankyrin: 1n0r.A, 3ehq.A
45+
* leucine repeats: 2bnh.A, 3o6n
46+
* helical: 1d0b.A
47+
*
48+
* MULTIPLE AXES
49+
* dihedral: 4hhb, 1vym, 1hiv
50+
* hierarchical: 4gcr, 1ppr.O, 1hiv
51+
* monoclonal Ab: 4NZU
52+
*
53+
* - For more examples see the symmetry benchmark
54+
*/
55+
56+
//Set the name of the protein structure to analyze
57+
String name = "1u6d";
58+
List<Atom[]> atoms = new ArrayList<Atom[]>();
59+
60+
//Download the atoms
61+
AtomCache cache = new AtomCache();
62+
Structure s = cache.getStructure(name);
63+
Atom[] array = StructureTools.getRepresentativeAtomArray(s);
64+
atoms.add(array);
65+
66+
CeSymm ceSymm = new CeSymm();
67+
68+
//Choose some parameters
69+
CESymmParameters params = (CESymmParameters) ceSymm.getParameters();
70+
params.setRefineMethod(RefineMethod.SINGLE);
71+
params.setSymmetryType(SymmetryType.AUTO);
72+
params.setOptimization(true);
73+
params.setMultipleAxes(true);
74+
75+
//Run the alignment
76+
MultipleAlignment symmetry = ceSymm.align(atoms, params);
77+
78+
//Display the results in jmol
79+
SymmetryDisplay.display(symmetry, ceSymm.getSymmetryAxes());
80+
}
81+
82+
}

0 commit comments

Comments
 (0)