Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix release 2 of mmtf version 1.0 #26

Merged
merged 10 commits into from
Sep 1, 2016
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ All notable changes to this project will be documented in this file, following t
## v1.0.1 - 2016-08-18
### Changed
- Added saccharides to the reduced format


## v1.0.2 - 2016-08-29
### Changed
- Added inter group saccharide bonds to the reduced format
- Cleanup of WriterUtils
- Updated version string in MmtfStructure
- Updated test data
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/rcsb/mmtf-java.svg?branch=master)](https://travis-ci.org/rcsb/mmtf-java)
[![Coverage Status](https://coveralls.io/repos/github/rcsb/mmtf-java/badge.svg?branch=master)](https://coveralls.io/github/rcsb/mmtf-java?branch=master)
[![Dependency Status](https://www.versioneye.com/user/projects/56feb8e5fcd19a0039f1553c/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56feb8e5fcd19a0039f1553c)
[![Version](http://img.shields.io/badge/version-1.0.1-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt)
[![Version](http://img.shields.io/badge/version-1.0.2-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt)
[![Changelog](https://img.shields.io/badge/changelog--lightgrey.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/CHANGELOG.md)


Expand All @@ -16,12 +16,12 @@ The alpha release is available on Maven central.
<dependency>
<groupId>org.rcsb</groupId>
<artifactId>mmtf-codec</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.rcsb</groupId>
<artifactId>mmtf-api</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```

Expand Down
50 changes: 41 additions & 9 deletions mmtf-codec/src/main/java/org/rcsb/mmtf/encoder/ReducedEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.rcsb.mmtf.api.StructureDataInterface;
import org.rcsb.mmtf.decoder.DecoderUtils;

Expand Down Expand Up @@ -34,9 +35,12 @@ public static StructureDataInterface getReduced(StructureDataInterface structure
DecoderUtils.generateBioAssembly(structureDataInterface, adapterToStructureData);
DecoderUtils.addEntityInfo(structureDataInterface, adapterToStructureData);
// Loop through the Structure data interface this with the appropriate data
int atomCounter=-1;
int groupCounter=-1;
int chainCounter=-1;
int atomCounter= - 1;
int redAtomCounter = -1;
int groupCounter= - 1;
int chainCounter= - 1;
List<Integer> interGroupBondsToAdd = new ArrayList<>();
List<Integer> interGroupRedIndsToAdd = new ArrayList<>();
for (int i=0; i<structureDataInterface.getNumModels(); i++){
int numChains = structureDataInterface.getChainsPerModel()[i];
adapterToStructureData.setModelInfo(i, numChains);
Expand All @@ -48,7 +52,7 @@ public static StructureDataInterface getReduced(StructureDataInterface structure
groupCounter++;
int groupType = structureDataInterface.getGroupTypeIndices()[groupCounter];
List<Integer> atomIndicesToAdd = getIndicesToAdd(structureDataInterface, groupType, chainType);
int bondsToAdd = findBondsToAdd(atomIndicesToAdd, structureDataInterface, groupType);
int bondsToAdd = findBondsToAdd(atomIndicesToAdd, structureDataInterface, groupType,atomCounter+1);
// If there's an atom to add in this group - add it
if(atomIndicesToAdd.size()>0){
adapterToStructureData.setGroupInfo(structureDataInterface.getGroupName(groupType), structureDataInterface.getGroupIds()[groupCounter],
Expand All @@ -60,9 +64,14 @@ public static StructureDataInterface getReduced(StructureDataInterface structure
for(int l=0; l<structureDataInterface.getNumAtomsInGroup(groupType);l++){
atomCounter++;
if(atomIndicesToAdd.contains(l)){
redAtomCounter++;
adapterToStructureData.setAtomInfo(structureDataInterface.getGroupAtomNames(groupType)[l], structureDataInterface.getAtomIds()[atomCounter], structureDataInterface.getAltLocIds()[atomCounter],
structureDataInterface.getxCoords()[atomCounter], structureDataInterface.getyCoords()[atomCounter], structureDataInterface.getzCoords()[atomCounter],
structureDataInterface.getOccupancies()[atomCounter], structureDataInterface.getbFactors()[atomCounter], structureDataInterface.getGroupElementNames(groupType)[l], structureDataInterface.getGroupAtomCharges(groupType)[l]);
if (structureDataInterface.getGroupChemCompType(groupType).toUpperCase().contains("SACCHARIDE")){
interGroupBondsToAdd.add(atomCounter);
interGroupRedIndsToAdd.add(redAtomCounter);
}
}
}
if(bondsToAdd>0){
Expand All @@ -78,6 +87,17 @@ public static StructureDataInterface getReduced(StructureDataInterface structure
structureDataInterface.getChainNames()[chainCounter], numGroups);
}
}
// Add the inter group bonds
for(int i=0; i<structureDataInterface.getInterGroupBondOrders().length;i++){
int bondIndOne = structureDataInterface.getInterGroupBondIndices()[i*2];
int bondIndTwo = structureDataInterface.getInterGroupBondIndices()[i*2+1];
int bondOrder = structureDataInterface.getInterGroupBondOrders()[i];
if(interGroupBondsToAdd.contains(bondIndOne) && interGroupBondsToAdd.contains(bondIndTwo) ){
int indexOne = interGroupBondsToAdd.indexOf(bondIndOne);
int indexTwo = interGroupBondsToAdd.indexOf(bondIndTwo);
adapterToStructureData.setInterGroupBond(interGroupRedIndsToAdd.get(indexOne), interGroupRedIndsToAdd.get(indexTwo), bondOrder);
}
}
adapterToStructureData.finalizeStructure();
// Return the AdapterToStructureData
return adapterToStructureData;
Expand All @@ -88,18 +108,30 @@ public static StructureDataInterface getReduced(StructureDataInterface structure
* @param indicesToAdd the indices of the atoms to add
* @param structureDataInterface the {@link StructureDataInterface} of the total structure
* @param groupType the index of the groupType
* @param atomCounter the current atom counter position
* @return the integer number of bonds to add
*/
private static int findBondsToAdd(List<Integer> indicesToAdd, StructureDataInterface structureDataInterface, int groupType) {
private static int findBondsToAdd(List<Integer> indicesToAdd, StructureDataInterface structureDataInterface, int groupType, int atomCounter) {
// Add the bonds if we've copied all the elements
int interGroupBonds = 0;
if(indicesToAdd.size()>1){
if (structureDataInterface.getGroupChemCompType(groupType).toUpperCase().contains("SACCHARIDE")){
for(int i=0; i<structureDataInterface.getGroupBondOrders(groupType).length; i++) {
if(ArrayUtils.contains(structureDataInterface.getInterGroupBondIndices(),atomCounter+i)){
interGroupBonds++;
}
}
}
if(indicesToAdd.size()==structureDataInterface.getNumAtomsInGroup(groupType)){
return structureDataInterface.getGroupBondOrders(groupType).length;
return structureDataInterface.getGroupBondOrders(groupType).length+interGroupBonds;
}
}
return 0;
}




/**
* Get the number of bonds, atoms and groups as a map.
* @param structureDataInterface the input {@link StructureDataInterface}
Expand All @@ -113,6 +145,7 @@ private static SummaryData getDataSummaryData(StructureDataInterface structureDa
summaryData.numBonds = 0;
int groupCounter = -1;
int chainCounter=-1;
int atomCounter = 0;
for (int i=0; i<structureDataInterface.getNumModels(); i++){
int numChains = structureDataInterface.getChainsPerModel()[i];
for(int j=0; j<numChains; j++){
Expand All @@ -131,11 +164,10 @@ private static SummaryData getDataSummaryData(StructureDataInterface structureDa
if(indicesToAdd.contains(l)){
summaryData.numAtoms++;
}
atomCounter++;
}
// Add the bonds if we've copied all the elements
if (findBondsToAdd(indicesToAdd, structureDataInterface, groupType)>0){
summaryData.numBonds+=structureDataInterface.getGroupBondOrders(groupType).length;
}
summaryData.numBonds+=findBondsToAdd(indicesToAdd, structureDataInterface, groupType, atomCounter);
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions mmtf-codec/src/main/java/org/rcsb/mmtf/encoder/WriterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void writeDataToFile(AdapterToStructureData writerToEncoder, Path
*/
public static byte[] getDataAsByteArr(AdapterToStructureData writerToEncoder) throws IOException {
MessagePackSerialization mmtfBeanSeDerializerInterface = new MessagePackSerialization();
// Get to bean
GenericEncoder genericEncoder = new GenericEncoder(writerToEncoder);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
mmtfBeanSeDerializerInterface.serialize(genericEncoder.getMmtfEncodedStructure(), bos);
Expand All @@ -53,13 +52,10 @@ public static byte[] getDataAsByteArr(AdapterToStructureData writerToEncoder) th
* @throws IOException an exception creating the GZIP stream
*/
public static byte[] gzipCompress(byte[] byteArray) throws IOException {
// Function to gzip compress the data for the hashmaps
ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(byteArray.length);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(byteArray.length);
try
{
GZIPOutputStream zipStream =
new GZIPOutputStream(byteStream);
GZIPOutputStream zipStream = new GZIPOutputStream(byteStream);
try
{
zipStream.write(byteArray);
Expand All @@ -73,7 +69,6 @@ public static byte[] gzipCompress(byte[] byteArray) throws IOException {
{
byteStream.close();
}
byte[] compressedData = byteStream.toByteArray();
return compressedData;
return byteStream.toByteArray();
}
}
Binary file modified mmtf-codec/src/test/resources/mmtf/4cup.mmtf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MmtfStructure implements Serializable {
/** The number of characters in a chain.*/
public static final int CHAIN_LENGTH = 4;
/** The version of MMTF */
public static final String VERSION = "0.2.0";
public static final String VERSION = "1.0.0";


/** Serial id for this version of the format. */
Expand Down