Databases
ChemistryLab.build_reactionsChemistryLab.build_solid_solutionsChemistryLab.build_speciesChemistryLab.extract_primary_speciesChemistryLab.get_compatible_speciesChemistryLab.merge_jsonChemistryLab.read_thermofun_database
ChemistryLab.extract_primary_species — Function
extract_primary_species(file_path::AbstractString) -> DataFrameExtract primary aqueous species from a PHREEQC database file.
Arguments
file_path: path to PHREEQC .dat file.
Returns
- DataFrame with columns: species, symbol, formula, aggregate_state, atoms, charge, gamma.
Parses the SOLUTION_SPECIES section to extract master species and their properties. The "Zz" charge placeholder is handled specially. Gamma coefficients for activity models are extracted from "-gamma" lines.
ChemistryLab.read_thermofun_database — Function
read_thermofun_database(filename::AbstractString) -> (DataFrame, DataFrame, DataFrame)Read a ThermoFun database from a JSON file.
Arguments
filename: path to the JSON database file.
Returns
df_elements: DataFrame of chemical elements.df_substances: DataFrame of chemical substances (species).df_reactions: DataFrame of chemical reactions.
ChemistryLab.build_species — Function
build_species(df_substances::AbstractDataFrame, list_symbols=nothing; verbose=false) -> Vector{Species}Build Species objects from a substance DataFrame.
Arguments
df_substances: DataFrame containing substance data.list_symbols: optional list of symbols to filter (default: nothing, process all).verbose: if true, print details during processing (default: false).
Returns
- Vector of
Species.
ChemistryLab.build_reactions — Function
build_reactions(df_reactions::AbstractDataFrame, dict_species=Dict(), list_symbols=nothing; verbose=false) -> Vector{Reaction}Build Reaction objects from a reaction DataFrame.
Arguments
df_reactions: DataFrame containing reaction data.species_list: vector of existingSpeciesobjects to use in reactions.list_symbols: optional list of reaction symbols to filter (default: nothing, process all).verbose: if true, print details during processing (default: false).
Returns
- Vector of
Reactionobjects.
ChemistryLab.build_solid_solutions — Function
build_solid_solutions(toml_file, dict_species; skip_missing=true) -> Vector{SolidSolutionPhase}Load solid solution phase definitions from a TOML file and assemble SolidSolutionPhase objects from an existing species dictionary.
Each end-member species is automatically requalified to SC_SSENDMEMBER via with_class, regardless of the class stored in the database.
Arguments
toml_file: path to a TOML file with[[solid_solution]]entries (seedata/solid_solutions.tomlfor the format).dict_species:Dict{String, <:AbstractSpecies}mapping symbol → species (typically built fromDict(symbol(s) => s for s in build_species(...))).skip_missing: iftrue(default), silently skip phases whose end-members are not all present indict_species; iffalse, throw an error.
TOML format
[[solid_solution]]
name = "CSHQ"
end_members = ["CSHQ-TobD", "CSHQ-TobH", "CSHQ-JenH", "CSHQ-JenD"]
model = "ideal" # or "redlich_kister"
# For redlich_kister only:
a0 = 3000.0 # J/mol
a1 = 500.0 # J/mol
a2 = 0.0 # J/molExample
substances = build_species("data/cemdata18-thermofun.json")
dict = Dict(symbol(s) => s for s in substances)
ss_phases = build_solid_solutions("data/solid_solutions.toml", dict)
cs = ChemicalSystem(species, CEMDATA_PRIMARIES; solid_solutions = ss_phases)ChemistryLab.get_compatible_species — Function
get_compatible_species(df_substances::AbstractDataFrame, species_list; aggregate_states=[AS_AQUEOUS], exclude_species=[], union=false) -> DataFrameFind species in the database compatible with a given list of species (sharing atoms).
Arguments
df_substances: substance DataFrame.species_list: list of target species symbols.aggregate_states: filter for specific aggregate states (default:[AS_AQUEOUS]).exclude_species: list of species symbols to exclude.union: if true, includes the originalspecies_listin the result (default: false).
Returns
- DataFrame of compatible substances.
ChemistryLab.merge_json — Function
merge_json(json_path::AbstractString, dat_path::AbstractString, output_path::AbstractString)Merge PHREEQC .dat phase data into a ThermoFun JSON database file.
Arguments
json_path: path to input ThermoFun JSON file.dat_path: path to PHREEQC .dat file containing phase definitions.output_path: path for output merged JSON file.
Reads both files, extracts phases from the .dat file, merges them into the JSON database structure, and writes the result preserving the original JSON formatting.