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 @@ -68,6 +68,8 @@
* Should be ported to biojava code.
*
* @author Anthony Bradley
* @since 5.0
*
*/
public class MmtfStructureReader implements StructureAdapterInterface, Serializable {

Expand Down Expand Up @@ -227,7 +229,7 @@ public void setGroupInfo(String groupName, int groupNumber,
group = new HetatomImpl();
break;
}
atomsInGroup = new ArrayList<Atom>();
atomsInGroup = new ArrayList<>();
ChemComp chemComp = new ChemComp();
chemComp.setOne_letter_code(String.valueOf(singleLetterCode));
chemComp.setType(chemCompType.toUpperCase());
Expand All @@ -241,7 +243,7 @@ public void setGroupInfo(String groupName, int groupNumber,
group.setResidueNumber(chain.getName().trim(),
groupNumber, insertionCode);
}
group.setAtoms(new ArrayList<Atom>(atomCount));
group.setAtoms(new ArrayList<>(atomCount));
if (polymerType==1 || polymerType==2) {
MmtfUtils.insertSeqResGroup(chain, group, sequenceIndexId);
}
Expand Down Expand Up @@ -327,29 +329,30 @@ public void setAtomInfo(String atomName,
* face#setGroupBonds(int, int, int)
*/
@Override
public void setGroupBond(int indOne,
int indTwo, int bondOrder) {
// Get the atom
public void setGroupBond(int indOne, int indTwo, int bondOrder) {

// Get the atoms
Atom atomOne = atomsInGroup.get(indOne);
Atom atomTwo = atomsInGroup.get(indTwo);

// set the new bond
@SuppressWarnings("unused")
BondImpl bond = new BondImpl(atomOne, atomTwo, bondOrder);
new BondImpl(atomOne, atomTwo, bondOrder);

}

/* (non-Javadoc)
* @see org.rcsb.mmtf.decoder.StructureDecoder
* Interface#setInterGroupBonds(int, int, int)
*/
@Override
public void setInterGroupBond(int indOne,
int indTwo, int bondOrder) {
// Get the atom
public void setInterGroupBond(int indOne, int indTwo, int bondOrder) {

// Get the atoms
Atom atomOne = allAtoms[indOne];
Atom atomTwo = allAtoms[indTwo];
// set the new bond
@SuppressWarnings("unused")
BondImpl bond = new BondImpl(atomOne, atomTwo, bondOrder);

// set the new bond (this
new BondImpl(atomOne, atomTwo, bondOrder);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
/**
* Class to take Biojava structure data and covert to the DataApi for encoding.
* Must implement all the functions in {@link StructureAdapterInterface}.
*
* @author Anthony Bradley
* @since 5.0
*
*/
public class MmtfStructureWriter {


private StructureAdapterInterface mmtfDecoderInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.biojava.nbio.structure.io.FileParsingParameters;
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
import org.biojava.nbio.structure.io.mmcif.chem.ChemCompTools;
import org.biojava.nbio.structure.io.mmcif.model.ChemComp;
import org.biojava.nbio.structure.quaternary.BioAssemblyInfo;
import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation;
Expand Down Expand Up @@ -371,16 +372,14 @@ public static int getSecStructType(Group group) {
/**
* Get the secondary structure as defined by DSSP.
* @param group the input group to be calculated
* @param the integer index of the group type.
* @param dsspIndex integer index of the group type.
*/
public static void setSecStructType(Group group, int dsspIndex) {
SecStrucType secStrucType = getSecStructTypeFromDsspIndex(dsspIndex);
SecStrucState secStrucState = new SecStrucState(group, "MMTF_ASSIGNED", secStrucType);
if(secStrucType!=null){
group.setProperty("secstruc", secStrucState);
}
else{
}
}


Expand All @@ -394,7 +393,7 @@ public static SecStrucType getSecStructTypeFromDsspIndex(int dsspIndex) {
String dsspType = DsspType.dsspTypeFromInt(dsspIndex).getDsspType();
for(SecStrucType secStrucType : SecStrucType.values())
{
if(dsspType==secStrucType.name)
if(dsspType.equals(secStrucType.name))
{
return secStrucType;
}
Expand Down Expand Up @@ -500,31 +499,29 @@ public static void insertSeqResGroup(Chain chain, Group group, int sequenceIndex
* @param sequence the sequence of the construct
*/
public static void addSeqRes(Chain modelChain, String sequence) {

List<Group> seqResGroups = modelChain.getSeqResGroups();
GroupType chainType = getChainType(modelChain.getAtomGroups());

for(int i=0; i<sequence.length(); i++){

char singleLetterCode = sequence.charAt(i);
Group group = null;
if(seqResGroups.size()<=i){
}
else{
if (seqResGroups.size() > i) {
group=seqResGroups.get(i);
}
if(group!=null){
continue;
}
group = getSeqResGroup(modelChain, singleLetterCode, chainType);

group = getSeqResGroup(singleLetterCode, chainType);
addGroupAtId(seqResGroups, group, i);
seqResGroups.set(i, group);
}
}

private static GroupType getChainType(List<Group> groups) {
for(Group group : groups) {
if(group==null){
continue;
}
else if(group.getType()!=GroupType.HETATM){
if(group!=null && group.getType()!=GroupType.HETATM){
return group.getType();
}
}
Expand All @@ -540,20 +537,27 @@ private static <T> void addGroupAtId(List<T> seqResGroups, T group, int sequence
}
}

private static Group getSeqResGroup(Chain modelChain, char singleLetterCode, GroupType type) {
private static Group getSeqResGroup(char singleLetterCode, GroupType type) {

if(type==GroupType.AMINOACID){
String threeLetter = ChemCompTools.getAminoThreeLetter(singleLetterCode);
if (threeLetter == null) return null;
ChemComp chemComp = ChemCompGroupFactory.getChemComp(threeLetter);

AminoAcidImpl a = new AminoAcidImpl();
a.setRecordType(AminoAcid.SEQRESRECORD);
a.setAminoType(singleLetterCode);
ChemComp chemComp = new ChemComp();
chemComp.setOne_letter_code(""+singleLetterCode);
a.setPDBName(threeLetter);
a.setChemComp(chemComp);
return a;

} else if (type==GroupType.NUCLEOTIDE) {
String twoLetter = ChemCompTools.getDNATwoLetter(singleLetterCode);
if (twoLetter == null) return null;
ChemComp chemComp = ChemCompGroupFactory.getChemComp(twoLetter);

NucleotideImpl n = new NucleotideImpl();
ChemComp chemComp = new ChemComp();
chemComp.setOne_letter_code(""+singleLetterCode);
n.setPDBName(twoLetter);
n.setChemComp(chemComp);
return n;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@

/**
* Test bond finding in BioJava
*
* @author Anthony Bradley
*
*/
public class TestBondFinding {

/**
* Test that the bonds we are finding is consistenty.
* Test that the bonds we are finding are consistent.
*
* @throws IOException
* @throws StructureException
*/
@Test
public void testInterGroupBonds() throws IOException, StructureException {

// Normal
assertEquals(2236, getInterBonds("1QMZ"));

// Disulphide
assertEquals(956, getInterBonds("2QWO"));

// Covalent ligand
assertEquals(2294, getInterBonds("4QDV"));
// DNA
Expand All @@ -65,13 +70,16 @@ public void testInterGroupBonds() throws IOException, StructureException {
}

/**
* Find all of the inter group bonds in a structure
* Find all of the inter group bonds in a structure.
*
* @param pdbId the pdb id of the structure to determine
* @return the number of inter group bonds (double counted) in a structure
* @throws IOException
* @throws StructureException
*/
public int getInterBonds(String pdbId) throws IOException, StructureException{
public int getInterBonds(String pdbId) throws IOException, StructureException {

// Download parameters
AtomCache cache = new AtomCache();
cache.setUseMmCif(true);
cache.setFetchBehavior(FetchBehavior.FETCH_FILES);
Expand All @@ -84,10 +92,13 @@ public int getInterBonds(String pdbId) throws IOException, StructureException{
dcc.checkDoFirstInstall();
cache.setFileParsingParams(params);
StructureIO.setAtomCache(cache);
int counter =0;
// Now get the structure

// Get the structure
Structure newStruc = StructureIO.getStructure(pdbId);
// Now loop through the atoms

int counter =0;

// Loop through the atoms and count the bonds
for(Chain c: newStruc.getChains()){
for(Group g: c.getAtomGroups()){
List<Atom> theseAtoms = g.getAtoms();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,62 +32,26 @@
import static org.junit.Assert.assertTrue;

/**
* Created by andreas on 1/9/17.
* Test the performance of MMTF format in BioJava.
*
* @author Andreas Prlic
* on 1/9/17.
*
*/
public class TestMmtfPerformance {

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

private static final int NUMBER_OF_REPEATS = 10;

// Returns the contents of the file in a byte array.
public static byte[] getBytesFromFile(File file) throws IOException {
// Get the size of the file
long length = file.length();

// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
throw new IOException("File is too large!");
}

// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];

// Read in the bytes
int offset = 0;
int numRead = 0;

InputStream is = new FileInputStream(file);
try {
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
} finally {
is.close();
}

// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
return bytes;
}

static String convertStreamToString(java.io.InputStream is) {
private static String convertStreamToString(java.io.InputStream is) {
try (
java.util.Scanner s = new java.util.Scanner(is)){
return s.useDelimiter("\\A").hasNext() ? s.next() : "";
}

}


public byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
private byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

int nRead;
Expand All @@ -100,7 +64,6 @@ public byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
buffer.flush();

return buffer.toByteArray();

}

@Test
Expand All @@ -124,31 +87,30 @@ public void test3HBX() throws Exception{

byte[] mmtfdata = getByteArrayFromInputStream(new GZIPInputStream((mmtfURL.openStream())));

// first make sure chemcomp cache is warmed up (chemcomp files are parsed). Like that we count the parsing time without the influence of chemcomp parsing
MmtfActions.readFromInputStream(new ByteArrayInputStream(mmtfdata));
parser.parsePDBFile(new ByteArrayInputStream(pdbBytes));

for ( int i =0 ; i< NUMBER_OF_REPEATS ; i++) {

long mmtfStart = System.nanoTime();
MmtfActions.readFromInputStream(new ByteArrayInputStream(mmtfdata));
long mmtfEnd = System.nanoTime();



long pdbStart = System.nanoTime();
parser.parsePDBFile(new ByteArrayInputStream(pdbBytes));
long pdbEnd = System.nanoTime();

totalTimePDB += (pdbEnd - pdbStart);


totalTimeMMTF += (mmtfEnd-mmtfStart);
}


long timePDB = (totalTimePDB/NUMBER_OF_REPEATS);
long timeMMTF = (totalTimeMMTF/NUMBER_OF_REPEATS);


logger.warn("average time to parse mmtf: " + timeMMTF/(1000*1000) + " ms.");
logger.warn("average time to parse PDB : " + timePDB/(1000*1000) + " ms. ");
logger.info("average time to parse mmtf: " + timeMMTF/(1000*1000) + " ms.");
logger.info("average time to parse PDB : " + timePDB/(1000*1000) + " ms. ");

assertTrue( "It should not be the case, but it is faster to parse a PDB file ("+timePDB+" ns.) than MMTF ("+( timeMMTF)+" ns.)!",( timePDB) > ( timeMMTF));

Expand Down
Loading