Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.biojava.nbio.structure.io;

import org.biojava.nbio.structure.AminoAcid;
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -134,7 +135,7 @@ public void setDefault(){
parseCAOnly = false;

// don't download ChemComp dictionary by default.
loadChemCompInfo = false;
setLoadChemCompInfo(false);
headerOnly = false;

storeEmptySeqRes = false;
Expand Down Expand Up @@ -180,17 +181,19 @@ public boolean isLoadChemCompInfo()
return loadChemCompInfo;
}

/** Sets if chemical component defintions should be loaded from the web
/** Sets if chemical component defintions should be loaded or not.
* The decision from where the definitions are obtained is
* in the static variable inside {@link ChemCompGroupFactory}.
*
* @param loadChemCompInfo flag
*/
public void setLoadChemCompInfo(boolean loadChemCompInfo)
{
public void setLoadChemCompInfo(boolean loadChemCompInfo) {

if ( loadChemCompInfo)
if (loadChemCompInfo){
System.setProperty(PDBFileReader.LOAD_CHEM_COMP_PROPERTY, "true");
else
} else {
System.setProperty(PDBFileReader.LOAD_CHEM_COMP_PROPERTY, "false");
}
this.loadChemCompInfo = loadChemCompInfo;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3544,10 +3544,6 @@ public void setFileParsingParameters(FileParsingParameters params)
load_max_atoms = params.getMaxAtoms();
my_ATOM_CA_THRESHOLD = params.getAtomCaThreshold();

if ( !params.isLoadChemCompInfo()) {
ChemCompGroupFactory.setChemCompProvider(new ReducedChemCompProvider());
}

}

public FileParsingParameters getFileParsingParameters(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,6 @@ public void downloadPDB(String pdbId) throws IOException {
downloadStructure(pdbId);
}

@Override
public void setFileParsingParameters(FileParsingParameters params){
super.setFileParsingParameters(params);
if ( ! params.isLoadChemCompInfo()) {
ChemCompGroupFactory.setChemCompProvider(new ReducedChemCompProvider());
}
}


/**
* <b>N.B.</b> This feature won't work unless the structure wasn't found & autoFetch is set to <code>true</code>.
* @param fetchFileEvenIfObsolete the fetchFileEvenIfObsolete to set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ChemCompGroupFactory {

private static final Logger logger = LoggerFactory.getLogger(ChemCompGroupFactory.class);

private static ChemCompProvider chemCompProvider = new DownloadChemCompProvider();
private static ChemCompProvider chemCompProvider = new ReducedChemCompProvider();

private static SoftHashMap<String, ChemComp> cache = new SoftHashMap<String, ChemComp>(0);

Expand All @@ -53,14 +53,26 @@ public static ChemComp getChemComp(String recordName){
logger.debug("Chem comp "+recordName+" read from provider "+chemCompProvider.getClass().getCanonicalName());
cc = chemCompProvider.getChemComp(recordName);

cache.put(recordName, cc);
if (!cc.getOne_letter_code().equals("?")){
cache.put(recordName, cc);
}
return cc;
}

/**
* The new ChemCompProvider will be set in the static variable,
* so this provider will be used from now on until it is changed
* again. Note that this change can have unexpected behavior of
* code executed afterwards.
* <p>
* Changing the provider does not reset the cache, so Chemical
* Component definitions already downloaded from previous providers
* will be used. To reset the cache see {@link #getCache()).
*
* @param provider
*/
public static void setChemCompProvider(ChemCompProvider provider) {
logger.debug("Setting new chem comp provider to "+provider.getClass().getCanonicalName());
logger.debug("Chem comp provider cache reset after change of provider ");
cache = new SoftHashMap<String, ChemComp>(0);
chemCompProvider = provider;
}

Expand Down Expand Up @@ -137,7 +149,9 @@ public static String getOneLetterCode(ChemComp cc){
return oneLetter;
}


public static SoftHashMap<String, ChemComp> getCache() {
return cache;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.biojava.nbio.structure;

import org.biojava.nbio.core.util.SoftHashMap;
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.nbio.structure.io.mmcif.ChemCompProvider;
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
Expand Down Expand Up @@ -116,6 +117,10 @@ public void testPRR(){
@Test
public void testChangingProviders(){

//reset the cache
SoftHashMap<String, ChemComp> cache = ChemCompGroupFactory.getCache();
cache.clear();

// test for issue #145

String chemID = "MEA";
Expand All @@ -128,11 +133,9 @@ public void testChangingProviders(){
assertNotNull(cc);

assertTrue(" is not mea" , cc.getId().equals(chemID));

// an empty description is returned as expected

assertNull(cc.getThree_letter_code());


// now we change to download chem comp provider

ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());
Expand All @@ -148,7 +151,7 @@ public void testChangingProviders(){


// now testing in opposite order

cache.clear();

// first we test with download chem comp provider

Expand All @@ -171,8 +174,8 @@ public void testChangingProviders(){

assertTrue(" is not mea" , cc.getId().equals(chemID));

// an empty description is returned as expected
assertNull(cc.getThree_letter_code());
//the cached description contains all information even with the ReducedProvider
assertNotNull(cc.getThree_letter_code());


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import org.biojava.nbio.structure.io.FileParsingParameters;
import org.biojava.nbio.structure.io.PDBFileParser;
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.nbio.structure.io.mmcif.ReducedChemCompProvider;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -95,6 +97,7 @@ private Structure getStructure(String fileName) throws IOException{
InputStream inStream = this.getClass().getResourceAsStream(fileName);
assertNotNull(inStream);

ChemCompGroupFactory.setChemCompProvider(new ReducedChemCompProvider());
PDBFileParser pdbpars = new PDBFileParser();
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
Expand Down Expand Up @@ -82,6 +82,7 @@ public void testChemCompProvider(){
ChemCompProvider prov3 = ChemCompGroupFactory.getChemCompProvider();
String name3 = prov3.getClass().getName();

assertEquals( "org.biojava.nbio.structure.io.mmcif.ReducedChemCompProvider",name3);
//changing the load to false does not change the provider
assertEquals("The ChemCompProvider got modified from " + name1 + " to " + name3, name1, name3);
}
}