Skip to content

Commit 849d2b0

Browse files
committed
Adding test
1 parent 0bdf25a commit 849d2b0

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/contact/InterfaceFinder.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.ArrayList;
99
import java.util.Iterator;
1010
import java.util.List;
11+
import java.util.stream.IntStream;
1112

1213
/**
1314
* A class containing methods to find interfaces in a given structure.
@@ -38,11 +39,8 @@ public InterfaceFinder(Structure structure) {
3839
private void trimPolyChains() {
3940
Iterator<Chain> it = polyChains.iterator();
4041
while (it.hasNext()) {
41-
int count = 0;
42-
for (Group g:it.next().getAtomGroups())
43-
count += g.getAtoms().size();
44-
if (count==0)
45-
it.remove();
42+
int count = it.next().getAtomGroups().stream().flatMapToInt(g-> IntStream.of(g.getAtoms().size())).sum();
43+
if (count==0) it.remove();
4644
}
4745
}
4846

biojava-structure/src/test/java/org/biojava/nbio/structure/contact/TestInterfaceFinder.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TestInterfaceFinder {
2929

3030
@Test
3131
public void testGetAllInterfaces() {
32-
Structure s = mockStructure();
32+
Structure s = mockStructure(false);
3333
InterfaceFinder finder = new InterfaceFinder(s);
3434

3535
StructureInterfaceList list = finder.getAllInterfaces();
@@ -50,11 +50,27 @@ public void testGetAllInterfaces() {
5050
assertEquals(3, unique.size());
5151
}
5252

53+
/**
54+
* Check that interfaces can be calculated if one polymer chain has no atoms at all
55+
*/
56+
@Test
57+
public void testGetAllInterfacesNoAtomsPoly() {
58+
Structure s = mockStructure(true);
59+
InterfaceFinder finder = new InterfaceFinder(s);
60+
61+
StructureInterfaceList list = finder.getAllInterfaces();
62+
63+
assertEquals(1, list.size());
64+
65+
// make sure we did not alter the original poly chains
66+
assertEquals(3, s.getPolyChains().size());
67+
}
68+
5369
/**
5470
* Create a mock structure with 2 entities 1 (chains A, B) and 2 (chain C).
5571
* @return a structure
5672
*/
57-
private Structure mockStructure() {
73+
private Structure mockStructure(boolean addNoAtomsPolyChain) {
5874
Structure structure = new StructureImpl();
5975
EntityInfo entity1 = new EntityInfo();
6076
entity1.setMolId(1);
@@ -91,7 +107,13 @@ private Structure mockStructure() {
91107
chainB.setSeqResGroups(bGroups);
92108
chainB.setEntityInfo(entity1);
93109

94-
List<Group> cGroups = getGroupList(20, "GLY", chainC, new Point3d(0, 4, 0));
110+
int size;
111+
if (addNoAtomsPolyChain)
112+
size = 0;
113+
else
114+
size = 20;
115+
116+
List<Group> cGroups = getGroupList(size, "GLY", chainC, new Point3d(0, 4, 0));
95117
chainC.setAtomGroups(new ArrayList<>(cGroups));
96118
chainC.setSeqResGroups(cGroups);
97119
chainC.setEntityInfo(entity2);

0 commit comments

Comments
 (0)