From 3b091c0bd44c1aa9bede54004e8ec361dee65fa5 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 21 May 2024 19:35:04 -0400 Subject: [PATCH] type label support for dump xyz --- doc/src/dump.rst | 5 +++-- doc/src/dump_modify.rst | 14 +++++++++++--- src/dump_xyz.cpp | 27 +++++++++++++++++++++++++++ src/label_map.h | 1 + 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/doc/src/dump.rst b/doc/src/dump.rst index 2e61ad9921..9f2be8c129 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -470,8 +470,9 @@ followed by one line per atom with the atom type and the :math:`x`-, :math:`y`-, and :math:`z`-coordinate of that atom. You can use the :doc:`dump_modify element ` option to change the output from using the (numerical) atom type to an element name (or some other -label). This will help many visualization programs to guess bonds and -colors. +label). This option will help many visualization programs to guess bonds +and colors. You can use the :doc:`dump_modify types labels ` +option to replace numeric atom types with :doc:`type labels `. .. versionadded:: 22Dec2022 diff --git a/doc/src/dump_modify.rst b/doc/src/dump_modify.rst index a9b71a98e2..79fdf2cc3e 100644 --- a/doc/src/dump_modify.rst +++ b/doc/src/dump_modify.rst @@ -17,7 +17,7 @@ Syntax * one or more keyword/value pairs may be appended * these keywords apply to various dump styles -* keyword = *append* or *at* or *balance* or *buffer* or *colname* or *delay* or *element* or *every* or *every/time* or *fileper* or *first* or *flush* or *format* or *header* or *image* or *label* or *maxfiles* or *nfile* or *pad* or *pbc* or *precision* or *region* or *refresh* or *scale* or *sfactor* or *skip* or *sort* or *tfactor* or *thermo* or *thresh* or *time* or *triclinic/general* or *units* or *unwrap* +* keyword = *append* or *at* or *balance* or *buffer* or *colname* or *delay* or *element* or *every* or *every/time* or *fileper* or *first* or *flush* or *format* or *header* or *image* or *label* or *maxfiles* or *nfile* or *pad* or *pbc* or *precision* or *region* or *refresh* or *scale* or *sfactor* or *skip* or *sort* or *tfactor* or *thermo* or *thresh* or *time* or *triclinic/general* or *types* or *units* or *unwrap* .. parsed-literal:: @@ -81,6 +81,7 @@ Syntax these 3 args can be replaced by the word "none" to turn off thresholding *time* arg = *yes* or *no* *triclinic/general* arg = *yes* or *no* + *types* value = *numeric* or *labels* *units* arg = *yes* or *no* *unwrap* arg = *yes* or *no* @@ -849,6 +850,13 @@ The default setting is *no*\ . ---------- +The *types* keyword applies only to the dump xyz style. If this keyword is +used with a value of *numeric*, then numeric atom types are printed in the +xyz file (default). If the value *labels* is specified, then +:doc:`type labels ` are printed for atom types. + +---------- + The *triclinic/general* keyword only applies to the dump *atom* and *custom* styles. It can only be used with a value of *yes* if the simulation box was created as a general triclinic box. See the @@ -960,11 +968,11 @@ The option defaults are * sort = id for dump styles *dcd*, *xtc*, and *xyz* * thresh = none * time = no -* triclinic/general no +* triclinic/general = no +* types = numeric * units = no * unwrap = no * compression_level = 9 (gz variants) * compression_level = 0 (zstd variants) * checksum = yes (zstd variants) - diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index f7ab77b2bf..c424a98feb 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "error.h" +#include "label_map.h" #include "memory.h" #include "update.h" @@ -122,6 +123,32 @@ int DumpXYZ::modify_param(int narg, char **arg) return ntypes+1; } + if (strcmp(arg[0],"types") == 0) { + if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + if (strcmp(arg[1],"numeric") == 0) { + return 2; + } else if (strcmp(arg[1],"labels") == 0) { + if (!atom->labelmapflag) + error->all(FLERR, "Label map must be defined when using 'types labels'"); + } else error->all(FLERR, "Illegal option for dump_modify 'types' keyword"); + + + if (typenames) { + for (int i = 1; i <= ntypes; i++) + delete [] typenames[i]; + + delete [] typenames; + typenames = nullptr; + } + + typenames = new char*[ntypes+1]; + for (int itype = 1; itype <= ntypes; itype++) { + typenames[itype] = utils::strdup(atom->lmap->typelabel[itype-1]); + } + + return 2; + } + return 0; } diff --git a/src/label_map.h b/src/label_map.h index a96fcc255c..0dfc42c9b5 100644 --- a/src/label_map.h +++ b/src/label_map.h @@ -22,6 +22,7 @@ namespace LAMMPS_NS { class LabelMap : protected Pointers { friend class AtomVec; + friend class DumpXYZ; friend class ReadData; public: