Skip to content

Commit 3f94fe5

Browse files
committed
Ugly, basic MMTF support in AtomCache
1 parent fc5d557 commit 3f94fe5

File tree

1 file changed

+59
-2
lines changed
  • biojava-structure/src/main/java/org/biojava/nbio/structure/align/util

1 file changed

+59
-2
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior;
5050
import org.biojava.nbio.structure.io.MMCIFFileReader;
5151
import org.biojava.nbio.structure.io.PDBFileReader;
52+
import org.biojava.nbio.structure.io.mmtf.ParseUsingBioJava;
5253
import org.biojava.nbio.structure.io.util.FileDownloadUtils;
5354
import org.biojava.nbio.structure.quaternary.io.BioUnitDataProviderFactory;
5455
import org.biojava.nbio.structure.quaternary.io.MmCifBiolAssemblyProvider;
@@ -58,6 +59,8 @@
5859
import org.biojava.nbio.structure.scop.ScopDescription;
5960
import org.biojava.nbio.structure.scop.ScopDomain;
6061
import org.biojava.nbio.structure.scop.ScopFactory;
62+
import org.rcsb.mmtf.decoder.ParsingParams;
63+
import org.rcsb.mmtf.examples.HandleIO;
6164
import org.slf4j.Logger;
6265
import org.slf4j.LoggerFactory;
6366

@@ -100,6 +103,12 @@ public class AtomCache {
100103
private String path;
101104

102105
private boolean useMmCif;
106+
107+
// MMTF caches
108+
private boolean useMMTF;
109+
private HandleIO mmtfHandle;
110+
private ParsingParams mmtfParams;
111+
private ParseUsingBioJava mmtfParser;
103112

104113
/**
105114
* Default AtomCache constructor.
@@ -159,7 +168,7 @@ public AtomCache(String pdbFilePath, String cachePath) {
159168
//
160169

161170
setUseMmCif(true);
162-
171+
setUseMMTF(false);
163172
}
164173

165174
/**
@@ -937,6 +946,13 @@ public boolean isUseMmCif() {
937946
return useMmCif;
938947
}
939948

949+
/**
950+
* @return Whether MMTF should be used
951+
*/
952+
public boolean isUseMMTF() {
953+
return useMMTF;
954+
}
955+
940956
/**
941957
* @param useMmCif
942958
* the useMmCif to set
@@ -956,6 +972,15 @@ public void setUseMmCif(boolean useMmCif) {
956972
}
957973
}
958974

975+
/**
976+
* @param useMmCif
977+
* the useMmCif to set
978+
*/
979+
public void setUseMMTF(boolean useMMTF) {
980+
this.useMMTF = useMMTF;
981+
// TODO set BioUnitDataProviderFactory? --SB 2016-04
982+
}
983+
959984
private boolean checkLoading(String name) {
960985
return currentlyLoading.contains(name);
961986

@@ -1031,7 +1056,9 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur
10311056
}
10321057

10331058
Structure s;
1034-
if (useMmCif) {
1059+
if( useMMTF ) {
1060+
s = loadStructureFromMMCF(pdbId);
1061+
} else if (useMmCif) {
10351062
s = loadStructureFromCifByPdbId(pdbId);
10361063
} else {
10371064
s = loadStructureFromPdbByPdbId(pdbId);
@@ -1040,6 +1067,36 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur
10401067
}
10411068

10421069

1070+
protected Structure loadStructureFromMMCF(String pdbId) throws IOException, StructureException {
1071+
flagLoading(pdbId);
1072+
Structure s;
1073+
try {
1074+
synchronized(this) {
1075+
if( mmtfHandle == null) {
1076+
mmtfHandle = new HandleIO();
1077+
}
1078+
if( mmtfParams == null) {
1079+
mmtfParams = new ParsingParams();
1080+
mmtfParams.setParseInternal(false);
1081+
}
1082+
if( mmtfParser == null) {
1083+
mmtfParser = new ParseUsingBioJava();
1084+
}
1085+
}
1086+
1087+
long startTime = System.currentTimeMillis();
1088+
byte[] inputByteArr = mmtfHandle.getFromUrl(pdbId);
1089+
long dlTime = System.currentTimeMillis();
1090+
s = mmtfParser.getBiojavaStruct(inputByteArr, mmtfParams);
1091+
long parserTime = System.currentTimeMillis();
1092+
logger.info("Downloaded MMTF file for {} in {} s and parsed in {} s",
1093+
pdbId, (dlTime-startTime)/1000., (parserTime-dlTime)/1000.);
1094+
} finally {
1095+
flagLoadingFinished(pdbId);
1096+
}
1097+
1098+
return s;
1099+
}
10431100
protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException, StructureException {
10441101

10451102
Structure s;

0 commit comments

Comments
 (0)