Skip to content

Vsite training#73

Closed
jthorton wants to merge 3 commits intomainfrom
vsite-training
Closed

Vsite training#73
jthorton wants to merge 3 commits intomainfrom
vsite-training

Conversation

@jthorton
Copy link
Copy Markdown
Collaborator

@jthorton jthorton commented Aug 30, 2024

Description

This PR extends theTrainable class to also work with vsites making it much easier to fit the geometric parameters of the sites such as the distance from the parent atom.

Status

  • Ready to go

@codecov-commenter
Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@lilyminium
Copy link
Copy Markdown
Contributor

Thanks for opening this PR @jthorton, are you still keen on having it in? If so do you think it would be straightforward to refactor the vsites so they behave similarly to the other potentials in _prepare instead of treating them specially?

@jthorton
Copy link
Copy Markdown
Collaborator Author

Hi @lilyminium yeah, this would be great to have and probably good for @fjclark and @JMorado as well.

If so do you think it would be straightforward to refactor the vsites so they behave similarly to the other potentials in _prepare instead of treating them specially?

Its been a while since I looked at it, but from what I remeber the issue was that some info is missing from the tensor vsite potential like the distance and angles, so this was needed as a workaround, but it might be possible to fix this.

@lilyminium
Copy link
Copy Markdown
Contributor

Right, thanks @jthorton! @fjclark would you be up to take a look at this PR for a quick review?

@fjclark
Copy link
Copy Markdown
Contributor

fjclark commented Mar 3, 2026

Thanks both, yes this would be great to have for the long run! I'll try to take a look this week.

openff.toolkit.ForceField("tip4p_fb.offxml"),
openff.toolkit.Molecule.from_smiles("O").to_topology(),
)
ff, _ = smee.converters.convert_interchange(interachange)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny typo: "interachange"

n_rows = vsite_parameters.shape[0]
vsite_parameters_flat = vsite_parameters.flatten()
# define the cols as they are not on the tensor model
vsite_cols = ["distance", "inPlaneAngle", "outOfPlaneAngle"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be any better to get these from e.g. list(tff.v_sites.default_units().keys())? Avoids hard-coding here but is maybe less clear.

Comment on lines +353 to +376
key_to_row = {key: row_idx for row_idx, key in enumerate(all_keys)}
assert len(key_to_row) == len(all_keys), "duplicate keys found"

unfrozen_rows = {
key_to_row[key] for key in unfrozen_keys if key not in excluded_keys
}

unfrozen_idxs = [
col_idx + row_idx * vsite_parameters.shape[1]
for row_idx in range(n_rows)
if row_idx in unfrozen_rows
# the vsite model has no parameter cols so define here
for col_idx, col in enumerate(vsite_cols)
if col in config.cols
]
vsite_scales = [config.scales.get(col, 1.0) for col in vsite_cols] * n_rows
clamp_lower = [
config.limits.get(col, (None, None))[0] for col in vsite_cols
] * n_rows
clamp_lower = [-torch.inf if x is None else x for x in clamp_lower]
clamp_upper = [
config.limits.get(col, (None, None))[1] for col in vsite_cols
] * n_rows
clamp_upper = [torch.inf if x is None else x for x in clamp_upper]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could refactor a bit to avoid duplication with the standard _prepare fn?

@fjclark
Copy link
Copy Markdown
Contributor

fjclark commented Mar 9, 2026

Looks good to me, though I'll need to add regularisation support consistent with the normal parameters. I'll create a separate PR based off this to do that.

@lilyminium
Copy link
Copy Markdown
Contributor

Thanks for the review @fjclark , @jthorton would you be able to make the suggested changes? (Or does #89 include these?)

@fjclark
Copy link
Copy Markdown
Contributor

fjclark commented Mar 24, 2026

Sorry I wasn't clear -- #89 includes the suggested changes. I'll try to address the review comments later this week.

@lilyminium
Copy link
Copy Markdown
Contributor

Great, thanks @fjclark! In that case I'll close this PR as superseded by #89.

@lilyminium lilyminium closed this Mar 25, 2026
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.

4 participants