Skip to content

Commit 577e108

Browse files
committed
fixing a bug with setting the file parsing type in AtomCache. (mmtf and mmcif flags were both always set to true)
1 parent 447bd92 commit 577e108

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public AtomCache(UserConfiguration config) {
184184
fetchBehavior = config.getFetchBehavior();
185185
obsoleteBehavior = config.getObsoleteBehavior();
186186
useMmCif = config.getFileFormat().equals( UserConfiguration.MMCIF_FORMAT );
187+
188+
if ( useMmCif)
189+
useMmtf = false;
190+
187191
}
188192

189193
/**
@@ -936,6 +940,14 @@ public void setUseMmtf(boolean useMmtf) {
936940

937941
}
938942

943+
/** Returns useMmtf flag
944+
*
945+
* @return true if will load data via mmtf file format
946+
*/
947+
public boolean isUseMmtf(){
948+
return this.useMmtf;
949+
}
950+
939951
private boolean checkLoading(String name) {
940952
return currentlyLoading.contains(name);
941953

@@ -1014,11 +1026,14 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur
10141026

10151027
Structure s;
10161028
if (useMmtf) {
1029+
logger.debug("loading from mmtf");
10171030
s = loadStructureFromMmtfByPdbId(pdbId);
10181031
}
10191032
else if (useMmCif) {
1033+
logger.debug("loading from mmcif");
10201034
s = loadStructureFromCifByPdbId(pdbId);
10211035
} else {
1036+
logger.debug("loading from pdb");
10221037
s = loadStructureFromPdbByPdbId(pdbId);
10231038
}
10241039
return s;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class UserConfiguration
4646

4747
public static final String PDB_FORMAT = "PDB";
4848
public static final String MMCIF_FORMAT = "mmCif";
49+
public static final String MMTF_FORMAT = "mmtf";
4950

5051
public static final String TMP_DIR = "java.io.tmpdir";
5152

@@ -97,7 +98,7 @@ public UserConfiguration(){
9798
// note that in initCacheFilePath, we set to the provided one (if readable) or to the same as pdbFilePath
9899
cacheFilePath = initCacheFilePath();
99100

100-
fileFormat = MMCIF_FORMAT;
101+
fileFormat = MMTF_FORMAT;
101102
}
102103

103104
private String initPdbFilePath() {

biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,66 @@ public void testFetchObsolete() throws IOException, StructureException {
212212

213213
}
214214

215+
216+
@Test
217+
public void testSettingFileParsingType(){
218+
219+
AtomCache cache = new AtomCache();
220+
221+
//test defaults
222+
223+
// by default we either use mmtf or mmcif, but not both.
224+
assertNotEquals(cache.isUseMmtf(), cache.isUseMmCif());
225+
226+
// first is mmtf, second is mmcif
227+
testFlags(cache,true,false);
228+
229+
// now change the values
230+
231+
cache.setUseMmCif(true);
232+
233+
testFlags(cache,false,true);
234+
235+
cache.setUseMmtf(true);
236+
237+
testFlags(cache,true,false);
238+
239+
// this sets to use PDB!
240+
cache.setUseMmCif(false);
241+
242+
testFlags(cache,false,false);
243+
244+
// back to defaults
245+
cache.setUseMmtf(true);
246+
247+
testFlags(cache,true,false);
248+
249+
250+
// back to parsing PDB
251+
cache.setUseMmtf(false);
252+
253+
testFlags(cache,false,false);
254+
255+
256+
257+
}
258+
259+
260+
/** test the flags for parsing in the atom cache
261+
*
262+
* @param cache
263+
* @param useMmTf
264+
* @param useMmCif
265+
*/
266+
private void testFlags(AtomCache cache ,boolean useMmTf, boolean useMmCif) {
267+
268+
assertEquals("flag for parsing mmtf is set to " + cache.isUseMmtf() + " but should be " + useMmTf,
269+
cache.isUseMmtf(), useMmTf);
270+
assertEquals("flag for parsing mmcif is set to " + cache.isUseMmCif() + " but should be set to " + useMmCif,
271+
cache.isUseMmCif(), useMmCif);
272+
273+
274+
275+
}
276+
215277
}

0 commit comments

Comments
 (0)