|
6 | 6 | from __future__ import absolute_import |
7 | 7 |
|
8 | 8 | import numpy as np |
| 9 | +from copy import deepcopy |
| 10 | +from collections import namedtuple |
9 | 11 | from .linear_fitting import weighted_constrained_least_squares |
| 12 | +from ..utils.chemistry import dictionarize_formula |
| 13 | +from ..utils.chemistry import process_solution_chemistry |
| 14 | +from ..classes.solution import Solution |
| 15 | + |
| 16 | + |
| 17 | +class DummyCompositionSolution(Solution): |
| 18 | + """ |
| 19 | + This is a dummy base class for a solution object to |
| 20 | + facilitate composition fitting when no solution model has |
| 21 | + been prepared. The model is initialized with appropriate |
| 22 | + chemical formulae for each endmember, and can do all basic |
| 23 | + compositional processing that doesn't involve any material |
| 24 | + properties. |
| 25 | +
|
| 26 | + :param endmember_element_formulae: Formulae for each of the independent endmembers. |
| 27 | + e.g. ['Mg2SiO4', 'Fe2SiO4']. |
| 28 | + :type endmember_element_formulae: list of str |
| 29 | + :param endmember_site_formulae: Site formulae for each of the independent endmembers, |
| 30 | + in the same order as endmember_element_formulae. e.g. ['[Mg]2SiO4', '[Fe]2SiO4']. |
| 31 | + :type endmember_site_formulae: list of str |
| 32 | + """ |
| 33 | + |
| 34 | + def __init__(self, endmember_element_formulae, endmember_site_formulae): |
| 35 | + self.endmember_formulae = [ |
| 36 | + dictionarize_formula(f) for f in endmember_element_formulae |
| 37 | + ] |
| 38 | + self.solution_model = type( |
| 39 | + "Dimension", (object,), {"formulas": endmember_site_formulae} |
| 40 | + )() |
| 41 | + self.solution_model.endmembers = [None for f in endmember_site_formulae] |
| 42 | + process_solution_chemistry(self.solution_model) |
10 | 43 |
|
11 | 44 |
|
12 | 45 | def fit_composition_to_solution( |
@@ -59,17 +92,15 @@ def fit_composition_to_solution( |
59 | 92 | :rtype: tuple of 1D numpy.array, 2D numpy.array and float |
60 | 93 | """ |
61 | 94 |
|
62 | | - n_vars = len(fitted_variables) |
63 | | - n_mbrs = len(solution.endmembers) |
64 | | - |
65 | | - solution_variables = solution.elements |
| 95 | + solution_variables = deepcopy(solution.elements) |
66 | 96 | solution_variables.extend(solution.solution_model.site_names) |
67 | 97 |
|
68 | 98 | solution_matrix = np.hstack( |
69 | 99 | (solution.stoichiometric_matrix, solution.solution_model.endmember_noccupancies) |
70 | 100 | ) |
71 | 101 |
|
72 | | - n_sol_vars = solution_matrix.shape[1] |
| 102 | + n_vars = len(fitted_variables) |
| 103 | + n_mbrs, n_sol_vars = solution_matrix.shape |
73 | 104 |
|
74 | 105 | if variable_conversions is not None: |
75 | 106 | solution_matrix = np.hstack( |
|
0 commit comments