Complicator 0.1.2__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ import sys, os
3
3
  import re
4
4
  from datetime import datetime
5
5
  import pandas as pd
6
- import pkg_resources
7
6
  import decimal
8
7
  import math
9
8
  import chemparse
@@ -50,20 +49,20 @@ def __get_formula_ox_dict(name, df):
50
49
  def __write_output(filename, cation, ligand, nth_complex, G, H, S, CP, V,
51
50
  a1, a2, a3, a4, c1, c2, wcon, Z, azero,
52
51
  cation_dissrxn_dict, ligand_dissrxn_dict, thermo_data,
53
- cation_formula_ox_dict, ligand_formula_ox_dict, replace,
54
- skip_duplicates, ligand_name_abbrv_pairs):
52
+ cation_formula_ox_dict, ligand_formula_ox_dict,
53
+ skip_duplicates, ligand_name_abbrv_pairs, organic):
55
54
  """
56
55
  Write output to a CSV.
57
56
  """
58
57
 
59
58
  duplicate_list = []
60
- cat_nocharge = re.sub("\+.*$", "", cation)
61
- lig_nocharge = re.sub("\-.*$", "", ligand)
59
+ cat_nocharge = re.sub(r"\+.*$", "", cation)
60
+ lig_nocharge = re.sub(r"\-.*$", "", ligand)
62
61
 
63
62
  cat_formula = thermo_data[thermo_data["name"]==cation]["formula"].values[0]
64
63
  lig_formula = thermo_data[thermo_data["name"]==ligand]["formula"].values[0]
65
- cat_formula_nocharge = re.sub("\+.*$", "", cat_formula)
66
- lig_formula_nocharge = re.sub("\-.*$", "", lig_formula)
64
+ cat_formula_nocharge = re.sub(r"\+.*$", "", cat_formula)
65
+ lig_formula_nocharge = re.sub(r"\-.*$", "", lig_formula)
67
66
 
68
67
  if Z > 1:
69
68
  this_charge = "+" + str(Z)
@@ -146,6 +145,10 @@ def __write_output(filename, cation, ligand, nth_complex, G, H, S, CP, V,
146
145
 
147
146
  complex_formula_ox = " ".join(complex_formula_ox)
148
147
 
148
+ if organic:
149
+ cat_1 = "organic_aq"
150
+ else:
151
+ cat_1 = "inorganic_aq"
149
152
 
150
153
  data={
151
154
  "name": [complex_name],
@@ -174,7 +177,7 @@ def __write_output(filename, cation, ligand, nth_complex, G, H, S, CP, V,
174
177
  "dissrxn":[complex_dissrxn],
175
178
  "tag":[""],
176
179
  "formula_ox":[complex_formula_ox],
177
- "category_1":["inorganic_aq"],
180
+ "category_1":[cat_1],
178
181
  "category_2":[""],
179
182
  }
180
183
  df = pd.DataFrame(data)
@@ -187,13 +190,13 @@ def __write_output(filename, cation, ligand, nth_complex, G, H, S, CP, V,
187
190
  with open(filename+'.csv', 'a') as f:
188
191
 
189
192
  f_df = pd.read_csv(filename+'.csv')
190
-
193
+
191
194
  # check that a monoligand complex without parentheses isn't already
192
195
  # in the thermodynamic database. Warn or skip.
193
196
  keep = True
194
197
  complex_name_no_parentheses = complex_name.replace("(", "").replace(")", "")
195
198
 
196
- if complex_name_no_parentheses in list(f_df["name"]):
199
+ if complex_name_no_parentheses in list(thermo_data["name"]):
197
200
  if skip_duplicates:
198
201
  keep = False
199
202
  duplicate_list.append([complex_name, complex_name_no_parentheses])
@@ -206,24 +209,21 @@ def __write_output(filename, cation, ligand, nth_complex, G, H, S, CP, V,
206
209
  # checking for duplicate entries
207
210
  complex_name_organic_abbv = complex_name.replace(name, abbv)
208
211
 
209
- if complex_name_organic_abbv in list(f_df["name"]):
212
+ if complex_name_organic_abbv in list(thermo_data["name"]):
210
213
  if skip_duplicates:
211
214
  keep = False
212
215
  duplicate_list.append([complex_name, complex_name_organic_abbv])
213
216
 
214
217
  break
215
218
 
216
- if keep and replace and complex_name in list(f_df["name"]):
217
- cols = list(f_df.columns)
218
- f_df.iloc[f_df["name"]==complex_name, :] = df
219
+ # if keep and replace and complex_name in list(f_df["name"]):
220
+ # cols = list(f_df.columns)
221
+ # f_df.iloc[f_df["name"]==complex_name, :] = df
219
222
 
220
- f_df.to_csv(filename+'.csv', header=True, index=False)
223
+ # f_df.to_csv(filename+'.csv', header=True, index=False)
221
224
 
222
- elif keep and complex_name not in list(f_df["name"]):
225
+ if keep: # was elif prior to the block above being commented out
223
226
  df.to_csv(f, header=False, index=False)
224
-
225
- else:
226
- pass
227
227
 
228
228
  else:
229
229
  df.to_csv(filename+'.csv', index=False)
@@ -231,74 +231,6 @@ def __write_output(filename, cation, ligand, nth_complex, G, H, S, CP, V,
231
231
  return df, duplicate_list
232
232
 
233
233
 
234
- # # function to count significant digits
235
- # # adapted from https://stackoverflow.com/questions/8142676/python-counting-significant-digits
236
- # def find_sigfigs(x):
237
-
238
- # '''
239
- # Get the number of significant digits in a string representing a number up to
240
- # eight digits long.
241
-
242
- # Parameters
243
- # ----------
244
- # x : str
245
- # A string denoting a number. This can include scientific notation.
246
-
247
- # Parameters
248
- # ----------
249
- # int
250
- # The number of significant digits.
251
-
252
- # Examples
253
- # --------
254
- # >>> find_sigfigs("5.220")
255
- # 4
256
-
257
- # This also takes into account scientific notation.
258
-
259
- # >>> find_sigfigs("1.23e+3")
260
- # 3
261
-
262
- # Insignificant zeros are ignored.
263
-
264
- # >>> find_sigfigs("4000")
265
- # 1
266
-
267
- # A decimal point denotes that zeros are significant.
268
-
269
- # >>> find_sigfigs("4000.")
270
- # 4
271
- # '''
272
-
273
- # x = str(x)
274
-
275
- # # change all the 'E' to 'e'
276
- # x = x.lower()
277
- # if ('-' == x[0]):
278
- # x = x[1:]
279
- # if ('e' in x):
280
- # # return the length of the numbers before the 'e'
281
- # myStr = x.split('e')
282
- # return len(myStr[0]) - 1 # to compenstate for the decimal point
283
- # else:
284
- # # put it in e format and return the result of that
285
- # ### NOTE: because of the 8 below, it may do crazy things when it parses 9 sigfigs
286
- # n = ('%.*e' % (8, float(x))).split('e')
287
- # # remove and count the number of removed user added zeroes. (these are sig figs)
288
- # if '.' in x:
289
- # s = x.replace('.', '')
290
- # #number of zeroes to add back in
291
- # l = len(s) - len(s.rstrip('0'))
292
- # #strip off the python added zeroes and add back in the ones the user added
293
- # n[0] = n[0].rstrip('0') + ''.join(['0' for num in range(l)])
294
- # else:
295
- # #the user had no trailing zeroes so just strip them all
296
- # n[0] = n[0].rstrip('0')
297
- # #pass it back to the beginning to be parsed
298
- # return find_sigfigs('e'.join(n))
299
-
300
-
301
-
302
234
  def find_sigfigs(number_string):
303
235
  """
304
236
  Count significant figures (cannot handle scientific notation)
@@ -326,11 +258,11 @@ def find_sigfigs(number_string):
326
258
 
327
259
  def calc_params_WORMutils(Z, G, H, S, CP, V,
328
260
  a1, a2, a3, a4, c1, c2, omega,
329
- water_model="SUPCRT92"):
261
+ water_model="SUPCRT92", organic=False):
330
262
 
331
263
  kwargs = {"V": V, "Cp": CP, "Gf": G, "Hf": H, "Saq": S,
332
264
  "a1":a1, "a2":a2, "a3":a3, "a4":a4, "c1":c1, "c2":c2,
333
- "aq_complex": True, "HKF_scale":False, "Z":Z}
265
+ "aq_complex": True, "HKF_scale":False, "Z":Z, "organic":organic}
334
266
 
335
267
  if water_model == "DEW":
336
268
  kwargs["DEW"] = True
@@ -356,217 +288,12 @@ def calc_params_WORMutils(Z, G, H, S, CP, V,
356
288
  return G, H, S, a1, a2, a3, a4, c1, c2, wcon, eqn_list
357
289
 
358
290
 
359
- ### No longer used!
360
- def calc_params(Z, G, H, S, CP, V, a1, a2, a3, a4, c1, c2, omega, water_model="SUPCRT92"):
361
- # The following are the Born functions at 25 C, and various other constants.
362
-
363
- AK = float('nan')
364
- RX = float('nan')
365
- sigma = float('nan')
366
- POLAR = 2.0
367
-
368
- Q= 5.903E-07
369
- X= -3.090E-07
370
- Y= -5.802E-05
371
- xN= -1.820E-10
372
- conv=41.8393
373
- tr=298.15
374
- theta = 228.0
375
- pfunk=2601.0
376
- eta=1.66027E+05
377
- wabsh = 0.5387E+05
378
-
379
- # Calculation of GAMMA term (Helgeson & Kirkham 1976, page 153)
380
-
381
- if Z > 0:
382
- gamma=0.94
383
- elif Z < 0:
384
- gamma=0.0
385
- else:
386
- gamma=float('NaN')
387
-
388
- if Z != 0:
389
- if abs(Z) == 1:
390
- alphaz=72
391
- elif abs(Z) == 2:
392
- alphaz = 141
393
- elif abs(Z) == 3:
394
- alphaz = 211
395
- elif abs(Z) == 4:
396
- alphaz = 286
397
- else:
398
- print("alphaz cannot be calculated!")
399
- return
400
-
401
- if not math.isnan(S):
402
- # GB: RX is always 'NaN' because it's set at the start of the function. Why is this here?
403
- if not math.isnan(RX):
404
- re = RX+R*gamma
405
- else:
406
- ra=(Z**2 *(eta * Y - 100.)/(S - alphaz))
407
- ire=int(100.*ra +.5)
408
- re=ire/100.
409
- else:
410
- # GB: RX is always 'NaN' because it's set at the start of the function. Why is this here?
411
- if not math.isnan(RX):
412
- re = RX+Z*gamma
413
- S =(Z**2)*(eta*Y - 100.) / re + alphaz
414
- else:
415
- print('IF Z IS 0.0, EITHER S OR RX MUST BE GIVEN!')
416
- return
417
-
418
- wabs = (eta*Z**2)/re
419
- wcon = wabs-Z*wabsh
420
-
421
- else:
422
- if POLAR == 2:
423
- wcon= -0.03*100000
424
- iwcon = int(wcon + .5)
425
- wcon = iwcon
426
-
427
- # Calculation of solvation contributions to the standard partial molal properties
428
- vs=-wcon*Q*conv
429
- cps=wcon*tr*X
430
- ss=wcon*Y
431
-
432
- # Calculation of the non-solvation contributions to the standard partial molal properties
433
- vn=V-vs
434
- cpn=CP-cps
435
- sn=S-ss
436
-
437
- # THE CORRELATIONS FOR E.O.S. PARAMETERS BEGIN !
438
-
439
- # AK is always NaN because it is set at the beginning of the function.
440
- # Is there a reason it is this way in the original code?
441
- # This section will always be skipped!
442
- if not math.isnan(AK):
443
- aks=wcon*xN*conv
444
- akn=AK-aks
445
-
446
- # sigma is always 0 because it is set at the beginning of the function.
447
- # Is there a reason it is this way in the original code?
448
- if not math.isnan(sigma):
449
- a2=17.19E+4*akn+421.1
450
- # rounding
451
- ia2 = int(a2*100 + .5)
452
- a2 = ia2/100
453
-
454
- if water_model == "DEW":
455
- if Z == 0:
456
- a1 = (0.1942*vn + 1.52)/10
457
- else:
458
- a1 = ((0.1304*abs(Z) - 0.0217)*vn + (1.4567*abs(Z)+0.6187))/10
459
- else:
460
- a1 = sigma/conv-(a2/pfunk)
461
-
462
- # rounding
463
- ia1 = int(a1*100000 + .5)
464
- a1 = ia1/100000
465
-
466
- else:
467
- a2=17.19E+4*akn+421.1
468
- # rounding
469
- ia2 = int(a2*100 + .5)
470
- a2 = ia2/100
471
-
472
- sigma=1.11*vn+1.8
473
- # rounding
474
- isigma = int(sigma*100 + .5)
475
- sigma = isigma/100
476
-
477
- if water_model == "DEW":
478
- if Z == 0:
479
- a1 = (0.1942*vn + 1.52)/10
480
- else:
481
- a1 = ((0.1304*abs(Z) - 0.0217)*vn + (1.4567*abs(Z)+0.6187))/10
482
- else:
483
- a1=sigma/conv-(a2/pfunk)
484
-
485
- # rounding
486
- ia1 = int(a1*100000 + .5)
487
- a1 = ia1/100000
488
- else:
489
-
490
- # sigma is always NaN because it is set at the beginning of the function.
491
- # Is there a reason it is this way in the original code?
492
- # This section will always be skipped!
493
- if not math.isnan(sigma):
494
-
495
- if water_model == "DEW":
496
- if Z == 0:
497
- a1 = (0.1942*vn + 1.52)/10
498
- else:
499
- a1 = ((0.1304*abs(Z) - 0.0217)*vn + (1.4567*abs(Z)+0.6187))/10
500
- else:
501
- a1 = 1.3684E-2*vn+0.1765
502
-
503
- # rounding
504
- ia1 = int(a1*100000. + .5)
505
- a1 = ia1/100000.
506
-
507
- a2=((sigma/conv)-a1)*pfunk
508
- # rounding
509
- ia2 = int(a2*100. + .5)
510
- a2 = ia2/100.
511
-
512
- else:
513
- sigma=1.11*vn+1.8
514
-
515
- # rounding
516
- isigma = int(sigma*100. + .5)
517
- sigma = isigma/100.
518
-
519
- if water_model == "DEW":
520
- if Z == 0:
521
- a1 = (0.1942*vn + 1.52)/10
522
- else:
523
- a1 = ((0.1304*abs(Z) - 0.0217)*vn + (1.4567*abs(Z)+0.6187))/10
524
- else:
525
- a1 = 1.3684E-2*vn+0.1765
526
-
527
- # rounding
528
- ia1 = int(a1*100000 + .5)
529
- a1 = ia1/100000
530
-
531
- a2=((sigma/conv)-a1)*pfunk
532
- # rounding
533
- ia2 = int(a2*100 + .5)
534
- a2 = ia2/100
535
-
536
- a4 = -4.134*a2-27790.0
537
- # rounding
538
- ia4 = int(a4 +.5)
539
- a4 = ia4
540
-
541
- a3=((vn/conv)-a1-a2/pfunk)*(tr-theta)-(a4/pfunk)
542
- # rounding
543
- ia3 = int(a3*10000 + .5)
544
- a3 = ia3/10000
545
-
546
- c2= .2037*CP-3.0346
547
- # rounding
548
- ic2=int(c2*10000 + .5)
549
- c2 = ic2
550
-
551
- c1=cpn-c2/(tr-theta)**2
552
- # rounding
553
- ic1 = int(c1*10000 + .5)
554
- c1= ic1/10000
555
-
556
- akn=(a2+a4/(tr-theta))*(1/pfunk**2)
557
- aks=wcon*conv*xN
558
- ak=akn+aks
559
-
560
- return G, H, S, a1, a2, a3, a4, c1, c2, wcon
561
- # THAT'S ALL FOLKS !
562
-
563
-
564
291
  def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
565
292
  G=None, H=None, S=None, V=None, Cp=None, a1=None, a2=None, a3=None, a4=None,
566
293
  c1=None, c2=None, omega=None, azero=4, rt=3, sigfigs=False, df_in=None,
567
294
  data_path=None, ligand_abbrv_data_path=None, water_model="SUPCRT92",
568
- correct_basis=True, replace=False, skip_duplicates=True, print_warnings=True,
569
- SSH97_cp_eqns=False, focus_on=None):
295
+ correct_basis=True, skip_duplicates=True, print_warnings=True,
296
+ SSH97_cp_eqns=False, focus_on=None, metal_organic_complex=False):
570
297
 
571
298
  """
572
299
  Estimate the thermodynamic properties and Helgeson-Kirkham-Flowers (HKF)
@@ -684,16 +411,48 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
684
411
  added, check that a species named "CaHCO3+" isn't already in the database.
685
412
  If set to False, the species will be added anyway, but the user will
686
413
  be warned. If set to True, the species will not be added.
414
+
415
+ print_warnings : bool, default True
416
+ Print Complicator warnings?
417
+
418
+ SSH97_cp_eqns : bool, default False
419
+ Use equations given in Sverjensky et al. 1997 for estimating heat
420
+ capacities of chloride complexes, or of acetate complexes with divalent
421
+ cations? If False, the Complicator will use a built-in equations to
422
+ estimate complex heat capacities. These equations can be viewed in the
423
+ "equations" output of the complicator.
424
+
425
+ focus_on : list of str, optional
426
+ Allows the user to provide a list of metal or ligand names. The
427
+ Complicator will only make estimates for complexes that contain those
428
+ metals or ligands.
429
+
430
+ metal_organic_complex : bool, default False
431
+ Is this a metal-organic complex? If True, estimation assumptions from
432
+ Prapaipong and Shock (2001) will be used.
687
433
 
688
434
  Returns
689
435
  -------
690
436
  df_out : pandas dataframe
691
437
  A dataframe with estimated properties and HKF parameters of the aqueous
692
438
  complex.
439
+
440
+ equations : dict
441
+ A dictionary organizing equations that were used to estimate the
442
+ thermodynamic properties and parameters of aqueous complexes.
443
+
444
+ warnings : list
445
+ A list of warnings that were encountered.
446
+
447
+ duplicates : list
448
+ A list of estimated complexes that appear to match existing complexes in
449
+ the thermodynamic database, reported as duplicate pairs, e.g.,
450
+ [["Mg(OH)+", "MgOH+"], ...].
693
451
  """
694
452
 
695
453
  if print_warnings:
696
- print("The WORM Complicator is in currently in beta testing. Estimates should be treated with caution until the full release.")
454
+ print("The WORM Complicator is in currently in beta testing. "
455
+ "Estimates should be treated with caution until the full release.")
697
456
 
698
457
  if isinstance(df_in, str):
699
458
  df_in = pd.read_csv(df_in)
@@ -852,13 +611,14 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
852
611
  c1 = [c1_1, c1_2, c1_3, c1_4]
853
612
  c2 = [c2_1, c2_2, c2_3, c2_4]
854
613
  omega = [omega_1, omega_2, omega_3, omega_4]
855
-
614
+
856
615
  df_out_row, eqn_row, warn_row, dupe_row, = complicate(cation, ligand, beta, sass,
857
616
  out_name, df_in=None, sigfigs=sigfigs, data_path=data_path,
858
- replace=replace, skip_duplicates=skip_duplicates,
617
+ skip_duplicates=skip_duplicates,
859
618
  water_model=water_model, SSH97_cp_eqns=SSH97_cp_eqns,
860
619
  G=G, H=H, S=S, V=V, Cp=Cp, a1=a1, a2=a2, a3=a3, a4=a4, c1=c1, c2=c2,
861
620
  omega=omega, ligand_abbrv_data_path=ligand_abbrv_data_path,
621
+ metal_organic_complex=metal_organic_complex,
862
622
  print_warnings=False)
863
623
 
864
624
  df_out_list.append(df_out_row)
@@ -923,14 +683,12 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
923
683
  df_out_4 = pd.DataFrame()
924
684
 
925
685
  if data_path == None:
926
- thermo_data = pkg_resources.resource_stream(__name__, "wrm_data.csv")
927
- thermo_data = pd.read_csv(thermo_data, dtype=object)
686
+ thermo_data = WORMutils.import_package_file(__name__, "wrm_data.csv")
928
687
  else:
929
688
  thermo_data = pd.read_csv(data_path)
930
689
 
931
690
  if ligand_abbrv_data_path == None:
932
- ligand_abbrv = pkg_resources.resource_stream(__name__, "wrm_ligand_abbrv.csv")
933
- ligand_abbrv = pd.read_csv(ligand_abbrv)
691
+ ligand_abbrv = WORMutils.import_package_file(__name__, "wrm_ligand_abbrv.csv")
934
692
  elif isinstance(ligand_abbrv_data_path, str):
935
693
  ligand_abbrv = pd.read_csv(ligand_abbrv_data_path)
936
694
 
@@ -949,7 +707,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
949
707
  if ligand_entry.empty:
950
708
  msg = "Could not find an entry for " + ligand + " in reference sheet."
951
709
  warning_list.append(msg)
952
-
710
+
953
711
  if cation_entry.shape[0] == 0 or ligand_entry.shape[0] == 0:
954
712
  return pd.DataFrame(), eqs_used, warning_list, duplicate_list
955
713
 
@@ -1016,7 +774,6 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1016
774
  cation_formula_ox_dict = __get_formula_ox_dict(cation, df=thermo_data)
1017
775
  ligand_formula_ox_dict = __get_formula_ox_dict(ligand, df=thermo_data)
1018
776
 
1019
-
1020
777
  ZC = str(cation_entry["z.T"].values[0])
1021
778
  GC = str(cation_entry["G"].values[0])
1022
779
  HC = str(cation_entry["H"].values[0])
@@ -1090,6 +847,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1090
847
  alkaline_earths = ["Be", "Mg", "Ca", "Sr", "Ba", "Ra"]
1091
848
 
1092
849
  if not math.isnan(BETA1):
850
+
1093
851
  ###### Calculations for the first complex
1094
852
  eqs_used.append("Beginning calculations for the first complex...")
1095
853
 
@@ -1124,7 +882,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1124
882
  DELSR1 = S1 - SC - SL
1125
883
  DELS1 = DELSR1
1126
884
  eqs_used.append("Third law entropy of the complex S1 = {}, cation SC = {}, and ligand SL = {}, cal/mol/K".format(S_1, SC, SL))
1127
- eqs_used.append("DELS1 = DELSR1 = {} cal/mol/K = S1 - SC - SL, entropy of association of the first complex".format("{0:.5g}".format(DELS1)))
885
+ eqs_used.append("DELS1 = DELSR1 = {} cal/mol/K = S1 - SC - SL, entropy of association of the first complex".format("{0:.5g}".format(DELS1)))
1128
886
  else:
1129
887
  # if user provides neither a standard entropy of the first complex, nor an entropy of association...
1130
888
  if ligand == "OH-":
@@ -1192,13 +950,24 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1192
950
  # cations with >4 charge have been weeded out in entropy calculation already
1193
951
  CP1 = float('NaN')
1194
952
  DELCP1 = CP1 - CPC - CPL
953
+ elif metal_organic_complex:
954
+ DELCP1 = 80 # Prapaipong and Shock 2001
955
+ CP1 = DELCP1 + CPC + CPL
956
+ eqs_used.append("DELCP1 = {} cal/mol/K = 80, assumption for metal organic complexes made in Prapaipong and Shock 2001".format("{0:.5g}".format(DELCP1)))
957
+ eqs_used.append("CP1 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the first complex".format("{0:.5g}".format(CP1)))
1195
958
  else:
1196
- if SSH97_cp_eqns:
959
+ if SSH97_cp_eqns and ligand == "Cl-":
1197
960
  # GB modified 2024 to add equations as they appear in Sverjensky et al., 1997:
1198
961
  DELCP1 = 1.25*CPC + 45.3*(Z1+1) - 27.3
1199
962
  CP1 = DELCP1 + CPC + CPL
1200
963
  eqs_used.append("DELCP1 = {} cal/mol/K = 1.25*CPC + 45.3*(Z1+1) - 27.3, Eqn 53 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP1)))
1201
964
  eqs_used.append("CP1 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the first complex".format("{0:.5g}".format(CP1)))
965
+ elif SSH97_cp_eqns and ligand =="acetate" and ZC == 2:
966
+ # GB modified 2024 to add equations as they appear in Sverjensky et al., 1997:
967
+ DELCP1 = 1.25*CPC + +93.8
968
+ CP1 = DELCP1 + CPC + CPL
969
+ eqs_used.append("DELCP1 = {} cal/mol/K = 1.25*CPC + 93.8, Eqn 54 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP1)))
970
+ eqs_used.append("CP1 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the first complex".format("{0:.5g}".format(CP1)))
1202
971
  else:
1203
972
  # ES notes from original fortran code: Here the Cp predictor starts for the first complex.
1204
973
  # Modified 8 Aug 1992 after latest revision Modified 17 March 1992 to
@@ -1237,7 +1006,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1237
1006
  else:
1238
1007
  # this cation element is not supported by existing methods
1239
1008
  V1 = float("NaN")
1240
-
1009
+
1241
1010
  if ligand != "OH-" or use_sverjensky_V_methods:
1242
1011
  # Here the Volume predictor starts for the first complex
1243
1012
  DELVR1 = 0.11419*VC + 8.9432 # Eq. 62 in Sverjensky et al 1997
@@ -1346,13 +1115,18 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1346
1115
  DELCPR2 = CP2 - CPC - (2.0*CPL)
1347
1116
  DELCP2 = DELCPR2 - DELCP1
1348
1117
  else:
1349
- if SSH97_cp_eqns:
1118
+ if SSH97_cp_eqns and ligand == "Cl-":
1350
1119
  # GB added 2024: Cp equations as they appear in Sverjensky et al., 1997
1351
- DELCP2 = (0.89*CPC - 4.9)*2 + DELCP1
1120
+ DELCP2 = (0.89*CPC - 4.9)*1 + DELCP1
1352
1121
  CP2 = DELCP2 + CP1 + CPL
1353
- eqs_used.append("DELCP2 = {} cal/mol/K = (0.89*CPC - 4.9)*2 + DELCP1, Eqn 58 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP2)))
1122
+ eqs_used.append("DELCP2 = {} cal/mol/K = (0.89*CPC - 4.9)*1 + DELCP1, Eqn 58 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP2)))
1123
+ eqs_used.append("CP2 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the second complex".format("{0:.5g}".format(CP2)))
1124
+ elif SSH97_cp_eqns and ligand == "acetate" and ZC == 2:
1125
+ # GB modified 2024 to add equations as they appear in Sverjensky et al., 1997:
1126
+ DELCP2 = (0.89*CPC + 20.6)*1 + DELCP1
1127
+ CP2 = DELCP2 + CP1 + CPL
1128
+ eqs_used.append("DELCP2 = {} cal/mol/K = (0.89*CPC + 20.6)*1 + DELCP1, Eqn 59 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP2)))
1354
1129
  eqs_used.append("CP2 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the second complex".format("{0:.5g}".format(CP2)))
1355
-
1356
1130
  else:
1357
1131
  # ES note from original fortran code: CHANGED 17 MARCH 1992!!!
1358
1132
  gz = 0.89*CPC + 0.72*CPL + 16.3
@@ -1504,7 +1278,19 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1504
1278
  DELCPR3 = CP3 - CPC - (3.0*CPL)
1505
1279
  DELCP3 = DELCPR3 - DELCPR2 - DELCP1
1506
1280
  else:
1507
- if not SSH97_cp_eqns:
1281
+ if SSH97_cp_eqns and ligand == "Cl-":
1282
+ # GB added 2024
1283
+ DELCP3 = (0.89*CPC - 4.9)*2 + DELCP1
1284
+ CP3 = DELCP3 + CP2 + CPL
1285
+ eqs_used.append("DELCP3 = {} cal/mol/K = (0.89*CPC - 4.9)*2 + DELCP1, Eqn 58 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP3)))
1286
+ eqs_used.append("CP3 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the third complex".format("{0:.5g}".format(CP3)))
1287
+ elif SSH97_cp_eqns and ligand == "acetate" and ZC == 2:
1288
+ # GB modified 2024 to add equations as they appear in Sverjensky et al., 1997:
1289
+ DELCP3 = (0.89*CPC + 20.6)*2 + DELCP1
1290
+ CP3 = DELCP3 + CP2 + CPL
1291
+ eqs_used.append("DELCP4 = {} cal/mol/K = (0.89*CPC + 20.6)*2 + DELCP1, Eqn 59 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP3)))
1292
+ eqs_used.append("CP3 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the third complex".format("{0:.5g}".format(CP3)))
1293
+ else:
1508
1294
  # ES note from original fortran code: CHANGED 17 MARCH 1992!!!
1509
1295
  gz = 0.89*CPC + 0.72*CPL + 16.3
1510
1296
  DELCP3 = DELCP2 + gz
@@ -1512,12 +1298,6 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1512
1298
  eqs_used.append("gz = {} = 0.89*CPC + 0.72*CPL + 16.3, unpublished equation pertaining to Haas et al 1995, Shock et al. 1995, and Sverjensky et al. 1997".format("{0:.5g}".format(gz)))
1513
1299
  eqs_used.append("DELCP3 = {} cal/mol/K = DELCP2 + gz, unpublished equation pertaining to Haas et al 1995, Shock et al. 1995, and Sverjensky et al. 1997".format("{0:.5g}".format(DELCP3)))
1514
1300
  eqs_used.append("CP3 = {} cal/mol/K = DELCP3 + CP2 + CPL, standard isobaric heat capacity of the second complex".format("{0:.5g}".format(CP3)))
1515
- else:
1516
- # GB added 2024
1517
- DELCP3 = (0.89*CPC - 4.9)*3 + DELCP1
1518
- CP3 = DELCP3 + CP2 + CPL
1519
- eqs_used.append("DELCP3 = {} cal/mol/K = (0.89*CPC - 4.9)*3 + DELCP1, Eqn 58 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP3)))
1520
- eqs_used.append("CP3 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the third complex".format("{0:.5g}".format(CP3)))
1521
1301
 
1522
1302
  if ligand == "OH-":
1523
1303
  if ZC == 1:
@@ -1662,7 +1442,19 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1662
1442
  DELCPR4 = CP4 - CPC - (4.0*CPL)
1663
1443
  DELCP4 = DELCPR4 - DELCPR3 - DELCPR2 - DELCP1
1664
1444
  else:
1665
- if not SSH97_cp_eqns:
1445
+ if SSH97_cp_eqns and ligand == "Cl-":
1446
+ # GB added 2024
1447
+ DELCP4 = (0.89*CPC - 4.9)*3 + DELCP1
1448
+ CP4 = DELCP4 + CP3 + CPL
1449
+ eqs_used.append("DELCP4 = {} cal/mol/K = (0.89*CPC - 4.9)*3 + DELCP1, Eqn 58 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP4)))
1450
+ eqs_used.append("CP4 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the fourth complex".format("{0:.5g}".format(CP4)))
1451
+ elif SSH97_cp_eqns and ligand == "acetate" and ZC == 2:
1452
+ # GB modified 2024 to add equations as they appear in Sverjensky et al., 1997:
1453
+ DELCP4 = (0.89*CPC + 20.6)*3 + DELCP1
1454
+ CP4 = DELCP4 + CP3 + CPL
1455
+ eqs_used.append("DELCP4 = (0.89*CPC + 20.6)*3 + DELCP1, Eqn 59 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP4)))
1456
+ eqs_used.append("CP4 = {} cal/mol/K = DELCP4 + CP3 + CPL, standard isobaric heat capacity of the fourth complex".format("{0:.5g}".format(CP4)))
1457
+ else:
1666
1458
  # ES note from original fortran code: CHANGED 17 MARCH 1992!!!
1667
1459
  gz = 0.89*CPC + 0.72*CPL + 16.3
1668
1460
  DELCP4 = DELCP3 + gz
@@ -1670,13 +1462,6 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1670
1462
  eqs_used.append("gz = {} = 0.89*CPC + 0.72*CPL + 16.3, unpublished equation pertaining to Haas et al 1995, Shock et al. 1995, and Sverjensky et al. 1997".format("{0:.5g}".format(gz)))
1671
1463
  eqs_used.append("DELCP4 = {} cal/mol/K = DELCP3 + gz, unpublished equation pertaining to Haas et al 1995, Shock et al. 1995, and Sverjensky et al. 1997".format("{0:.5g}".format(DELCP4)))
1672
1464
  eqs_used.append("CP4 = {} cal/mol/K = DELCP4 + CP3 + CPL, standard isobaric heat capacity of the fourth complex".format("{0:.5g}".format(CP4)))
1673
- else:
1674
- # GB added 2024
1675
- DELCP4 = (0.89*CPC - 4.9)*4 + DELCP1
1676
- CP4 = DELCP4 + CP3 + CPL
1677
- eqs_used.append("DELCP4 = {} cal/mol/K = (0.89*CPC - 4.9)*4 + DELCP1, Eqn 58 in Sverjensky et al. 1997".format("{0:.5g}".format(DELCP4)))
1678
- eqs_used.append("CP4 = {} cal/mol/K = DELCP1 + CPC + CPL, standard isobaric heat capacity of the fourth complex".format("{0:.5g}".format(CP4)))
1679
-
1680
1465
  if ligand == "OH-":
1681
1466
  if ZC == 1:
1682
1467
  # fourth complex of a monovalent cation is not supported
@@ -1724,14 +1509,18 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1724
1509
  if not math.isnan(V_1):
1725
1510
  V1 = V_1
1726
1511
 
1727
-
1512
+ if metal_organic_complex:
1513
+ organic=True
1514
+ else:
1515
+ organic=False
1516
+
1728
1517
  if not math.isnan(BETA1):
1729
1518
  try:
1730
1519
  eqs_used.append("Estimating HKF parameters for the first complex...")
1731
- G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_1 = calc_params_WORMutils(Z1, G1, H1, S1, CP1, V1, a1_1, a2_1, a3_1, a4_1, c1_1, c2_1, omega_1, water_model=water_model)
1520
+ G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_1 = calc_params_WORMutils(Z1, G1, H1, S1, CP1, V1, a1_1, a2_1, a3_1, a4_1, c1_1, c2_1, omega_1, water_model=water_model, organic=organic)
1732
1521
  eqs_used.append("HKF parameters for the first complex were estimated...")
1733
1522
  except:
1734
- eqs_used.append("HKF parameters for the second complex could not be estimated...")
1523
+ eqs_used.append("HKF parameters for the first complex could not be estimated...")
1735
1524
  return pd.DataFrame(), eqs_used, warning_list, duplicate_list
1736
1525
 
1737
1526
  if not math.isnan(G):
@@ -1772,9 +1561,9 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1772
1561
  thermo_data=thermo_data,
1773
1562
  cation_formula_ox_dict=cation_formula_ox_dict,
1774
1563
  ligand_formula_ox_dict=ligand_formula_ox_dict,
1775
- replace=replace,
1776
1564
  skip_duplicates=skip_duplicates,
1777
- ligand_name_abbrv_pairs=ligand_name_abbrv_pairs)
1565
+ ligand_name_abbrv_pairs=ligand_name_abbrv_pairs,
1566
+ organic=organic)
1778
1567
 
1779
1568
  eqs_used = eqs_used + hkf_eqns_1
1780
1569
  duplicate_list = duplicate_list + duplicate_list_1
@@ -1794,7 +1583,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1794
1583
  if not math.isnan(BETA2):
1795
1584
  try:
1796
1585
  eqs_used.append("Estimating HKF parameters for the second complex...")
1797
- G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_2 = calc_params_WORMutils(Z2, G2, H2, S2, CP2, V2, a1_2, a2_2, a3_2, a4_2, c1_2, c2_2, omega_2, water_model=water_model)
1586
+ G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_2 = calc_params_WORMutils(Z2, G2, H2, S2, CP2, V2, a1_2, a2_2, a3_2, a4_2, c1_2, c2_2, omega_2, water_model=water_model, organic=organic)
1798
1587
  eqs_used.append("HKF parameters for the second complex were estimated...")
1799
1588
  except:
1800
1589
  eqs_used.append("HKF parameters for the second complex could not be estimated...")
@@ -1842,9 +1631,9 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1842
1631
  thermo_data=thermo_data,
1843
1632
  cation_formula_ox_dict=cation_formula_ox_dict,
1844
1633
  ligand_formula_ox_dict=ligand_formula_ox_dict,
1845
- replace=replace,
1846
1634
  skip_duplicates=skip_duplicates,
1847
- ligand_name_abbrv_pairs=ligand_name_abbrv_pairs)
1635
+ ligand_name_abbrv_pairs=ligand_name_abbrv_pairs,
1636
+ organic=organic)
1848
1637
 
1849
1638
  eqs_used = eqs_used + hkf_eqns_2
1850
1639
  duplicate_list = duplicate_list + duplicate_list_2
@@ -1864,7 +1653,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1864
1653
  if not math.isnan(BETA3):
1865
1654
  try:
1866
1655
  eqs_used.append("Estimating HKF parameters for the third complex...")
1867
- G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_3 = calc_params_WORMutils(Z3, G3, H3, S3, CP3, V3, a1_3, a2_3, a3_3, a4_3, c1_3, c2_3, omega_3, water_model=water_model)
1656
+ G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_3 = calc_params_WORMutils(Z3, G3, H3, S3, CP3, V3, a1_3, a2_3, a3_3, a4_3, c1_3, c2_3, omega_3, water_model=water_model, organic=organic)
1868
1657
  eqs_used.append("HKF parameters for the third complex were estimated...")
1869
1658
  except:
1870
1659
  eqs_used.append("HKF parameters for the third complex could not be estimated...")
@@ -1912,9 +1701,9 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1912
1701
  thermo_data=thermo_data,
1913
1702
  cation_formula_ox_dict=cation_formula_ox_dict,
1914
1703
  ligand_formula_ox_dict=ligand_formula_ox_dict,
1915
- replace=replace,
1916
1704
  skip_duplicates=skip_duplicates,
1917
- ligand_name_abbrv_pairs=ligand_name_abbrv_pairs)
1705
+ ligand_name_abbrv_pairs=ligand_name_abbrv_pairs,
1706
+ organic=organic)
1918
1707
 
1919
1708
  eqs_used = eqs_used + hkf_eqns_3
1920
1709
  duplicate_list = duplicate_list + duplicate_list_3
@@ -1934,7 +1723,7 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1934
1723
  if not math.isnan(BETA4):
1935
1724
  try:
1936
1725
  eqs_used.append("Estimating HKF parameters for the fourth complex...")
1937
- G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_4 = calc_params_WORMutils(Z4, G4, H4, S4, CP4, V4, a1_4, a2_4, a3_4, a4_4, c1_4, c2_4, omega, water_model=water_model)
1726
+ G, H, S, a1, a2, a3, a4, c1, c2, wcon, hkf_eqns_4 = calc_params_WORMutils(Z4, G4, H4, S4, CP4, V4, a1_4, a2_4, a3_4, a4_4, c1_4, c2_4, omega, water_model=water_model, organic=organic)
1938
1727
  eqs_used.append("HKF parameters for the fourth complex were estimated...")
1939
1728
  except:
1940
1729
  eqs_used.append("HKF parameters for the fourth complex could not be estimated...")
@@ -1969,7 +1758,8 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1969
1758
  wcon_out = round(wcon/100000, rt)
1970
1759
  Z_out = Z4
1971
1760
 
1972
- df_out_4, duplicate_list_4 = __write_output(filename=out_name, cation=cation,
1761
+ df_out_4, duplicate_list_4 = __write_output(filename=out_name,
1762
+ cation=cation,
1973
1763
  ligand=ligand, nth_complex=4,
1974
1764
  G=G_out, H=H_out, S=S_out,
1975
1765
  CP=CP_out, V=V_out, a1=a1_out,
@@ -1981,9 +1771,9 @@ def complicate(cation=None, ligand=None, beta=None, sass=None, out_name=None,
1981
1771
  thermo_data=thermo_data,
1982
1772
  cation_formula_ox_dict=cation_formula_ox_dict,
1983
1773
  ligand_formula_ox_dict=ligand_formula_ox_dict,
1984
- replace=replace,
1985
1774
  skip_duplicates=skip_duplicates,
1986
- ligand_name_abbrv_pairs=ligand_name_abbrv_pairs)
1775
+ ligand_name_abbrv_pairs=ligand_name_abbrv_pairs,
1776
+ organic=organic)
1987
1777
 
1988
1778
 
1989
1779
  eqs_used = eqs_used + hkf_eqns_4