Skip to content

Commit 994b7b4

Browse files
authored
Merge pull request lammps#4540 from evoyiatzis/fix-adapt-dihedral
extend fix adapt to treat dihedrals
2 parents 3aa3d45 + 813e650 commit 994b7b4

32 files changed

+364
-14
lines changed

doc/src/fix_adapt.rst

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Syntax
1414
* adapt = style name of this fix command
1515
* N = adapt simulation settings every this many timesteps
1616
* one or more attribute/arg pairs may be appended
17-
* attribute = *pair* or *bond* or *angle* or *improper* or *kspace* or *atom*
17+
* attribute = *pair* or *bond* or *angle* or *dihedral* or *improper* or *kspace* or *atom*
1818

1919
.. parsed-literal::
2020
@@ -33,6 +33,11 @@ Syntax
3333
aparam = parameter to adapt over time
3434
I = type angle to set parameter for (integer or type label)
3535
v_name = variable with name that calculates value of aparam
36+
*dihedral* args = dstyle dparam I v_name
37+
dstyle = dihedral style name (e.g., quadratic)
38+
dparam = parameter to adapt over time
39+
I = type dihedral to set parameter for (integer or type label)
40+
v_name = variable with name that calculates value of iparam
3641
*improper* args = istyle iparam I v_name
3742
istyle = improper style name (e.g., cvff)
3843
iparam = parameter to adapt over time
@@ -433,6 +438,48 @@ this fix uses to reset theta0 needs to generate values in radians.
433438

434439
----------
435440

441+
.. versionadded:: TBD
442+
443+
The *dihedral* keyword uses the specified variable to change the value of
444+
a dihedral coefficient over time, very similar to how the *angle* keyword
445+
operates. The only difference is that now a dihedral coefficient for a
446+
given dihedral type is adapted.
447+
448+
A wild-card asterisk can be used in place of or in conjunction with the
449+
dihedral type argument to set the coefficients for multiple dihedral types.
450+
This takes the form "\*" or "\*n" or "m\*" or "m\*n". If :math:`N` is
451+
the number of dihedral types, then an asterisk with no numeric values means
452+
all types from 1 to :math:`N`. A leading asterisk means all types from
453+
1 to n (inclusive). A trailing asterisk means all types from m to
454+
:math:`N` (inclusive). A middle asterisk means all types from m to n
455+
(inclusive).
456+
457+
If :doc:`dihedral_style hybrid <dihedral_hybrid>` is used, *dstyle* should be a
458+
sub-style name. The dihedral styles that currently work with fix adapt are:
459+
460+
+------------------------------------------------------------------------+-------------------------+----------------+
461+
| :doc:`charmm <dihedral_charmm>` | k,n,d | type dihedrals |
462+
+------------------------------------------------------------------------+-------------------------+----------------+
463+
| :doc:`charmmfsw <dihedral_charmm>` | k,n,d | type dihedrals |
464+
+------------------------------------------------------------------------+-------------------------+----------------+
465+
| :doc:`class2 <dihedral_class2>` | k1,k2,k3,phi1,phi2,phi3 | type dihedrals |
466+
+------------------------------------------------------------------------+-------------------------+----------------+
467+
| :doc:`cosine/squared/restricted <dihedral_cosine_squared_restricted>` | k,phi0 | type dihedrals |
468+
+------------------------------------------------------------------------+-------------------------+----------------+
469+
| :doc:`helix <dihedral_helix>` | a,b,c | type dihedrals |
470+
+------------------------------------------------------------------------+-------------------------+----------------+
471+
| :doc:`multi/harmonic <dihedral_multi_harmonic>` | a1,a2,a3,a4,a5 | type dihedrals |
472+
+------------------------------------------------------------------------+-------------------------+----------------+
473+
| :doc:`opls <dihedral_opls>` | k1,k2,k3,k4 | type dihedrals |
474+
+------------------------------------------------------------------------+-------------------------+----------------+
475+
| :doc:`quadratic <dihedral_quadratic>` | k,phi0 | type dihedrals |
476+
+------------------------------------------------------------------------+-------------------------+----------------+
477+
478+
Note that internally, phi0 is stored in radians, so the variable
479+
this fix use to reset phi0 needs to generate values in radians.
480+
481+
----------
482+
436483
.. versionadded:: 2Apr2025
437484

438485
The *improper* keyword uses the specified variable to change the value of

src/CLASS2/dihedral_class2.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,3 +946,18 @@ void DihedralClass2::write_data(FILE *fp)
946946
at_theta0_1[i]*180.0/MY_PI,at_theta0_2[i]*180.0/MY_PI);
947947
}
948948

949+
/* ----------------------------------------------------------------------
950+
return ptr to internal members upon request
951+
------------------------------------------------------------------------ */
952+
953+
void *DihedralClass2::extract(const char *str, int &dim)
954+
{
955+
dim = 1;
956+
if (strcmp(str, "k1") == 0) return (void *) k1;
957+
if (strcmp(str, "k2") == 0) return (void *) k2;
958+
if (strcmp(str, "k3") == 0) return (void *) k3;
959+
if (strcmp(str, "phi1") == 0) return (void *) phi1;
960+
if (strcmp(str, "phi2") == 0) return (void *) phi2;
961+
if (strcmp(str, "phi3") == 0) return (void *) phi3;
962+
return nullptr;
963+
}

src/CLASS2/dihedral_class2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class DihedralClass2 : public Dihedral {
3333
void write_restart(FILE *) override;
3434
void read_restart(FILE *) override;
3535
void write_data(FILE *) override;
36+
void *extract(const char *, int &) override;
3637

3738
protected:
3839
double *k1, *k2, *k3;

src/EXTRA-MOLECULE/dihedral_cosine_squared_restricted.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,15 @@ void DihedralCosineSquaredRestricted::born_matrix(int nd, int i1, int i2, int i3
393393

394394
du2 = 2 * k[type] * numerator / denominator;
395395
}
396+
397+
/* ----------------------------------------------------------------------
398+
return ptr to internal members upon request
399+
------------------------------------------------------------------------ */
400+
401+
void *DihedralCosineSquaredRestricted::extract(const char *str, int &dim)
402+
{
403+
dim = 1;
404+
if (strcmp(str, "k") == 0) return (void *) k;
405+
if (strcmp(str, "phi0") == 0) return (void *) phi0;
406+
return nullptr;
407+
}

src/EXTRA-MOLECULE/dihedral_cosine_squared_restricted.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DihedralCosineSquaredRestricted : public Dihedral {
3434
void read_restart(FILE *) override;
3535
void write_data(FILE *) override;
3636
void born_matrix(int, int, int, int, int, double &, double &) override;
37+
void *extract(const char *, int &) override;
3738

3839
protected:
3940
double *k, *phi0;

src/EXTRA-MOLECULE/dihedral_helix.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,16 @@ void DihedralHelix::born_matrix(int nd, int i1, int i2, int i3, int i4,
430430
du2 = -(9.0*bphi[type]*cos(3.0*phi) + cphi[type]*cos(phi + MY_PI4))*siinv*siinv +
431431
(3.0*bphi[type]*sin(3.0*phi) + cphi[type]*sin(phi + MY_PI4))*c*siinv*siinv*siinv;
432432
}
433+
434+
/* ----------------------------------------------------------------------
435+
return ptr to internal members upon request
436+
------------------------------------------------------------------------ */
437+
438+
void *DihedralHelix::extract(const char *str, int &dim)
439+
{
440+
dim = 1;
441+
if (strcmp(str, "a") == 0) return (void *) aphi;
442+
if (strcmp(str, "b") == 0) return (void *) bphi;
443+
if (strcmp(str, "c") == 0) return (void *) cphi;
444+
return nullptr;
445+
}

src/EXTRA-MOLECULE/dihedral_helix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DihedralHelix : public Dihedral {
3434
void read_restart(FILE *) override;
3535
void write_data(FILE *) override;
3636
void born_matrix(int, int, int, int, int, double &, double &) override;
37+
void *extract(const char *, int &) override;
3738

3839
protected:
3940
double *aphi, *bphi, *cphi;

src/EXTRA-MOLECULE/dihedral_quadratic.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,15 @@ void DihedralQuadratic::born_matrix(int nd, int i1, int i2, int i3, int i4,
435435
du = - 2.0 * k[type] * dphi * siinv;
436436
du2 = 2.0 * k[type] * siinv * siinv * ( 1.0 - dphi * c * siinv) ;
437437
}
438+
439+
/* ----------------------------------------------------------------------
440+
return ptr to internal members upon request
441+
------------------------------------------------------------------------ */
442+
443+
void *DihedralQuadratic::extract(const char *str, int &dim)
444+
{
445+
dim = 1;
446+
if (strcmp(str, "k") == 0) return (void *) k;
447+
if (strcmp(str, "phi0") == 0) return (void *) phi0;
448+
return nullptr;
449+
}

src/EXTRA-MOLECULE/dihedral_quadratic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DihedralQuadratic : public Dihedral {
3434
void read_restart(FILE *) override;
3535
void write_data(FILE *) override;
3636
void born_matrix(int, int, int, int, int, double &, double &) override;
37+
void *extract(const char *, int &) override;
3738

3839
protected:
3940
double *k, *phi0;

src/MOLECULE/dihedral_charmm.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,16 @@ void DihedralCharmm::write_data(FILE *fp)
432432
for (int i = 1; i <= atom->ndihedraltypes; i++)
433433
fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]);
434434
}
435+
436+
/* ----------------------------------------------------------------------
437+
return ptr to internal members upon request
438+
------------------------------------------------------------------------ */
439+
440+
void *DihedralCharmm::extract(const char *str, int &dim)
441+
{
442+
dim = 1;
443+
if (strcmp(str, "k") == 0) return (void *) k;
444+
if (strcmp(str, "n") == 0) return (void *) multiplicity;
445+
if (strcmp(str, "d") == 0) return (void *) shift;
446+
return nullptr;
447+
}

0 commit comments

Comments
 (0)