From e956e5ccdabe36620d7698a8fcccf346ae5848ef Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 7 Apr 2025 09:24:44 +0200 Subject: [PATCH] extract() implementation for dihedral charmm and charmmfsw --- doc/src/fix_adapt.rst | 4 ++++ src/MOLECULE/dihedral_charmm.cpp | 13 +++++++++++++ src/MOLECULE/dihedral_charmm.h | 1 + src/MOLECULE/dihedral_charmmfsw.cpp | 13 +++++++++++++ src/MOLECULE/dihedral_charmmfsw.h | 1 + unittest/force-styles/tests/dihedral-charmm.yaml | 5 ++++- unittest/force-styles/tests/dihedral-charmmfsw.yaml | 5 ++++- 7 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 9dd8b0cd2f..3238f43f47 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -457,6 +457,10 @@ all types from 1 to :math:`N`. A leading asterisk means all types from If :doc:`dihedral_style hybrid ` is used, *dstyle* should be a sub-style name. The dihedral styles that currently work with fix adapt are: ++------------------------------------------------------------------------+----------------+----------------+ +| :doc:`charmm ` | k,n,d | type dihedrals | ++------------------------------------------------------------------------+----------------+----------------+ +| :doc:`charmmfsw ` | k,n,d | type dihedrals | +------------------------------------------------------------------------+----------------+----------------+ | :doc:`cosine/squared/restricted ` | k,phi0 | type dihedrals | +------------------------------------------------------------------------+----------------+----------------+ diff --git a/src/MOLECULE/dihedral_charmm.cpp b/src/MOLECULE/dihedral_charmm.cpp index de6d59c1d4..2d8979493c 100644 --- a/src/MOLECULE/dihedral_charmm.cpp +++ b/src/MOLECULE/dihedral_charmm.cpp @@ -432,3 +432,16 @@ void DihedralCharmm::write_data(FILE *fp) for (int i = 1; i <= atom->ndihedraltypes; i++) fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]); } + + /* ---------------------------------------------------------------------- + return ptr to internal members upon request + ------------------------------------------------------------------------ */ + + void *DihedralCharmm::extract(const char *str, int &dim) + { + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k0; + if (strcmp(str, "n") == 0) return (void *) multiplicity; + if (strcmp(str, "d") == 0) return (void *) shift; + return nullptr; + } diff --git a/src/MOLECULE/dihedral_charmm.h b/src/MOLECULE/dihedral_charmm.h index 71e857d5f0..d9af7a56cf 100644 --- a/src/MOLECULE/dihedral_charmm.h +++ b/src/MOLECULE/dihedral_charmm.h @@ -34,6 +34,7 @@ class DihedralCharmm : public Dihedral { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k, *weight, *cos_shift, *sin_shift; diff --git a/src/MOLECULE/dihedral_charmmfsw.cpp b/src/MOLECULE/dihedral_charmmfsw.cpp index a46fb8680c..1b249ea9e8 100644 --- a/src/MOLECULE/dihedral_charmmfsw.cpp +++ b/src/MOLECULE/dihedral_charmmfsw.cpp @@ -475,3 +475,16 @@ void DihedralCharmmfsw::write_data(FILE *fp) for (int i = 1; i <= atom->ndihedraltypes; i++) fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]); } + + /* ---------------------------------------------------------------------- + return ptr to internal members upon request + ------------------------------------------------------------------------ */ + + void *DihedralCharmmfsw::extract(const char *str, int &dim) + { + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k0; + if (strcmp(str, "n") == 0) return (void *) multiplicity; + if (strcmp(str, "d") == 0) return (void *) shift; + return nullptr; + } diff --git a/src/MOLECULE/dihedral_charmmfsw.h b/src/MOLECULE/dihedral_charmmfsw.h index 3930034356..660dafcd08 100644 --- a/src/MOLECULE/dihedral_charmmfsw.h +++ b/src/MOLECULE/dihedral_charmmfsw.h @@ -34,6 +34,7 @@ class DihedralCharmmfsw : public Dihedral { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: int implicit, weightflag, dihedflag; diff --git a/unittest/force-styles/tests/dihedral-charmm.yaml b/unittest/force-styles/tests/dihedral-charmm.yaml index cf407709b0..ebd47e2f41 100644 --- a/unittest/force-styles/tests/dihedral-charmm.yaml +++ b/unittest/force-styles/tests/dihedral-charmm.yaml @@ -19,7 +19,10 @@ dihedral_coeff: ! | 3 56.0 0 110 0.0 4 23.0 1 180 0.5 5 19.0 3 90 1.0 -extract: ! "" +extract: ! | + k 1 + n 1 + d 1 natoms: 29 init_energy: 1317.959844120986 init_stress: ! |2- diff --git a/unittest/force-styles/tests/dihedral-charmmfsw.yaml b/unittest/force-styles/tests/dihedral-charmmfsw.yaml index 6d2035acc5..3e1e32f5e3 100644 --- a/unittest/force-styles/tests/dihedral-charmmfsw.yaml +++ b/unittest/force-styles/tests/dihedral-charmmfsw.yaml @@ -19,7 +19,10 @@ dihedral_coeff: ! | 3 56.0 0 110 0.0 4 23.0 1 180 0.5 5 19.0 3 90 1.0 -extract: ! "" +extract: ! | + k 1 + n 1 + d 1 natoms: 29 init_energy: 1317.959844120986 init_stress: ! |2-