Search in sources :

Example 6 with SymOp

use of ffx.crystal.SymOp in project ffx by mjschnie.

the class PDBFilter method writeAtom.

/**
 * <p>
 * writeAtom</p>
 *
 * @param atom a {@link ffx.potential.bonded.Atom} object.
 * @param serial a int.
 * @param sb a {@link java.lang.StringBuilder} object.
 * @param anisouSB a {@link java.lang.StringBuilder} object.
 * @param bw a {@link java.io.BufferedWriter} object.
 * @throws java.io.IOException if any.
 */
private void writeAtom(Atom atom, int serial, StringBuilder sb, StringBuilder anisouSB, BufferedWriter bw) throws IOException {
    if (ignoreUnusedAtoms && !atom.getUse()) {
        return;
    }
    String name = atom.getName();
    if (name.length() > 4) {
        name = name.substring(0, 4);
    } else if (name.length() == 1) {
        name = name + "  ";
    } else if (name.length() == 2) {
        if (atom.getAtomType().valence == 0) {
            name = name + "  ";
        } else {
            name = name + " ";
        }
    }
    double[] xyz = vdwH ? atom.getRedXYZ() : atom.getXYZ(null);
    if (nSymOp != 0) {
        Crystal crystal = activeMolecularAssembly.getCrystal();
        SymOp symOp = crystal.spaceGroup.getSymOp(nSymOp);
        double[] newXYZ = new double[xyz.length];
        crystal.applySymOp(xyz, newXYZ, symOp);
        xyz = newXYZ;
    }
    sb.replace(6, 16, String.format("%5s " + padLeft(name.toUpperCase(), 4), Hybrid36.encode(5, serial)));
    Character altLoc = atom.getAltLoc();
    if (altLoc != null) {
        sb.setCharAt(16, altLoc);
    } else {
        sb.setCharAt(16, ' ');
    }
    /*sb.replace(30, 66, String.format("%8.3f%8.3f%8.3f%6.2f%6.2f",
                xyz[0], xyz[1], xyz[2], atom.getOccupancy(), atom.getTempFactor()));*/
    /**
     * On the following code: #1: StringBuilder.replace will allow for
     * longer strings, expanding the StringBuilder's length if necessary.
     * #2: sb was never re-initialized, so if there was overflow, sb would
     * continue to be > 80 characters long, resulting in broken PDB files
     * #3: It may be wiser to have XYZ coordinates result in shutdown, not
     * truncation of coordinates. #4: Excessive B-factors aren't much of an
     * issue; if the B-factor is past 999.99, that's the difference between
     * "density extends to Venus" and "density extends to Pluto".
     */
    StringBuilder decimals = new StringBuilder();
    for (int i = 0; i < 3; i++) {
        try {
            decimals.append(StringUtils.fwFpDec(xyz[i], 8, 3));
        } catch (IllegalArgumentException ex) {
            String newValue = StringUtils.fwFpTrunc(xyz[i], 8, 3);
            logger.info(String.format(" XYZ %d coordinate %8.3f for atom %s " + "overflowed bounds of 8.3f string specified by PDB " + "format; truncating value to %s", i, xyz[i], atom.toString(), newValue));
            decimals.append(newValue);
        }
    }
    try {
        decimals.append(StringUtils.fwFpDec(atom.getOccupancy(), 6, 2));
    } catch (IllegalArgumentException ex) {
        logger.severe(String.format(" Occupancy %f for atom %s is impossible; " + "value must be between 0 and 1", atom.getOccupancy(), atom.toString()));
    }
    try {
        decimals.append(StringUtils.fwFpDec(atom.getTempFactor(), 6, 2));
    } catch (IllegalArgumentException ex) {
        String newValue = StringUtils.fwFpTrunc(atom.getTempFactor(), 6, 2);
        logger.info(String.format(" Atom temp factor %6.2f for atom %s overflowed " + "bounds of 6.2f string specified by PDB format; truncating " + "value to %s", atom.getTempFactor(), atom.toString(), newValue));
        decimals.append(newValue);
    }
    sb.replace(30, 66, decimals.toString());
    name = Atom.ElementSymbol.values()[atom.getAtomicNumber() - 1].toString();
    name = name.toUpperCase();
    if (atom.isDeuterium()) {
        name = "D";
    }
    sb.replace(76, 78, padLeft(name, 2));
    sb.replace(78, 80, String.format("%2d", 0));
    if (!listMode) {
        bw.write(sb.toString());
        bw.newLine();
    } else {
        listOutput.add(sb.toString());
    }
    // =============================================================================
    // 1 - 6        Record name   "ANISOU"
    // 7 - 11       Integer       serial         Atom serial number.
    // 13 - 16       Atom          name           Atom name.
    // 17            Character     altLoc         Alternate location indicator
    // 18 - 20       Residue name  resName        Residue name.
    // 22            Character     chainID        Chain identifier.
    // 23 - 26       Integer       resSeq         Residue sequence number.
    // 27            AChar         iCode          Insertion code.
    // 29 - 35       Integer       u[0][0]        U(1,1)
    // 36 - 42       Integer       u[1][1]        U(2,2)
    // 43 - 49       Integer       u[2][2]        U(3,3)
    // 50 - 56       Integer       u[0][1]        U(1,2)
    // 57 - 63       Integer       u[0][2]        U(1,3)
    // 64 - 70       Integer       u[1][2]        U(2,3)
    // 77 - 78       LString(2)    element        Element symbol, right-justified.
    // 79 - 80       LString(2)    charge         Charge on the atom.
    // =============================================================================
    double[] anisou = atom.getAnisou(null);
    if (anisou != null) {
        anisouSB.replace(6, 80, sb.substring(6, 80));
        anisouSB.replace(28, 70, String.format("%7d%7d%7d%7d%7d%7d", (int) (anisou[0] * 1e4), (int) (anisou[1] * 1e4), (int) (anisou[2] * 1e4), (int) (anisou[3] * 1e4), (int) (anisou[4] * 1e4), (int) (anisou[5] * 1e4)));
        if (!listMode) {
            bw.write(anisouSB.toString());
            bw.newLine();
        } else {
            listOutput.add(anisouSB.toString());
        }
    }
}
Also used : SymOp(ffx.crystal.SymOp) Crystal(ffx.crystal.Crystal)

Example 7 with SymOp

use of ffx.crystal.SymOp in project ffx by mjschnie.

the class PDBFilter method writeSIFTAtom.

private void writeSIFTAtom(Atom atom, int serial, StringBuilder sb, StringBuilder anisouSB, BufferedWriter bw, String siftScore) throws IOException {
    String name = atom.getName();
    if (name.length() > 4) {
        name = name.substring(0, 4);
    } else if (name.length() == 1) {
        name = name + "  ";
    } else if (name.length() == 2) {
        if (atom.getAtomType().valence == 0) {
            name = name + "  ";
        } else {
            name = name + " ";
        }
    }
    double[] xyz = vdwH ? atom.getRedXYZ() : atom.getXYZ(null);
    if (nSymOp != 0) {
        Crystal crystal = activeMolecularAssembly.getCrystal();
        SymOp symOp = crystal.spaceGroup.getSymOp(nSymOp);
        double[] newXYZ = new double[xyz.length];
        crystal.applySymOp(xyz, newXYZ, symOp);
        xyz = newXYZ;
    }
    sb.replace(6, 16, String.format("%5s " + padLeft(name.toUpperCase(), 4), Hybrid36.encode(5, serial)));
    Character altLoc = atom.getAltLoc();
    if (altLoc != null) {
        sb.setCharAt(16, altLoc);
    } else {
        sb.setCharAt(16, ' ');
    }
    if (siftScore == null) {
        sb.replace(30, 66, String.format("%8.3f%8.3f%8.3f%6.2f%6.2f", xyz[0], xyz[1], xyz[2], atom.getOccupancy(), 110.0));
    } else {
        sb.replace(30, 66, String.format("%8.3f%8.3f%8.3f%6.2f%6.2f", xyz[0], xyz[1], xyz[2], atom.getOccupancy(), (1 + (-1 * Float.parseFloat(siftScore))) * 100));
    }
    name = Atom.ElementSymbol.values()[atom.getAtomicNumber() - 1].toString();
    name = name.toUpperCase();
    if (atom.isDeuterium()) {
        name = "D";
    }
    sb.replace(76, 78, padLeft(name, 2));
    sb.replace(78, 80, String.format("%2d", 0));
    if (!listMode) {
        bw.write(sb.toString());
        bw.newLine();
    } else {
        listOutput.add(sb.toString());
    }
    // =============================================================================
    // 1 - 6        Record name   "ANISOU"
    // 7 - 11       Integer       serial         Atom serial number.
    // 13 - 16       Atom          name           Atom name.
    // 17            Character     altLoc         Alternate location indicator
    // 18 - 20       Residue name  resName        Residue name.
    // 22            Character     chainID        Chain identifier.
    // 23 - 26       Integer       resSeq         Residue sequence number.
    // 27            AChar         iCode          Insertion code.
    // 29 - 35       Integer       u[0][0]        U(1,1)
    // 36 - 42       Integer       u[1][1]        U(2,2)
    // 43 - 49       Integer       u[2][2]        U(3,3)
    // 50 - 56       Integer       u[0][1]        U(1,2)
    // 57 - 63       Integer       u[0][2]        U(1,3)
    // 64 - 70       Integer       u[1][2]        U(2,3)
    // 77 - 78       LString(2)    element        Element symbol, right-justified.
    // 79 - 80       LString(2)    charge         Charge on the atom.
    // =============================================================================
    double[] anisou = atom.getAnisou(null);
    if (anisou != null) {
        anisouSB.replace(6, 80, sb.substring(6, 80));
        anisouSB.replace(28, 70, String.format("%7d%7d%7d%7d%7d%7d", (int) (anisou[0] * 1e4), (int) (anisou[1] * 1e4), (int) (anisou[2] * 1e4), (int) (anisou[3] * 1e4), (int) (anisou[4] * 1e4), (int) (anisou[5] * 1e4)));
        if (!listMode) {
            bw.write(anisouSB.toString());
            bw.newLine();
        } else {
            listOutput.add(anisouSB.toString());
        }
    }
}
Also used : SymOp(ffx.crystal.SymOp) Crystal(ffx.crystal.Crystal)

Example 8 with SymOp

use of ffx.crystal.SymOp in project ffx by mjschnie.

the class XYZFilter method writeFileAsP1.

/**
 * <p>
 * writeFileAsP1</p>
 *
 * @param saveFile a {@link java.io.File} object.
 * @param append a boolean.
 * @param crystal a {@link ffx.crystal.Crystal} object.
 * @return a boolean.
 */
public boolean writeFileAsP1(File saveFile, boolean append, Crystal crystal) {
    if (saveFile == null) {
        return false;
    }
    try {
        File newFile = saveFile;
        if (!append) {
            newFile = version(saveFile);
        }
        activeMolecularAssembly.setFile(newFile);
        activeMolecularAssembly.setName(newFile.getName());
        FileWriter fw = new FileWriter(newFile, append);
        BufferedWriter bw = new BufferedWriter(fw);
        int nSymm = crystal.spaceGroup.symOps.size();
        // XYZ File First Line
        int numberOfAtoms = activeMolecularAssembly.getAtomList().size() * nSymm;
        String output = format("%7d %s\n", numberOfAtoms, activeMolecularAssembly.toString());
        bw.write(output);
        if (!crystal.aperiodic()) {
            Crystal uc = crystal.getUnitCell();
            String params = String.format("%14.8f%14.8f%14.8f%14.8f%14.8f%14.8f\n", uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma);
            bw.write(params);
        }
        Atom a2;
        StringBuilder line;
        StringBuilder[] lines = new StringBuilder[numberOfAtoms];
        // XYZ File Atom Lines
        Atom[] atoms = activeMolecularAssembly.getAtomArray();
        double[] xyz = new double[3];
        for (int iSym = 0; iSym < nSymm; iSym++) {
            SymOp symOp = crystal.spaceGroup.getSymOp(iSym);
            int indexOffset = iSym * atoms.length;
            for (Atom a : atoms) {
                int index = a.getIndex() + indexOffset;
                String id = a.getAtomType().name;
                if (vdwH) {
                    a.getRedXYZ(xyz);
                } else {
                    xyz[0] = a.getX();
                    xyz[1] = a.getY();
                    xyz[2] = a.getZ();
                }
                crystal.applySymOp(xyz, xyz, symOp);
                int type = a.getType();
                line = new StringBuilder(format("%7d %3s%14.8f%14.8f%14.8f%6d", index, id, xyz[0], xyz[1], xyz[2], type));
                for (Bond b : a.getBonds()) {
                    a2 = b.get1_2(a);
                    line.append(format("%8d", a2.getIndex() + indexOffset));
                }
                lines[index - 1] = line.append("\n");
            }
        }
        try {
            for (int i = 0; i < numberOfAtoms; i++) {
                bw.write(lines[i].toString());
            }
        } catch (IOException e) {
            String message = format(" Their was an unexpected error writing to %s.", getActiveMolecularSystem().toString());
            logger.log(Level.WARNING, message, e);
            return false;
        }
        bw.close();
        fw.close();
    } catch (IOException e) {
        String message = format(" Their was an unexpected error writing to %s.", getActiveMolecularSystem().toString());
        logger.log(Level.WARNING, message, e);
        return false;
    }
    return true;
}
Also used : SymOp(ffx.crystal.SymOp) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Atom(ffx.potential.bonded.Atom) BufferedWriter(java.io.BufferedWriter) Bond(ffx.potential.bonded.Bond) File(java.io.File) Crystal(ffx.crystal.Crystal)

Example 9 with SymOp

use of ffx.crystal.SymOp in project ffx by mjschnie.

the class MTZWriter method write.

/**
 * <p>
 * write</p>
 */
public void write() {
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileOutputStream fileOutputStream;
    DataOutputStream dataOutputStream;
    try {
        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(format("\n Writing MTZ HKL file: \"%s\"\n", fileName));
            logger.info(sb.toString());
        }
        fileOutputStream = new FileOutputStream(fileName);
        dataOutputStream = new DataOutputStream(fileOutputStream);
        byte[] bytes = new byte[80];
        int offset = 0;
        int writeLen = 0;
        int iMapData;
        float fMapData;
        // Header.
        StringBuilder sb = new StringBuilder();
        sb.append("MTZ ");
        dataOutputStream.writeBytes(sb.toString());
        // Header offset.
        int headerOffset = n * nCol + 21;
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        byteBuffer.order(byteOrder).putInt(headerOffset);
        // 0x4441 for LE, 0x1111 for BE
        if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
            iMapData = 0x4441;
        } else {
            iMapData = 0x1111;
        }
        byteBuffer.order(byteOrder).putInt(iMapData);
        dataOutputStream.write(bytes, offset, 8);
        sb = new StringBuilder();
        sb.append(" ");
        sb.setLength(68);
        dataOutputStream.writeBytes(sb.toString());
        // Data.
        Vector<String> colname = new Vector<>(nCol);
        char[] colType = new char[nCol];
        double[] res = new double[2];
        res[0] = Double.POSITIVE_INFINITY;
        res[1] = Double.NEGATIVE_INFINITY;
        float[][] colMinMax = new float[nCol][2];
        for (int i = 0; i < nCol; i++) {
            colMinMax[i][0] = Float.POSITIVE_INFINITY;
            colMinMax[i][1] = Float.NEGATIVE_INFINITY;
        }
        ReflectionSpline sigmaASpline = new ReflectionSpline(reflectionList, refinementData.sigmaa.length);
        int col = 0;
        colname.add("H");
        colType[col++] = 'H';
        colname.add("K");
        colType[col++] = 'H';
        colname.add("L");
        colType[col++] = 'H';
        writeLen += 12;
        if (mtzType != MTZType.FCONLY) {
            colname.add("FO");
            colType[col++] = 'F';
            colname.add("SIGFO");
            colType[col++] = 'Q';
            colname.add("FreeR");
            colType[col++] = 'I';
            writeLen += 12;
        }
        if (mtzType != MTZType.DATAONLY) {
            colname.add("Fs");
            colType[col++] = 'F';
            colname.add("PHIFs");
            colType[col++] = 'P';
            colname.add("Fc");
            colType[col++] = 'F';
            colname.add("PHIFc");
            colType[col++] = 'P';
            writeLen += 16;
        }
        if (mtzType == MTZType.ALL) {
            colname.add("FOM");
            colType[col++] = 'W';
            colname.add("PHIW");
            colType[col++] = 'P';
            colname.add("SigmaAs");
            colType[col++] = 'F';
            colname.add("SigmaAw");
            colType[col++] = 'Q';
            colname.add("FWT");
            colType[col++] = 'F';
            colname.add("PHWT");
            colType[col++] = 'P';
            colname.add("DELFWT");
            colType[col++] = 'F';
            colname.add("PHDELWT");
            colType[col++] = 'P';
            writeLen += 32;
        }
        for (HKL ih : reflectionList.hkllist) {
            col = 0;
            int i = ih.index();
            // Skip the 0 0 0 reflection.
            if (ih.h() == 0 && ih.k() == 0 && ih.l() == 0) {
                continue;
            }
            double ss = Crystal.invressq(crystal, ih);
            res[0] = min(ss, res[0]);
            res[1] = max(ss, res[1]);
            // HKL first (3)
            fMapData = ih.h();
            colMinMax[col][0] = min(fMapData, colMinMax[0][0]);
            colMinMax[col][1] = max(fMapData, colMinMax[0][1]);
            byteBuffer.rewind();
            byteBuffer.order(byteOrder).putFloat(fMapData);
            col++;
            fMapData = ih.k();
            colMinMax[col][0] = min(fMapData, colMinMax[1][0]);
            colMinMax[col][1] = max(fMapData, colMinMax[1][1]);
            byteBuffer.order(byteOrder).putFloat(fMapData);
            col++;
            fMapData = ih.l();
            colMinMax[col][0] = min(fMapData, colMinMax[2][0]);
            colMinMax[col][1] = max(fMapData, colMinMax[2][1]);
            byteBuffer.order(byteOrder).putFloat(fMapData);
            col++;
            if (mtzType != MTZType.FCONLY) {
                // F/sigF (2)
                fMapData = (float) refinementData.getF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) refinementData.getSigF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                // Free R (1)
                fMapData = (float) refinementData.getFreeR(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
            }
            if (mtzType == MTZType.FCONLY) {
                // Fs (2)
                fMapData = (float) refinementData.fsF(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fsPhi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                // Fc (unscaled!) (2)
                fMapData = (float) refinementData.fcF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) Math.toDegrees(refinementData.fcPhi(i));
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
            }
            if (mtzType == MTZType.ALL) {
                // Fs (2)
                fMapData = (float) refinementData.fsF(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fsPhi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                // Fctot (2)
                fMapData = (float) refinementData.fcTotF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fcTotPhi(i));
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = Math.min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = Math.max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                // FOM/phase (2)
                fMapData = (float) refinementData.fomphi[i][0];
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = Math.min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = Math.max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fomphi[i][1]);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                // Spline setup.
                double fh = spline.f(ss, refinementData.spline);
                double sa = sigmaASpline.f(ss, refinementData.sigmaa);
                double wa = sigmaASpline.f(ss, refinementData.sigmaw);
                // sigmaA/w (2)
                fMapData = (float) sa;
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) wa;
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                // Map coeffs (4).
                fMapData = (float) refinementData.FoFc2F(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.FoFc2Phi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) refinementData.foFc1F(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.foFc1Phi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
            }
            dataOutputStream.write(bytes, offset, writeLen);
        }
        // Header.
        sb = new StringBuilder();
        sb.append("VERS MTZ:V1.1 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss ");
        sb = new StringBuilder();
        sb.append("TITLE FFX output: " + sdf.format(now));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append(String.format("NCOL %8d %12d %8d", nCol, n, 0));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("SORT    0    0    0    0    0 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        char cdata = spaceGroup.shortName.charAt(0);
        if (cdata == 'H') {
            cdata = 'R';
        }
        sb.append(String.format("SYMINF %3d %2d %c %5d %22s %5s", spaceGroup.getNumberOfSymOps(), spaceGroup.numPrimitiveSymEquiv, cdata, spaceGroup.number, "'" + spaceGroup.shortName + "'", spaceGroup.pointGroupName));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        for (int i = 0; i < spaceGroup.symOps.size(); i++) {
            sb = new StringBuilder();
            sb.append("SYMM ");
            SymOp symop = spaceGroup.symOps.get(i);
            sb.append(symop.toXYZString());
            while (sb.length() < 80) {
                sb.append(" ");
            }
            dataOutputStream.writeBytes(sb.toString());
        }
        sb = new StringBuilder();
        sb.append(String.format("RESO %8.6f%13s%8.6f", res[0], " ", res[1]));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("VALM NAN ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("NDIF        1 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("PROJECT       1 project ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("CRYSTAL       1 crystal ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("DATASET       1 dataset ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        for (int j = 0; j < nCol; j++) {
            sb = new StringBuilder();
            sb.append(String.format("COLUMN %-30s %c %17.4f %17.4f    1", colname.get(j), colType[j], colMinMax[j][0], colMinMax[j][1]));
            dataOutputStream.writeBytes(sb.toString());
        }
        sb = new StringBuilder();
        sb.append(String.format("CELL %10.4f %9.4f %9.4f %9.4f %9.4f %9.4f ", crystal.a, crystal.b, crystal.c, crystal.alpha, crystal.beta, crystal.gamma));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append(String.format("DCELL %9d %10.4f %9.4f %9.4f %9.4f %9.4f %9.4f ", 1, crystal.a, crystal.b, crystal.c, crystal.alpha, crystal.beta, crystal.gamma));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("DWAVEL        1    1.00000 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("END ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        sb = new StringBuilder();
        sb.append("MTZENDOFHEADERS ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());
        dataOutputStream.close();
    } catch (Exception e) {
        String message = "Fatal exception evaluating structure factors.\n";
        logger.log(Level.SEVERE, message, e);
    }
}
Also used : ReflectionSpline(ffx.crystal.ReflectionSpline) SymOp(ffx.crystal.SymOp) DataOutputStream(java.io.DataOutputStream) HKL(ffx.crystal.HKL) ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) FileOutputStream(java.io.FileOutputStream) Vector(java.util.Vector) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SymOp (ffx.crystal.SymOp)9 Crystal (ffx.crystal.Crystal)5 Atom (ffx.potential.bonded.Atom)3 HKL (ffx.crystal.HKL)2 MultiResidue (ffx.potential.bonded.MultiResidue)2 Residue (ffx.potential.bonded.Residue)2 ResidueState (ffx.potential.bonded.ResidueState)2 IOException (java.io.IOException)2 ParallelTeam (edu.rit.pj.ParallelTeam)1 SharedInteger (edu.rit.pj.reduction.SharedInteger)1 ReflectionSpline (ffx.crystal.ReflectionSpline)1 ComplexNumber (ffx.numerics.ComplexNumber)1 Bond (ffx.potential.bonded.Bond)1 NACorrectionException (ffx.potential.bonded.NACorrectionException)1 Rotamer (ffx.potential.bonded.Rotamer)1 RotamerLibrary.applyRotamer (ffx.potential.bonded.RotamerLibrary.applyRotamer)1 NeighborList (ffx.potential.nonbonded.NeighborList)1 BufferedWriter (java.io.BufferedWriter)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1