Skip to content

Commit 62801b0

Browse files
committed
Updated to initialise all the arrays during the writing process
1 parent 81eb1a1 commit 62801b0

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

biojava-structure/src/main/java/demo/DemoMmtfRoundTrip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DemoMmtfRoundTrip {
1212

1313
public static void main(String[] args) throws IOException, StructureException {
1414
MmtfUtils.setUpBioJava();
15-
Structure structure = StructureIO.getStructure("4cup");
15+
Structure structure = StructureIO.getStructure("/Users/abradley/Downloads/4cup.cif");
1616
// We can do somme comparisons on the round tripped structure
1717
MmtfActions.roundTrip(structure);
1818
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public MmtfStructureWriter(Structure data) {
4343
public void write(MmtfDecoderInterface decoder) {
4444

4545
this.mmtfDecoderInterface = decoder;
46-
4746
// Reset structure to consider altloc groups with the same residue number but different group names as seperate groups
4847
MmtfUtils.fixMicroheterogenity(structure);
4948
// Generate the secondary structure
@@ -52,6 +51,8 @@ public void write(MmtfDecoderInterface decoder) {
5251
Map<String, Integer> chainIdToIndexMap = MmtfUtils.getChainIdToIndexMap(structure);
5352
List<Chain> allChains = MmtfUtils.getAllChains(structure);
5453
List<Atom> allAtoms = MmtfUtils.getAllAtoms(structure);
54+
55+
mmtfDecoderInterface.initStructure(allAtoms.size(), MmtfUtils.getNumGroups(structure), allChains.size(), structure.nrModels(), structure.getPDBCode());
5556
// Get the header and the xtal info.
5657
PDBHeader pdbHeader = structure.getPDBHeader();
5758
PDBCrystallographicInfo xtalInfo = pdbHeader.getCrystallographicInfo();
@@ -89,6 +90,7 @@ public void write(MmtfDecoderInterface decoder) {
8990
}
9091
}
9192
}
93+
mmtfDecoderInterface.finalizeStructure();
9294

9395
}
9496

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,20 @@ public static List<Chain> getAllChains(Structure structure) {
325325
chainList.addAll(structure.getChains(i));
326326
}
327327
return chainList;
328+
}
329+
330+
/**
331+
* Count the total number of groups in the structure
332+
* @param structure the input structure
333+
* @return the total number of groups
334+
*/
335+
public static int getNumGroups(Structure structure) {
336+
int count = 0;
337+
for(int i=0; i<structure.nrModels(); i++) {
338+
for(Chain chain : structure.getChains(i)){
339+
count+= chain.getAtomGroups().size();
340+
}
341+
}
342+
return count;
328343
}
329344
}

0 commit comments

Comments
 (0)