#! /usr/bin/python3 # Last edited on 2021-11-25 21:19:27 by stolfi # Computes the ternary phase diagram MgO MgCl2 H2O and writes # gnuplot commands for the same. import ternary_phase_diagram_IMP from math import sqrt, log, hypot from sys import stderr, stdout # The following procedures use two dictionaries {g} and {c} # whose keys are compound labels (strings). # # The value of {g[lab]} is the molar mass of compound {lab} in grams. # # The value {c[lab]} is the Cartesian coordinates {(X,Y)} # of the corresponding point on the diagram. They assume that the triangle is isosceles # with horizontal base. def g_c_set(g, c, f, g_f, c_f): # Assumes {g,c} as defined above. Defines the molar mass of compound # label {f} as {g_f} and its coordinates as the 2-tuple {c_f}. Also # prints to stderr. ternary_phase_diagram_IMP.g_c_set(g, c, f, g_f, c_f) def g_c_combine(g, c, molar, f, L): # Assumes {g,c} as defined above. Defines the molar mass and # coordinates of compound label {f} by linear combination of the # components in list {L}. Each component is a pair {(mi,fi)} where # {mi} is a numeric multiplier and {fi} is the label of a compound # whose molar mass and coordinates are already in {g,c}. # The numeric multiplier is assumed to be moles if {molar} is true, # or a mass fraction if {molar} is false. In the second case, the # molar mass {g[f]} is set to {None}. Also prints to stderr.""" ternary_phase_diagram_IMP.g_c_combine(g, c, molar, f, L) def map_coords(c, f, fa, fb, fc): # Assumes {c} is a point coordinate dict as defined above. # # Computes the XY plot coordinates of the compoind with label {f}. # Assumes that {fa,fb,fc} are the formulas of the compounds at # bottom left, top center, and bottm right corners # of the diagram, respectively. # # The coordinates in {c} are mapped so that the triangle is # equilateral with base corners {(0,0), (1,0)} # and the apex up. return ternary_phase_diagram_IMP.map_coords(c, f, fa, fb, fc) def write_XY_point_file(fname, c, psz, off, moff, fa, fb, fc): # Assumes {c} is a point coordinate dict as defined above. # # Assumes {psz} maps compound labels to point sizes, {off} maps # compound labels to label coordinate offset pairs. The {moff} is a # scale factor applied to each coordinate of each offset in {off} # # Writes to "{fname}-pt.txt" the XY point data file of the # tri-component phase diagram for all compounds in the dictionary. # Assumes that {fa,fb,fc} are the formulas of the compounds at bottom # left, top center, and bottm right corners of the diagram, # respectively.""" ternary_phase_diagram_IMP.write_XY_point_file(fname, c, psz, off, moff, fa, fb, fc) def write_XY_line_file(fname, c, seg, fa, fb, fc): # Assumes {c} is a point coordinate dict as in {define_diagram_points}. # # Assumes that {seg} is a list of pairs of compound labels to be # connected by straight lines. # # Writes to "{fname}-pt.txt" the point data file of the tri-component # phase diagram for all compounds in the dictionary. Assumes that # {fa,fb,fc} are the formulas of the compounds at bottom left, top # center, and bottm right corners of the diagram, respectively.""" ternary_phase_diagram_IMP.write_XY_line_file(fname, c, seg, fa, fb, fc) def write_XY_region_files(fname, c, reg, fa, fb, fc): # Assumes {c} is a point coordinate dict as in {define_diagram_points}. # # Assumes that {reg} is a dict that maps region labels to vertex lists, # as in {define_diagram_regions}. # # For each region {ri} in {reg}, writes to "{fname}-rg-{ri}.txt" the # coordinates of the vertices of the region {ri}. Assumes that {fa,fb,fc} # are the formulas of the compounds at bottom left, top center, and # bottm right corners of the diagram, respectively.""" ternary_phase_diagram_IMP.write_XY_region_files(fname, c, reg, fa, fb, fc)