Example usage for org.apache.commons.configuration CompositeConfiguration getDouble

List of usage examples for org.apache.commons.configuration CompositeConfiguration getDouble

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration getDouble.

Prototype

public double getDouble(String key, double defaultValue) 

Source Link

Usage

From source file:ffx.xray.Looptimizer.java

/**
 * OSRW Asynchronous MultiWalker Constructor.
 *
 * @param lambdaInterface defines Lambda and dU/dL.
 * @param potential defines the Potential energy.
 * @param lambdaFile contains the current Lambda particle position and
 * velocity.//from   www  .  j  a  v  a 2s . c  o m
 * @param histogramFile contains the Lambda and dU/dL histogram.
 * @param properties defines System properties.
 * @param temperature the simulation temperature.
 * @param dt the time step.
 * @param printInterval number of steps between logging updates.
 * @param saveInterval number of steps between restart file updates.
 * @param asynchronous set to true if walkers run asynchronously.
 * @param algorithmListener the AlgorithmListener to be notified of
 * progress.
 */
public Looptimizer(LambdaInterface lambdaInterface, Potential potential, File lambdaFile, File histogramFile,
        CompositeConfiguration properties, double temperature, double dt, double printInterval,
        double saveInterval, boolean asynchronous, AlgorithmListener algorithmListener) {
    this.lambdaInterface = lambdaInterface;
    this.potential = potential;
    this.lambdaFile = lambdaFile;
    this.histogramFile = histogramFile;
    this.temperature = temperature;
    this.asynchronous = asynchronous;
    this.algorithmListener = algorithmListener;

    nVariables = potential.getNumberOfVariables();
    lowEnergyCoordsZero = new double[nVariables];
    lowEnergyCoordsOne = new double[nVariables];

    /**
     * Convert the time step to picoseconds.
     */
    this.dt = dt * 0.001;

    /**
     * Convert the print interval to a print frequency.
     */
    printFrequency = 100;
    if (printInterval >= this.dt) {
        printFrequency = (int) (printInterval / this.dt);
    }

    /**
     * Convert the save interval to a save frequency.
     */
    saveFrequency = 1000;
    if (saveInterval >= this.dt) {
        saveFrequency = (int) (saveInterval / this.dt);
    }

    biasCutoff = properties.getInt("lambda-bias-cutoff", 5);
    biasMag = properties.getDouble("bias-gaussian-mag", 0.002);
    dL = properties.getDouble("lambda-bin-width", 0.005);
    dFL = properties.getDouble("flambda-bin-width", 2.0);

    /**
     * Require modest sampling of the lambda path.
     */
    if (dL > 0.1) {
        dL = 0.1;
    }

    /**
     * Many lambda bin widths do not evenly divide into 1.0; here we correct
     * for this by computing an integer number of bins, then re-setting the
     * lambda variable appropriately. Note that we also choose to have an
     * odd number of lambda bins, so that the centers of the first and last
     * bin are at 0 and 1.
     */
    lambdaBins = (int) (1.0 / dL);
    if (lambdaBins % 2 == 0) {
        lambdaBins++;
    }

    /**
     * The initial number of FLambda bins does not really matter, since a
     * larger number is automatically allocated as needed. The center of the
     * central bin is at 0.
     */
    FLambdaBins = 401;
    minFLambda = -(dFL * FLambdaBins) / 2.0;

    /**
     * Allocate space for the recursion kernel that stores counts.
     */
    recursionKernel = new int[lambdaBins][FLambdaBins];

    /**
     * Load the OSRW histogram restart file if it exists.
     */
    boolean readHistogramRestart = false;
    if (histogramFile != null && histogramFile.exists()) {
        try {
            OSRWHistogramReader osrwHistogramReader = new OSRWHistogramReader(new FileReader(histogramFile));
            osrwHistogramReader.readHistogramFile();
            logger.info(String.format("\n Continuing OSRW histogram from %s.", histogramFile.getName()));
            readHistogramRestart = true;
        } catch (FileNotFoundException ex) {
            logger.info(" Histogram restart file could not be found and will be ignored.");
        }
    }

    /**
     * Load the OSRW lambda restart file if it exists.
     */
    if (lambdaFile != null && lambdaFile.exists()) {
        try {
            OSRWLambdaReader osrwLambdaReader = new OSRWLambdaReader(new FileReader(lambdaFile));
            osrwLambdaReader.readLambdaFile();
            logger.info(String.format("\n Continuing OSRW lambda from %s.", lambdaFile.getName()));
        } catch (FileNotFoundException ex) {
            logger.info(" Lambda restart file could not be found and will be ignored.");
        }
    }

    dL = 1.0 / (lambdaBins - 1);
    dL_2 = dL / 2.0;
    minLambda = -dL_2;
    dFL_2 = dFL / 2.0;
    maxFLambda = minFLambda + FLambdaBins * dFL;
    FLambda = new double[lambdaBins];
    dUdXdL = new double[nVariables];
    energyCount = -1;
    stochasticRandom = new Random(0);

    /**
     * Set up the multi-walker communication variables for Parallel Java
     * communication between nodes.
     */
    world = Comm.world();
    numProc = world.size();
    rank = world.rank();
    jobBackend = JobBackend.getJobBackend();

    if (asynchronous) {
        /**
         * Use asynchronous communication.
         */
        myRecursionCount = new double[2];
        myRecursionCountBuf = DoubleBuf.buffer(myRecursionCount);
        receiveThread = new ReceiveThread();
        receiveThread.start();
        recursionCounts = null;
        recursionCountsBuf = null;
    } else {
        /**
         * Use synchronous communication.
         */
        recursionCounts = new double[numProc][2];
        recursionCountsBuf = new DoubleBuf[numProc];
        for (int i = 0; i < numProc; i++) {
            recursionCountsBuf[i] = DoubleBuf.buffer(recursionCounts[i]);
        }
        myRecursionCount = recursionCounts[rank];
        myRecursionCountBuf = recursionCountsBuf[rank];
        receiveThread = null;
    }

    /**
     * Log OSRW parameters.
     */
    logger.info(" Orthogonal Space Random Walk Parameters");
    logger.info(String.format(" Gaussian Bias Magnitude:        %6.5f (kcal/mole)", biasMag));
    logger.info(String.format(" Gaussian Bias Cutoff:           %6d bins", biasCutoff));

    /**
     * Update and print out the recursion slave.
     */
    if (readHistogramRestart) {
        updateFLambda(true);
    }

}

From source file:ffx.xray.CIFFilter.java

/**
 * {@inheritDoc}/*from w  w w. ja v a  2s  . c  o  m*/
 */
@Override
public ReflectionList getReflectionList(File cifFile, CompositeConfiguration properties) {
    try {
        BufferedReader br = new BufferedReader(new FileReader(cifFile));

        String str;
        while ((str = br.readLine()) != null) {
            // reached reflections, break
            if (str.startsWith("_refln.")) {
                break;
            }

            String strarray[] = str.split("\\s+");

            if (strarray[0].startsWith("_reflns") || strarray[0].startsWith("_cell")
                    || strarray[0].startsWith("_symmetry")) {
                String cifarray[] = strarray[0].split("\\.+");

                switch (Header.toHeader(cifarray[1])) {
                case d_resolution_high:
                    reshigh = Double.parseDouble(strarray[1]);
                    break;
                case number_all:
                    nall = Integer.parseInt(strarray[1]);
                    break;
                case number_obs:
                    nobs = Integer.parseInt(strarray[1]);
                    break;
                case length_a:
                    cell[0] = Double.parseDouble(strarray[1]);
                    break;
                case length_b:
                    cell[1] = Double.parseDouble(strarray[1]);
                    break;
                case length_c:
                    cell[2] = Double.parseDouble(strarray[1]);
                    break;
                case angle_alpha:
                    cell[3] = Double.parseDouble(strarray[1]);
                    break;
                case angle_beta:
                    cell[4] = Double.parseDouble(strarray[1]);
                    break;
                case angle_gamma:
                    cell[5] = Double.parseDouble(strarray[1]);
                    break;
                case Int_Tables_number:
                    sgnum = Integer.parseInt(strarray[1]);
                    break;
                case space_group_name_H_M:
                    String sgnamearray[] = str.split("'+");
                    if (sgnamearray.length > 1) {
                        sgname = sgnamearray[1];
                    } else if (strarray.length > 1) {
                        sgname = strarray[1];
                    }
                    break;
                }
            }
        }

        br.close();
    } catch (IOException ioe) {
        System.out.println("IO Exception: " + ioe.getMessage());
        return null;
    }

    if (sgnum < 0 && sgname != null) {
        sgnum = SpaceGroup.spaceGroupNumber(SpaceGroup.pdb2ShortName(sgname));
    }

    if (sgnum < 0 || reshigh < 0 || cell[0] < 0) {
        logger.info(" The CIF header contains insufficient information to generate the reflection list.");
        return null;
    }

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\nOpening %s\n", cifFile.getName()));
        sb.append(String.format("setting up Reflection List based on CIF:\n"));
        sb.append(
                String.format("  spacegroup #: %d (name: %s)\n", sgnum, SpaceGroup.spaceGroupNames[sgnum - 1]));
        sb.append(String.format("  resolution: %8.3f\n", 0.999999 * reshigh));
        sb.append(String.format("  cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", cell[0], cell[1], cell[2],
                cell[3], cell[4], cell[5]));
        sb.append(String.format("\n  CIF # HKL (observed): %d\n", nobs));
        sb.append(String.format("  CIF # HKL (all):      %d\n", nall));
        logger.info(sb.toString());
    }

    Crystal crystal = new Crystal(cell[0], cell[1], cell[2], cell[3], cell[4], cell[5],
            SpaceGroup.spaceGroupNames[sgnum - 1]);
    double sampling = 1.0 / 1.5;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 1.0 / 1.5);
    }
    Resolution resolution = new Resolution(0.999999 * reshigh, sampling);

    ReflectionList reflectionlist = new ReflectionList(crystal, resolution, properties);
    return reflectionlist;
}

From source file:ffx.xray.parsers.CIFFilter.java

/**
 * {@inheritDoc}//from w  ww . j av a  2 s  .c  o  m
 */
@Override
public ReflectionList getReflectionList(File cifFile, CompositeConfiguration properties) {
    try {
        BufferedReader br = new BufferedReader(new FileReader(cifFile));
        String string;
        while ((string = br.readLine()) != null) {

            // Reached reflections, break.
            if (string.startsWith("_refln.")) {
                break;
            }
            String strArray[] = string.split("\\s+");
            if (strArray[0].startsWith("_reflns") || strArray[0].startsWith("_cell")
                    || strArray[0].startsWith("_symmetry")) {
                String cifArray[] = strArray[0].split("\\.+");
                switch (Header.toHeader(cifArray[1])) {
                case d_resolution_high:
                    resHigh = Double.parseDouble(strArray[1]);
                    break;
                case number_all:
                    nAll = Integer.parseInt(strArray[1]);
                    break;
                case number_obs:
                    nObs = Integer.parseInt(strArray[1]);
                    break;
                case length_a:
                    cell[0] = Double.parseDouble(strArray[1]);
                    break;
                case length_b:
                    cell[1] = Double.parseDouble(strArray[1]);
                    break;
                case length_c:
                    cell[2] = Double.parseDouble(strArray[1]);
                    break;
                case angle_alpha:
                    cell[3] = Double.parseDouble(strArray[1]);
                    break;
                case angle_beta:
                    cell[4] = Double.parseDouble(strArray[1]);
                    break;
                case angle_gamma:
                    cell[5] = Double.parseDouble(strArray[1]);
                    break;
                case Int_Tables_number:
                    spacegroupNum = Integer.parseInt(strArray[1]);
                    break;
                case space_group_name_H_M:
                    String spacegroupNameArray[] = string.split("'+");
                    if (spacegroupNameArray.length > 1) {
                        spacegroupName = spacegroupNameArray[1];
                    } else if (strArray.length > 1) {
                        spacegroupName = strArray[1];
                    }
                    break;
                }
            }
        }
        br.close();
    } catch (IOException e) {
        String message = " CIF IO Exception.";
        logger.log(Level.WARNING, message, e);
        return null;
    }

    if (spacegroupNum < 0 && spacegroupName != null) {
        spacegroupNum = SpaceGroup.spaceGroupNumber(SpaceGroup.pdb2ShortName(spacegroupName));
    }

    if (spacegroupNum < 0 || resHigh < 0 || cell[0] < 0) {
        logger.info(" The CIF header contains insufficient information to generate the reflection list.");
        return null;
    }

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\nOpening %s\n", cifFile.getName()));
        sb.append(String.format("setting up Reflection List based on CIF:\n"));
        sb.append(String.format("  spacegroup #: %d (name: %s)\n", spacegroupNum,
                SpaceGroup.spaceGroupNames[spacegroupNum - 1]));
        sb.append(String.format("  resolution: %8.3f\n", 0.999999 * resHigh));
        sb.append(String.format("  cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", cell[0], cell[1], cell[2],
                cell[3], cell[4], cell[5]));
        sb.append(String.format("\n  CIF # HKL (observed): %d\n", nObs));
        sb.append(String.format("  CIF # HKL (all):      %d\n", nAll));
        logger.info(sb.toString());
    }

    Crystal crystal = new Crystal(cell[0], cell[1], cell[2], cell[3], cell[4], cell[5],
            SpaceGroup.spaceGroupNames[spacegroupNum - 1]);
    double sampling = 1.0 / 1.5;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 1.0 / 1.5);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);
    ReflectionList reflectionlist = new ReflectionList(crystal, resolution, properties);
    return reflectionlist;
}

From source file:ffx.xray.MTZFilter.java

/**
 * {@inheritDoc}/*from   w w  w  .  j  ava2s. c o m*/
 */
@Override
public ReflectionList getReflectionList(File mtzFile, CompositeConfiguration properties) {
    ByteOrder b = ByteOrder.nativeOrder();
    FileInputStream fis;
    DataInputStream dis;
    try {
        fis = new FileInputStream(mtzFile);
        dis = new DataInputStream(fis);

        byte headeroffset[] = new byte[4];
        byte bytes[] = new byte[80];
        int offset = 0;

        // eat "MTZ" title
        dis.read(bytes, offset, 4);
        String mtzstr = new String(bytes);

        // header offset
        dis.read(headeroffset, offset, 4);

        // machine stamp
        dis.read(bytes, offset, 4);
        ByteBuffer bb = ByteBuffer.wrap(bytes);
        int stamp = bb.order(ByteOrder.BIG_ENDIAN).getInt();
        String stampstr = Integer.toHexString(stamp);
        switch (stampstr.charAt(0)) {
        case '1':
        case '3':
            if (b.equals(ByteOrder.LITTLE_ENDIAN)) {
                b = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (b.equals(ByteOrder.BIG_ENDIAN)) {
                b = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }

        bb = ByteBuffer.wrap(headeroffset);
        int headeroffseti = bb.order(b).getInt();

        // skip to header and parse
        dis.skipBytes((headeroffseti - 4) * 4);

        for (Boolean parsing = true; parsing; dis.read(bytes, offset, 80)) {
            mtzstr = new String(bytes);
            parsing = parseHeader(mtzstr);
        }
    } catch (EOFException eof) {
        System.out.println("EOF reached ");
    } catch (IOException ioe) {
        System.out.println("IO Exception: " + ioe.getMessage());
        return null;
    }

    // column identifiers
    foString = sigfoString = rfreeString = null;
    if (properties != null) {
        foString = properties.getString("fostring", null);
        sigfoString = properties.getString("sigfostring", null);
        rfreeString = properties.getString("rfreestring", null);
    }
    h = k = l = fo = sigfo = rfree = -1;
    fplus = sigfplus = fminus = sigfminus = rfreeplus = rfreeminus = -1;
    fc = phic = -1;
    boolean print = false;
    parseColumns(print);
    parseFcColumns(print);

    if (fo < 0 && fplus < 0 && sigfo < 0 && sigfplus < 0 && fc < 0 && phic < 0) {
        logger.info(
                " The MTZ header contains insufficient information to generate the reflection list.\n For non-default column labels set fostring/sigfostring in the properties file.");
        return null;
    }

    Column c;
    if (fo > 0) {
        c = (Column) columns.get(fo);
    } else if (fplus > 0) {
        c = (Column) columns.get(fplus);
    } else {
        c = (Column) columns.get(fc);
    }
    Dataset d = (Dataset) datasets.get(c.id - dsetoffset);

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n Reading %s\n\n", mtzFile.getName()));
        sb.append(String.format(" Setting up reflection list based on MTZ file.\n"));
        sb.append(String.format(" Space group number: %d (name: %s)\n", sgnum,
                SpaceGroup.spaceGroupNames[sgnum - 1]));
        sb.append(String.format(" Resolution: %8.3f\n", 0.999999 * resHigh));
        sb.append(String.format(" Cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", d.cell[0], d.cell[1], d.cell[2],
                d.cell[3], d.cell[4], d.cell[5]));
        logger.info(sb.toString());
    }

    Crystal crystal = new Crystal(d.cell[0], d.cell[1], d.cell[2], d.cell[3], d.cell[4], d.cell[5],
            SpaceGroup.spaceGroupNames[sgnum - 1]);

    double sampling = 0.6;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 0.6);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);

    return new ReflectionList(crystal, resolution, properties);
}

From source file:ffx.xray.parsers.MTZFilter.java

/**
 * {@inheritDoc}/*from   w w w  .  j a v  a 2 s .c  o  m*/
 */
@Override
public ReflectionList getReflectionList(File mtzFile, CompositeConfiguration properties) {
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileInputStream fileInputStream;
    DataInputStream dataInputStream;
    try {
        fileInputStream = new FileInputStream(mtzFile);
        dataInputStream = new DataInputStream(fileInputStream);

        byte headerOffset[] = new byte[4];
        byte bytes[] = new byte[80];
        int offset = 0;

        // Eat "MTZ" title.
        dataInputStream.read(bytes, offset, 4);
        String mtzstr = new String(bytes);

        // Header offset.
        dataInputStream.read(headerOffset, offset, 4);

        // Machine stamp.
        dataInputStream.read(bytes, offset, 4);
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        int stamp = byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt();
        String stampstr = Integer.toHexString(stamp);
        switch (stampstr.charAt(0)) {
        case '1':
        case '3':
            if (byteOrder.equals(ByteOrder.LITTLE_ENDIAN)) {
                byteOrder = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
                byteOrder = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }

        byteBuffer = ByteBuffer.wrap(headerOffset);
        int headerOffsetI = byteBuffer.order(byteOrder).getInt();

        // skip to header and parse
        dataInputStream.skipBytes((headerOffsetI - 4) * 4);

        for (Boolean parsing = true; parsing; dataInputStream.read(bytes, offset, 80)) {
            mtzstr = new String(bytes);
            parsing = parseHeader(mtzstr);
        }
    } catch (EOFException e) {
        String message = " MTZ end of file reached.";
        logger.log(Level.WARNING, message, e);
        return null;
    } catch (IOException e) {
        String message = " MTZ IO exception.";
        logger.log(Level.WARNING, message, e);
        return null;
    }

    // column identifiers
    foString = sigFoString = rFreeString = null;
    if (properties != null) {
        foString = properties.getString("fostring", null);
        sigFoString = properties.getString("sigfostring", null);
        rFreeString = properties.getString("rfreestring", null);
    }
    h = k = l = fo = sigFo = rFree = -1;
    fPlus = sigFPlus = fMinus = sigFMinus = rFreePlus = rFreeMinus = -1;
    fc = phiC = -1;
    boolean print = false;
    parseColumns(print);
    parseFcColumns(print);

    if (fo < 0 && fPlus < 0 && sigFo < 0 && sigFPlus < 0 && fc < 0 && phiC < 0) {
        logger.info(" The MTZ header contains insufficient information to generate the reflection list.");
        logger.info(" For non-default column labels set fostring/sigfostring in the properties file.");
        return null;
    }

    Column column;
    if (fo > 0) {
        column = (Column) columns.get(fo);
    } else if (fPlus > 0) {
        column = (Column) columns.get(fPlus);
    } else {
        column = (Column) columns.get(fc);
    }
    Dataset dataSet = (Dataset) dataSets.get(column.id - dsetOffset);

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(format("\n Reading %s\n\n", mtzFile.getName()));
        sb.append(format(" Setting up reflection list based on MTZ file.\n"));
        sb.append(format("  Space group number: %d (name: %s)\n", spaceGroupNum,
                SpaceGroup.spaceGroupNames[spaceGroupNum - 1]));
        sb.append(format("  Resolution:         %8.3f\n", 0.999999 * resHigh));
        sb.append(format("  Cell:               %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", dataSet.cell[0],
                dataSet.cell[1], dataSet.cell[2], dataSet.cell[3], dataSet.cell[4], dataSet.cell[5]));
        logger.info(sb.toString());
    }

    Crystal crystal = new Crystal(dataSet.cell[0], dataSet.cell[1], dataSet.cell[2], dataSet.cell[3],
            dataSet.cell[4], dataSet.cell[5], SpaceGroup.spaceGroupNames[spaceGroupNum - 1]);

    double sampling = 0.6;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 0.6);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);

    return new ReflectionList(crystal, resolution, properties);
}