Skip to content

Conversation

@aehogan
Copy link

@aehogan aehogan commented Jun 20, 2024

Description

Support for DampedExp6810 and Multipole from the smirnoff-plugins repository.

Status

  • Ready to go

@aehogan
Copy link
Author

aehogan commented Jun 20, 2024

@SimonBoothroyd To get the explicit polarization potential working I'm going to need the electrostatic potential (dV/dr)*q from the Coulomb potential. Right now potential_energy_fn only takes as inputs the TensorSystem and its own TensorPotential.

Is there an easy way I can get access to the electrostatics potential? Perhaps just the charges from that potential?

The way this is structured in a .offxml / smirnoff plugins is to have both an Electrostatics and Multipole tag, when constructing an openmm system the multipole handler is loaded second, copies the charges from the nonbonded handler to the AmoebaMultipoleForce and then zeros out the nonbonded charges.

@SimonBoothroyd
Copy link
Collaborator

SimonBoothroyd commented Jul 17, 2024

ok @aehogan you'll need to rebase onto main, but everything should pretty much be there now! i think something like this should work for the converter:

@smee.converters.smirnoff_parameter_converter(
    "Multipole",
    {"polarity": _ANGSTROM**3, "cutoff": _ANGSTROM},
    depends_on=["Electrostatics"],
)
def convert_multipole(
    handlers: list[
        "smirnoff_plugins.collections.nonbonded.SMIRNOFFMultipoleCollection"
    ],
    topologies: list[openff.toolkit.Topology],
    v_site_maps: list[smee.VSiteMap | None],
    dependencies: dict[
        str, tuple[smee.TensorPotential, list[smee.NonbondedParameterMap]]
    ],
) -> tuple[smee.TensorPotential, list[smee.NonbondedParameterMap]]:

    potential_chg, parameter_maps_chg = dependencies["Electrostatics"]

    (
        potential_pol,
        parameter_maps_pol,
    ) = smee.converters.openff.nonbonded.convert_nonbonded_handlers(
        handlers,
        "Multipole",
        topologies,
        v_site_maps,
        ("polarity",),
        ("cutoff",),
        has_exclusions=False,
    )

    cutoff_idx_pol = potential_pol.attribute_cols.index("cutoff")
    cutoff_idx_chg = potential_chg.attribute_cols.index("cutoff")

    assert torch.isclose(
        potential_pol.attributes[cutoff_idx_pol],
        potential_chg.attributes[cutoff_idx_chg],
    )

    potential_chg.fn = smee.EnergyFn.POLARIZATION

    potential_chg.parameter_cols = (
        *potential_chg.parameter_cols,
        *potential_pol.parameter_cols,
    )
    potential_chg.parameter_units = (
        *potential_chg.parameter_units,
        *potential_pol.parameter_units,
    )
    potential_chg.parameter_keys = [
        *potential_chg.parameter_keys,
        *potential_pol.parameter_keys,
    ]

    parameters_chg = torch.cat(
        (potential_chg.parameters, torch.zeros_like(potential_chg.parameters)), dim=1
    )
    parameters_pol = torch.cat(
        (torch.zeros_like(potential_pol.parameters), potential_pol.parameters), dim=1
    )
    potential_chg.parameters = torch.cat((parameters_chg, parameters_pol), dim=0)

    for parameter_map_chg, parameter_map_pol in zip(
        parameter_maps_chg, parameter_maps_pol, strict=True
    ):
        parameter_map_chg.assignment_matrix = torch.block_diag(
            parameter_map_chg.assignment_matrix.to_dense(),
            parameter_map_pol.assignment_matrix.to_dense(),
        ).to_sparse()

    return potential_chg, parameter_maps_chg

aehogan and others added 18 commits July 17, 2024 10:40
…if permanent electric field isn't), also a=0.39 for Amoeba
- Add polarization_type parameter with options: "direct", "mutual", "extrapolated"
- Implement direct polarization solver (0 iterations, no mutual coupling)
- Implement extrapolated polarization solver using OPT3 coefficients
- Maintain mutual polarization as default (60 iterations, original behavior)
- Add parameterized test for all three polarization types
- Ensure backward compatibility with existing code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… multipole energy

- Apply exclusion scaling factors in compute_dampedexp6810_energy to fix massive unphysical energies
- Add batch processing support to compute_multipole_energy for multiple conformers
- Implement 3 polarization calculation options: direct, extrapolated (OPT3), and mutual
- Use proper three-component energy decomposition for direct and extrapolated types
- All tests now passing with appropriate tolerances for each polarization method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants