From d5e911bfd4fecedeae2589e4ba1de951d45c28c0 Mon Sep 17 00:00:00 2001 From: ab5424 Date: Tue, 16 Nov 2021 15:46:03 +0100 Subject: [PATCH] Modifiers for structure analysis. --- autogabi/analysis.py | 81 ++++++++++++++++++++++++++++++ autogabi/io/__init__.py | 0 autogabi/io/inputs.py | 0 autogabi/io/outputs.py | 0 autogabi/minimiser.py | 2 +- autogabi/orientation.py | 37 +++++++------- examples/grain_analysis.ipynb | 93 +++++++++++++++++++++++++++++++++++ 7 files changed, 194 insertions(+), 19 deletions(-) delete mode 100644 autogabi/io/__init__.py delete mode 100644 autogabi/io/inputs.py delete mode 100644 autogabi/io/outputs.py create mode 100644 examples/grain_analysis.ipynb diff --git a/autogabi/analysis.py b/autogabi/analysis.py index f1d6d3d..5abb16a 100644 --- a/autogabi/analysis.py +++ b/autogabi/analysis.py @@ -166,6 +166,87 @@ def perform_voroni_analysis(self): # https://tess.readthedocs.io/en/stable/ # https://github.com/materialsproject/pymatgen/blob/v2022.0.14/pymatgen/analysis/structure_analyzer.py#L61-L174 + def perform_ptm(self, enabled: list = ['fcc', 'hpc', 'bcc'], compute: bool=True, *args, **kwargs): + """ + + Args: + enabled (list): List of strings for enabled structure types. Possible values: + fcc-hcp-bcc-ico-sc-dcub-dhex-graphene + + output_deformation_gradient = False + output_interatomic_distance = False + output_ordering = False + output_orientation = False + output_rmsd = False + rmsd_cutoff = 0.1 + + Returns: + + """ + + if self.backend == 'ovito': + + from ovito.plugins.ParticlesPython import PolyhedralTemplateMatchingModifier + ptm = PolyhedralTemplateMatchingModifier(*args, **kwargs) + + # Enabled by default: FCC, HCP, BCC + if 'fcc' not in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.FCC].enabled = False + if 'hcp' not in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.HCP].enabled = False + if 'bcc' not in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.BCC].enabled = False + if 'ico' in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.ICO].enabled = True + if 'sc' in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.SC].enabled = True + if 'dcub' in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.CUBIC_DIAMOND].enabled = True + if 'dhex' in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.HEX_DIAMOND].enabled = True + if 'graphene' in enabled: + ptm.structures[PolyhedralTemplateMatchingModifier.Type.GRAPHENE].enabled = True + + self.pipeline.modifiers.append(ptm) + + if compute: + self.data = self.pipeline.compute() + + elif self.backend == 'lammps': + # https://docs.lammps.org/compute_ptm_atom.html + pass + else: + # print error + pass + + def perform_ajm(self): + # AcklandJonesModifier + pass + + def get_distinct_grains(self, *args, **kwargs): + """ + Get distinct grains from the structure. + Args: + ovito: + algorithm = GrainSegmentationModifier.Algorithm.GraphClusteringAuto + color_particles = True + handle_stacking_faults = True + merging_threshold = 0.0 + min_grain_size = 100 + orphan_adoption = True + + Returns: + + """ + + if self.backend == 'ovito': + from ovito.plugins.CrystalAnalysisPython import GrainSegmentationModifier + gsm = GrainSegmentationModifier(*args, **kwargs) + self.pipeline.modifiers.append(gsm) + self.data = self.pipeline.compute() + + + def set_analysis(self): if self.backend == 'ovito': diff --git a/autogabi/io/__init__.py b/autogabi/io/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/autogabi/io/inputs.py b/autogabi/io/inputs.py deleted file mode 100644 index e69de29..0000000 diff --git a/autogabi/io/outputs.py b/autogabi/io/outputs.py deleted file mode 100644 index e69de29..0000000 diff --git a/autogabi/minimiser.py b/autogabi/minimiser.py index 7de0500..152dfe1 100644 --- a/autogabi/minimiser.py +++ b/autogabi/minimiser.py @@ -1 +1 @@ -# Minimiser for lammps, vasp, gulp +# Minimiser for lammps, vasp, gulp diff --git a/autogabi/orientation.py b/autogabi/orientation.py index 3e06016..3320adf 100644 --- a/autogabi/orientation.py +++ b/autogabi/orientation.py @@ -1,18 +1,19 @@ -# Get grain orientation - -# https://github.com/paulhof/GraDe-A -# Centrosymetric parameter - - -# Polyhedral template matching is implemented in ovito, ASAP, and LAMMPS -# P. M. Larsen, S. Schmidt, J. Schiøtz, Modelling Simul. Mater. Sci. Eng. 2016, 24, 055007. -# https://docs.lammps.org/compute_ptm_atom.html - -def get_grain_orientation(backend): - if backend == 'ovito': - # First, perform PTM - # Iterate over all ions to get grains - # Pick one fcc ion, if > 2 ffc neighbors, count to grain, otherwise disregard - # Get average - - return None +# Get grain orientation + +# https://github.com/paulhof/GraDe-A +# Centrosymetric parameter + + +# Polyhedral template matching is implemented in ovito, ASAP, and LAMMPS +# P. M. Larsen, S. Schmidt, J. Schiøtz, Modelling Simul. Mater. Sci. Eng. 2016, 24, 055007. +# https://docs.lammps.org/compute_ptm_atom.html + +def get_grain_orientation(backend): + if backend == 'ovito': + + # First, perform PTM + # Iterate over all ions to get grains + # Pick one fcc ion, if > 2 ffc neighbors, count to grain, otherwise disregard + # Get average + + return None diff --git a/examples/grain_analysis.ipynb b/examples/grain_analysis.ipynb new file mode 100644 index 0000000..c6106c3 --- /dev/null +++ b/examples/grain_analysis.ipynb @@ -0,0 +1,93 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "This notebook demonstrates how Auto-GABI can be used to get distinct grains and their properties" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "outputs": [], + "source": [ + "from analysis import GBStructure\n", + "import numpy as np" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 4, + "outputs": [], + "source": [ + "gb = GBStructure('ovito', 'LSF_supercell_md3.lmp')\n", + "gb.delete_particles('O')\n", + "gb.perform_ptm(\n", + " enabled = ['bcc'],\n", + " output_orientation=True,\n", + " rmsd_cutoff = 0.15)\n", + "gb.set_analysis()" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 5, + "outputs": [], + "source": [ + "gb.get_distinct_grains(min_grain_size=10)" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + } + ], + "metadata": { + "kernelspec": { + "name": "pycharm-1f46a509", + "language": "python", + "display_name": "PyCharm (03_postprocessing)" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file