Skip to content

Add support for dihedral potentials - #157

Open
rajkumarrb wants to merge 4 commits into
pyMBE-dev:mainfrom
rajkumarrb:dihedral-potentials
Open

rajkumarrb wants to merge 4 commits into
pyMBE-dev:mainfrom
rajkumarrb:dihedral-potentials

Conversation

@rajkumarrb

Copy link
Copy Markdown

Adds the dihedral (torsion) potentials part of #143 (bonds and angles #150 are already in).

Follows the discussion in #143 and the pyMBE-dev meeting of 14.09.2026.

What it adds

  • DihedralTemplate / DihedralInstance in pyMBE/storage, mirroring the angle types. A template holds a list of terms, so GROMACS-style stacked multiplicities on the same quadruplet are supported. The template name is invariant under full reversal (A-B-C-D == D-C-B-A).
  • define_dihedral_potential, define_default_dihedral_potential, create_dihedral_potential, get_dihedral_template.
  • gen_dihedral argument in create_residue, create_molecule and create_hydrogel, following the gen_angle pattern. In hydrogels, only dihedrals internal to the chains are generated; dihedrals involving crosslinker nodes are not.
  • ESPResSo engine support, storage manager and io (save/load) support.
  • Tests (testsuite/dihedral_tests.py), sample script (samples/setup_dihedral_potential.py) and CHANGELOG entries.

Convention

As agreed in #143, the API uses the IUPAC/GROMACS convention (phi = 0 at cis). Users pass the parameters of the GROMACS proper dihedral type 1, V(phi) = k*[1 + cos(n*phi - phi_s)], as k, phi_s and mult. The ESPResSo-specific conversion is done inside the ESPResSo engine (phase = -(phi_s + pi)) and is documented in _create_dihedral_instance.

The ESPResSo Dihedral bond is attached to the second particle of the quadruplet, as in the ESPResSo documentation.

Testing

Besides checking that the right ESPResSo objects are created, the tests compare the dihedral set up in ESPResSo with independent numpy references:

  • energies for several multiplicities, phases and angles, multi-term sums, and GROMACS type 1 parameters;
  • forces against finite differences of the analytical energy, and net force and torque equal to zero;
  • energy conservation in a short NVE run, and relaxation to the expected minimum with the right sign;
  • reversed quadruplets and periodic boundaries;
  • generation of dihedrals compared with a brute-force enumeration of the bond graph, and for nested residues and hydrogels.

The force tests use geometries away from the angles affected by espressomd/espresso#5401 (phi = 0 and pi).

make tests (36/36), make pylint and make docs passed locally with ESPResSo 5.0.1. The nested-residue and hydrogel generation tests were added after that run; dihedral_tests.py passes 27/27 and pylint is clean.

Not included

  • Improper dihedrals and tabulated types ("tabulated" raises NotImplementedError).
  • A comparison against a GROMACS .itp file, which can be a follow-up.
  • Dihedrals involving hydrogel crosslinker nodes. Only dihedrals internal to the chains are generated (the angle potentials handle crosslinker junctions in _generate_hydrogel_crosslinker_angles).

Questions for reviewers

  • Is phi_s an acceptable name for the parameter key (instead of phi_0 as in the angle potentials)?
  • For molecules and residues, gen_dihedral=True skips quadruplets without a matching template silently, as gen_angle does. Should it log a warning instead? Should hydrogel crosslinker dihedrals follow the same all-or-nothing rule as the crosslinker angles?

Completes the last unchecked task of pyMBE-dev#143 (angles were
merged in pyMBE-dev#150; dihedrals are the remaining bonded-potential scope).
The motivating case is Martini 2.1 peptide backbone dihedrals.

New:
- DihedralTemplate / DihedralInstance in pyMBE/storage. The template
  holds a list of terms, so GROMACS-style stacked multiplicities on the
  same quadruplet register as one Dihedral object per term.
- pmb.define_dihedral_potential / define_default_dihedral_potential /
  create_dihedral_potential / get_dihedral_template.
- _generate_dihedrals_for_entity and a gen_dihedral kwarg on
  create_residue / create_molecule / create_hydrogel, mirroring gen_angle.
- espresso_engine _add_dihedral / _get_dihedral_instance /
  _create_dihedral_instance, wired into add_instances_to_engine.
- storage manager + io: register / update / delete / templates-df /
  save / load branches for the dihedral type.
- testsuite/dihedral_tests.py, samples/setup_dihedral_potential.py.

The canonical template key is invariant under full reversal of the
quadruplet. The "periodic" type maps onto the ESPResSo Dihedral bond
V(phi) = k*[1 - cos(n*phi - phi_0)]; "tabulated" is reserved but raises
NotImplementedError. GROMACS proper dihedral type 1,
V(phi) = k*[1 + cos(n*phi - phi_s)], is recovered with phi_0 = phi_s + pi
(documented in the docstrings and the sample, not applied implicitly).
add_instances_to_engine now performs a fifth _find_instance_ids_by_attribute
call for pmb_type='dihedral', mirroring the bond and angle blocks. The
pre-existing test_espresso_engine_add_instances_id_collision mocked that
method with a four-element side_effect list, so the dihedral lookup raised
StopIteration. Add the missing entry.
…chment

Dihedral parameters (k, phi_s, mult) now follow the IUPAC/GROMACS type 1
convention, V(phi) = k*[1 + cos(n*phi - phi_s)] with phi = 0 at the cis
conformation. The ESPResSo engine converts them internally to the
ESPResSo Dihedral form (phase = -(phi_s + pi)) and documents the conversion.

Attach the ESPResSo Dihedral bond to the second particle of the quadruplet,
as required by ESPResSo, instead of the first one, which made ESPResSo
evaluate a different torsion.

Add tests that compare energies and forces set up in ESPResSo with the
analytical expression: energy and forces vs. finite differences, momentum
conservation, NVE energy conservation, relaxation to the minimum, GROMACS
type 1 parameters, reversed quadruplets, periodic boundaries, and generation
of dihedrals for residues, molecules and hydrogels.
@rajkumarrb rajkumarrb mentioned this pull request Oct 28, 2026
3 tasks done
@pm-blanco
pm-blanco requested a review from 1234somesh October 28, 2026 12:38
@pm-blanco pm-blanco added the enhancement New feature or request label Oct 29, 2026
@pm-blanco pm-blanco added this to the pyMBEv2.0.0 milestone Oct 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants