Search in sources :

Example 1 with Point3f

use of javax.vecmath.Point3f in project mmtf-spark by sbl-sdsc.

the class StructureToBioassembly2 method call.

@Override
public Iterator<Tuple2<String, StructureDataInterface>> call(Tuple2<String, StructureDataInterface> t) throws Exception {
    StructureDataInterface structure = t._2;
    // Map<Integer, Integer> atomMap = new HashMap<>();
    List<Tuple2<String, StructureDataInterface>> resList = new ArrayList<>();
    // for each of them, create one structure.
    for (int i = 0; i < structure.getNumBioassemblies(); i++) {
        int[] chainsPerModel = new int[structure.getNumModels()];
        // initiate the bioassembly structure.
        AdapterToStructureData bioAssembly = new AdapterToStructureData();
        // set the structureID.
        String structureId = structure.getStructureId() + "-BioAssembly" + structure.getBioassemblyName(i);
        int totAtoms = 0, totBonds = 0, totGroups = 0, totChains = 0, totModels = 0;
        int numTrans = structure.getNumTransInBioassembly(i);
        totModels = structure.getNumModels();
        int[][] bioChainList = new int[numTrans][];
        double[][] transMatrix = new double[numTrans][];
        // calculate the total data we will use to initialize the structure.
        for (int ii = 0; ii < numTrans; ii++) {
            bioChainList[ii] = structure.getChainIndexListForTransform(i, ii);
            transMatrix[ii] = structure.getMatrixForTransform(i, ii);
            for (int j = 0; j < totModels; j++) {
                totChains += bioChainList[ii].length;
                chainsPerModel[j] += bioChainList[ii].length;
                // System.out.println(bioChainList[ii].length + " "  + Arrays.toString(bioChainList[ii]));
                for (int k = 0, groupCounter = 0; k < structure.getChainsPerModel()[j]; k++) {
                    boolean adding = false;
                    for (int currChain : bioChainList[ii]) {
                        if (currChain == k)
                            adding = true;
                    }
                    if (adding) {
                        // System.out.println("adding groups");
                        totGroups += structure.getGroupsPerChain()[k];
                    }
                    for (int h = 0; h < structure.getGroupsPerChain()[k]; h++, groupCounter++) {
                        if (adding) {
                            int groupIndex = structure.getGroupTypeIndices()[groupCounter];
                            totAtoms += structure.getNumAtomsInGroup(groupIndex);
                            totBonds += structure.getGroupBondOrders(groupIndex).length;
                        }
                    }
                }
            }
        }
        // init
        // System.out.println("Initializing the structure with\n"
        // + " totModel = " + totModels + ", totChains = " + totChains + ", totGroups = " + totGroups + ", totAtoms = "
        // + totAtoms + ", totBonds = " + totBonds + ", name : " + structureId);
        bioAssembly.initStructure(totBonds, totAtoms, totGroups, totChains, totModels, structureId);
        DecoderUtils.addXtalographicInfo(structure, bioAssembly);
        DecoderUtils.addHeaderInfo(structure, bioAssembly);
        /*
			 * Now we have bioChainList and transMatrix.
			 * bioChainList[i] is the ith trans' list of chains it has.  
			 * transMatrix[i] is the matrix that is going to be applied on those chains.
			 */
        // initialize the indices.
        int modelIndex = 0;
        int chainIndex = 0;
        int groupIndex = 0;
        int atomIndex = 0;
        int chainCounter = 0;
        // loop through models
        for (int ii = 0; ii < structure.getNumModels(); ii++) {
            // precalculate indices
            // this number is not correct if BA has fewer chains than the AU
            // int numChainsPerModel = structure.getChainsPerModel()[modelIndex] * numTrans;
            int numChainsPerModel = chainsPerModel[ii];
            System.out.println("numChainsPerModel: " + numChainsPerModel);
            bioAssembly.setModelInfo(modelIndex, numChainsPerModel);
            int[] chainToEntityIndex = getChainToEntityIndex(structure);
            // loop through chains
            for (int j = 0; j < structure.getChainsPerModel()[modelIndex]; j++) {
                // loop through each trans
                int currGroupIndex = groupIndex;
                int currAtomIndex = atomIndex;
                for (int k = 0; k < numTrans; k++) {
                    // get the currChainList that needs to be added
                    int[] currChainList = bioChainList[k];
                    double[] currMatrix = transMatrix[k];
                    boolean addThisChain = false;
                    for (int currChain : currChainList) {
                        if (currChain == j)
                            addThisChain = true;
                    }
                    groupIndex = currGroupIndex;
                    atomIndex = currAtomIndex;
                    float[] xCoords = structure.getxCoords();
                    float[] yCoords = structure.getyCoords();
                    float[] zCoords = structure.getzCoords();
                    // float[] floatMatrix = Floats.toArray(Doubles.asList(currMatrix));
                    // Matrix4f m = new Matrix4f(floatMatrix);
                    Matrix4d md = new Matrix4d(currMatrix);
                    if (addThisChain) {
                        int entityToChainIndex = chainToEntityIndex[chainIndex];
                        // System.out.println("adding chain : " + chainIndex);
                        // TODO
                        // not sure
                        bioAssembly.setEntityInfo(new int[] { chainCounter }, structure.getEntitySequence(entityToChainIndex), structure.getEntityDescription(entityToChainIndex), structure.getEntityType(entityToChainIndex));
                        // TODO create unique chain ids
                        bioAssembly.setChainInfo(structure.getChainIds()[chainIndex] + (k + 1), structure.getChainNames()[chainIndex] + (k + 1), // bioAssembly.setChainInfo(structure.getChainIds()[chainIndex], structure.getChainNames()[chainIndex],
                        structure.getGroupsPerChain()[chainIndex]);
                        chainCounter++;
                    }
                    // loop through the groups in the chain
                    for (int jj = 0; jj < structure.getGroupsPerChain()[chainIndex]; jj++) {
                        int currgroup = structure.getGroupTypeIndices()[groupIndex];
                        if (addThisChain) {
                            bioAssembly.setGroupInfo(structure.getGroupName(currgroup), structure.getGroupIds()[groupIndex], structure.getInsCodes()[groupIndex], structure.getGroupChemCompType(currgroup), structure.getNumAtomsInGroup(currgroup), structure.getGroupBondOrders(currgroup).length, structure.getGroupSingleLetterCode(currgroup), structure.getGroupSequenceIndices()[groupIndex], structure.getSecStructList()[groupIndex]);
                        }
                        for (int kk = 0; kk < structure.getNumAtomsInGroup(currgroup); kk++) {
                            // System.out.println("currgroup : " + currgroup + " curratom : " + kk);
                            if (addThisChain) {
                                Point3f p1 = new Point3f(xCoords[atomIndex], yCoords[atomIndex], zCoords[atomIndex]);
                                // m.transform(p1);
                                md.transform(p1);
                                // System.out.println(kk + " " + currgroup);
                                bioAssembly.setAtomInfo(structure.getGroupAtomNames(currgroup)[kk], structure.getAtomIds()[atomIndex], structure.getAltLocIds()[atomIndex], p1.x, p1.y, p1.z, structure.getOccupancies()[atomIndex], structure.getbFactors()[atomIndex], structure.getGroupElementNames(currgroup)[kk], structure.getGroupAtomCharges(currgroup)[kk]);
                            }
                            // inc the atomIndex
                            atomIndex++;
                        }
                        if (addThisChain) {
                            for (int l = 0; l < structure.getGroupBondOrders(currgroup).length; l++) {
                                // System.out.println(structure.getGroupBondOrders(currgroup).length + " " + l);
                                int bondIndOne = structure.getGroupBondIndices(currgroup)[l * 2];
                                int bondIndTwo = structure.getGroupBondIndices(currgroup)[l * 2 + 1];
                                int bondOrder = structure.getGroupBondOrders(currgroup)[l];
                                bioAssembly.setGroupBond(bondIndOne, bondIndTwo, bondOrder);
                            }
                        }
                        // inc the groupIndex
                        groupIndex++;
                    }
                    if (addThisChain) {
                    // Add inter-group bond info
                    // for(int l = 0;  l < structure.getInterGroupBondOrders().length; l++){
                    // int bondIndOne = structure.getInterGroupBondIndices()[l*2];
                    // int bondIndTwo = structure.getInterGroupBondIndices()[l*2+1];
                    // int bondOrder = structure.getInterGroupBondOrders()[l];
                    // Integer indexOne = atomMap.get(bondIndOne);
                    // if (indexOne != null) {
                    // Integer indexTwo = atomMap.get(bondIndTwo);
                    // if (indexTwo != null) {
                    // bioAssembly.setInterGroupBond(indexOne, indexTwo, bondOrder);
                    // }
                    // }
                    }
                }
                // inc the chainIndex
                chainIndex++;
            }
            // inc the modelIndex
            modelIndex++;
        }
        bioAssembly.finalizeStructure();
        resList.add(new Tuple2<String, StructureDataInterface>(structureId, bioAssembly));
    }
    return resList.iterator();
}
Also used : ArrayList(java.util.ArrayList) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Matrix4d(javax.vecmath.Matrix4d) AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) Point3f(javax.vecmath.Point3f) Tuple2(scala.Tuple2)

Example 2 with Point3f

use of javax.vecmath.Point3f in project BuildCraft by BuildCraft.

the class ModelUtil method getPointsForFace.

public static Point3f[] getPointsForFace(EnumFacing face, Tuple3f center, Tuple3f radius) {
    Point3f centerOfFace = new Point3f(center);
    Point3f faceAdd = new Point3f(face.getFrontOffsetX() * radius.x, face.getFrontOffsetY() * radius.y, face.getFrontOffsetZ() * radius.z);
    centerOfFace.add(faceAdd);
    Vector3f faceRadius = new Vector3f(radius);
    if (face.getAxisDirection() == AxisDirection.POSITIVE) {
        faceRadius.sub(faceAdd);
    } else {
        faceRadius.add(faceAdd);
    }
    return getPoints(centerOfFace, faceRadius);
}
Also used : Point3f(javax.vecmath.Point3f) Vector3f(javax.vecmath.Vector3f)

Example 3 with Point3f

use of javax.vecmath.Point3f in project BuildCraft by BuildCraft.

the class ModelUtil method getPoints.

public static Point3f[] getPoints(Point3f centerFace, Tuple3f faceRadius) {
    Point3f[] array = { new Point3f(centerFace), new Point3f(centerFace), new Point3f(centerFace), new Point3f(centerFace) };
    array[0].add(addOrNegate(faceRadius, false, false));
    array[1].add(addOrNegate(faceRadius, false, true));
    array[2].add(addOrNegate(faceRadius, true, true));
    array[3].add(addOrNegate(faceRadius, true, false));
    return array;
}
Also used : Point3f(javax.vecmath.Point3f)

Example 4 with Point3f

use of javax.vecmath.Point3f in project BuildCraft by BuildCraft.

the class RenderPartCube method render.

/**
 * Renders an element, without changing the vertex. However this does ignore the "normal" and "texture" components
 * of the vertex.
 */
public void render(BufferBuilder bb) {
    Point3f pos = center.positionvf();
    double x = pos.x;
    double y = pos.y;
    double z = pos.z;
    double rX = sizeX / 2;
    double rY = sizeY / 2;
    double rZ = sizeZ / 2;
    vertex(bb, center, x - rX, y + rY, z + rZ);
    vertex(bb, center, x + rX, y + rY, z + rZ);
    vertex(bb, center, x + rX, y + rY, z - rZ);
    vertex(bb, center, x - rX, y + rY, z - rZ);
    vertex(bb, center, x - rX, y - rY, z - rZ);
    vertex(bb, center, x + rX, y - rY, z - rZ);
    vertex(bb, center, x + rX, y - rY, z + rZ);
    vertex(bb, center, x - rX, y - rY, z + rZ);
    vertex(bb, center, x - rX, y - rY, z + rZ);
    vertex(bb, center, x - rX, y + rY, z + rZ);
    vertex(bb, center, x - rX, y + rY, z - rZ);
    vertex(bb, center, x - rX, y - rY, z - rZ);
    vertex(bb, center, x + rX, y - rY, z - rZ);
    vertex(bb, center, x + rX, y + rY, z - rZ);
    vertex(bb, center, x + rX, y + rY, z + rZ);
    vertex(bb, center, x + rX, y - rY, z + rZ);
    vertex(bb, center, x - rX, y - rY, z - rZ);
    vertex(bb, center, x - rX, y + rY, z - rZ);
    vertex(bb, center, x + rX, y + rY, z - rZ);
    vertex(bb, center, x + rX, y - rY, z - rZ);
    vertex(bb, center, x + rX, y - rY, z + rZ);
    vertex(bb, center, x + rX, y + rY, z + rZ);
    vertex(bb, center, x - rX, y + rY, z + rZ);
    vertex(bb, center, x - rX, y - rY, z + rZ);
}
Also used : Point3f(javax.vecmath.Point3f)

Example 5 with Point3f

use of javax.vecmath.Point3f in project BuildCraft by BuildCraft.

the class MatrixUtil method multiply.

public static AxisAlignedBB multiply(AxisAlignedBB box, Matrix4f matrix) {
    Point3f min = new Point3f(new Point3d(box.minX, box.minY, box.minZ));
    Point3f max = new Point3f(new Point3d(box.maxX, box.maxY, box.maxZ));
    matrix.transform(min);
    matrix.transform(max);
    return new AxisAlignedBB(min.x, min.y, min.z, max.x, max.y, max.z);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Point3f(javax.vecmath.Point3f) Point3d(javax.vecmath.Point3d)

Aggregations

Point3f (javax.vecmath.Point3f)12 ArrayList (java.util.ArrayList)2 Matrix4f (javax.vecmath.Matrix4f)2 Vector3f (javax.vecmath.Vector3f)2 EnumFacing (net.minecraft.util.EnumFacing)2 StructureDataInterface (org.rcsb.mmtf.api.StructureDataInterface)2 AdapterToStructureData (org.rcsb.mmtf.encoder.AdapterToStructureData)2 Tuple2 (scala.Tuple2)2 BCBuildersSprites (buildcraft.builders.BCBuildersSprites)1 ITileForSnapshotBuilder (buildcraft.builders.snapshot.ITileForSnapshotBuilder)1 SnapshotBuilder (buildcraft.builders.snapshot.SnapshotBuilder)1 BuildCraftLaserManager (buildcraft.core.client.BuildCraftLaserManager)1 ModelUtil (buildcraft.lib.client.model.ModelUtil)1 UvFaceData (buildcraft.lib.client.model.ModelUtil.UvFaceData)1 MutableQuad (buildcraft.lib.client.model.MutableQuad)1 ItemRenderUtil (buildcraft.lib.client.render.ItemRenderUtil)1 LaserData_BC8 (buildcraft.lib.client.render.laser.LaserData_BC8)1 LaserRenderer_BC8 (buildcraft.lib.client.render.laser.LaserRenderer_BC8)1 MathUtil (buildcraft.lib.misc.MathUtil)1 VecUtil (buildcraft.lib.misc.VecUtil)1