Package org.qcschema

Class QCSchemaUnits

java.lang.Object
org.qcschema.QCSchemaUnits

public class QCSchemaUnits extends Object
A general Java class for working with QCShema units and array types. j2sNative blocks can be ignored -- they just increase efficiency in the JavaScript rendition of Jmol. for examples of use, see org.jmol.adapters.readers.quantum.QCJSONReader org.jmol.adapters.writers.QCJSONWriter extends org.jmol.util.JSONWriter
Author:
Bob Hanson
  • Field Details

  • Constructor Details

    • QCSchemaUnits

      public QCSchemaUnits()
  • Method Details

    • getFactorToAU

      public static double getFactorToAU(String units)
      Get the standard conversion factor to atomic units for this unit.
      Parameters:
      units -
      Returns:
      the nominal conversion factor or 0 ("fractional") or Double.NaN (unknown)
    • getUnitConversion

      public static double getUnitConversion(String fromUnits, String toUnits)
      Calculate the unit conversion between two units, using a static unit-to-unit cache for efficiency. Not used in Jmol.
      Parameters:
      fromUnits -
      toUnits -
      Returns:
      conversion factor or Double.NaN if anything goes wrong.
    • getConversionFactorTo

      public static double getConversionFactorTo(ArrayList<Object> unitsFactor, String unitsDesired)
      For a reader, use the JSON [units, factor] along with a desired unit to get the conversion factor from file values to desired units. Currently, this method only looks at the factor in the JSON if we do not already know the conversion factor.
      Parameters:
      unitsFactor - [units, factor] list or null if to AU is desired.
      unitsDesired -
      Returns:
      the conversion factor or Double.NaN if not uncodable
    • convertValue

      public static double convertValue(Map<String,Object> valueUnits, String toUnits)
      Read a {value:xxxx, units:["name",toAU]} map, converting it to the desired units.
      Parameters:
      valueUnits -
      toUnits -
      Returns:
      converted value
    • getUnitsJSON

      public static Object getUnitsJSON(String name, boolean asArray)
      Get the [name, toAU] JSON code or just a new String[] {name, toAU}. If the conversion is not known, return [name, "?"]
      Parameters:
      name -
      asArray -
      Returns:
      String or String[]
    • getConversionFactor

      public static double getConversionFactor(Map<String,Object> map, String key, String toUnits)
      Get the necessary conversion factor to the desired units from a key_units or atomic units
      Parameters:
      map -
      key - map key that has associated key_units element or null for "from atomic units"
      toUnits -
      Returns:
      conversion factor
    • getDouble

      public static double getDouble(Map<String,Object> map, String key, String toUnits)
      Reads a value from an associative array, converting it to the desired units.
      Parameters:
      map -
      key -
      toUnits -
      Returns:
      value
    • getList

      public static ArrayList<Object> getList(Object mapOrList, String key)
      Retrieve an array of any sort as a list of objects, possibly unpacking it if it is run-length encoded.
      Parameters:
      mapOrList -
      key -
      Returns:
      unpacked array
    • newList

      protected static ArrayList<Object> newList()
      Returns:
      ArrayList, or in JavaScript javajs.util.Lst
    • getDoubleArray

      public static double[] getDoubleArray(Object mapOrList, String key)
      Retrieve a double array, possibly unpacking it if it is run-length encoded. Read any error as Double.NaN.
      Parameters:
      mapOrList -
      key - into mapOrList, or null if mapOrList is a list
      Returns:
      unpacked double[]
    • getIntArray

      public static int[] getIntArray(Object mapOrList, String key)
      Retrieve an int array, possibly unpacking it if it is run-length encoded. Any error causes this method to return null.
      Parameters:
      mapOrList - the list to unpack, or map to pull the list form using the key
      key - the map key, or null if mapOrList is already a list
      Returns:
      unpacked int[] or null if mapOrList is null or there is an error
    • getStringArray

      public static String[] getStringArray(Object mapOrList, String key)
      Retrieve a String array, possibly unpacking it if it is run-length encoded. Any "null" string is read as null.
      Parameters:
      mapOrList - the list to unpack, or map to pull the list form using the key
      key - the map key, or null if mapOrList is already a list
      Returns:
      unpacked string[] or null if mapOrList is null