# 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 Summary

Fields
Modifier and Type
Field
Description
`static final double`
`TOAU_ANGSTROMS`
`static final double`
`TOAU_AU`
`static final double`
`TOAU_BOHR`
`static final double`
`TOAU_CM`
`static final double`
`TOAU_CM_1`
`static final double`
`TOAU_EV`
`static final double`
`TOAU_HARTREE`
`static final double`
`TOAU_KCAL_MOL`
`static final double`
`TOAU_KJ_MOL`
`static final double`
`TOAU_M`
`static final String`
`UNITS_ANGSTROMS`
`static final String`
`UNITS_AU`
`static final String`
`UNITS_BOHR`
`static final String`
`UNITS_CM`
`static final String`
`UNITS_CM_1`
`static final String`
`UNITS_EV`
`static final String`
`UNITS_FRACTIONAL`
`static final String`
`UNITS_HARTREE`
`static final String`
`UNITS_KCAL_MOL`
`static final String`
`UNITS_KJ_MOL`
`static final String`
`UNITS_M`
`static final String`
`version`

## Constructor Summary

Constructors
Constructor
Description
`QCSchemaUnits()`

## Method Summary

Modifier and Type
Method
Description
`static double`
`convertValue(Map<String,Object> valueUnits, String toUnits)`
Read a {value:xxxx, units:["name",toAU]} map, converting it to the desired units.
`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
`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.
`static double`
`getDouble(Map<String,Object> map, String key, String toUnits)`
Reads a value from an associative array, converting it to the desired units.
`static double[]`
`getDoubleArray(Object mapOrList, String key)`
Retrieve a double array, possibly unpacking it if it is run-length encoded.
`static double`
`getFactorToAU(String units)`
Get the standard conversion factor to atomic units for this unit.
`static int[]`
`getIntArray(Object mapOrList, String key)`
Retrieve an int array, possibly unpacking it if it is run-length encoded.
`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.
`static String[]`
`getStringArray(Object mapOrList, String key)`
Retrieve a String array, possibly unpacking it if it is run-length encoded.
`static double`
`getUnitConversion(String fromUnits, String toUnits)`
Calculate the unit conversion between two units, using a static unit-to-unit cache for efficiency.
`static Object`
`getUnitsJSON(String name, boolean asArray)`
Get the [name, toAU] JSON code or just a new String[] {name, toAU}.
`protected static ArrayList<Object>`
`newList()`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### version

public static final String version

### UNITS_FRACTIONAL

public static final String UNITS_FRACTIONAL

See Also:
  - Constant Field Values

### UNITS_AU

public static final String UNITS_AU

See Also:
  - Constant Field Values

### TOAU_AU

public static final double TOAU_AU

See Also:
  - Constant Field Values

### UNITS_CM

public static final String UNITS_CM

See Also:
  - Constant Field Values

### TOAU_CM

public static final double TOAU_CM

See Also:
  - Constant Field Values

### UNITS_M

public static final String UNITS_M

See Also:
  - Constant Field Values

### TOAU_M

public static final double TOAU_M

See Also:
  - Constant Field Values

### UNITS_ANGSTROMS

public static final String UNITS_ANGSTROMS

See Also:
  - Constant Field Values

### TOAU_ANGSTROMS

public static final double TOAU_ANGSTROMS

See Also:
  - Constant Field Values

### UNITS_BOHR

public static final String UNITS_BOHR

See Also:
  - Constant Field Values

### TOAU_BOHR

public static final double TOAU_BOHR

See Also:
  - Constant Field Values

### UNITS_HARTREE

public static final String UNITS_HARTREE

See Also:
  - Constant Field Values

### TOAU_HARTREE

public static final double TOAU_HARTREE

See Also:
  - Constant Field Values

### UNITS_EV

public static final String UNITS_EV

See Also:
  - Constant Field Values

### TOAU_EV

public static final double TOAU_EV

See Also:
  - Constant Field Values

### UNITS_CM_1

public static final String UNITS_CM_1

See Also:
  - Constant Field Values

### TOAU_CM_1

public static final double TOAU_CM_1

See Also:
  - Constant Field Values

### UNITS_KJ_MOL

public static final String UNITS_KJ_MOL

See Also:
  - Constant Field Values

### TOAU_KJ_MOL

public static final double TOAU_KJ_MOL

See Also:
  - Constant Field Values

### UNITS_KCAL_MOL

public static final String UNITS_KCAL_MOL

See Also:
  - Constant Field Values

### TOAU_KCAL_MOL

public static final double TOAU_KCAL_MOL

See Also:
  - Constant Field Values

## 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