Mercurial > repos > ximgchess > hedm_lattice_parameter_correction
changeset 1:6e5e9abb4139 draft default tip
"planemo upload for repository https://github.com/ximg-chess/galaxytools/tools/hedm_lattice_parameter_correction commit a8f7424061c14ed403820ebddcda94a38006c699"
author | ximgchess |
---|---|
date | Thu, 19 May 2022 17:38:53 +0000 |
parents | 59453ad6e219 |
children | |
files | hedm_lattice_parameter_correction.xml lattice_parameter_correction.py.orig |
diffstat | 2 files changed, 0 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/hedm_lattice_parameter_correction.xml Thu May 19 16:48:22 2022 +0000 +++ b/hedm_lattice_parameter_correction.xml Thu May 19 17:38:53 2022 +0000 @@ -10,7 +10,6 @@ cp '$material' '$material_file' && #set $instrument_file = $ln_name($instrument,'yml') cp '$instrument' '$instrument_file' && - ls -ltr && $__tool_directory__/lattice_parameter_correction.py --min-completeness $min_completeness $force_symmetry @@ -18,7 +17,6 @@ $grains --average_lattice '$lattice_out' --materials_out '$materials_out' - && ls -ltr ]]></command> <configfiles> <configfile name="hexrd_cfg"><![CDATA[#slurp
--- a/lattice_parameter_correction.py.orig Thu May 19 16:48:22 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -#!/usr/bin/env python3 - -import argparse - -import numpy as np - -from hexrd import rotations as rot -from hexrd import matrixutil as mutil -from hexrd import config - - -def _lp_calc(v_mat, f_mat, r_mat): - """ - do strained lappi - - Parameters - ---------- - vmat : TYPE - DESCRIPTION. - f_mat : TYPE - DESCRIPTION. - r_mat : TYPE - DESCRIPTION. - - Returns - ------- - lparams : TYPE - DESCRIPTION. - - """ - f_prime = np.dot(v_mat, np.dot(r_mat, f_mat)) - f_prime_hat = mutil.unitVector(f_prime) - - lp_mags = mutil.columnNorm(f_prime) - - lp_angs = np.hstack( - [np.arccos(np.dot(f_prime_hat[:, 1], f_prime_hat[:, 2])), - np.arccos(np.dot(f_prime_hat[:, 2], f_prime_hat[:, 0])), - np.arccos(np.dot(f_prime_hat[:, 0], f_prime_hat[:, 1]))] - ) - return np.hstack([lp_mags, np.degrees(lp_angs)]) - - -def extract_lattice_parameters( - cfg_file, grains_file, - min_completeness=0.90, force_symmetry=False - ): - """ - """ - cfg = config.open(cfg_file)[0] - - pd = cfg.material.plane_data - qsym_mats = rot.quatProductMatrix(pd.getQSym()) - - f_mat = pd.latVecOps['F'] - - gt = np.loadtxt(grains_file) - - idx = gt[:, 1] >= min_completeness - - expMaps = gt[idx, 3:6].T - vinv = gt[idx, 9:15] - - lparms = [] - for i in range(sum(idx)): - quat = rot.quatOfExpMap(expMaps[:, i].reshape(3, 1)) - v_mat = np.linalg.inv(mutil.vecMVToSymm(vinv[i, :].reshape(6, 1))) - if force_symmetry: - for qpm in qsym_mats: - lparms.append( - _lp_calc(v_mat, f_mat, rot.rotMatOfQuat(np.dot(qpm, quat))) - ) - else: - lparms.append( - _lp_calc(v_mat, f_mat, rot.rotMatOfQuat(quat)) - ) - lp_avg = np.average(np.vstack(lparms), axis=0) - return lp_avg, sum(idx), len(idx) - - -if __name__ == '__main__': - """ - maybe make this smart enough to average properly for symmetry? - """ - parser = argparse.ArgumentParser( - description="Extract average lattice parameters from grains.out" - ) - parser.add_argument( - 'cfg', help="ff-HEDM config YAML file", type=str - ) - parser.add_argument( - 'grains_file', help="grains.out file", type=str - ) - parser.add_argument( - '-m', '--min-completeness', help="completeness threshold", type=float, - default=0.75 - ) - - parser.add_argument( - '-f', '--force-symmetry', - help="symmetrize results", - action="store_true" - ) - - args = parser.parse_args() - - cfg_file = args.cfg - grains_file = args.grains_file - min_completeness = args.min_completeness - force_symmetry = args.force_symmetry - - lp_avg, n_used, n_total = extract_lattice_parameters( - cfg_file, grains_file, - min_completeness=min_completeness, force_symmetry=force_symmetry - ) - print("Using %d grains out of %d above %.2f%% completeness threshold:" - % (n_used, n_total, 100*min_completeness)) - print("---------------------------------------------------------------") - print("a \tb \tc " - + "\talpha \tbeta \tgamma \n" - + "%.6f\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f" % tuple(lp_avg))