Skip to content

Commit 3da36b0

Browse files
committed
Updates to the reader and writer due to downstream changes in the mmtf
1 parent f24baca commit 3da36b0

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

biojava-structure/src/main/java/demo/DemoMmtfRoundTrip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DemoMmtfRoundTrip {
1212

1313
public static void main(String[] args) throws IOException, StructureException {
1414
MmtfUtils.setUpBioJava();
15-
Structure structure = StructureIO.getStructure("/Users/abradley/Downloads/4cup.cif");
15+
Structure structure = StructureIO.getStructure("4cup");
1616
// We can do somme comparisons on the round tripped structure
1717
MmtfActions.roundTrip(structure);
1818
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public void finalizeStructure() {
101101
}
102102

103103
@Override
104-
public void initStructure(int totalNumAtoms, int totalNumGroups, int totalNumChains, int totalNumModels, String modelId) {
104+
public void initStructure(int totalNumBonds, int totalNumAtoms, int totalNumGroups,
105+
int totalNumChains, int totalNumModels, String modelId) {
105106
structure.setPDBCode(modelId);
106107
}
107108

@@ -146,7 +147,8 @@ public void setChainInfo(String chainId, String chainName, int groupCount) {
146147
*/
147148
@Override
148149
public void setGroupInfo(String groupName, int groupNumber,
149-
char insertionCode, String chemCompType, int atomCount, char singleLetterCode, int sequenceIndexId) {
150+
char insertionCode, String chemCompType, int atomCount, int bondCount,
151+
char singleLetterCode, int sequenceIndexId) {
150152
// Get the polymer type
151153
int polymerType = getGroupTypIndicator(chemCompType);
152154
switch (polymerType) {

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.biojava.nbio.structure.quaternary.BioAssemblyInfo;
1717
import org.rcsb.mmtf.api.MmtfDecoderInterface;
1818
import org.rcsb.mmtf.api.MmtfWriter;
19+
import org.rcsb.mmtf.dataholders.MmtfBean;
1920

2021
/**
2122
* Class to take Biojava structure data and covert to the DataApi for encoding.
@@ -49,8 +50,9 @@ public void write(MmtfDecoderInterface decoder) {
4950
Map<String, Integer> chainIdToIndexMap = MmtfUtils.getChainIdToIndexMap(structure);
5051
List<Chain> allChains = MmtfUtils.getAllChains(structure);
5152
List<Atom> allAtoms = MmtfUtils.getAllAtoms(structure);
53+
int numBonds = MmtfUtils.getNumBonds(allAtoms);
5254

53-
mmtfDecoderInterface.initStructure(allAtoms.size(), MmtfUtils.getNumGroups(structure), allChains.size(), structure.nrModels(), structure.getPDBCode());
55+
mmtfDecoderInterface.initStructure(numBonds, allAtoms.size(), MmtfUtils.getNumGroups(structure), allChains.size(), structure.nrModels(), structure.getPDBCode());
5456
// Get the header and the xtal info.
5557
PDBHeader pdbHeader = structure.getPDBHeader();
5658
PDBCrystallographicInfo xtalInfo = pdbHeader.getCrystallographicInfo();
@@ -77,8 +79,12 @@ public void write(MmtfDecoderInterface decoder) {
7779
List<Atom> atomsInGroup = MmtfUtils.getAtomsForGroup(group);
7880
// Get the group type
7981
ChemComp chemComp = group.getChemComp();
80-
mmtfDecoderInterface.setGroupInfo(group.getPDBName(), group.getResidueNumber().getSeqNum(), group.getResidueNumber().getInsCode().charValue(),
81-
chemComp.getPdbx_type(), atomsInGroup.size(), chemComp.getOne_letter_code().charAt(0), sequenceGroups.indexOf(group));
82+
Character insCode = group.getResidueNumber().getInsCode();
83+
if(insCode==null){
84+
insCode=MmtfBean.UNAVAILABLE_CHAR_VALUE;
85+
}
86+
mmtfDecoderInterface.setGroupInfo(group.getPDBName(), group.getResidueNumber().getSeqNum(), insCode.charValue(),
87+
chemComp.getPdbx_type(), atomsInGroup.size(), chemComp.getBonds().size(), chemComp.getOne_letter_code().charAt(0), sequenceGroups.indexOf(group));
8288
for (Atom atom : atomsInGroup){
8389
mmtfDecoderInterface.setAtomInfo(atom.getName(), atom.getPDBserial(), atom.getAltLoc().charValue(), (float) atom.getX(),
8490
(float) atom.getY(), (float) atom.getZ(), atom.getOccupancy(),
@@ -99,6 +105,9 @@ public void write(MmtfDecoderInterface decoder) {
99105
* @param allAtoms the list of atoms in the whole structure
100106
*/
101107
private void addBonds(Atom atom, List<Atom> atomsInGroup, List<Atom> allAtoms) {
108+
if(atom.getBonds()==null){
109+
return;
110+
}
102111
for(Bond bond : atom.getBonds()) {
103112
// Now set the bonding information.
104113
Atom other = bond.getOther(atom);
@@ -119,7 +128,7 @@ private void addBonds(Atom atom, List<Atom> atomsInGroup, List<Atom> allAtoms) {
119128
// Don't add the same bond twice
120129
if (firstBondIndex<secondBondIndex){
121130
int bondOrder = bond.getBondOrder();
122-
mmtfDecoderInterface.setGroupBond(firstBondIndex, secondBondIndex, bondOrder);
131+
mmtfDecoderInterface.setInterGroupBond(firstBondIndex, secondBondIndex, bondOrder);
123132
}
124133
}
125134
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.vecmath.Matrix4d;
1616

1717
import org.biojava.nbio.structure.Atom;
18+
import org.biojava.nbio.structure.Bond;
1819
import org.biojava.nbio.structure.Chain;
1920
import org.biojava.nbio.structure.ExperimentalTechnique;
2021
import org.biojava.nbio.structure.Group;
@@ -339,5 +340,26 @@ public static int getNumGroups(Structure structure) {
339340
}
340341
}
341342
return count;
343+
}
344+
345+
/**
346+
* Get the number of unique bonds in the strucutre.
347+
* @param allAtoms
348+
* @return
349+
*/
350+
public static int getNumBonds(List<Atom> allAtoms) {
351+
int bondCount = 0;
352+
for(int indexAtomOne=0;indexAtomOne<allAtoms.size();indexAtomOne++) {
353+
Atom atomOne = allAtoms.get(indexAtomOne);
354+
if(atomOne.getBonds()==null){
355+
continue;
356+
}
357+
for(Bond bond : atomOne.getBonds()) {
358+
if(allAtoms.indexOf(bond.getOther(atomOne))>indexAtomOne){
359+
bondCount++;
360+
}
361+
}
362+
}
363+
return bondCount;
342364
}
343365
}

0 commit comments

Comments
 (0)