<commit_before>% units.pl: Defines the conversion and formatting of units of various chemical quantities.
% This file is from Chemlogic, a logic programming computer chemistry system
% <http://icebergsystems.ca/chemlogic>
% (C) Copyright 2012-2015 <NAME>


:- module(units,[convert/4,unit/3]).


:- use_module(sigfigs).



convert(input,Formula,[[[QtyIn,SF],UnitIn]],[[[QtyOut,SF],UnitOut]]) :-
	unit(Formula,[QtyIn,UnitIn],[QtyOut,UnitOut]).

convert(output,Formula,[[[QtyIn,SF],UnitIn]],[[[QtyOutRound,SF],UnitOut]]) :-
	unit(Formula,[QtyIn,UnitIn],[QtyOut,UnitOut]),
	round_sigfigs(QtyOut,SF,QtyOutRound).


convert(input,Formula,[[[QtyIn1,SF1],UnitIn1],[[QtyIn2,SF2],UnitIn2]],[[[QtyOut,SF],UnitOut]]) :-
	SF is min(SF1,SF2),
	unit(Formula,[[QtyIn1,UnitIn1],[QtyIn2,UnitIn2]],[QtyOut,UnitOut]).

% Perhaps output from the 2 unit form might be useful in some cases.

% In this case, some aspects of the result are known, while others are unknown. The variable could be in either term. 
% This clause determines which quantities represent each argument and then calls the actual procedure.

%convert_fmt(output,Formula,[QtyCalc,UnitCalc],[[QtyR1,UnitR1],[QtyR2,UnitR2]],MaxSF) :-
%	(var(QtyR1) -> convert_fmt_complex_result(Formula,[QtyCalc,UnitCalc],[QtyR2,UnitR2],[QtyR1,UnitR1],MaxSF);
%	convert_fmt_complex_result(Formula,[QtyCalc,UnitCalc],[QtyR1,UnitR1],[QtyR2,UnitR2],MaxSF)).

convert(Formula,[[[QtyCalc,MaxSF],UnitCalc]],[[[QtyIn,SFIn],UnitIn],[[QtyOutRound,SF],UnitOut]]) :-
	unit(Formula,[[QtyCalc,UnitCalc],[QtyIn,UnitIn]],[QtyOut,UnitOut]),
	SF is min(MaxSF,SFIn),
	round_sigfigs(QtyOut,SF,QtyOutRound).


/*** NOTE:
STP is assumed to be calculated as defined by IUPAC: temperature of 0 °C and a pressure of 101.325 kPa.
The value used was obtained from CODATA: the NIST Reference on Constants, Units and Uncertainty.
***/
v_molar(22.413968 /* L/mol */).

%%% No conversion %%%
unit(_,Unit,Unit) :- !.

%%% Mass units %%%
unit(Formula,[Mass,g],[Mol,mol]) :-
	molar_mass(Formula,MMass),
	Mol /* mol */ is Mass /* g */ * 1 /* mol */ / MMass /* g */, !.

unit(Formula,[Mol,mol],[Mass,g]) :-
	molar_mass(Formula,MMass),
	Mass /* g */ is Mol /* mol */ * MMass /* g */ / 1 /* mol */, !.

%%% Volume units %%%
/*** NOTE:
Formula is assumed to represent a gas at STP (standard temperature and pressure)
***/

unit(_,[Vol,'L'],[Mol,mol]) :-
	v_molar(Vm),
	Mol /* mol */ is Vol /* L */ * 1 /* mol */ / Vm /* L */, !.

<commit_msg>Make the quantity DCG produce sigfigs output.<commit_after>% units.pl: Defines the conversion and formatting of units of various chemical quantities.
% This file is from Chemlogic, a logic programming computer chemistry system
% <http://icebergsystems.ca/chemlogic>
% (C) Copyright 2012-2015 <NAME>


:- module(units,[convert/4,unit/3]).


:- use_module(sigfigs).



convert(_,Formula,[[[QtyIn,SF],UnitIn]],[[[QtyOut,SF],UnitOut]]) :-
	unit(Formula,[QtyIn,UnitIn],[QtyOut,UnitOut]).

/*convert(output,Formula,[[[QtyIn,SF],UnitIn]],[[[QtyOutRound,SF],UnitOut]]) :-
	unit(Formula,[QtyIn,UnitIn],[QtyOut,UnitOut]),
	round_sigfigs(QtyOut,SF,QtyOutRound).
*/

convert(input,Formula,[[[QtyIn1,SF1],UnitIn1],[[QtyIn2,SF2],UnitIn2]],[[[QtyOut,SF],UnitOut]]) :-
	SF is min(SF1,SF2),
	unit(Formula,[[QtyIn1,UnitIn1],[QtyIn2,UnitIn2]],[QtyOut,UnitOut]).

% Perhaps output from the 2 unit form might be useful in some cases.

% In this case, some aspects of the result are known, while others are unknown. The variable could be in either term. 
% This clause determines which quantities represent each argument and then calls the actual procedure.

%convert_fmt(output,Formula,[QtyCalc,UnitCalc],[[QtyR1,UnitR1],[QtyR2,UnitR2]],MaxSF) :-
%	(var(QtyR1) -> convert_fmt_complex_result(Formula,[QtyCalc,UnitCalc],[QtyR2,UnitR2],[QtyR1,UnitR1],MaxSF);
%	convert_fmt_complex_result(Formula,[QtyCalc,UnitCalc],[QtyR1,UnitR1],[QtyR2,UnitR2],MaxSF)).

convert(output,Formula,[[[QtyCalc,MaxSF],UnitCalc]],[[[QtyIn,SFIn],UnitIn],[[QtyOut,SF],UnitOut]]) :-
	unit(Formula,[[QtyCalc,UnitCalc],[QtyIn,UnitIn]],[QtyOut,UnitOut]),
 	SF is min(MaxSF,SFIn).


/*** NOTE:
STP is assumed to be calculated as defined by IUPAC: temperature of 0 °C and a pressure of 101.325 kPa.
The value used was obtained from CODATA: the NIST Reference on Constants, Units and Uncertainty.
***/
v_molar(22.413968 /* L/mol */).

%%% No conversion %%%
unit(_,Unit,Unit) :- !.

%%% Mass units %%%
unit(Formula,[Mass,g],[Mol,mol]) :-
	molar_mass(Formula,MMass),
	Mol /* mol */ is Mass /* g */ * 1 /* mol */ / MMass /* g */, !.

unit(Formula,[Mol,mol],[Mass,g]) :-
	molar_mass(Formula,MMass),
	Mass /* g */ is Mol /* mol */ * MMass /* g */ / 1 /* mol */, !.

%%% Volume units %%%
/*** NOTE:
Formula is assumed to represent a gas at STP (standard temperature and pressure)
***/

unit(_,[Vol,'L'],[Mol,mol]) :-
	v_molar(Vm),
	Mol /* mol */ is Vol /* L */ * 1 /* mol */ / Vm /* L */, !.


{'fraction_non_alphanumeric': 0.19009453349773942, 'fraction_numerical': 0.02219482120838471, 'mean_word_length': 5.515394912985275, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2433947', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1866, 'n_words': 387}