Class Composition

java.lang.Object
_global.tri.oxidationstates.util.Composition

public class Composition extends Object
A utility class to represent a composition
  • Constructor Details

    • Composition

      public Composition(Map map)
      Create a composition from a map in which the keys are ion type symbols and the values are amounts.
      Parameters:
      map - a map in which the keys are symbols and the values are amounts.
    • Composition

      public Composition(String[] symbols, int[] counts)
      Create a composition from the given symbols and counts.
      Parameters:
      symbols - The symbols for tne ion types in this composition (or similar molecular units)
      counts - The amounds for each symbol. The indices of this array correspond to those for the symbols array.
    • Composition

      public Composition(String[] symbols, double[] counts)
      Create a composition from the given symbols and counts.
      Parameters:
      symbols - The symbols for tne ion types in this composition (or similar molecular units)
      counts - The amounds for each symbol. The indices of this array correspond to those for the symbols array.
    • Composition

      public Composition(String composition)
      Create a composition from the given composition string
      Parameters:
      composition - A string representation of the composition
  • Method Details

    • getReducedComposition

      public Composition getReducedComposition()
      For compositions with integer (or near-integer) counts for all symbols, returns the composition with all counts divided by their greater common factor.
      Returns:
      the composition with all counts divided by their greater common factor for compositions with integer (or near-integer) counts for all symbols
    • getSymbols

      public Set<String> getSymbols()
      Returns the symbols for this composition
      Returns:
      the symbols for this composition
    • getCount

      public double getCount(String symbol)
      Returns the amount of the given symbol in this composition.
      Parameters:
      symbol - The given symbol (typically an element symbol or ion type).
      Returns:
      the amount of the given symbol in this composition.
    • getCompositionMap

      public Map<String,Double> getCompositionMap()
      Returns a map representation of this composition in which the keys are symbols and the values are amounts. The map is sorted by symbol.
      Returns:
      a map representation of this composition in which the keys are symbols and the values are amounts. The map is sorted by symbol.
    • getElementalComposition

      public Composition getElementalComposition()
      Return the composition in terms of elements. E.g. all symbols for polyatomic ion types will be replaced by the symbols for the corresponding elements.
      Returns:
      the composition in terms of elements. E.g. all symbols for polyatomic ion types will be replaced by the symbols for the corresponding elements.
    • getDistinctElements

      public matsci.Element[] getDistinctElements()
      Returns the distinct elements in the compound represented by this composition.
      Returns:
      the distinct elements in the compound represented by this composition.
    • getElementalCompositionMap

      public Map<String,Double> getElementalCompositionMap()
      Returns a map in which the keys are the distinct elements in the compound represented by this composition, and the values are the corresponding amounts.
      Returns:
      a map in which the keys are the distinct elements in the compound represented by this composition, and the values are the corresponding amounts.
    • getKnownIonComposition

      public Composition getKnownIonComposition()
      Returns this composition in terms of known ion types, including polyatomic ions.
      Returns:
      this composition in terms of known ion types, including polyatomic ions.
    • getKnownIonCompositionMap

      public Map<String,Double> getKnownIonCompositionMap()
      Returns a composition in terms of known ion types, including polyatomic ions.
      Returns:
      a composition in terms of known ion types, including polyatomic ions.
    • getStandardizedCompositionString

      public String getStandardizedCompositionString()
      Returns a standardized string representation of this composition.
      Returns:
      a standardized string representation of this composition.
    • getStandardizedCompositionString

      public String getStandardizedCompositionString(String delimiter)
      Returns a standardized string representation of this composition, using the given delimiter to separate terms.
      Parameters:
      delimiter - The delimiter used to separate terms.
      Returns:
      a standardized string representation of this composition, using the given delimiter to separate terms.
    • matches

      public boolean matches(Composition composition, double tolerance)
      Returns true if the given composition matches this one, within the given tolerance for amounts.
      Parameters:
      composition - The given composition.
      tolerance - The given tolerance for amounts.
      Returns:
      true if the given composition matches this one, within the given tolerance for amounts.
    • isChargeBalanced

      public boolean isChargeBalanced(double tolerance)
      Returns true if this composition is charge balanced within the given charge sum tolerance, or false if it is not.
      Parameters:
      tolerance - The given charge sum tolerance
      Returns:
      true if this composition is charge balanced within the given charge sum tolerance, or false if it is not.