ReducedEncoder implements Serializable { public static StructureDataInterface getReduced(StructureDataInterface full) { Map<Integer, Integer> atomMap = new HashMap<>(); Integer[] centerAtomIndices = getCenterAtomGroupIndices(full); AdapterToStructureData reduced = new AdapterToStructureData(); reduced.setMmtfProducer(full.getMmtfProducer()); SummaryData dataSummary = getDataSummaryData(full, centerAtomIndices); reduced.initStructure(dataSummary.numBonds, dataSummary.numAtoms, dataSummary.numGroups, dataSummary.numChains, full.getNumModels(), full.getStructureId()); DecoderUtils.addXtalographicInfo(full, reduced); DecoderUtils.addHeaderInfo(full, reduced); DecoderUtils.generateBioAssembly(full, reduced); DecoderUtils.addEntityInfo(full, reduced); for (int i = 0, atomCount = 0, groupCount = 0, chainCount = 0, reducedAtomCount = -1; i<full.getNumModels(); i++) { int numChains = full.getChainsPerModel()[i]; reduced.setModelInfo(i, numChains); for (int j = 0; j < numChains; j++, chainCount++){ String chainType = EncoderUtils.getTypeFromChainId(full, chainCount); int reducedGroupsPerChain = 0; for (int k = 0; k < full.getGroupsPerChain()[chainCount]; k++, groupCount++) { int groupType = full.getGroupTypeIndices()[groupCount]; Set<Integer> atomIndicesToAdd = getIndicesToAdd(full, groupType, chainType, centerAtomIndices); int bondsToAdd = getNumIntraGroupBonds(atomIndicesToAdd, full, groupType, centerAtomIndices); if (atomIndicesToAdd.size() > 0) { reduced.setGroupInfo(full.getGroupName(groupType), full.getGroupIds()[groupCount], full.getInsCodes()[groupCount], full.getGroupChemCompType(groupType), atomIndicesToAdd.size(), bondsToAdd, full.getGroupSingleLetterCode(groupType), full.getGroupSequenceIndices()[groupCount], full.getSecStructList()[groupCount]); reducedGroupsPerChain ++; } for (int l = 0; l < full.getNumAtomsInGroup(groupType); l++, atomCount++) { if (atomIndicesToAdd.contains(l)) { reducedAtomCount++; atomMap.put(atomCount, reducedAtomCount); reduced.setAtomInfo(full.getGroupAtomNames(groupType)[l], full.getAtomIds()[atomCount], full.getAltLocIds()[atomCount], full.getxCoords()[atomCount], full.getyCoords()[atomCount], full.getzCoords()[atomCount], full.getOccupancies()[atomCount], full.getbFactors()[atomCount], full.getGroupElementNames(groupType)[l], full.getGroupAtomCharges(groupType)[l]); } } if (bondsToAdd > 0){ for(int l=0; l<full.getGroupBondOrders(groupType).length; l++){ int index1 = full.getGroupBondIndices(groupType)[l*2]; int index2 = full.getGroupBondIndices(groupType)[l*2+1]; int bondOrder = full.getGroupBondOrders(groupType)[l]; reduced.setGroupBond(index1, index2, bondOrder); } } }; reduced.setChainInfo(full.getChainIds()[chainCount], full.getChainNames()[chainCount], reducedGroupsPerChain ); } } addInterGroupBonds(full, reduced, atomMap); reduced.finalizeStructure(); return reduced; }  static StructureDataInterface getReduced(StructureDataInterface full);  }
@Test public void testReducedRoundTrip() throws IOException, ParseException { StructureDataInterface structureDataInterface = ReducedEncoder.getReduced(getDefaultFullData()); testStructDataInterface(structureDataInterface); Utils.compare(structureDataInterface); }
@Test public void testReducedData() throws IOException, ParseException { StructureDataInterface full = getDefaultFullData(); StructureDataInterface reduced = ReducedEncoder.getReduced(full); assertArrayEquals(full.getChainNames(), reduced.getChainNames()); assertArrayEquals(full.getChainIds(), reduced.getChainIds()); assertEquals(removeWaters(full), reduced.getGroupTypeIndices().length); }