Skip to content

Commit c62509e

Browse files
committed
1) Update Biojava to use 0.2.0 MMTF
2) Updates the Reader and Writer to work with 0.2.0 MMTF 3) Added tests for the new functionality 4) Some cleanup of the docs and code
1 parent 1dcfe70 commit c62509e

6 files changed

Lines changed: 125 additions & 38 deletions

File tree

biojava-structure/pom.xml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,21 @@
2323
<dependency>
2424
<groupId>org.rcsb</groupId>
2525
<artifactId>mmtf-api</artifactId>
26-
<version>0.1.0</version>
26+
<version>${mmtf.version}</version>
2727
<scope>compile</scope>
2828
</dependency>
2929
<dependency>
3030
<groupId>org.rcsb</groupId>
3131
<artifactId>mmtf-serialization</artifactId>
32-
<version>0.1.0</version>
33-
<scope>compile</scope>
34-
</dependency>
35-
<dependency>
36-
<groupId>org.rcsb</groupId>
37-
<artifactId>mmtf-decoder</artifactId>
38-
<version>0.1.0</version>
39-
<scope>compile</scope>
40-
</dependency>
41-
<dependency>
42-
<groupId>org.rcsb</groupId>
43-
<artifactId>mmtf-encoder</artifactId>
44-
<version>0.1.0</version>
32+
<version>${mmtf.version}</version>
4533
<scope>compile</scope>
4634
</dependency>
35+
<dependency>
36+
<groupId>org.rcsb</groupId>
37+
<artifactId>mmtf-codec</artifactId>
38+
<version>${mmtf.version}</version>
39+
<scope>compile</scope>
40+
</dependency>
4741
<dependency>
4842
<groupId>org.biojava</groupId>
4943
<artifactId>biojava-alignment</artifactId>
@@ -107,10 +101,9 @@
107101
<properties>
108102
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
109103
<project.build.targetEncoding>UTF-8</project.build.targetEncoding>
110-
104+
<mmtf.version>0.2.0-SNAPSHOT</mmtf.version>
111105
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
112106
<timestamp>${maven.build.timestamp}</timestamp>
113-
114107
</properties>
115108
<build>
116109

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class MmtfActions {
1919

2020
/**
21-
* Utility function to get a Structure object from a mmtf file.
21+
* Get a Structure object from a mmtf file.
2222
* @param filePath the mmtf file
2323
* @return a Structure object relating to the input byte array.
2424
* @throws IOException
@@ -33,7 +33,7 @@ public static Structure readFromFile(Path filePath) throws IOException {
3333
}
3434

3535
/**
36-
* Utility function to write a Structure object to a file.
36+
* Write a Structure object to a file.
3737
* @param structure the Structure to write
3838
* @param path the file to write
3939
* @throws IOException
@@ -49,7 +49,7 @@ public static void writeToFile(Structure structure, Path path) throws IOExceptio
4949

5050

5151
/**
52-
* Utility function to get a Biojava structure from the mmtf REST service.
52+
* Get a Biojava structure from the mmtf REST service.
5353
* @param pdbId the PDB code of the required structure
5454
* @return a Structure object relating to the input byte array
5555
* @throws IOException

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public void finalizeStructure() {
127127
structure.addChain(modelChain, i);
128128
}
129129
}
130-
// Ensure all altlocs have all atoms
131130
StructureTools.cleanUpAltLocs(structure);
132131
}
133132

@@ -368,8 +367,7 @@ private Group getCorrectAltLocGroup(Character altLoc) {
368367
* setXtalInfo(java.lang.String, java.util.List)
369368
*/
370369
@Override
371-
public void setXtalInfo(String spaceGroupString,
372-
float[] unitCell) {
370+
public void setXtalInfo(String spaceGroupString, float[] unitCell, double[] ncsOperMatrixList) {
373371
// Now set the xtalographic information
374372
PDBCrystallographicInfo pci = new PDBCrystallographicInfo();
375373
SpaceGroup spaceGroup = SpaceGroup.parseSpaceGroup(spaceGroupString);
@@ -380,6 +378,8 @@ public void setXtalInfo(String spaceGroupString,
380378
pci.setCrystalCell(cell);
381379
structure.setCrystallographicInfo(pci);
382380
}
381+
382+
pci.setNcsOperators(MmtfUtils.getNcsAsMatrix4d(ncsOperMatrixList));
383383
}
384384

385385

@@ -410,7 +410,7 @@ private int getGroupTypIndicator(String currentGroupType) {
410410

411411

412412
@Override
413-
public void setBioAssemblyTrans(int bioAssemblyId, int[] inputChainIndices, double[] inputTransform) {
413+
public void setBioAssemblyTrans(int bioAssemblyId, int[] inputChainIndices, double[] inputTransform, String name) {
414414
if(bioassIndex!=bioAssemblyId){
415415
transformList = new ArrayList<>();
416416
bioassIndex = bioAssemblyId;
@@ -506,5 +506,6 @@ public void setHeaderInfo(float rFree, float rWork, float resolution, String tit
506506
else{
507507
pdbHeader.setModDate(new Date(0));
508508
}
509+
509510
}
510511
}

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ public class MmtfStructureWriter {
2828

2929

3030
private StructureAdapterInterface mmtfDecoderInterface;
31-
private Structure structure;
32-
3331

3432
/**
35-
* Function to pass data from Biojava structure
36-
* to another generic output type.Loops through the data
33+
* Ppass data from Biojava structure to another generic output type.Loops through the data
3734
* structure and calls all the set functions.
35+
* @param structure the input {@link Structure} to write
3836
* @param dataTransferInterface the generic interface that
3937
* implements all the set methods.
4038
*/
41-
public MmtfStructureWriter(Structure data, StructureAdapterInterface dataTransferInterface) {
39+
public MmtfStructureWriter(Structure structure, StructureAdapterInterface dataTransferInterface) {
4240
this.mmtfDecoderInterface = dataTransferInterface;
43-
this.structure = data;
4441
// Reset structure to consider altloc groups with the same residue number but different group names as seperate groups
4542
MmtfUtils.fixMicroheterogenity(structure);
4643
// Get the chain name to index map
@@ -57,7 +54,7 @@ public MmtfStructureWriter(Structure data, StructureAdapterInterface dataTransfe
5754
PDBCrystallographicInfo xtalInfo = pdbHeader.getCrystallographicInfo();
5855
mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(), pdbHeader.getRwork(), pdbHeader.getResolution(), pdbHeader.getTitle(), MmtfUtils.dateToIsoString(pdbHeader.getDepDate()),
5956
MmtfUtils.dateToIsoString(pdbHeader.getModDate()), MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques()));
60-
mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()), MmtfUtils.getUnitCellAsArray(xtalInfo));
57+
mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()), MmtfUtils.getUnitCellAsArray(xtalInfo), MmtfUtils.getNcsAsArray(xtalInfo.getNcsOperators()));
6158
// Store the bioassembly data
6259
storeBioassemblyInformation(chainIdToIndexMap, pdbHeader.getBioAssemblies());
6360
// Store the entity data
@@ -73,10 +70,8 @@ public MmtfStructureWriter(Structure data, StructureAdapterInterface dataTransfe
7370
List<Group> sequenceGroups = chain.getSeqResGroups();
7471
mmtfDecoderInterface.setChainInfo(chain.getId(), chain.getName(), groups.size());
7572
for(int groupInChainIndex=0; groupInChainIndex<groups.size(); groupInChainIndex++){
76-
// Get the major compy of this group
7773
Group group = groups.get(groupInChainIndex);
7874
List<Atom> atomsInGroup = MmtfUtils.getAtomsForGroup(group);
79-
// Get the group type
8075
ChemComp chemComp = group.getChemComp();
8176
Character insCode = group.getResidueNumber().getInsCode();
8277
if(insCode==null){
@@ -192,7 +187,7 @@ private void storeBioassemblyInformation(Map<String, Integer> chainIdToIndexMap,
192187
for (Entry<Integer, BioAssemblyInfo> entry : inputBioAss.entrySet()) {
193188
Map<double[], int[]> transformMap = MmtfUtils.getTransformMap(entry.getValue(), chainIdToIndexMap);
194189
for(Entry<double[], int[]> transformEntry : transformMap.entrySet()) {
195-
mmtfDecoderInterface.setBioAssemblyTrans(bioAssemblyIndex, transformEntry.getValue(), transformEntry.getKey());
190+
mmtfDecoderInterface.setBioAssemblyTrans(bioAssemblyIndex, transformEntry.getValue(), transformEntry.getKey(), Integer.toString(bioAssemblyIndex));
196191
}
197192
bioAssemblyIndex+=1;
198193
}

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

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.text.DateFormat;
55
import java.text.SimpleDateFormat;
66
import java.util.ArrayList;
7+
import java.util.Arrays;
78
import java.util.Date;
89
import java.util.HashMap;
910
import java.util.HashSet;
@@ -64,7 +65,9 @@ public static AtomCache setUpBioJava() {
6465
}
6566

6667
/**
67-
* Set up the configuration parameters for BioJava. - with an extra URL
68+
* Set up the configuration parameters for BioJava.
69+
* @param extraUrl the string describing the URL (or file path) from which
70+
* to get missing CCD entries.
6871
*/
6972
public static AtomCache setUpBioJava(String extraUrl) {
7073
// Set up the atom cache etc
@@ -122,7 +125,7 @@ public static void fixMicroheterogenity(Structure bioJavaStruct) {
122125

123126

124127
/**
125-
* Function to generate the secondary structure for a Biojava structure object.
128+
* Generate the secondary structure for a Biojava structure object.
126129
* @param bioJavaStruct the Biojava structure for which it is to be calculate.
127130
*/
128131
public static void calculateDsspSecondaryStructure(Structure bioJavaStruct) {
@@ -273,7 +276,7 @@ public static int getNumGroups(Structure structure) {
273276

274277

275278
/**
276-
* Function to get a list of atoms for a group. Only add each atom once.
279+
* Get a list of atoms for a group. Only add each atom once.
277280
* @param inputGroup the Biojava Group to consider
278281
* @return the atoms for the input Biojava Group
279282
*/
@@ -354,7 +357,7 @@ public static void setSecStructType(Group group, int dsspIndex) {
354357

355358

356359
/**
357-
* Helper function to set the DSSP type based on a numerical index.
360+
* Set the DSSP type based on a numerical index.
358361
* @param dsspIndex the integer index of the type to set
359362
* @return the instance of the SecStrucType object holding this secondary
360363
* structure type.
@@ -373,7 +376,7 @@ public static SecStrucType getSecStructTypeFromDsspIndex(int dsspIndex) {
373376
}
374377

375378
/**
376-
* Function to get summary information for the structure.
379+
* Get summary information for the structure.
377380
* @param structure the structure for which to get the information.
378381
*/
379382
public static MmtfSummaryDataBean getStructureInfo(Structure structure) {
@@ -412,4 +415,41 @@ public static MmtfSummaryDataBean getStructureInfo(Structure structure) {
412415
return mmtfSummaryDataBean;
413416

414417
}
418+
419+
/**
420+
* Get a list of N 4*4 matrices from a single list of doubles of length 16*N.
421+
* @param ncsOperMatrixList the input list of doubles
422+
* @return the list of 4*4 matrics
423+
*/
424+
public static Matrix4d[] getNcsAsMatrix4d(double[] ncsOperMatrixList) {
425+
if(ncsOperMatrixList==null){
426+
return new Matrix4d[0];
427+
}
428+
int numMats = ncsOperMatrixList.length/16;
429+
Matrix4d[] outList = new Matrix4d[numMats];
430+
for(int i=0; i<numMats; i++){
431+
double[] inputData = Arrays.copyOfRange(ncsOperMatrixList, i*0, (i+1)*16);
432+
outList[i] = new Matrix4d(inputData);
433+
}
434+
return outList;
435+
}
436+
437+
/**
438+
* Get a list of length N*16 of a list of Matrix4d*N.
439+
* @param ncsOperators the {@link Matrix4d} list
440+
* @return the list of length N*16 of the list of matrices
441+
*/
442+
public static double[] getNcsAsArray(Matrix4d[] ncsOperators) {
443+
if(ncsOperators==null){
444+
return new double[0];
445+
}
446+
double[] outList = new double[ncsOperators.length*16];
447+
for(int i=0; i<ncsOperators.length;i++){
448+
double[] doubleList = convertToDoubleArray(ncsOperators[i]);
449+
for(int j=0; j<16; j++){
450+
outList[i*16+j] = doubleList[j];
451+
}
452+
}
453+
return outList;
454+
}
415455
}

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfUtils.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,5 +410,63 @@ private Set<Atom> findDuplicates(List<Atom> listContainingDuplicates)
410410
}
411411
return setToReturn;
412412
}
413+
414+
/**
415+
* Test that the NCS data can be roundtripped.
416+
*/
417+
@Test
418+
public void testGetNcsMatrix() {
419+
double[] testData = new double[] {1.0, 2.0,3.0,4.0,
420+
11.0,12.0,13.0,14.0,
421+
21.0,22.0,23.0,24.0,
422+
31.0,32.0,33.0,34.0};
423+
testInput(testData);
424+
}
425+
426+
/**
427+
* Test that the NCS data can be roundtripped.
428+
*/
429+
@Test
430+
public void testEmptyNcsMatrix() {
431+
double[] testData = new double[] {};
432+
testInput(testData);
433+
double[] output = MmtfUtils.getNcsAsArray(new Matrix4d[0]);
434+
assertNotNull(output);
435+
}
436+
437+
/**
438+
* Test what happens if the NCS is null
439+
*/
440+
@Test
441+
public void testNullNcsMatrix(){
442+
double[] output = MmtfUtils.getNcsAsArray(null);
443+
assertArrayEquals(output, new double[0], 0.0);
444+
Matrix4d[] outputMat = MmtfUtils.getNcsAsMatrix4d(null);
445+
double[] outputMatArr = MmtfUtils.getNcsAsArray(outputMat);
446+
assertArrayEquals(outputMatArr, new double[0], 0.0);
447+
}
448+
449+
450+
/**
451+
* Test that the NCS data can be roundtripped - when two matrices are present.
452+
*/
453+
@Test
454+
public void testGetNcsMatrixHard() {
455+
double[] testData = new double[] {1.0, 2.0,3.0,4.0,
456+
11.0,12.0,13.0,14.0,
457+
21.0,22.0,23.0,24.0,
458+
31.0,32.0,33.0,34.0,
459+
1.0, 2.0,3.0,4.0,
460+
11.0,12.0,13.0,14.0,
461+
21.0,22.0,23.0,24.0,
462+
31.0,32.0,33.0,34.0};
463+
testInput(testData);
464+
}
465+
466+
private void testInput(double[] testData) {
467+
Matrix4d[] matArr = MmtfUtils.getNcsAsMatrix4d(testData);
468+
double[] roundTrippedData = MmtfUtils.getNcsAsArray(matArr);
469+
assertArrayEquals(testData, roundTrippedData, 0.0);
470+
}
413471
}
414472

0 commit comments

Comments
 (0)