Search in sources :

Example 1 with AdapterToStructureData

use of org.rcsb.mmtf.encoder.AdapterToStructureData in project mm-dev by sbl-sdsc.

the class MergeMmtf method MergeStructures.

public static StructureDataInterface MergeStructures(String structureId, StructureDataInterface... structures) {
    for (StructureDataInterface s : structures) {
        if (s.getNumModels() != 1) {
            throw new IllegalArgumentException("ERROR: Cannot merge structures with more than one model");
        }
    }
    AdapterToStructureData complex = new AdapterToStructureData();
    initStructure(structureId, structures, complex);
    addEntityInfo(structures, complex);
    for (StructureDataInterface structure : structures) {
        addStructure(structure, complex);
    }
    complex.finalizeStructure();
    return complex;
}
Also used : AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Example 2 with AdapterToStructureData

use of org.rcsb.mmtf.encoder.AdapterToStructureData in project mm-dev by sbl-sdsc.

the class Molmporter method readFile.

public AdapterToStructureData readFile(String fileName) throws IOException {
    InputStream is = new FileInputStream(fileName);
    AdapterToStructureData structure = read(is, fileName);
    is.close();
    return structure;
}
Also used : AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream)

Example 3 with AdapterToStructureData

use of org.rcsb.mmtf.encoder.AdapterToStructureData in project mm-dev by sbl-sdsc.

the class Molmporter method readUrl.

public AdapterToStructureData readUrl(String url) throws IOException {
    URL u = new URL(url);
    InputStream is = null;
    try {
        is = u.openStream();
    } catch (IOException e) {
        return null;
    }
    AdapterToStructureData structure = read(is, url);
    return structure;
}
Also used : AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with AdapterToStructureData

use of org.rcsb.mmtf.encoder.AdapterToStructureData in project mmtf-spark by sbl-sdsc.

the class StructureToPolymerChains method call.

@Override
public Iterator<Tuple2<String, StructureDataInterface>> call(Tuple2<String, StructureDataInterface> t) throws Exception {
    StructureDataInterface structure = t._2;
    // precalculate indices
    int numChains = structure.getChainsPerModel()[0];
    int[] chainToEntityIndex = getChainToEntityIndex(structure);
    int[] atomsPerChain = new int[numChains];
    int[] bondsPerChain = new int[numChains];
    getNumAtomsAndBonds(structure, atomsPerChain, bondsPerChain);
    List<Tuple2<String, StructureDataInterface>> chainList = new ArrayList<>();
    Set<String> seqSet = new HashSet<>();
    for (int i = 0, atomCounter = 0, groupCounter = 0; i < numChains; i++) {
        AdapterToStructureData polymerChain = new AdapterToStructureData();
        int entityToChainIndex = chainToEntityIndex[i];
        boolean polymer = structure.getEntityType(entityToChainIndex).equals("polymer");
        int polymerAtomCount = 0;
        Map<Integer, Integer> atomMap = new HashMap<>();
        if (polymer) {
            // to avoid of information loss, add chainName/IDs and entity id
            // this required by some queries
            String structureId = structure.getStructureId() + "." + structure.getChainNames()[i] + "." + structure.getChainIds()[i] + "." + (entityToChainIndex + 1);
            // set header
            polymerChain.initStructure(bondsPerChain[i], atomsPerChain[i], structure.getGroupsPerChain()[i], 1, 1, structureId);
            DecoderUtils.addXtalographicInfo(structure, polymerChain);
            DecoderUtils.addHeaderInfo(structure, polymerChain);
            // set model info (only one model: 0)
            polymerChain.setModelInfo(0, 1);
            // set entity and chain info
            polymerChain.setEntityInfo(new int[] { 0 }, structure.getEntitySequence(entityToChainIndex), structure.getEntityDescription(entityToChainIndex), structure.getEntityType(entityToChainIndex));
            polymerChain.setChainInfo(structure.getChainIds()[i], structure.getChainNames()[i], structure.getGroupsPerChain()[i]);
        }
        for (int j = 0; j < structure.getGroupsPerChain()[i]; j++, groupCounter++) {
            int groupIndex = structure.getGroupTypeIndices()[groupCounter];
            if (polymer) {
                // set group info
                polymerChain.setGroupInfo(structure.getGroupName(groupIndex), structure.getGroupIds()[groupCounter], structure.getInsCodes()[groupCounter], structure.getGroupChemCompType(groupIndex), structure.getNumAtomsInGroup(groupIndex), structure.getGroupBondOrders(groupIndex).length, structure.getGroupSingleLetterCode(groupIndex), structure.getGroupSequenceIndices()[groupCounter], structure.getSecStructList()[groupCounter]);
            }
            for (int k = 0; k < structure.getNumAtomsInGroup(groupIndex); k++, atomCounter++) {
                if (polymer) {
                    // set atom info
                    atomMap.put(atomCounter, polymerAtomCount);
                    polymerAtomCount++;
                    polymerChain.setAtomInfo(structure.getGroupAtomNames(groupIndex)[k], structure.getAtomIds()[atomCounter], structure.getAltLocIds()[atomCounter], structure.getxCoords()[atomCounter], structure.getyCoords()[atomCounter], structure.getzCoords()[atomCounter], structure.getOccupancies()[atomCounter], structure.getbFactors()[atomCounter], structure.getGroupElementNames(groupIndex)[k], structure.getGroupAtomCharges(groupIndex)[k]);
                }
            }
            if (polymer) {
                // add intra-group bond info
                for (int l = 0; l < structure.getGroupBondOrders(groupIndex).length; l++) {
                    int bondIndOne = structure.getGroupBondIndices(groupIndex)[l * 2];
                    int bondIndTwo = structure.getGroupBondIndices(groupIndex)[l * 2 + 1];
                    int bondOrder = structure.getGroupBondOrders(groupIndex)[l];
                    polymerChain.setGroupBond(bondIndOne, bondIndTwo, bondOrder);
                }
            }
        }
        if (polymer) {
            // Add inter-group bond info
            for (int ii = 0; ii < structure.getInterGroupBondOrders().length; ii++) {
                int bondIndOne = structure.getInterGroupBondIndices()[ii * 2];
                int bondIndTwo = structure.getInterGroupBondIndices()[ii * 2 + 1];
                int bondOrder = structure.getInterGroupBondOrders()[ii];
                Integer indexOne = atomMap.get(bondIndOne);
                if (indexOne != null) {
                    Integer indexTwo = atomMap.get(bondIndTwo);
                    if (indexTwo != null) {
                        polymerChain.setInterGroupBond(indexOne, indexTwo, bondOrder);
                    }
                }
            }
            polymerChain.finalizeStructure();
            String chId = structure.getChainNames()[i];
            if (useChainIdInsteadOfChainName) {
                chId = structure.getChainIds()[i];
            }
            if (excludeDuplicates) {
                if (seqSet.contains(structure.getEntitySequence(chainToEntityIndex[i]))) {
                    continue;
                }
                seqSet.add(structure.getEntitySequence(chainToEntityIndex[i]));
            }
            chainList.add(new Tuple2<String, StructureDataInterface>(structure.getStructureId() + "." + chId, polymerChain));
        }
    }
    return chainList.iterator();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) Tuple2(scala.Tuple2) HashSet(java.util.HashSet)

Example 5 with AdapterToStructureData

use of org.rcsb.mmtf.encoder.AdapterToStructureData in project mmtf-spark by sbl-sdsc.

the class StructureToProteinDimers method combineChains.

/**
 * A method that takes two structure of chains and return a single structur of two chains.
 */
private static Tuple2<String, StructureDataInterface> combineChains(StructureDataInterface s1, StructureDataInterface s2) {
    int groupCounter = 0;
    int atomCounter = 0;
    String structureId = s1.getStructureId() + "_append_" + s2.getStructureId();
    AdapterToStructureData combinedStructure = new AdapterToStructureData();
    combinedStructure.initStructure(s1.getNumBonds() + s2.getNumBonds(), s1.getNumAtoms() + s2.getNumAtoms(), s1.getNumGroups() + s2.getNumGroups(), 2, 1, structureId);
    DecoderUtils.addXtalographicInfo(s1, combinedStructure);
    DecoderUtils.addHeaderInfo(s1, combinedStructure);
    combinedStructure.setModelInfo(0, 2);
    // set entity and chain info
    combinedStructure.setEntityInfo(new int[] { 0 }, s1.getEntitySequence(getChainToEntityIndex(s1)[0]), s1.getEntityDescription(getChainToEntityIndex(s1)[0]), s1.getEntityType(getChainToEntityIndex(s1)[0]));
    combinedStructure.setChainInfo(s1.getChainIds()[0], s1.getChainNames()[0], s1.getGroupsPerChain()[0]);
    for (int i = 0; i < s1.getGroupsPerChain()[0]; i++, groupCounter++) {
        int groupIndex = s1.getGroupTypeIndices()[groupCounter];
        // set group info
        combinedStructure.setGroupInfo(s1.getGroupName(groupIndex), s1.getGroupIds()[groupCounter], s1.getInsCodes()[groupCounter], s1.getGroupChemCompType(groupIndex), s1.getNumAtomsInGroup(groupIndex), s1.getGroupBondOrders(groupIndex).length, s1.getGroupSingleLetterCode(groupIndex), s1.getGroupSequenceIndices()[groupCounter], s1.getSecStructList()[groupCounter]);
        for (int j = 0; j < s1.getNumAtomsInGroup(groupIndex); j++, atomCounter++) {
            combinedStructure.setAtomInfo(s1.getGroupAtomNames(groupIndex)[j], s1.getAtomIds()[atomCounter], s1.getAltLocIds()[atomCounter], s1.getxCoords()[atomCounter], s1.getyCoords()[atomCounter], s1.getzCoords()[atomCounter], s1.getOccupancies()[atomCounter], s1.getbFactors()[atomCounter], s1.getGroupElementNames(groupIndex)[j], s1.getGroupAtomCharges(groupIndex)[j]);
        }
        // TODO : not sure if we should add bonds like this.
        for (int j = 0; j < s1.getGroupBondOrders(groupIndex).length; j++) {
            int bondIndOne = s1.getGroupBondIndices(groupIndex)[j * 2];
            int bondIndTwo = s1.getGroupBondIndices(groupIndex)[j * 2 + 1];
            int bondOrder = s1.getGroupBondOrders(groupIndex)[j];
            combinedStructure.setGroupBond(bondIndOne, bondIndTwo, bondOrder);
        }
    }
    // set entity and chain info
    combinedStructure.setEntityInfo(new int[] { 1 }, s1.getEntitySequence(getChainToEntityIndex(s2)[0]), s2.getEntityDescription(getChainToEntityIndex(s2)[0]), s2.getEntityType(getChainToEntityIndex(s2)[0]));
    combinedStructure.setChainInfo(s2.getChainIds()[0], s2.getChainNames()[0], s2.getGroupsPerChain()[0]);
    groupCounter = 0;
    atomCounter = 0;
    for (int i = 0; i < s2.getGroupsPerChain()[0]; i++, groupCounter++) {
        int groupIndex = s2.getGroupTypeIndices()[groupCounter];
        // set group info
        combinedStructure.setGroupInfo(s2.getGroupName(groupIndex), s2.getGroupIds()[groupCounter], s2.getInsCodes()[groupCounter], s2.getGroupChemCompType(groupIndex), s2.getNumAtomsInGroup(groupIndex), s2.getGroupBondOrders(groupIndex).length, s2.getGroupSingleLetterCode(groupIndex), s2.getGroupSequenceIndices()[groupCounter], s2.getSecStructList()[groupCounter]);
        for (int j = 0; j < s2.getNumAtomsInGroup(groupIndex); j++, atomCounter++) {
            combinedStructure.setAtomInfo(s2.getGroupAtomNames(groupIndex)[j], s2.getAtomIds()[atomCounter], s2.getAltLocIds()[atomCounter], s2.getxCoords()[atomCounter], s2.getyCoords()[atomCounter], s2.getzCoords()[atomCounter], s2.getOccupancies()[atomCounter], s2.getbFactors()[atomCounter], s2.getGroupElementNames(groupIndex)[j], s2.getGroupAtomCharges(groupIndex)[j]);
        }
        // TODO : not sure if we should add bonds like this.
        for (int j = 0; j < s2.getGroupBondOrders(groupIndex).length; j++) {
            int bondIndOne = s2.getGroupBondIndices(groupIndex)[j * 2];
            int bondIndTwo = s2.getGroupBondIndices(groupIndex)[j * 2 + 1];
            int bondOrder = s2.getGroupBondOrders(groupIndex)[j];
            combinedStructure.setGroupBond(bondIndOne, bondIndTwo, bondOrder);
        }
    }
    combinedStructure.finalizeStructure();
    return (new Tuple2<String, StructureDataInterface>(structureId, combinedStructure));
}
Also used : AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Aggregations

AdapterToStructureData (org.rcsb.mmtf.encoder.AdapterToStructureData)14 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 StructureDataInterface (org.rcsb.mmtf.api.StructureDataInterface)7 IOException (java.io.IOException)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 ArrayList (java.util.ArrayList)4 Tuple2 (scala.Tuple2)4 URL (java.net.URL)3 Structure (org.biojava.nbio.structure.Structure)3 MmtfStructureWriter (org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter)3 HashMap (java.util.HashMap)2 Point3f (javax.vecmath.Point3f)2 FileParsingParameters (org.biojava.nbio.structure.io.FileParsingParameters)2 MMCIFFileReader (org.biojava.nbio.structure.io.MMCIFFileReader)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Matrix4d (javax.vecmath.Matrix4d)1 Matrix4f (javax.vecmath.Matrix4f)1