add labelmap function to variable command
This commit is contained in:
@ -24,6 +24,7 @@
|
|||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "lmppython.h"
|
#include "lmppython.h"
|
||||||
|
#include "label_map.h"
|
||||||
#include "math_const.h"
|
#include "math_const.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "modify.h"
|
#include "modify.h"
|
||||||
@ -2067,7 +2068,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// ----------------
|
// ----------------
|
||||||
// math or group or special function
|
// math or group or special or labelmap function
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
if (str[i] == '(') {
|
if (str[i] == '(') {
|
||||||
@ -2081,7 +2082,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
argstack,nargstack,ivar));
|
argstack,nargstack,ivar));
|
||||||
else if (special_function(word,contents,tree,treestack,ntreestack,
|
else if (special_function(word,contents,tree,treestack,ntreestack,
|
||||||
argstack,nargstack,ivar));
|
argstack,nargstack,ivar));
|
||||||
else print_var_error(FLERR,fmt::format("Invalid math/group/special "
|
else if (labelmap_function(word,contents,tree,treestack,ntreestack,
|
||||||
|
argstack,nargstack,ivar));
|
||||||
|
else print_var_error(FLERR,fmt::format("Invalid math/group/special/labelmap "
|
||||||
"function '{}()'in variable "
|
"function '{}()'in variable "
|
||||||
"formula", word),ivar);
|
"formula", word),ivar);
|
||||||
delete [] contents;
|
delete [] contents;
|
||||||
@ -4508,6 +4511,69 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
process a type label function in formula
|
||||||
|
push result (numeric type) onto tree or arg stack
|
||||||
|
word = interaction type
|
||||||
|
contents = str between parentheses (one type label)
|
||||||
|
return 0 if not a match, 1 if successfully processed
|
||||||
|
customize by adding a label map function:
|
||||||
|
label(typelabel),blabel(typelabel),alabel(typelabel),
|
||||||
|
dlabel(typelabel),ilabel(typelabel)
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int Variable::labelmap_function(char *word, char *contents, Tree **tree,
|
||||||
|
Tree **treestack, int &ntreestack,
|
||||||
|
double *argstack, int &nargstack, int ivar)
|
||||||
|
{
|
||||||
|
// word not a match to any label map function
|
||||||
|
|
||||||
|
if (strcmp(word,"label") && strcmp(word,"blabel") &&
|
||||||
|
strcmp(word,"alabel") && strcmp(word,"dlabel") &&
|
||||||
|
strcmp(word,"ilabel"))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!atom->labelmapflag)
|
||||||
|
print_var_error(FLERR,"Invalid type label in "
|
||||||
|
"variable formula",ivar);
|
||||||
|
|
||||||
|
int value;
|
||||||
|
std::string typestr = contents;
|
||||||
|
|
||||||
|
if (strcmp(word,"label") == 0) {
|
||||||
|
value = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes);
|
||||||
|
|
||||||
|
} else if (strcmp(word,"blabel") == 0) {
|
||||||
|
value = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes);
|
||||||
|
|
||||||
|
} else if (strcmp(word,"alabel") == 0) {
|
||||||
|
value = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes);
|
||||||
|
|
||||||
|
} else if (strcmp(word,"dlabel") == 0) {
|
||||||
|
value = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes);
|
||||||
|
|
||||||
|
} else if (strcmp(word,"ilabel") == 0) {
|
||||||
|
value = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == -1)
|
||||||
|
print_var_error(FLERR,"Invalid type label in "
|
||||||
|
"variable formula",ivar);
|
||||||
|
|
||||||
|
// save value in tree or on argstack
|
||||||
|
|
||||||
|
if (tree) {
|
||||||
|
Tree *newtree = new Tree();
|
||||||
|
newtree->type = VALUE;
|
||||||
|
newtree->value = value;
|
||||||
|
newtree->first = newtree->second = nullptr;
|
||||||
|
newtree->nextra = 0;
|
||||||
|
treestack[ntreestack++] = newtree;
|
||||||
|
} else argstack[nargstack++] = value;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
extract a global value from a per-atom quantity in a formula
|
extract a global value from a per-atom quantity in a formula
|
||||||
flag = 0 -> word is an atom vector
|
flag = 0 -> word is an atom vector
|
||||||
|
|||||||
@ -118,6 +118,8 @@ class Variable : protected Pointers {
|
|||||||
int region_function(char *, int);
|
int region_function(char *, int);
|
||||||
int special_function(char *, char *, Tree **, Tree **,
|
int special_function(char *, char *, Tree **, Tree **,
|
||||||
int &, double *, int &, int);
|
int &, double *, int &, int);
|
||||||
|
int labelmap_function(char *, char *, Tree **, Tree **,
|
||||||
|
int &, double *, int &, int);
|
||||||
void peratom2global(int, char *, double *, int, tagint,
|
void peratom2global(int, char *, double *, int, tagint,
|
||||||
Tree **, Tree **, int &, double *, int &);
|
Tree **, Tree **, int &, double *, int &);
|
||||||
int is_atom_vector(char *);
|
int is_atom_vector(char *);
|
||||||
|
|||||||
Reference in New Issue
Block a user